From b794e19d75436ba048787ba2cf2031efc27d6076 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Fri, 14 Jul 2017 11:43:17 +0100 Subject: [PATCH] Automatically highlight widgets that set a custom cursor --- EDMarketConnector.py | 6 +----- theme.py | 15 ++++----------- ttkHyperlinkLabel.py | 9 +++++---- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 95ad2300..d4accf59 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -228,7 +228,7 @@ class AppWindow: # Alternate title bar and menu for dark theme self.theme_menubar = tk.Frame(frame) self.theme_menubar.columnconfigure(2, weight=1) - theme_titlebar = tk.Label(self.theme_menubar, text=applongname, image=self.theme_icon, anchor=tk.W, compound=tk.LEFT) + theme_titlebar = tk.Label(self.theme_menubar, text=applongname, image=self.theme_icon, cursor='fleur', anchor=tk.W, compound=tk.LEFT) theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW) self.drag_offset = None theme_titlebar.bind('', self.drag_start) @@ -250,7 +250,6 @@ class AppWindow: self.theme_help_menu = tk.Label(self.theme_menubar, anchor=tk.W) self.theme_help_menu.grid(row=1, column=2, sticky=tk.W) theme.button_bind(self.theme_help_menu, lambda e: self.help_menu.tk_popup(e.widget.winfo_rootx(), e.widget.winfo_rooty() + e.widget.winfo_height())) - theme.register_highlight(theme_titlebar) theme.register(self.theme_minimize) # images aren't automatically registered theme.register(self.theme_close) self.blank_menubar = tk.Frame(frame) @@ -279,9 +278,6 @@ class AppWindow: self.w.resizable(tk.TRUE, tk.FALSE) theme.register(frame) - theme.register_highlight(self.ship) - theme.register_highlight(self.system) - theme.register_highlight(self.station) theme.apply(self.w) self.w.bind('', self.onmap) # Special handling for overrideredict diff --git a/theme.py b/theme.py index 687fa61b..05ca660c 100644 --- a/theme.py +++ b/theme.py @@ -20,7 +20,6 @@ class _Theme: self.active = None # Starts out with no theme self.minwidth = None self.widgets = set() - self.widgets_highlight = set() self.widgets_pair = [] def register(self, widget): @@ -30,12 +29,6 @@ class _Theme: self.register(child) self.widgets.add(widget) - def register_highlight(self, widget): - assert isinstance(widget, tk.Widget) or isinstance(widget, tk.BitmapImage), widget - if isinstance(widget, tk.Frame) or isinstance(widget, ttk.Frame): - self.register_highlight(widget.winfo_children()) - self.widgets_highlight.add(widget) - def register_alternate(self, pair, gridopts): self.widgets_pair.append((pair, gridopts)) @@ -128,6 +121,10 @@ class _Theme: # not a widget widget.configure(foreground = self.current['foreground'], background = self.current['background']) + elif 'cursor' in widget.keys() and str(widget['cursor']) not in ['', 'arrow']: + # Hack - highlight widgets like HyperlinkLabel with a non-default cursor + widget.configure(foreground = self.current['highlight'], + background = self.current['background']) elif 'activeforeground' in widget.keys(): # e.g. tk.Button, tk.Label, tk.Menu widget.configure(foreground = self.current['foreground'], @@ -146,10 +143,6 @@ class _Theme: # e.g. Frame widget.configure(background = self.current['background']) - for widget in self.widgets_highlight: - widget.configure(foreground = self.current['highlight'], - background = self.current['background']) - for pair, gridopts in self.widgets_pair: for widget in pair: widget.grid_remove() diff --git a/ttkHyperlinkLabel.py b/ttkHyperlinkLabel.py index e845e45a..734d44c9 100644 --- a/ttkHyperlinkLabel.py +++ b/ttkHyperlinkLabel.py @@ -95,12 +95,13 @@ class HyperlinkLabel(platform == 'darwin' and tk.Label or ttk.Label, object): self.font_u.configure(underline = True) kw['font'] = self.underline is True and self.font_u or self.font_n - # Hover cursor only if widget is enabled and text is non-empty - if ('text' in kw or 'state' in kw) and 'cursor' not in kw: - if self.url and (kw['text'] if 'text' in kw else self['text']) and (kw['state'] if 'state' in kw else str(self['state']))!=tk.DISABLED: + if 'cursor' not in kw: + if (kw['state'] if 'state' in kw else str(self['state'])) == tk.DISABLED: + kw['cursor'] = 'arrow' # System default + elif self.url and (kw['text'] if 'text' in kw else self['text']): kw['cursor'] = platform=='darwin' and 'pointinghand' or 'hand2' else: - kw['cursor'] = 'arrow' # System default + kw['cursor'] = (platform=='darwin' and 'notallowed') or (platform=='win32' and 'no') or 'circle' super(HyperlinkLabel, self).configure(cnf, **kw)