jarvisteach / appJar

Simple Tkinter GUIs in Python
http://appJar.info
Other
615 stars 68 forks source link

Menu Keybind Shortcuts don't seem to toggle CheckBox Menuitems #512

Closed robertmlinden closed 6 years ago

robertmlinden commented 6 years ago
self.addMenuCheckBox(self.config_menu_id, self.autolaunch_option, func=self.toggle_autolaunch, shortcut='Control-G')

Metainformation: appJar 0.93 Python 3.6 Windows 10

jarvisteach commented 6 years ago

Interesting one... the code across the menu widgets is all fairly generic.

The accelerator (shortcut) & function are passed straight to the tkinter function that creates the checkbox - this links the function to the action of clicking the menu item, and displays the shortcut alongside it.

There is then a separate piece of code that binds the shortcut to the function - which seems to have been causing you some issues already!

There's obviously a gap here - the binding is triggering the function, rather than triggering the menu

So, you could use: .setMenuCheckBox(menu, name) & .getMenuCheckBox(menu, name) to toggle the menu when your function is called (although you might need to set a flag so that toggling the checkbox doesn't run your function again!)

But, it should be toggled automatically....

I think the code will need to be changed, so that an internal function is associated with checkboxes, that first toggles the checkbox, before then calling the user's function.

jarvisteach commented 6 years ago

Just tested this on the Pi - including the line .setMenuCheckBox(menu, name) in your function will toggle the checkbox, and doesn't trigger the function again - result!

robertmlinden commented 6 years ago

That did the trick, thanks for all the hlp!

jarvisteach commented 6 years ago

@robertmlinden - actually, playing with this some more this morning, it fixes the keyboard shortcut, but breaks simply clicking the menu item - as it now gets toggled twice.

I've pushed a fix into next_release which fixes it for all, so you won't need to add any extra code to get it to work...