Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
feat: modify Tk backend managers to use ttk buttons and separators#28659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes fromall commits
61f2e47
25d58f9
4963bf4
c713159
188d698
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -11,6 +11,7 @@ | ||
import tkinter.font | ||
import tkinter.messagebox | ||
from tkinter.simpledialog import SimpleDialog | ||
from tkinter import ttk | ||
import numpy as np | ||
from PIL import Image, ImageTk | ||
@@ -685,7 +686,7 @@ | ||
scale correctly to pixels. | ||
""" | ||
for widget in self.winfo_children(): | ||
if isinstance(widget, (tk.Button, tk.Checkbutton, ttk.Button)): | ||
if hasattr(widget, '_image_file'): | ||
# Explicit class because ToolbarTk calls _rescale. | ||
NavigationToolbar2Tk._set_image_for_button(self, widget) | ||
@@ -920,6 +921,29 @@ | ||
self._buttons['Forward']['state'] = state_map[can_forward] | ||
class NavigationToolbar2Ttk(NavigationToolbar2Tk): | ||
"""Subclass of NavigationToolbar2Tk that implements ttk widgets""" | ||
def _Button(self, text, image_file, toggle, command): | ||
im = tk.PhotoImage(master=self, file=image_file) | ||
b = ttk.Button(self, text=text, padding=(2, 2), image=im, command=command) | ||
b._ntimage = im | ||
b.pack(side='left') | ||
return b | ||
Comment on lines +927 to +931 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This implementation appears outdated compared to the original There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm not sure I see what you mean; the original | ||
def _Spacer(self): | ||
s = ttk.Separator(master=self, orient='vertical') | ||
s.pack(side='left', padx='3p', pady='5p', fill='y') | ||
return s | ||
def _update_buttons_checked(self): | ||
for text in ['Zoom', 'Pan']: | ||
if text in self._buttons: | ||
if self.mode.name == text.upper(): | ||
self._buttons[text].state(['pressed']) | ||
else: | ||
self._buttons[text].state(['!pressed']) | ||
def add_tooltip(widget, text): | ||
tipwindow = None | ||
@@ -957,11 +981,11 @@ | ||
@backend_tools._register_tool_class(FigureCanvasTk) | ||
class RubberbandTk(backend_tools.RubberbandBase): | ||
def draw_rubberband(self, x0, y0, x1, y1): | ||
NavigationToolbar2Ttk.draw_rubberband( | ||
self._make_classic_style_pseudo_toolbar(), None, x0, y0, x1, y1) | ||
def remove_rubberband(self): | ||
NavigationToolbar2Ttk.remove_rubberband( | ||
self._make_classic_style_pseudo_toolbar()) | ||
@@ -992,7 +1016,7 @@ | ||
self._groups = {} | ||
def _rescale(self): | ||
returnNavigationToolbar2Ttk._rescale(self) | ||
def add_toolitem( | ||
self, name, group, position, image_file, description, toggle): | ||
@@ -1002,8 +1026,8 @@ | ||
before = None | ||
else: | ||
before = buttons[position] | ||
button =NavigationToolbar2Ttk._Button(frame, name, image_file, toggle, | ||
lambda: self._button_click(name)) | ||
button.pack_configure(before=before) | ||
if description is not None: | ||
add_tooltip(button, description) | ||
@@ -1021,7 +1045,7 @@ | ||
return self._groups[group] | ||
def _add_separator(self): | ||
returnNavigationToolbar2Ttk._Spacer(self) | ||
def _button_click(self, name): | ||
self.trigger_tool(name) | ||
@@ -1046,14 +1070,14 @@ | ||
@backend_tools._register_tool_class(FigureCanvasTk) | ||
class SaveFigureTk(backend_tools.SaveFigureBase): | ||
def trigger(self, *args): | ||
NavigationToolbar2Ttk.save_figure( | ||
self._make_classic_style_pseudo_toolbar()) | ||
@backend_tools._register_tool_class(FigureCanvasTk) | ||
class ConfigureSubplotsTk(backend_tools.ConfigureSubplotsBase): | ||
def trigger(self, *args): | ||
NavigationToolbar2Ttk.configure_subplots(self) | ||
@backend_tools._register_tool_class(FigureCanvasTk) | ||
@@ -1065,7 +1089,7 @@ | ||
Toolbar = ToolbarTk | ||
FigureManagerTk._toolbar2_class =NavigationToolbar2Ttk | ||
FigureManagerTk._toolmanager_toolbar_class = ToolbarTk | ||
Uh oh!
There was an error while loading.Please reload this page.