Page#

class toui.pages.Page(html_file=None, html_str=None, url=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

window#

A pywebview.Window object. It is automatically created when adding the Page to DesktopApp and running the app.

Type:

pywebview.Window, default = None

view_func#

The view function of the Page. This is the function that will be decorated by Flask.route() in when creating web apps.

Type:

Callable

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.

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_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.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.