mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2026-12-02 03:45:25 +03:00
[Minor] Don't Allow Negative Resizing
This commit is contained in:
2 files changed
+63
-30
No files matched your search
+13
-3
@@ -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
|
||||
|
||||
@@ -220,38 +220,61 @@ class _Theme:
|
||||
widget.bind('<Enter>', lambda e: self._enter(e, image))
|
||||
widget.bind('<Leave>', 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:
|
||||
|
||||
Reference in new issue
Block a user