From 749181b0b5c4ce554542f6c3213be31f39421240 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 25 Jul 2019 15:52:37 +0200 Subject: Tooltip label for menubar --- jfr_playoff/gui/__init__.py | 17 +++++++++++------ jfr_playoff/gui/frames/__init__.py | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/jfr_playoff/gui/__init__.py b/jfr_playoff/gui/__init__.py index b563493..09d9c98 100644 --- a/jfr_playoff/gui/__init__.py +++ b/jfr_playoff/gui/__init__.py @@ -10,6 +10,7 @@ import tkMessageBox as tkmb from .tabs import * from .icons import GuiImage +from .frames import LabelButton class PlayoffGUI(tk.Tk): def __init__(self): @@ -71,13 +72,17 @@ class PlayoffGUI(tk.Tk): def _buildMenu(self): menu = tk.Frame(self) menu.pack(side=tk.TOP, fill=tk.X) + statusBar = ttk.Label(menu) + statusBar.pack(side=tk.RIGHT) self.menuButtons = {} - for icon, command in [('new', self.onNewFile), - ('open', self.onFileOpen), - ('save', self.onSave), - ('saveas', self.onSaveAs)]: - self.menuButtons[icon] = ttk.Button( - menu, image=GuiImage.get_icon(icon), command=command) + for icon, command, tooltip in [ + ('new', self.onNewFile, 'Nowa drabinka...'), + ('open', self.onFileOpen, 'Otwórz drabinkę...'), + ('save', self.onSave, 'Zapisz'), + ('saveas', self.onSaveAs, 'Zapisz jako...')]: + self.menuButtons[icon] = LabelButton( + menu, image=GuiImage.get_icon(icon), command=command, + tooltip=tooltip, label=statusBar) self.menuButtons[icon].pack(side=tk.LEFT) def onNewFile(self): diff --git a/jfr_playoff/gui/frames/__init__.py b/jfr_playoff/gui/frames/__init__.py index 855be4e..f996263 100644 --- a/jfr_playoff/gui/frames/__init__.py +++ b/jfr_playoff/gui/frames/__init__.py @@ -476,3 +476,24 @@ class NumericSpinbox(tk.Spinbox): val = self._variable.get() if val is None: self._variable.set(self._default) + +class LabelButton(ttk.Button): + def __init__(self, *args, **kwargs): + self.label = None + self.tooltip = None + self._prevTooltip = None + for param in ['label', 'tooltip']: + if param in kwargs: + setattr(self, param, kwargs[param]) + del kwargs[param] + ttk.Button.__init__(self, *args, **kwargs) + if self.label and self.tooltip: + self.bind('', self._onEnter) + self.bind('', self._onLeave) + + def _onEnter(self, *args): + self._prevTooltip = self.label.cget('text') + self.label.configure(text=self.tooltip) + + def _onLeave(self, *args): + self.label.configure(text=self._prevTooltip) -- cgit v1.2.3