From 726fbbdb347cb931e6f6a36b4654d8660b283a93 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 1 Jan 2026 21:13:42 -0500 Subject: [PATCH] [Minor] Don't Allow Negative Resizing --- EDMarketConnector.py | 16 +++++++-- theme.py | 77 ++++++++++++++++++++++++++++---------------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 35397ecf..e3aff1d4 100644 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -807,9 +807,19 @@ class AppWindow: def _resize_drag(event: tk.Event): dx = event.x_root - self._resize_start_x dy = event.y_root - self._resize_start_y - self.w.geometry( - f"{self._resize_start_w + dx}x{self._resize_start_h + dy}" - ) + + # calculate proposed size + new_w = self._resize_start_w + dx + new_h = self._resize_start_h + dy + + # enforce minimum size + min_w, min_h = 50, 50 + if new_w < min_w: + new_w = min_w + if new_h < min_h: + new_h = min_h + + self.w.geometry(f"{new_w}x{new_h}") def _resize_start(event: tk.Event): self._resize_start_x = event.x_root diff --git a/theme.py b/theme.py index 68a1a391..79278b96 100644 --- a/theme.py +++ b/theme.py @@ -220,38 +220,61 @@ class _Theme: widget.bind('', lambda e: self._enter(e, image)) widget.bind('', lambda e: self._leave(e, image)) - def _enter(self, event: tk.Event, image: tk.BitmapImage | None) -> None: - widget = event.widget - if widget and widget['state'] != tk.DISABLED: - try: - widget.configure(state=tk.ACTIVE) # type: ignore + def _enter(self, event, widget=None, image=None): + """Handle mouse entering a widget or image.""" + if widget is not None: + # Only apply foreground/background if the widget supports them + config_keys = widget.keys() if hasattr(widget, 'keys') else [] + kwargs = {} + if 'foreground' in config_keys: + kwargs['foreground'] = self.current.get('highlightforeground', '') + if 'background' in config_keys: + kwargs['background'] = self.current.get('highlightbackground', '') + if kwargs: + widget.configure(**kwargs) - except Exception: - logger.exception(f'Failure setting widget active: {widget=}') - - if image: + if image is not None: + # PhotoImage cannot be configured with fg/bg, skip safely + if not isinstance(image, tk.PhotoImage): try: - image.configure(foreground=self.current['activeforeground'], - background=self.current['activebackground']) + config_keys = image.keys() if hasattr(image, 'keys') else [] + kwargs = {} + if 'foreground' in config_keys: + kwargs['foreground'] = self.current.get('highlightforeground', '') + if 'background' in config_keys: + kwargs['background'] = self.current.get('highlightbackground', '') + if kwargs: + image.configure(**kwargs) + except tk.TclError: + # silently ignore unsupported image types + pass - except Exception: - logger.exception(f'Failure configuring image: {image=}') + def _leave(self, event, widget=None, image=None): + """Handle mouse leaving a widget or image.""" + if widget is not None: + config_keys = widget.keys() if hasattr(widget, 'keys') else [] + kwargs = {} + if 'foreground' in config_keys: + kwargs['foreground'] = self.current.get('foreground', '') + if 'background' in config_keys: + kwargs['background'] = self.current.get('background', '') + if kwargs: + widget.configure(**kwargs) - def _leave(self, event: tk.Event, image: tk.BitmapImage | None) -> None: - widget = event.widget - if widget and widget['state'] != tk.DISABLED: - try: - widget.configure(state=tk.NORMAL) # type: ignore - - except Exception: - logger.exception(f'Failure setting widget normal: {widget=}') - - if image: + if image is not None: + # Skip PhotoImage objects; safely handle other types + if not isinstance(image, tk.PhotoImage): try: - image.configure(foreground=self.current['foreground'], background=self.current['background']) - - except Exception: - logger.exception(f'Failure configuring image: {image=}') + config_keys = image.keys() if hasattr(image, 'keys') else [] + kwargs = {} + if 'foreground' in config_keys: + kwargs['foreground'] = self.current.get('foreground', '') + if 'background' in config_keys: + kwargs['background'] = self.current.get('background', '') + if kwargs: + image.configure(**kwargs) + except tk.TclError: + pass # Set up colors def _colors(self, root: tk.Tk, theme: int) -> None: