-
Notifications
You must be signed in to change notification settings - Fork 1
BHoM Tkinter bug fixes and improvements #214
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
base: develop
Are you sure you want to change the base?
Changes from 6 commits
f70a772
c2315f9
54d1bd1
f393d6a
30c871f
ccec381
ea57c5e
465152c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ def __init__( | |||||||||||||||||||
| custom_validation: Optional[Callable[[object], Tuple[bool, Optional[str], Optional[Literal['info', 'warning', 'error']]]]] = None, | ||||||||||||||||||||
| disable_validation: bool = False, | ||||||||||||||||||||
| build_options: BuildOptions = PackingOptions(), | ||||||||||||||||||||
| on_change: Optional[Callable] = None, | ||||||||||||||||||||
| **kwargs): | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| Initialize the widget base. | ||||||||||||||||||||
|
|
@@ -46,6 +47,10 @@ def __init__( | |||||||||||||||||||
| Receives the current widget value and must return | ||||||||||||||||||||
| `(is_valid, message, severity)`. | ||||||||||||||||||||
| disable_validation: When `True`, all validation returns valid. | ||||||||||||||||||||
| on_change: Optional callback invoked whenever the widget value | ||||||||||||||||||||
| changes. The current value is passed as the single argument. | ||||||||||||||||||||
| Supported by all widgets; supplements widget-specific ``command`` | ||||||||||||||||||||
| parameters where those exist. | ||||||||||||||||||||
| **kwargs: Additional Frame options | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| super().__init__(parent, **kwargs) | ||||||||||||||||||||
|
|
@@ -57,6 +62,7 @@ def __init__( | |||||||||||||||||||
| self.fill_extents = self._normalise_bool(fill_extents) | ||||||||||||||||||||
| self.custom_validation = custom_validation | ||||||||||||||||||||
| self.disable_validation = bool(disable_validation) | ||||||||||||||||||||
| self.on_change: Optional[Callable] = on_change | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if id is None: | ||||||||||||||||||||
| self.id = str(uuid4()) | ||||||||||||||||||||
|
|
@@ -212,10 +218,11 @@ def align_child_text(self, widget: tk.Widget, alignment: Optional[Literal['left' | |||||||||||||||||||
| if alignment is not None: | ||||||||||||||||||||
| self.alignment = self._normalise_alignment(alignment) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| self._apply_text_alignment(widget) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if alignment is not None: | ||||||||||||||||||||
| self.alignment = previous_alignment | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| self._apply_text_alignment(widget) | ||||||||||||||||||||
| finally: | ||||||||||||||||||||
| if alignment is not None: | ||||||||||||||||||||
| self.alignment = previous_alignment | ||||||||||||||||||||
|
Comment on lines
+221
to
+225
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use a try/finally here? no exception is caught so the program doesn't actually continue to run after this point, at which point the child align text doesn't actually matter as the program has crashed, it was fine as before.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def set_alignment(self, alignment: Literal['left', 'center', 'right']) -> None: | ||||||||||||||||||||
| """Set widget-wide alignment and refresh built-in labels. | ||||||||||||||||||||
|
|
@@ -247,6 +254,21 @@ def set_fill_extents(self, fill_extents: bool) -> None: | |||||||||||||||||||
| label.pack_configure(anchor=self._pack_anchor) | ||||||||||||||||||||
| self._apply_text_alignment(label) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def _fire_on_change(self, value: object) -> None: | ||||||||||||||||||||
| """Invoke the ``on_change`` callback with the current widget value. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| This is called internally by each widget subclass whenever its value | ||||||||||||||||||||
| changes. It is safe to call even when ``on_change`` is ``None``. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Args: | ||||||||||||||||||||
| value: The current widget value to pass to the callback. | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| if self.on_change is not None: | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| self.on_change(value) | ||||||||||||||||||||
| except Exception: | ||||||||||||||||||||
| pass | ||||||||||||||||||||
|
Comment on lines
+269
to
+270
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
please log exceptions |
||||||||||||||||||||
|
|
||||||||||||||||||||
| @abstractmethod | ||||||||||||||||||||
| def get(self): | ||||||||||||||||||||
| """Get the current value of the widget.""" | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially remove this try/except as it was originally added when you were locally testing in the wrong environment.