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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcut for numeric keys not working with addMenuItem #298

Closed
WilfriedBl opened this Issue Nov 21, 2017 · 10 comments

Comments

Projects
None yet
2 participants
@WilfriedBl

WilfriedBl commented Nov 21, 2017

I tried to create menu items with the shortcut Control-1 and Control-2. Pressing Ctrl+1 neither calls the specified function produces nor produces any error message. Same result for Alt-, Alt-Control-, or Shift-Control- for any of the numeric keys 1-9.
Interestingly, some of the special characters, e.g. Control-! show the same behavior, whereas others produce an error message '_tkinter.TclError: bad event type or keysym "§"' immediately when addMenuItem is called and others (e.g. <,:#=%& ....) do work fine.
The above applies to appJar version 0.82.1, Python 3.6.2 under Windows 10 pro 64bit Version 1709

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Nov 22, 2017

Could you let me know what platform/version of python?

@WilfriedBl

This comment has been minimized.

WilfriedBl commented Nov 22, 2017

Forgot to mention it yesterday, edited my post this morning and added:
"The above applies to appJar version 0.82.1, Python 3.6.2 under Windows 10 pro 64bit Version 1709"

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Nov 23, 2017

Haha, so you did sorry!

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Nov 23, 2017

Have done a bit of digging, and found this:

https://stackoverflow.com/questions/17241474/controlnumber-tkinter-binding

appJar creates a binding, such as: <Control-1>or <Shift-Control-1>. Accoring to SO, this actually binds the mouse buttons!?!

So, I will need to add in a check to see if it's a number, and if it is, create a slightly different binding: <Control-Key-1> or <Shift-Control-Key-1>

@jarvisteach jarvisteach added the bug label Nov 23, 2017

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Nov 23, 2017

It should also be possible to set shortcut="Control-Key-1" but that breaks it, appJar is messing around with the case, so I will fix that too.

jarvisteach added a commit that referenced this issue Nov 23, 2017

Fixed bug in shortcuts #298
Numeric shortcuts now supported
Updated testing to remove drop and introduce numeric menus
@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Nov 23, 2017

This is resolved (for numeric shortcuts) in the next release.

There was no error, because a shortcut was being created - it was just linking to the mouse button, instead of the number key.

I imagine similar issues exist with special characters - if there's no error, a binding is getting created, just maybe not the one we're expecting...

@WilfriedBl

This comment has been minimized.

WilfriedBl commented Nov 24, 2017

Now, you mentioned it, I remember having had exactly the same issue a couple of month ago while trying to learn using tkinter directly ...
One minor issue with the shortcut:
Regardless, whether you specify a lower or upper case character with shortcut="Control-x", the text in the menu will always be uppercase (e.g. Ctrl-X). While I like it, because it is better to read, it can create some confusion for the programmer as well as the user:

  • Ctrl-X means pressing and holding the control and pressing the x key (which really means lower case x)
  • If the user takes "uppercase" literally and presses Ctrl-Shift-x => nothing happens
  • If the programmer really intends the shift key to pressed => I could not get it to work, neither with "Shift-Control-X", nor "Control-Shift-x". If I remember correctly, tkinter indeed requires the shift key to be pressed, when you code "Control-X" ....?

@jarvisteach jarvisteach added this to the 0.90 milestone Nov 26, 2017

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Nov 26, 2017

Yeah, this is all a bit of a hangover from when I initially introduced the feature.

I tried to make it as bomb proof as possible, so that it was cross-platform and could deal with most of what you threw at it.

Combine that, with the fact that on MAC - all apps display the shortcut in upper case, and I think it does break things a little.

I will look into refactoring the shortcuts for the 1.0 release, and raise that as a new request.

@WilfriedBl

This comment has been minimized.

WilfriedBl commented Nov 26, 2017

A good workaround for numeric keys is the bindKey method as described here:
I just tried "<Control-Key 1>" and it works fine.

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Nov 26, 2017

That's actually how the shortcuts work behind the scenes:

  • a top level binding is created on the gui
  • the displayed menu text is modified to show the shortcut

There's not actually any link between them!

@jarvisteach jarvisteach referenced this issue Nov 26, 2017

Open

Refactor menus #305

6 of 7 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment