forked from zauberzeug/nicegui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feature/per_session_data' into f…
…eature/per_session_data
- Loading branch information
Showing
23 changed files
with
464 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from typing import Any, Callable, Optional | ||
|
||
from ..events import ClickEventArguments, handle_event | ||
from .mixins.color_elements import BackgroundColorElement | ||
from .mixins.disableable_element import DisableableElement | ||
from .mixins.text_element import TextElement | ||
from .mixins.value_element import ValueElement | ||
|
||
|
||
class DropdownButton(TextElement, DisableableElement, BackgroundColorElement, ValueElement): | ||
|
||
def __init__(self, | ||
text: str = '', *, | ||
value: bool = False, | ||
on_value_change: Optional[Callable[..., Any]] = None, | ||
on_click: Optional[Callable[..., Any]] = None, | ||
color: Optional[str] = 'primary', | ||
icon: Optional[str] = None, | ||
auto_close: Optional[bool] = False, | ||
split: Optional[bool] = False, | ||
) -> None: | ||
"""Dropdown Button | ||
This element is based on Quasar's `QBtnDropDown <https://quasar.dev/vue-components/button-dropdown>`_ component. | ||
The ``color`` parameter accepts a Quasar color, a Tailwind color, or a CSS color. | ||
If a Quasar color is used, the button will be styled according to the Quasar theme including the color of the text. | ||
Note that there are colors like "red" being both a Quasar color and a CSS color. | ||
In such cases the Quasar color will be used. | ||
:param text: the label of the button | ||
:param value: if the dropdown is open or not (default: `False`) | ||
:param on_value_change: callback which is invoked when the dropdown is opened or closed | ||
:param on_click: callback which is invoked when button is pressed | ||
:param color: the color of the button (either a Quasar, Tailwind, or CSS color or `None`, default: 'primary') | ||
:param icon: the name of an icon to be displayed on the button (default: `None`) | ||
:param auto_close: whether the dropdown should close automatically when an item is clicked (default: `False`) | ||
:param split: whether to split the dropdown icon into a separate button (default: `False`) | ||
""" | ||
super().__init__(tag='q-btn-dropdown', | ||
text=text, background_color=color, value=value, on_value_change=on_value_change) | ||
|
||
if icon: | ||
self._props['icon'] = icon | ||
|
||
if auto_close: | ||
self._props['auto-close'] = True | ||
|
||
if split: | ||
self._props['split'] = True | ||
|
||
if on_click: | ||
self.on('click', lambda _: handle_event(on_click, ClickEventArguments(sender=self, client=self.client)), []) | ||
|
||
def _text_to_model_text(self, text: str) -> None: | ||
self._props['label'] = text | ||
|
||
def open(self) -> None: | ||
"""Open the dropdown.""" | ||
self.value = True | ||
|
||
def close(self) -> None: | ||
"""Close the dropdown.""" | ||
self.value = False | ||
|
||
def toggle(self) -> None: | ||
"""Toggle the dropdown.""" | ||
self.value = not self.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from ..element import Element | ||
|
||
|
||
class ButtonGroup(Element): | ||
|
||
def __init__(self) -> None: | ||
"""Button Group | ||
This element is based on Quasar's `QBtnGroup <https://quasar.dev/vue-components/button-group>`_ component. | ||
You must use the same design props on both the parent button group and the children buttons. | ||
""" | ||
super().__init__(tag='q-btn-group') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,68 @@ | ||
from pathlib import Path | ||
from typing import Union | ||
|
||
import sass | ||
from .. import optional_features | ||
|
||
try: | ||
import sass | ||
optional_features.register('sass') | ||
except ImportError: | ||
pass | ||
|
||
from .. import helpers | ||
from ..logging import log | ||
from .html import add_head_html | ||
|
||
|
||
def add_style(content: Union[str, Path], indented: bool = False) -> None: | ||
"""Add style definitions to the page. | ||
def add_style(content: Union[str, Path], indented: bool = False) -> None: # DEPRECATED | ||
"""Add style definitions to the page. [DEPRECATED] | ||
Note: | ||
This function is deprecated, because it can't reliably detect the style language. | ||
Use `add_css`, `add_scss` or `add_sass` instead. | ||
""" | ||
if helpers.is_file(content): | ||
content = Path(content).read_text() | ||
if optional_features.has('sass'): | ||
content = sass.compile(string=str(content).strip(), indented=indented) | ||
log.warning("`ui.add_style` is deprecated, because it can't reliably detect the style language. " | ||
'Use `ui.add_css`, `ui.add_scss` or `ui.add_sass` instead.') | ||
add_head_html(f'<style>{content}</style>') | ||
|
||
|
||
def add_css(content: Union[str, Path]) -> None: | ||
"""Add CSS style definitions to the page. | ||
This function can be used to add CSS style definitions to the head of the HTML page. | ||
:param content: CSS content (string or file path) | ||
""" | ||
if helpers.is_file(content): | ||
content = Path(content).read_text() | ||
add_head_html(f'<style>{content}</style>') | ||
|
||
|
||
This function can be used to add CSS, SCSS, or SASS style definitions to the head of the HTML page. | ||
def add_scss(content: Union[str, Path], *, indented: bool = False) -> None: | ||
"""Add SCSS style definitions to the page. | ||
:param content: style content (string or file path) | ||
:param indented: whether the content is indented (SASS) or not (SCSS/CSS) (default: `False`) | ||
This function can be used to add SCSS style definitions to the head of the HTML page. | ||
:param content: SCSS content (string or file path) | ||
:param indented: whether the content is indented (SASS) or not (SCSS) (default: `False`) | ||
""" | ||
if not optional_features.has('sass'): | ||
raise ImportError('Please run "pip install libsass" to use SASS or SCSS.') | ||
|
||
if helpers.is_file(content): | ||
content = Path(content).read_text() | ||
css = sass.compile(string=str(content).strip(), indented=indented) | ||
add_head_html(f'<style>{css}</style>') | ||
add_css(sass.compile(string=str(content).strip(), indented=indented)) | ||
|
||
|
||
def add_sass(content: Union[str, Path]) -> None: | ||
"""Add SASS style definitions to the page. | ||
This function can be used to add SASS style definitions to the head of the HTML page. | ||
:param content: SASS content (string or file path) | ||
""" | ||
add_scss(content, indented=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
'plotly', | ||
'pyecharts', | ||
'webview', | ||
'sass', | ||
] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.