Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix autocompletions #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions client_code/Layouts/NavigationDrawerLayout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,17 @@ def on_finished(e):
)

@anvil_prop
def background_color(self, value):
@property
def background_color(self, value) -> str:
"""The background color of Forms using this Layout."""
if value:
value = theme_color_to_css(value)
window.document.body.style.backgroundColor = value

@anvil_prop
def text_color(self, value):
@property
def text_color(self, value) -> str:
"""The default color of the text on Forms using this Layout."""
if value:
value = theme_color_to_css(value)
window.document.body.style.color = value
Expand Down
16 changes: 12 additions & 4 deletions client_code/Layouts/NavigationRailLayout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,34 @@ def _icon_button_1_click(self, **event_args):
content_padding = padding_property('anvil-m3-content')

@anvil_prop
def background_color(self, value):
@property
def background_color(self, value) -> str:
"""The background color of Forms using this Layout."""
if value:
value = theme_color_to_css(value)
window.document.body.style.backgroundColor = value

@anvil_prop
def text_color(self, value):
@property
def text_color(self, value) -> str:
"""The default color of the text on Forms using this Layout."""
if value:
value = theme_color_to_css(value)
window.document.body.style.color = value

@anvil_prop
def navigation_rail_collapse_to(self, value):
@property
def navigation_rail_collapse_to(self, value) -> str:
"""The way the side navigation will collapse on mobile."""
value = value.lower().replace('_', '-')
for c in ['anvil-m3-bottom-app-bar', 'anvil-m3-modal-navigation-drawer']:
self.nav_rail.classList.remove(c)
self.nav_rail.classList.add(f"anvil-m3-{value}")

@anvil_prop
def navigation_rail_vertical_align(self, value):
@property
def navigation_rail_vertical_align(self, value) -> str:
"""The vertical position of the content in the navigation rail."""
value = value.lower()
for c in ['anvil-m3-align-top', 'anvil-m3-align-center', 'anvil-m3-align-bottom']:
self.nav_rail.classList.remove(c)
Expand Down
16 changes: 12 additions & 4 deletions client_code/_Components/Button/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,36 @@ def _set_text(self):
visible = HtmlTemplate.visible

@anvil_prop
def align(self, value):
@property
def align(self, value) -> str:
"""The position of this component in the available space."""
self.dom_nodes['anvil-m3-button'].classList.toggle('anvil-m3-full-width', False)
if value == 'full':
self.dom_nodes['anvil-m3-button'].classList.toggle('anvil-m3-full-width', True)
else:
self.dom_nodes['anvil-m3-button-component'].style.justifyContent = value

@anvil_prop
def icon_align(self, value):
@property
def icon_align(self, value) -> str:
"""The alignment of the icon on this component."""
self.dom_nodes['anvil-m3-button'].classList.toggle(
'anvil-m3-right-icon', value == 'right'
)

@anvil_prop
def enabled(self, value):
@property
def enabled(self, value) -> bool:
"""If True, this component allows user interaction."""
if value:
self.dom_nodes['anvil-m3-button'].removeAttribute("disabled")
else:
self.dom_nodes['anvil-m3-button'].setAttribute("disabled", " ")

@anvil_prop
def appearance(self, value):
@property
def appearance(self, value) -> str:
"""A predefined style for this component."""
button = self.dom_nodes['anvil-m3-button']
button.classList.remove('anvil-m3-elevated')
button.classList.remove('anvil-m3-filled')
Expand Down
80 changes: 60 additions & 20 deletions client_code/_Components/ButtonMenu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def _handle_click(self, event):
visible = HtmlTemplate.visible

@anvil_prop
def text(self, value):
@property
def text(self, value) -> str:
"""The text displayed on the Button"""
v = value
self.menu_button.dom_nodes['anvil-m3-button-text'].classList.toggle(
'anvil-m3-textlessComponentText', False
Expand All @@ -111,67 +113,99 @@ def text(self, value):
self.menu_button.text = v

@anvil_prop
def appearance(self, value):
@property
def appearance(self, value) -> str:
"""A predefined style for the Button."""
self.menu_button.appearance = value

@anvil_prop
def tooltip(self, value):
@property
def tooltip(self, value) -> str:
"""The text to display when the mouse is hovered over this component."""
self.menu_button.tooltip = value

@anvil_prop
def enabled(self, value):
@property
def enabled(self, value) -> bool:
"""If True, this component allows user interaction."""
self.menu_button.enabled = value

@anvil_prop
def bold(self, value):
@property
def bold(self, value) -> bool:
"""If True, the Button’s text will be bold."""
self.menu_button.bold = value

@anvil_prop
def italic(self, value):
@property
def italic(self, value) -> bool:
"""If True, the Button’s text will be italic."""
self.menu_button.italic = value

@anvil_prop
def underline(self, value):
@property
def underline(self, value) -> bool:
"""If True, the Button’s text will be underlined."""
self.menu_button.underline = value

@anvil_prop
def button_border(self, value):
@property
def button_border(self, value) -> str:
"""The border of the Button. Can take any valid CSS border value."""
self.menu_button.border = value

@anvil_prop
def button_background_color(self, value):
@property
def button_background_color(self, value) -> str:
"""The colour of the background of the Button."""
self.menu_button.background_color = value

@anvil_prop
def button_text_color(self, value):
@property
def button_text_color(self, value) -> str:
"""The colour of the text on the Button."""
self.menu_button.text_color = value

@anvil_prop
def button_font_size(self, value):
@property
def button_font_size(self, value) -> int:
"""The font size of the text displayed on the Button."""
self.menu_button.font_size = value

@anvil_prop
def icon(self, value):
@property
def icon(self, value) -> str:
"""The icon to display on the Button."""
self.menu_button.icon = value

@anvil_prop
def icon_color(self, value):
@property
def icon_color(self, value) -> str:
"""The colour of the icon displayed on the Button."""
self.menu_button.icon_color = value

@anvil_prop
def icon_size(self, value):
@property
def icon_size(self, value) -> int:
"""The size (pixels) of the icon displayed on this component."""
self.menu_button.icon_size = value

@anvil_prop
def icon_position(self, value):
@property
def icon_position(self, value) -> str:
"""The alignment of the icon on this component."""
self.menu_button.icon_position = value

@anvil_prop
def spacing(self, value):
@property
def spacing(self, value) -> list:
"""The margin and padding (pixels) of the component."""
self.menu_button.spacing = value

@anvil_prop
def align(self, value):
@property
def align(self, value) -> str:
"""The position of this component in the available space."""
self.menu_button.dom_nodes['anvil-m3-button'].classList.toggle(
'anvil-m3-full-width', False
)
Expand All @@ -189,15 +223,21 @@ def align(self, value):
self._setup_fui()

@anvil_prop
def button_font_family(self, value):
@property
def button_font_family(self, value) -> str:
"""The font family to use for the Button"""
self.menu_button.font_family = value

@anvil_prop
def role(self, value):
@property
def role(self, value) -> str:
"""A style for this component defined in CSS and added to Roles"""
self.menu_button.role = value

@anvil_prop
def menu_items(self, value=[]):
@property
def menu_items(self, value=[]) -> list:
"""A list of components to be added to the menu."""
for i in value:
self.add_component(i, slot='anvil-m3-buttonMenu-slot')

Expand Down
8 changes: 6 additions & 2 deletions client_code/_Components/Card/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ def _set_class_of_nodes(self, appearance, val):
self.dom_nodes['content'].classList.toggle(f'anvil-m3-{appearance}', val)

@anvil_prop
def appearance(self, value):
@property
def appearance(self, value) -> str:
"""A predefined style for this component."""
for appearance in ['outlined', 'filled', 'elevated']:
self._set_class_of_nodes(appearance, False)
self._set_class_of_nodes(value, True)

@anvil_prop
def orientation(self, value):
@property
def orientation(self, value) -> str:
"""The orientation of the content in this Card"""
for c in ['anvil-m3-card-direction-column', 'anvil-m3-card-direction-row']:
self.dom_nodes['anvil-m3-card'].classList.remove(c)
self.dom_nodes['anvil-m3-card'].classList.add(f'anvil-m3-card-direction-{value}')
Expand Down
19 changes: 14 additions & 5 deletions client_code/_Components/Checkbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
italic_property,
role_property,
spacing_property,
simple_prop,
style_property,
theme_color_to_css,
tooltip_property,
Expand Down Expand Up @@ -130,26 +131,32 @@ def _handle_change(self, event):
spacing = spacing_property('anvil-m3-checkbox-component')
tooltip = tooltip_property('anvil-m3-checkbox-container')
role = role_property('anvil-m3-checkbox-container')
allow_indeterminate = anvil_prop('allow_indeterminate')
allow_indeterminate = simple_prop('allow_indeterminate')

@anvil_prop
def text(self, value):
@property
def text(self, value) -> str:
"""The text displayed on this component"""
if value:
self.dom_nodes['anvil-m3-checkbox-label'].innerText = value
self.dom_nodes['anvil-m3-checkbox-label'].style.display = 'block'
else:
self.dom_nodes['anvil-m3-checkbox-label'].style.display = 'none'

@anvil_prop
def checkbox_color(self, value):
@property
def checkbox_color(self, value) -> str:
"""The color of the checkbox."""
if value:
value = theme_color_to_css(value)
self.dom_nodes['anvil-m3-checkbox-unchecked'].style.color = value
self.dom_nodes['anvil-m3-checkbox-checked'].style.color = value
self.dom_nodes['anvil-m3-checkbox-indeterminate'].style.color = value

@anvil_prop
def checked(self, value):
@property
def checked(self, value) -> bool:
"""If True, the checkbox is checked."""
if value is None and self.allow_indeterminate:
self.dom_nodes['anvil-m3-checkbox'].indeterminate = True
self.dom_nodes['anvil-m3-checkbox-unchecked'].style.display = 'none'
Expand All @@ -167,7 +174,9 @@ def checked(self, value):
self.dom_nodes['anvil-m3-checkbox-indeterminate'].style.display = 'none'

@anvil_prop
def error(self, value):
@property
def error(self, value) -> bool:
"""If True, the checkbox is in an error state."""
self.dom_nodes['anvil-m3-checkbox-container'].classList.remove(
'anvil-m3-checkbox-error'
)
Expand Down
12 changes: 9 additions & 3 deletions client_code/_Components/CircularProgressIndicator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def _anvil_get_unset_property_values_(self):
role = role_property('anvil-m3-progressindicator')

@anvil_prop
def color(self, value):
@property
def color(self, value) -> str:
"""The colour of the progress bar"""
if value:
value = theme_color_to_css(value)
self.dom_nodes['anvil-m3-progressindicator-arc'].style['stroke'] = value
Expand All @@ -45,7 +47,9 @@ def color(self, value):
)

@anvil_prop
def type(self, value):
@property
def type(self, value) -> str:
"""Display a determinate or indeterminate progress indicator. Use determinate to set the progress with the progress property. Use indeterminate to express an unspecified amount of wait time."""
v = value == "determinate"
self.dom_nodes['anvil-m3-progressindicator-indeterminate'].classList.toggle(
'anvil-m3-progressindicator-hidden', v
Expand All @@ -55,7 +59,9 @@ def type(self, value):
)

@anvil_prop
def progress(self, value):
@property
def progress(self, value) -> float:
"""The progress of the CircularProgressIndicator."""
v = max(min(value or 0, 100), 0)
self._draw_path(v)

Expand Down
4 changes: 3 additions & 1 deletion client_code/_Components/Divider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def _anvil_get_unset_property_values_(self):
margin = margin_property('anvil-m3-divider')

@anvil_prop
def type(self, value):
@property
def type(self, value) -> str:
"""Display the Divider across the full width of the container or inset."""
divider = self.dom_nodes['anvil-m3-divider']
value = value.lower().replace(' ', '-')
divider.className = "anvil-m3-divider"
Expand Down
Loading