Skip to content

Commit

Permalink
Update docs + Add 'toui' command + Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarakalmehairbi committed Jul 29, 2023
1 parent fd83f2f commit cda9c95
Show file tree
Hide file tree
Showing 46 changed files with 602 additions and 59 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ Run this command:
```shell
pip install toui
```
To install only the required dependencies, run these commands:
```shell
pip install --no-deps toui
toui --minimal-reqs
```

# How to create a basic website
Import the required classes:
Expand Down Expand Up @@ -77,6 +82,13 @@ if __name__ == "__main__":
app.run()
```

# Start with a template
To start with a basic template for a ToUI project. Run the command:
```
toui init
```
Alternatively, use this [template](https://github.com/mubarakalmehairbi/BasicToUIProject).

# Make the app responsive
Check this [example](https://toui.readthedocs.io/en/latest/Examples.example_1_simple_website.html)
and [other examples](https://toui.readthedocs.io/en/latest/Examples.html) to learn how
Expand Down
1 change: 1 addition & 0 deletions docs/API Reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Other classes
toui.elements.IFrameElement
toui._signals.File
toui.structure.ToUIBlueprint
toui.pages.RedirectingPage



Expand Down
62 changes: 62 additions & 0 deletions docs/Examples.advanced_example_3_toui_with_google_sign_in.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
ToUI with Google sign in
========================

ToUI can be used with Google sign in. This example shows how to use Google sign in with ToUI.
Make sure to create a Google app first. Also, add the following as an authorized redirect URI to your Google app:
`https://<your-domain>/toui-google-sign-in`

One way to create a Google app is through Google Firebase. Perhaps check it out.

This example uses the HTML file "test6.html":

.. code-block:: html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="sign-in"><img width="200px" src="./google_button.png"></img></button>
<p id="user-info"></p>
</body>
</html>

Python code:

.. code-block:: python
import os
from toui import Website, Page
# Create app
app = Website(__name__, assets_folder="assets", secret_key="some secret key")
app.add_user_database_using_sql(f"sqlite:///{os.getcwd()}/.user_database.db")
# Create pages
pg = Page(html_file="assets/test6.html", url="/")
# Create functions that will be called from HTML
def get_user_info():
pg = app.get_user_page()
if app.get_current_user():
pg.get_element("user-info").set_content(f"User: {app.get_current_user().username}")
def sign_in():
"""Sign in using Google."""
app.sign_in_using_google(client_id=os.environ['GOOGLE_CLIENT_ID'],
client_secret=os.environ['GOOGLE_CLIENT_SECRET'],
after_auth_url="/")
# Connect functions to elements
pg.get_body_element().on("load", get_user_info)
pg.get_element("sign-in").onclick(sign_in)
# Add pages to app
app.add_pages(pg)
if __name__ == '__main__':
app.run()
107 changes: 107 additions & 0 deletions docs/Examples.advanced_example_4_toui_with_firebase.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
ToUI with Firebase
==================

ToUI can be used with Firebase. Create a Firebase app to use this example. In this example, ToUI is used with Firebase for:

- User authentication
- Stroing user data in database
- File storage
- File retrieval


This example uses the HTML file "test7.html":

.. code-block:: html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Sign in users:</h1>
<input id="username"/>
<input id="password"/>
<button id="sign-in">Sign in</button>
<button id="sign-up">Sign up</button>
<p id="output"></p>
<h1>Upload files:</h1>
<input type="file" id="file"/>
<button id="get-file">Download uploaded file</button>
<p id="output2"></p>
</body>
</html>

Python code:

.. code-block:: python
import sys
sys.path.append("..")
import os
from toui import Website, Page
app = Website(__name__, assets_folder="assets", secret_key="some text")
app.add_firebase(".my_firebase_credentials.json") # You can get this file from your firebase project settings
app.add_user_database_using_firebase() # Connects to firestore database. Make sure that you created one in Firebase.
BUCKET_NAME = "test-14583.appspot.com" # Change this value to match your bucket name in Firebase Storage
main_pg = Page(html_file="assets/test7.html", url="/")
def sign_in():
pg = app.get_user_page()
username = pg.get_element("username").get_value()
password = pg.get_element("password").get_value()
pg.get_element("output").set_content("loading")
success = app.signin_user(username=username, password=password)
if success:
age = app.get_current_user_data("age")
pg.get_element("output").set_content(f"Signed in successfully. Age of user: {age}")
else:
pg.get_element("output").set_content("Sign in failed")
def sign_up():
pg = app.get_user_page()
username = pg.get_element("username").get_value()
password = pg.get_element("password").get_value()
pg.get_element("output").set_content("loading")
success = app.signup_user(username=username, password=password)
if success:
app.signin_user(username=username, password=password)
value_added = app.set_current_user_data("age", 20)
pg.get_element("output").set_content(f"Signed up successfully. Age added: {value_added}")
else:
pg.get_element("output").set_content("Sign up failed")
def store_file():
pg = app.get_user_page()
file = pg.get_element("file").get_files()[0]
with open(".test_file", "w") as f:
file.save(f)
app.store_file_using_firebase(destination_path=f"{app.get_current_user_id()}/test_file", file_path=".test_file", bucket_name=BUCKET_NAME)
pg.get_element("output2").set_content("File stored")
def retrieve_file():
pg = app.get_user_page()
if os.path.exists(".new_test_file"):
raise Exception(".new_test_file already exists")
app.get_file_from_firebase(source_path=f"{app.get_current_user_id()}/test_file", new_file_path=".new_test_file", bucket_name=BUCKET_NAME)
with open(".new_test_file", "r") as f:
pg.get_element("output2").set_content("Downloaded file content: " + f.read())
main_pg.get_element("sign-in").onclick(sign_in)
main_pg.get_element("sign-up").onclick(sign_up)
main_pg.get_element("file").on("change", store_file)
main_pg.get_element("get-file").onclick(retrieve_file)
app.add_pages(main_pg)
if __name__ == '__main__':
app.run()
4 changes: 4 additions & 0 deletions docs/Examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Basic examples

Examples.advanced_example_1_toui_blueprint
Examples.advanced_example_2_toui_with_javascript
Examples.advanced_example_3_toui_with_google_sign_in
Examples.advanced_example_4_toui_with_firebase
Examples.example_1_simple_website
Examples.example_2_simple_desktop_app
Examples.example_3_updating_page
Expand All @@ -32,3 +34,5 @@ Advanced examples

Examples.advanced_example_1_toui_blueprint
Examples.advanced_example_2_toui_with_javascript
Examples.advanced_example_3_toui_with_google_sign_in
Examples.advanced_example_4_toui_with_firebase
2 changes: 0 additions & 2 deletions docs/how_it_works.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ For desktop applications, ToUI uses also [pywebview](https://pywebview.flowrl.co
For both web apps and desktop apps, ToUI uses Flask web framework, Flask-Sock for communicating through WebSockets, and other flask extensions. To know more about the security of these Python packages, please find their documentations below:
- [Flask docs](https://flask.palletsprojects.com/)
- [Flask-Sock docs](https://flask-sock.readthedocs.io/en/latest/)
- [Flask-Session docs](https://flask-session.readthedocs.io/en/latest/)
- [Flask-Caching docs](https://flask-caching.readthedocs.io/en/latest/)
- [Flask-BasicAuth docs](https://flask-basicauth.readthedocs.io/en/latest/)
- [Flask-Login docs](https://flask-login.readthedocs.io/en/latest/)
- [Flask-SQLAlchemy docs](https://flask-sqlalchemy.palletsprojects.com/)
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ToUI
====

Version: v2.4.3-beta
Version: v3.0.0-beta

.. include:: ../README.md
:parser: myst_parser.sphinx_
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
beautifulsoup4==4.12.2
Flask==2.2.5
Flask_BasicAuth==0.2.0
Flask_Session==0.4.1
Flask_Caching==2.0.2
firebase_admin==6.2.0
requests
Flask_Login==0.6.2
flask_sock==0.6.0
flask_sqlalchemy==3.0.3
Expand Down
4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.add_firebase.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.add_firebase
-----------------------

.. automethod:: toui.apps.DesktopApp.add_firebase
4 changes: 0 additions & 4 deletions docs/toui.apps.DesktopApp.add_user_database.rst

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.add_user_database_using_firebase
-------------------------------------------

.. automethod:: toui.apps.DesktopApp.add_user_database_using_firebase
4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.add_user_database_using_sql.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.add_user_database_using_sql
--------------------------------------

.. automethod:: toui.apps.DesktopApp.add_user_database_using_sql
4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.email_exists.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.email_exists
-----------------------

.. automethod:: toui.apps.DesktopApp.email_exists
4 changes: 0 additions & 4 deletions docs/toui.apps.DesktopApp.get_current_user.rst

This file was deleted.

4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.get_current_user_data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.get_current_user_data
--------------------------------

.. automethod:: toui.apps.DesktopApp.get_current_user_data
4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.get_current_user_id.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.get_current_user_id
------------------------------

.. automethod:: toui.apps.DesktopApp.get_current_user_id
4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.get_file_from_firebase.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.get_file_from_firebase
---------------------------------

.. automethod:: toui.apps.DesktopApp.get_file_from_firebase
4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.is_signed_in.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.is_signed_in
-----------------------

.. automethod:: toui.apps.DesktopApp.is_signed_in
13 changes: 11 additions & 2 deletions docs/toui.apps.DesktopApp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,29 @@ Methods
:nosignatures:
:toctree:

toui.apps.DesktopApp.add_firebase
toui.apps.DesktopApp.add_pages
toui.apps.DesktopApp.add_restriction
toui.apps.DesktopApp.add_user_database
toui.apps.DesktopApp.add_user_database_using_firebase
toui.apps.DesktopApp.add_user_database_using_sql
toui.apps.DesktopApp.download
toui.apps.DesktopApp.get_current_user
toui.apps.DesktopApp.email_exists
toui.apps.DesktopApp.get_current_user_data
toui.apps.DesktopApp.get_current_user_id
toui.apps.DesktopApp.get_file_from_firebase
toui.apps.DesktopApp.get_request
toui.apps.DesktopApp.get_user_page
toui.apps.DesktopApp.is_signed_in
toui.apps.DesktopApp.open_new_page
toui.apps.DesktopApp.register_toui_blueprint
toui.apps.DesktopApp.run
toui.apps.DesktopApp.set_current_user_data
toui.apps.DesktopApp.set_data_validation
toui.apps.DesktopApp.set_ws_validation
toui.apps.DesktopApp.sign_in_using_google
toui.apps.DesktopApp.signin_user
toui.apps.DesktopApp.signin_user_from_id
toui.apps.DesktopApp.signout_user
toui.apps.DesktopApp.signup_user
toui.apps.DesktopApp.store_file_using_firebase
toui.apps.DesktopApp.username_exists
4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.set_current_user_data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.set_current_user_data
--------------------------------

.. automethod:: toui.apps.DesktopApp.set_current_user_data
4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.sign_in_using_google.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.sign_in_using_google
-------------------------------

.. automethod:: toui.apps.DesktopApp.sign_in_using_google
4 changes: 4 additions & 0 deletions docs/toui.apps.DesktopApp.store_file_using_firebase.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DesktopApp.store_file_using_firebase
------------------------------------

.. automethod:: toui.apps.DesktopApp.store_file_using_firebase
4 changes: 4 additions & 0 deletions docs/toui.apps.Website.add_firebase.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Website.add_firebase
--------------------

.. automethod:: toui.apps.Website.add_firebase
4 changes: 0 additions & 4 deletions docs/toui.apps.Website.add_user_database.rst

This file was deleted.

4 changes: 4 additions & 0 deletions docs/toui.apps.Website.add_user_database_using_firebase.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Website.add_user_database_using_firebase
----------------------------------------

.. automethod:: toui.apps.Website.add_user_database_using_firebase
4 changes: 4 additions & 0 deletions docs/toui.apps.Website.add_user_database_using_sql.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Website.add_user_database_using_sql
-----------------------------------

.. automethod:: toui.apps.Website.add_user_database_using_sql
4 changes: 4 additions & 0 deletions docs/toui.apps.Website.email_exists.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Website.email_exists
--------------------

.. automethod:: toui.apps.Website.email_exists
4 changes: 0 additions & 4 deletions docs/toui.apps.Website.get_current_user.rst

This file was deleted.

4 changes: 4 additions & 0 deletions docs/toui.apps.Website.get_current_user_data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Website.get_current_user_data
-----------------------------

.. automethod:: toui.apps.Website.get_current_user_data
4 changes: 4 additions & 0 deletions docs/toui.apps.Website.get_current_user_id.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Website.get_current_user_id
---------------------------

.. automethod:: toui.apps.Website.get_current_user_id
4 changes: 4 additions & 0 deletions docs/toui.apps.Website.get_file_from_firebase.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Website.get_file_from_firebase
------------------------------

.. automethod:: toui.apps.Website.get_file_from_firebase
4 changes: 4 additions & 0 deletions docs/toui.apps.Website.is_signed_in.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Website.is_signed_in
--------------------

.. automethod:: toui.apps.Website.is_signed_in
Loading

0 comments on commit cda9c95

Please sign in to comment.