Application and Server¶
WDOM applications consist of a single html Document
and a web server.
HTML Document Object¶
-
class
wdom.document.
WdomDocument
(*, doctype: str = ‘html’, title: str = ‘W-DOM’, charset: str = ‘utf-8’, default_class: type = <class ‘wdom.web_node.WdomElement’>, autoreload: bool = None, reload_wait: float = None, **kwargs: typing.Any) → None[source]¶ Bases:
wdom.document.Document
,wdom.event.WebEventTarget
Main document class for WDOM applications.
Create new document object for WDOM application.
Caution
Don’t create new document from
WdomDocument
class constructor. Useget_new_document()
function instead.Parameters: - doctype (str) – doctype of the document (default: html).
- title (str) – title of the document.
- charset (str) – charset of the document.
- default_class (type) – Set default Node class of the document. This
class is used when make node by
createElement()
- autoreload (bool) – Enable/Disable autoreload (default: False).
- reload_wait (float) – How long (seconds) wait to reload. This parameter is only used when autoreload is enabled.
-
tempdir
¶ Return temporary directory used by this document.
Return type: str
-
getElementByWdomId
(id)[source]¶ Get an element node with
wdom_id
.If this document does not have the element with the id, return None.
Return type: Optional
[WebEventTarget
]
-
add_jsfile
(src)[source]¶ Add JS file to load at this document’s bottom of the body.
Return type: None
-
add_header
(header)[source]¶ Insert header tag staring at this document’s header.
Parameters: header (str) – tag to insert <head> ~ </head> area. Return type: None
-
register_theme
(theme)[source]¶ Set theme for this docuemnt.
This method sets theme’s js/css files and headers on this document.
Parameters: theme (ModuleType) – a module which has js_files
,css_files
,headers
, andextended_classes
. seewdom.themes
directory actual theme module structures.Return type: None
-
wdom.document.
get_new_document
(include_wdom_js=True, include_skeleton=False, include_normalizecss=False, autoreload=None, reload_wait=None, log_level=None, log_prefix=None, log_console=False, ws_url=None, message_wait=None, document_factory=<class ‘wdom.document.WdomDocument’>, **kwargs)[source]¶ Create new
Document
object with options.Parameters: - include_wdom_js (bool) – Include wdom.js file. Usually should be True.
- include_skeleton (bool) – Include skelton.css.
- include_normalizecss (bool) – Include normalize.css.
- autoreload (bool) – Enable autoreload flag. This flag overwrites
--debug
flag, which automatically enables autoreload. - reload_wait (float) – Seconds to wait until reload when autoreload is enabled.
- log_level (str) – Log level string, chosen from DEBUG, INFO, WARN, ERROR.
Integer values are also acceptable like
logging.INFO
. By default usewdom.config.options.log_level
, which default isINFO
. - log_prefix (str) – Prefix of log outputs.
- log_console (bool) – Flag to show wdom log on browser console.
- ws_url (str) – URL string to the ws url.
Default:
ws://localhost:8888/wdom_ws
. - message_wait (float) – Duration (seconds) to send WS messages.
- document_factory (Callable) – Factory function/class to create Document object.
Return type:
Web Server¶
Web server control functions.
-
wdom.server.
add_static_path
(prefix, path, no_watch=False)[source]¶ Add directory to serve static files.
First argument
prefix
is a URL prefix for thepath
.path
must be a directory. Ifno_watch
is True, any change of the files in the path do not trigger restart if--autoreload
is enabled.Return type: None
-
wdom.server.
start
(**kwargs)[source]¶ Start web server.
Run until
Ctrl-c
pressed, or if auto-shutdown is enabled, until when all browser windows are closed.This function accepts keyword areguments same as
start_server()
and all arguments passed to it.Return type: None
-
wdom.server.
start_server
(address=None, port=None, check_time=500, **kwargs)[source]¶ Start web server on
address:port
.Use wrapper function
start()
instead.Parameters: - address (str) – address of the server [default: localhost].
- port (int) – tcp port of the server [default: 8888].
- check_time (int) – millisecondes to wait until reload browser when autoreload is enabled [default: 500].
Return type: HTTPServer