Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf79080

Browse files
committed
Switch tk pan/zoom to use togglable buttons.
... consistently with other backends.The code for syncing button state is similar to the one for gtk3.
1 parent065769b commitaf79080

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

‎lib/matplotlib/backends/_backend_tk.py

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,26 @@ def set_cursor(self, cursor):
533533
window.configure(cursor=cursord[cursor])
534534
window.update_idletasks()
535535

536-
def_Button(self,text,file,command,extension='.gif'):
537-
img_file=str(cbook._get_data_path('images',file+extension))
538-
im=tk.PhotoImage(master=self,file=img_file)
539-
b=tk.Button(
540-
master=self,text=text,padx=2,pady=2,image=im,command=command)
536+
def_Button(self,text,image_file,toggle,command):
537+
ifimage_fileisnotNone:
538+
im=tk.PhotoImage(master=self,file=image_file)
539+
else:
540+
im=None
541+
ifnottoggle:
542+
b=tk.Button(master=self,text=text,padx=2,pady=2,image=im,
543+
command=command)
544+
else:
545+
# There is a bug in tkinter included in some python 3.6 versions
546+
# that without this variable, produces a "visual" toggling of
547+
# other near checkbuttons
548+
# https://bugs.python.org/issue29402
549+
# https://bugs.python.org/issue25684
550+
var=tk.IntVar()
551+
b=tk.Checkbutton(master=self,text=text,padx=2,pady=2,
552+
image=im,indicatoron=False,
553+
command=command,
554+
variable=var)
555+
b.var=var
541556
b._ntimage=im
542557
b.pack(side=tk.LEFT)
543558
returnb
@@ -558,20 +573,42 @@ def _init_toolbar(self):
558573

559574
self.update()# Make axes menu
560575

576+
self._buttons= {}
561577
fortext,tooltip_text,image_file,callbackinself.toolitems:
562578
iftextisNone:
563579
# Add a spacer; return value is unused.
564580
self._Spacer()
565581
else:
566-
button=self._Button(text=text,file=image_file,
567-
command=getattr(self,callback))
582+
self._buttons[text]=button=self._Button(
583+
text,
584+
str(cbook._get_data_path(f"images/{image_file}.gif")),
585+
toggle=callbackin ["zoom","pan"],
586+
command=getattr(self,callback),
587+
)
568588
iftooltip_textisnotNone:
569589
ToolTip.createToolTip(button,tooltip_text)
570590

571591
self.message=tk.StringVar(master=self)
572592
self._message_label=tk.Label(master=self,textvariable=self.message)
573593
self._message_label.pack(side=tk.RIGHT)
574594

595+
def_update_buttons_checked(self):
596+
forname,activein [("Pan","PAN"), ("Zoom","ZOOM")]:
597+
button=self._buttons.get(name)
598+
ifbutton:
599+
ifself._active==activeandnotbutton.var.get():
600+
button.select()
601+
elifself._active!=activeandbutton.var.get():
602+
button.deselect()
603+
604+
defpan(self,*args):
605+
super().pan(*args)
606+
self._update_buttons_checked()
607+
608+
defzoom(self,*args):
609+
super().zoom(*args)
610+
self._update_buttons_checked()
611+
575612
defconfigure_subplots(self):
576613
toolfig=Figure(figsize=(6,3))
577614
window=tk.Toplevel()
@@ -717,7 +754,8 @@ def __init__(self, toolmanager, window):
717754
defadd_toolitem(
718755
self,name,group,position,image_file,description,toggle):
719756
frame=self._get_groupframe(group)
720-
button=self._Button(name,image_file,toggle,frame)
757+
button=NavigationToolbar2Tk._Button(self,name,image_file,toggle,
758+
lambda:self._button_click(name))
721759
ifdescriptionisnotNone:
722760
ToolTip.createToolTip(button,description)
723761
self._toolitems.setdefault(name, [])
@@ -736,30 +774,6 @@ def _add_separator(self):
736774
separator=tk.Frame(master=self,bd=5,width=1,bg='black')
737775
separator.pack(side=tk.LEFT,fill=tk.Y,padx=2)
738776

739-
def_Button(self,text,image_file,toggle,frame):
740-
ifimage_fileisnotNone:
741-
im=tk.PhotoImage(master=self,file=image_file)
742-
else:
743-
im=None
744-
745-
ifnottoggle:
746-
b=tk.Button(master=frame,text=text,padx=2,pady=2,image=im,
747-
command=lambda:self._button_click(text))
748-
else:
749-
# There is a bug in tkinter included in some python 3.6 versions
750-
# that without this variable, produces a "visual" toggling of
751-
# other near checkbuttons
752-
# https://bugs.python.org/issue29402
753-
# https://bugs.python.org/issue25684
754-
var=tk.IntVar()
755-
b=tk.Checkbutton(master=frame,text=text,padx=2,pady=2,
756-
image=im,indicatoron=False,
757-
command=lambda:self._button_click(text),
758-
variable=var)
759-
b._ntimage=im
760-
b.pack(side=tk.LEFT)
761-
returnb
762-
763777
def_button_click(self,name):
764778
self.trigger_tool(name)
765779

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp