mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 15:57:14 +03:00
Automatically highlight widgets that set a custom cursor
This commit is contained in:
parent
084128e797
commit
b794e19d75
@ -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('<Button-1>', 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('<Map>', self.onmap) # Special handling for overrideredict
|
||||
|
15
theme.py
15
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()
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user