DesktopApp#

class toui.apps.DesktopApp(name=None, assets_folder=None, secret_key=None)[source]#

Bases: _App

A class that creates a desktop application from HTML files.

Examples

Creating a desktop app:

>>> from toui import DesktopApp
>>> app = DesktopApp("MyApp")

Creating a page and adding it to the app:

>>> from toui import Page
>>> home_page = Page(html_str="<h1>This is the home page</h1>")
>>> app.add_pages(home_page)

Running the app:

>>> if __name__ == "__main__":
...     app.run() 
Parameters:
  • name (str (optional)) – The name of the app.

  • assets_folder (str (optional)) – The path to the folder that contains the HTML files and other assets.

  • secret_key (str (optional)) – Sets the secret_key attribute for flask.Flask. You can also set the environment variable SECRET_KEY from the command line and ToUI will get it using os.environ.

flask_app#

ToUI creates applications using Flask. You can access the Flask object using the attribute flask_app.

Type:

Flask

forbidden_urls#

These are URLs that ToUI does not allow the user to use because ToUI uses them.

Type:

list

user_vars#

A dictionary that stores temporary data unique to each user. The data are stored in a Cache object from flask-caching package.

Type:

dict

pages#

A list of added Page objects.

Type:

list

Warning

A folder called ‘flask_session’ will be created in the main directory when calling this class.

Behind The Scenes

ToUI uses Flask and its extenstions to create apps. When creating an instance of this class, the following extensions are used:

  • Session class extension from Flask-Session package.

  • Sock class extension from Flask-Sock package.

  • Cache class extension from Flask-Caching package.

The following Flask configurations are also set:

  • CACHE_TYPE = “SimpleCache”

  • SESSION_TYPE = “filesystem”

Methods#

toui.apps.DesktopApp.add_pages

Adds pages to the app.

toui.apps.DesktopApp.add_restriction

Makes the app private.

toui.apps.DesktopApp.add_user_database

Creates a simple database that has data specific to each user.

toui.apps.DesktopApp.download

Downloads a file from the server to a client.

toui.apps.DesktopApp.get_current_user

A static method that returns the current user.

toui.apps.DesktopApp.get_request

A static method that gets data sent from client using HTTP request.

toui.apps.DesktopApp.get_user_page

A static method that returns the current Page.

toui.apps.DesktopApp.open_new_page

Opens another URL.

toui.apps.DesktopApp.register_toui_blueprint

Registers a ToUIBlueprint object.

toui.apps.DesktopApp.run

Start a GUI loop and display previously created windows.

toui.apps.DesktopApp.set_data_validation

Validate data received from JavaScript before using it.

toui.apps.DesktopApp.set_ws_validation

Validate simple_websocket.ws.Server object before sending and accepting data.

toui.apps.DesktopApp.signin_user

Loads the data of a user from database.

toui.apps.DesktopApp.signin_user_from_id

Loads the data of a user from database using the user's ID.

toui.apps.DesktopApp.signout_user

A method that signs out the current user.

toui.apps.DesktopApp.signup_user

Creates a new user in the database.

toui.apps.DesktopApp.username_exists

Checks if the username is exists in the database.