DesktopApp#

class toui.apps.DesktopApp(name=None, assets_folder=None, secret_key=None, vars_timeout=86400, gen_sid_algo=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.

  • vars_timeout (int (optional)) – The timeout interval before the temporary user-specific variables are deleted from user_vars attribute. The default is 86400 seconds (1 day).

  • gen_sid_algo (Callable (optional)) – A callable that generates a unique user id so that ToUI can store data for each user/browser. If None, the IP address, user agent, and secret key will be used.

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.

Type:

dict

page_vars#

A dictionary that stores data that is deleted when the user leaves the page.

Type:

dict

pages#

A list of added Page objects.

Type:

list

firestore#

If firebase was added using add_firebase, you can access firestore database using this attribute. Otherwise, it will be None. See Firebase documentation and Firestore API Reference.

Type:

firebase_admin.firestore.Firestore

Behind The Scenes

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

  • Sock class extension from Flask-Sock package.

Methods#

toui.apps.DesktopApp.add_firebase

Adds Firebase to the app.

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_using_firebase

Adds Firebase user database to the app.

toui.apps.DesktopApp.add_user_database_using_sql

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

toui.apps.DesktopApp.checkout_using_paypal

Checkout using PayPal API.

toui.apps.DesktopApp.checkout_using_stripe

Opens a Stripe checkout page.

toui.apps.DesktopApp.download

Downloads a file from the server to a client.

toui.apps.DesktopApp.email_exists

Checks if the email is exists in the database.

toui.apps.DesktopApp.get_current_url

A method that returns the current full URL.

toui.apps.DesktopApp.get_current_user_data

Gets data specific to the currently signed in user from the database.

toui.apps.DesktopApp.get_current_user_id

Gets the ID of the currently signed in user.

toui.apps.DesktopApp.get_file_from_firebase

Downloads a file from Firebase storage.

toui.apps.DesktopApp.get_query_params

A method that returns the query parameters of the current URL.

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

Gets the user ids from the users data.

toui.apps.DesktopApp.is_signed_in

Checks if the user is signed in.

toui.apps.DesktopApp.open_new_page

Opens another URL.

toui.apps.DesktopApp.redirect_response

Use it with Page.on_url_request to redirect the user to another page.

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_current_user_data

Sets data specific to the currently signed in user in the database.

toui.apps.DesktopApp.set_data_validation

Validates data received from JavaScript before using it.

toui.apps.DesktopApp.set_ws_validation

Validates a WebSocket connection before sending and accepting data.

toui.apps.DesktopApp.sign_in_using_google

Signs in a user using Google (Experimental).

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

Uploads a file to Firebase storage.

toui.apps.DesktopApp.username_exists

Checks if the username is exists in the database.