Page#

class toui.pages.Page(html_file=None, html_str=None, url=None, title=None)[source]#

Bases: object

Creates an HTML page that can be used as a window or as a webpage.

url#

The URL of the page.

Type:

str

title#

In desktop app, this attribute will be the title of the window.

Type:

str

window_defaults#

In desktop apps, this dictionary sets the default parameters of the window. To set a certain default parameter for a window before creating it, include it in this dictionary. The parameters that can be set are the keyword arguments of the class [webview.create_window()](https://pywebview.flowrl.com/guide/api.html) in pywebview package.

Type:

dict

Examples

Importing the class:

>>> from toui import Page

Creating a Page from an HTML file:

>>> path = "../examples/assets/test1.html"
>>> page = Page(html_file=path)

Creating a Page from a string:

>>> page = Page(html_str="<html><h1>Hello</h1></html>")
>>> page
<html><h1>Hello</h1></html>

Creating a page with a URL:

>>> page = Page(html_str="<html><h1>Hello</h1></html>", url="/")

Getting an element in the Page from its id:

>>> page = Page(html_str='<html><h1 id="heading">Hello</h1></html>', url="/")
>>> element = page.get_element(element_id="heading")
>>> element
<h1 id="heading">Hello</h1>
Parameters:
  • html_file (str) – The path to the HTML file.

  • html_str (str) – A string containing HTML code.

  • url (str, optional) – If the page was used as a webpage, this will be the URL of the page.

  • title (str) – In desktop app, this parameter will be the title of the window.

Methods#

toui.pages.Page.add_function

Adds a function to the Page.

toui.pages.Page.from_bs4_soup

Converts a bs4.BeautifulSoap object to a Page object.

toui.pages.Page.from_html_file

Reads an HTML file and converts it to an Page object.

toui.pages.Page.from_str

Converts HTML code to a Page object.

toui.pages.Page.get_body_element

Gets the first <body> element.

toui.pages.Page.get_element

Gets an element from its id attribute.

toui.pages.Page.get_element_from_selector

Gets an element from its CSS selector.

toui.pages.Page.get_elements

Get elements from the Page by their tag name and attributes.

toui.pages.Page.get_html_element

Gets the first <html> element.

toui.pages.Page.get_window

toui.pages.Page.on_url_request

Sets a function that will be called when the user types the URL in a browser or when a request is sent to the URL.

toui.pages.Page.set_footer

Adds a footer to the page.

toui.pages.Page.set_navigation_bar

Adds a navigation bar to the page.

toui.pages.Page.to_bs4_soup

Converts the Page object to a bs4.BeautifulSoap object.

toui.pages.Page.to_html_file

Converts the Page object to an HTML file.

toui.pages.Page.to_str

Converts the Page object to HTML code.