Dict for storing toolbar buttons
@@ -120,6 +120,7 @@ class Workbench(tk.Tk):
self._current_theme_name = "clam" # will be overwritten later
self._backends = {} # type: Dict[str, BackendSpec]
self._commands = [] # type: List[Dict[str, Any]]
+ self._toolbar_buttons = {}
self._view_records = {} # type: Dict[str, Dict[str, Any]]
self.content_inspector_classes = [] # type: List[Type]
self._latin_shortcuts = {} # type: Dict[Tuple[int,int], List[Tuple[Callable, Callable]]]
@@ -826,8 +827,8 @@ class Workbench(tk.Tk):
accelerator += " or " + sequence_to_accelerator(extra_seq)
"""
-
if include_in_menu:
+
def dispatch_from_menu():
# I don't like that Tk menu toggles checbutton variable
# automatically before calling the handler.
@@ -841,7 +842,6 @@ class Workbench(tk.Tk):
dispatch(None)
-
if _image and lookup_style_option("OPTIONS", "icons_in_menus", True):
menu_image = _image # type: Optional[tk.PhotoImage]
elif flag_name:
@@ -850,7 +850,6 @@ class Workbench(tk.Tk):
else:
menu_image = self.get_image("16x16-blank")
-
# remember the details that can't be stored in Tkinter objects
self._menu_item_specs[(menu_name, command_label)] = MenuItem(
group, position_in_group, tester
@@ -872,7 +871,14 @@ class Workbench(tk.Tk):
toolbar_group = self._get_menu_index(menu) * 100 + group
assert caption is not None
self._add_toolbar_button(
- _image, command_label, caption, accelerator, handler, tester, toolbar_group
+ command_id,
+ _image,
+ command_label,
+ caption,
+ accelerator,
+ handler,
+ tester,
+ toolbar_group,
)
def add_view(
@@ -1611,6 +1617,7 @@ class Workbench(tk.Tk):
def _add_toolbar_button(
self,
+ command_id: str,
image: Optional[tk.PhotoImage],
command_label: str,
caption: str,
@@ -1654,6 +1661,11 @@ class Workbench(tk.Tk):
tooltip_text += " (" + accelerator + ")"
create_tooltip(button, tooltip_text)
+ self._toolbar_buttons[command_id] = button
+
+ def get_toolbar_button(self, command_id):
+ return self._toolbar_buttons[command_id]
+
def _update_toolbar(self) -> None:
if self._destroyed or not hasattr(self, "_toolbar"):
return
