Swole¶
Application¶
-
SWOLE_CACHE
= '~/.cache/swole'¶ Default directory to use for caching.
-
class
Application
[source]¶ Class representing an application. Application are used to serve declared pages.
-
fapi
¶ FastAPI app.
Type: fastapi.FastAPI
-
serve
(folder='~/.cache/swole', host='0.0.0.0', port=8000, log_level='info')[source]¶ Method to fire up the FastAPI server !
Parameters: - folder (str, optional) – Folder where to save HTML files. Defaults
to
SWOLE_CACHE
. - host (str, optional) – Run FastAPI on this host. Defaults to 0.0.0.0.
- port (int, optional) – Run FastAPI on this port. Defaults to 8000.
- log_level (str, optional) – Log level to use for FastAPI. Can be [critical, error, warning, info, debug, trace]. Defaults to info.
- folder (str, optional) – Folder where to save HTML files. Defaults
to
-
Page¶
-
HOME_ROUTE
= '/'¶ Default route for the Home page.
-
DEFAULT_FAVICON
= Doge¶ Default favicon (Doge).
-
class
Page
(route='/', skin='base', skin_path=None, title='Home', favicon='https://user-images.githubusercontent.com/22237185/95144545-e35d1200-07b3-11eb-9216-362b2a19c9aa.png')[source]¶ Class representing a page.
Parameters: - route (str, optional) – The route to access this page. Defaults to
HOME_ROUTE
. - skin (str, optional) – The name of the skin to use for this page. If None is given, no skin is loaded. Defaults to base.
- skin_path (str, optional) – The path of the Skin file to use. If different than None, the skin argument is ignored, and this file is used instead. Useful to provide custom Skin file. Defaults to None.
- title (str, optional) – The title of the page. Defaults to Home.
- favicon (str, optional) – The path to the favicon to use for this
page. Defaults to
DEFAULT_FAVICON
.
-
__enter__
()[source]¶ Context manager for easy definition of Widgets inside the page : Remember the declared widgets at this point.
- route (str, optional) – The route to access this page. Defaults to
Ajax¶
-
class
Ajax
(callback, inputs)[source]¶ Class representing an AJAX request. It is used as callback to update the webpage dynamically.
Constructor : Make the AJAX from the function to execute, and define the inputs as given.
Parameters: - callback (callable) – Function to execute when the AJAX is called.
- inputs (list of Widget) – Inputs to the callback.
-
__call__
(page, input_data)[source]¶ Main method, being called by the application with the right inputs. This method keep track of the value of each widget of the page, and based on what was changed, return only the element to change in the page.
Parameters: - page (Page) – Page calling the AJAX.
- input_data (dict) – Inputs data retrieved from the page after the AJAX request was triggered. It’s a dict of str -> str where the key is the ID of the widget and the value is the value of the widget.
Returns: Dictionary of ID to value, containing all widgets to update.
Return type: dict
Skin¶
-
class
Skin
(name='base', path=None)[source]¶ Class representing the skin to use for the page. A skin is basically a CSS file, with additional imports for CSS libraries and fonts.
-
path
¶ Path of the CSS file for this skin.
Type: str
-
libs
¶ External CSS libraries to import additionally.
Type: list of str
-
fonts
¶ External fonts to import additionally.
Type: list of str
-
rules
¶ Custom rules as defined in the Skin file.
Type: str
Constructor : Try to locate the file, then read it to extract external CSS resources links.
Parameters: - name (str, optional) – The name of the skin to use. Defaults to base.
- path (str, optional) – If different than None, the path of the CSS file to use. If different than None, name argument is ignored. Useful to provide custom skin. Defaults to None.
-