Website Widget#
The WebsiteWidget is a versatile tool that allows users to display websites directly within the BEC GUI. This widget is useful for embedding documentation, dashboards, or any web-based tools within the application interface. It is designed to be integrated within a BECDockArea or used as an individual component in your application through BEC Designer.
Key Features:
URL Display: Set and display any website URL within the widget.
Navigation Controls: Navigate through the website’s history with back and forward controls.
Reload Functionality: Reload the currently displayed website to ensure up-to-date content.
The WebsiteWidget can be embedded within a BECDockArea or used as an individual component in your application through BEC Designer. The following examples demonstrate how to create and use the WebsiteWidget in different scenarios.
Example 1 - Adding Website Widget to BECDockArea
In this example, we demonstrate how to add a WebsiteWidget to a BECDockArea and set the URL of the website to be displayed.
# Add a new dock with a WebsiteWidget
dock_area = gui.new()
web = dock_area.new().new(gui.available_widgets.WebsiteWidget)
# Set the URL of the website to display
web.set_url("https://bec.readthedocs.io/en/latest/")
The WebsiteWidget allows users to navigate back and forward through the website’s history. This example shows how to implement these navigation controls.
If you click on a link in the website, you can use the back and forward buttons to navigate through the history.
# Go back in the website history
web.back()
# Go forward in the website history
web.forward()
Example 3 - Reloading the Website
To ensure that the displayed website content is up-to-date, you can use the reload functionality.
# Reload the current website
web.reload()
Example 4 - Retrieving the Current URL
You may want to retrieve the current URL being displayed in the WebsiteWidget. The following example demonstrates how to access the current URL.
# Get the current URL of the WebsiteWidget
current_url = web.get_url()
print(f"The current URL is: {current_url}")
- class WebsiteWidget(gui_id: str | None = None, config: dict | None = None, object_name: str | None = None, parent=None, **kwargs)[source]#
Bases:
RPCBaseA simple widget to display a website
- detach()[source]#
Detach the widget from its parent dock widget (if widget is in the dock), making it a floating widget.
- get_url() str[source]#
Get the current url of the website widget
- Returns:
The current url
- Return type:
str