Skip to content
New issue

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

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

Already on GitHub? # to your account

Switch: make it work with undocumented designer api #470

Merged
merged 5 commits into from
Oct 3, 2023
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
## Minor Changes
* wait_for_writeback is now written in pure python
https://github.com/anvilistas/anvil-extras/pull/431
* Switch - improve designer behaviour
https://github.com/anvilistas/anvil-extras/pull/470

# v2.4.0 14-Jun-2023

Expand Down
47 changes: 47 additions & 0 deletions client_code/Switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,40 @@
"""
_html_injector.css(css)

_remove_props = ["allow_indeterminate", "text", "underline"]

_include_props = [
{
"name": "checked_color",
"type": "color",
"default_value": None,
"group": "appearance",
"important": False,
},
{
"name": "text_pre",
"type": "string",
"default_value": "",
"group": "text",
"important": True,
},
{
"name": "text_post",
"type": "string",
"default_value": "",
"group": "text",
"important": True,
},
]


def _clean_props(props):
props = [p for p in props if p.get("name") not in _remove_props]
return _include_props + props


_prop_descriptions = _clean_props(getattr(CheckBox, "_anvil_properties_", []))


class Switch(CheckBox):
def __init__(self, checked_color=primary, text_pre="", text_post="", **properties):
Expand Down Expand Up @@ -157,3 +191,16 @@ def text_post(self, value):
self._textnode_post.textContent = value

text = text_post # override the CheckBox property

_anvil_properties_ = _prop_descriptions

def _anvil_get_design_info_(self, *args, **kws):
design_info = super()._anvil_get_design_info_(*args, **kws)
prop_key = (
"propertyDescriptions"
if "propertyDescriptions" in design_info
else "properties"
)
props = design_info.get(prop_key, [])
design_info[prop_key] = _clean_props(props)
return design_info