| 658 | |
| 659 | |
| 660 | class NavigationToolbar2Tk(NavigationToolbar2, tk.Frame): |
| 661 | def __init__(self, canvas, window=None, *, pack_toolbar=True): |
| 662 | """ |
| 663 | Parameters |
| 664 | ---------- |
| 665 | canvas : `FigureCanvas` |
| 666 | The figure canvas on which to operate. |
| 667 | window : tk.Window |
| 668 | The tk.Window which owns this toolbar. |
| 669 | pack_toolbar : bool, default: True |
| 670 | If True, add the toolbar to the parent's pack manager's packing |
| 671 | list during initialization with ``side="bottom"`` and ``fill="x"``. |
| 672 | If you want to use the toolbar with a different layout manager, use |
| 673 | ``pack_toolbar=False``. |
| 674 | """ |
| 675 | |
| 676 | if window is None: |
| 677 | window = canvas.get_tk_widget().master |
| 678 | tk.Frame.__init__(self, master=window, borderwidth=2, |
| 679 | width=int(canvas.figure.bbox.width), height=50) |
| 680 | # Avoid message_label expanding the toolbar size, and in turn expanding the |
| 681 | # canvas size. |
| 682 | # Without pack_propagate(False), when the user defines a small figure size |
| 683 | # (e.g. 2x2): |
| 684 | # 1. Figure size that is bigger than the user's expectation. |
| 685 | # 2. When message_label is refreshed by mouse enter/leave, the canvas |
| 686 | # size will also be changed. |
| 687 | self.pack_propagate(False) |
| 688 | |
| 689 | self._buttons = {} |
| 690 | for text, tooltip_text, image_file, callback in self.toolitems: |
| 691 | if text is None: |
| 692 | # Add a spacer; return value is unused. |
| 693 | self._Spacer() |
| 694 | else: |
| 695 | self._buttons[text] = button = self._Button( |
| 696 | text, |
| 697 | str(cbook._get_data_path(f"images/{image_file}.png")), |
| 698 | toggle=callback in ["zoom", "pan"], |
| 699 | command=getattr(self, callback), |
| 700 | ) |
| 701 | if tooltip_text is not None: |
| 702 | add_tooltip(button, tooltip_text) |
| 703 | |
| 704 | self._label_font = tkinter.font.Font(root=window, size=10) |
| 705 | |
| 706 | # This filler item ensures the toolbar is always at least two text |
| 707 | # lines high. Otherwise the canvas gets redrawn as the mouse hovers |
| 708 | # over images because those use two-line messages which resize the |
| 709 | # toolbar. |
| 710 | label = tk.Label(master=self, font=self._label_font, |
| 711 | text='\N{NO-BREAK SPACE}\n\N{NO-BREAK SPACE}') |
| 712 | label.pack(side=tk.RIGHT) |
| 713 | |
| 714 | self.message = tk.StringVar(master=self) |
| 715 | self._message_label = tk.Label(master=self, font=self._label_font, |
| 716 | textvariable=self.message, |
| 717 | justify=tk.RIGHT) |
no outgoing calls
searching dependent graphs…