Skip to content

Commit a3b3f48

Browse files
committed
manipulating props through looks
1 parent 4dee595 commit a3b3f48

38 files changed

+144
-115
lines changed

examples/custom_vue_component/counter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Counter(Element):
1010

1111
def __init__(self, title: str, *, on_change: Optional[Callable] = None) -> None:
1212
super().__init__('counter')
13-
self._props['title'] = title
13+
self.looks._props['title'] = title
1414
self.on('change', on_change)
1515

1616
def reset(self) -> None:

looks_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
from nicegui import Looks, ui
2+
from nicegui import ButtonLooks, Looks, ui
33

44
shared = Looks().width.full().background.secondary()
55

@@ -8,11 +8,11 @@
88
with ui.card():
99
ui.label(str(i))
1010

11-
button_looks = Looks().background.teal(0.9)
11+
button_looks = ButtonLooks().rounded().background.teal(0.9)
1212
hover = Looks().text.gray(0.6)
1313

1414
with ui.row().looks.add(shared).height.fixed.twenty().background.grey(0.4).align.main_axis.evenly().align.cross_axis.center().element:
15-
ui.button('12').looks.width.fixed.twelve().add(button_looks)
15+
ui.button('12').looks.square().width.fixed.twelve().add(button_looks)
1616
ui.button('64').looks.width.fixed.sixty_four().add(button_looks).height.fractional.two_thirds()
1717
ui.button('1/6').looks.width.fractional.one_sixth().add(button_looks).on_hover(hover)
1818

nicegui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from . import elements, globals, ui
22
from .client import Client
3-
from .looks import Looks
3+
from .looks import ButtonLooks, Looks
44
from .nicegui import app

nicegui/element.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def __init__(self, tag: str, *, _client: Optional[Client] = None) -> None:
2626
self.tag = tag
2727
self.looks = Looks(self)
2828
self._style: Dict[str, str] = {}
29-
self._props: Dict[str, Any] = {}
3029
self._event_listeners: List[EventListener] = []
3130
self._text: str = ''
3231
self.slots: Dict[str, Slot] = {}
@@ -72,7 +71,7 @@ def to_dict(self) -> Dict:
7271
'tag': self.tag,
7372
'class': self.looks.classes,
7473
'style': self._style,
75-
'props': self._props,
74+
'props': self.looks._props,
7675
'events': events,
7776
'text': self._text,
7877
'slots': {name: [child.id for child in slot.children] for name, slot in self.slots.items()},
@@ -138,13 +137,13 @@ def props(self, add: Optional[str] = None, *, remove: Optional[str] = None):
138137
'''
139138
needs_update = False
140139
for key in self._parse_props(remove):
141-
if key in self._props:
140+
if key in self.looks._props:
142141
needs_update = True
143-
del self._props[key]
142+
del self.looks._props[key]
144143
for key, value in self._parse_props(add).items():
145-
if self._props.get(key) != value:
144+
if self.looks._props.get(key) != value:
146145
needs_update = True
147-
self._props[key] = value
146+
self.looks._props[key] = value
148147
if needs_update:
149148
self.update()
150149
return self

nicegui/elements/audio.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def __init__(self, src: str, *,
2020
for a list of events you can subscribe to using the generic event subscription `on()`.
2121
"""
2222
super().__init__('audio')
23-
self._props['src'] = src
24-
self._props['type'] = type
25-
self._props['controls'] = controls
26-
self._props['autoplay'] = autoplay
27-
self._props['muted'] = muted
23+
self.looks._props['src'] = src
24+
self.looks._props['type'] = type
25+
self.looks._props['controls'] = controls
26+
self.looks._props['autoplay'] = autoplay
27+
self.looks._props['muted'] = muted

nicegui/elements/badge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def __init__(self, text: str = '', *,
1616
:param outline: use 'outline' design (colored text and borders only) (default: False)
1717
"""
1818
super().__init__(tag='q-badge', text=text)
19-
self._props['color'] = color
20-
self._props['text_color'] = text_color
21-
self._props['outline'] = outline
19+
self.looks._props['color'] = color
20+
self.looks._props['text_color'] = text_color
21+
self.looks._props['outline'] = outline

nicegui/elements/button.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Callable, Optional
22

33
from ..events import ClickEventArguments, handle_event
4+
from ..looks import ButtonLooks
45
from .mixins.text_element import TextElement
56

67

@@ -13,9 +14,13 @@ def __init__(self, text: str = '', *, on_click: Optional[Callable] = None) -> No
1314
:param on_click: callback which is invoked when button is pressed
1415
"""
1516
super().__init__(tag='q-btn', text=text)
16-
self._props['color'] = 'primary'
17+
orig = self.looks
18+
self.looks = ButtonLooks(self)
19+
self.looks.classes = orig.classes
20+
self.looks._props = orig._props
21+
self.looks._props['color'] = 'primary'
1722

1823
self.on('click', lambda _: handle_event(on_click, ClickEventArguments(sender=self, client=self.client)))
1924

2025
def _text_to_model_text(self, text: str) -> None:
21-
self._props['label'] = text
26+
self.looks._props['label'] = text

nicegui/elements/chart.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ def __init__(self, options: Dict, *, type: str = 'chart', extras: List[str] = []
9999
:param extras: list of extra dependencies to include (e.g. "annotations", "arc-diagram", "solid-gauge", ...)
100100
"""
101101
super().__init__('chart')
102-
self._props['type'] = type
103-
self._props['options'] = options
104-
self._props['extras'] = [
102+
self.looks._props['type'] = type
103+
self.looks._props['options'] = options
104+
self.looks._props['extras'] = [
105105
dependency.import_path
106106
for dependency in js_dependencies.values()
107107
if dependency.optional and dependency.path.stem in extras and 'chart' in dependency.dependents
108108
]
109109

110110
@property
111111
def options(self) -> Dict:
112-
return self._props['options']
112+
return self.looks._props['options']
113113

114114
def update(self) -> None:
115115
super().update()

nicegui/elements/choice_element.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _update_values_and_labels(self) -> None:
1919
self._labels = self.options if isinstance(self.options, list) else list(self.options.values())
2020

2121
def _update_options(self) -> None:
22-
self._props['options'] = [{'value': index, 'label': option} for index, option in enumerate(self._labels)]
22+
self.looks._props['options'] = [{'value': index, 'label': option} for index, option in enumerate(self._labels)]
2323

2424
def update(self) -> None:
2525
self._update_values_and_labels()

nicegui/elements/color_input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def __init__(self, label: Optional[str] = None, *,
2020
"""
2121
super().__init__(tag='q-input', value=value, on_value_change=on_change)
2222
if label is not None:
23-
self._props['label'] = label
23+
self.looks._props['label'] = label
2424
if placeholder is not None:
25-
self._props['placeholder'] = placeholder
25+
self.looks._props['placeholder'] = placeholder
2626

2727
with self.add_slot('append'):
2828
self.picker = ColorPicker(on_pick=lambda e: self.set_value(e.color))

0 commit comments

Comments
 (0)