Skip to content

Commit

Permalink
introduce ui.page_title
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Dec 15, 2023
1 parent cda492f commit 6f07092
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nicegui/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __init__(self, page: page, *, shared: bool = False) -> None:

self.waiting_javascript_commands: Dict[str, Any] = {}

self.title: Optional[str] = None

self._head_html = ''
self._body_html = ''

Expand Down Expand Up @@ -127,7 +129,7 @@ def build_response(self, request: Request, status_code: int = 200) -> Response:
'imports': json.dumps(imports),
'js_imports': '\n'.join(js_imports),
'quasar_config': json.dumps(core.app.config.quasar_config),
'title': self.page.resolve_title(),
'title': self.page.resolve_title() if self.title is None else self.title,
'viewport': self.page.resolve_viewport(),
'favicon_url': get_favicon_url(self.page, prefix),
'dark': str(self.page.resolve_dark()),
Expand Down
12 changes: 12 additions & 0 deletions nicegui/functions/page_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .. import context, json


def page_title(title: str) -> None:
"""Set the page title for the current client.
:param title: page title
"""
client = context.get_client()
client.title = title
if client.has_socket_connection:
client.run_javascript(f'document.title = {json.dumps(title)}')
2 changes: 2 additions & 0 deletions nicegui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
'run_javascript',
'notify',
'open',
'page_title',
'refreshable',
'state',
'update',
Expand Down Expand Up @@ -188,6 +189,7 @@
from .functions.javascript import run_javascript
from .functions.notify import notify
from .functions.open import open # pylint: disable=redefined-builtin
from .functions.page_title import page_title
from .functions.refreshable import refreshable, state
from .functions.update import update
from .page import page
Expand Down

0 comments on commit 6f07092

Please sign in to comment.