EDCD / EDCD/EDMarketConnector

Destroyed widgets can break theme switching and saving settings

Open
#2,555 4 comments 0 reactions 1 assignee Claimed by @Rixxan View on GitHub
bug unconfirmed
Dominant language
Python
Stars
1.3k
Forks
182
Avg merge
1m
Merged PRs (30d)
1

Description

From [theme._Theme](https://github.com/EDCD/EDMarketConnector/blob/48dafaf31fb5ada830ac76e99bd236e6315d0592/theme.py#L396):

```python
def apply(self, root: tk.Tk) -> None: # noqa: CCR001, C901
theme = config.get_int('theme')
self._colors(root, theme)

# Apply colors
for widget in set(self.widgets):
if isinstance(widget, tk.Widget) and not widget.winfo_exists():
self.widgets.pop(widget) # has been destroyed
else:
self._update_widget(widget)

# Switch menus
for pair, gridopts in self.widgets_pair:
for widget in pair:
if isinstance(widget, tk.Widget):
widget.grid_remove()
```

Note that the `and not widget.winfo_exists()` check is done for widgets in `self.widgets`, but not for ones in `self.widgets_pair` which is populated by calling `_Theme.register_alternate`. There's also no method for explicitly "unregistering" pairs of widgets in case the caller knows they are about to get destroyed.

This leads to an issue when a widget previously registered for pair switching is destroyed: when user tries to save settings *(regardless of whether they actually changed the app theme)*, `_Theme.apply` gets called, iterates through `self.widgets_pair` and throws exception on the last line from the snippet above:

```python
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.pyc", line 2074, in __call__
File "prefs.pyc", line 1358, in apply
File "theme.pyc", line 411, in apply
File "tkinter\__init__.pyc", line 2715, in grid_remove
_tkinter.TclError: bad window path name ".edmarketconnector.plugin_2.!frame.!frame.!notifier.!_message.!button"
```

This not only prevents the settings from being saved correctly, but also causes the settings window to get stuck open unless the user closes it without saving.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.