FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixes issue #1259 - Added modifier key handling for macosx backend by cimarronm · Pull Request #1841 · matplotlib/matplotlib · GitHub

Repository navigation

Fixes issue #1259 - Added modifier key handling for macosx backend - #1841

Merged
dmcdougall merged 3 commits into
matplotlib:masterfrom
cimarronm:macosx+modifiers
Mar 27, 2013
Merged

dmcdougall merged 3 commits into
matplotlib:masterfrom
cimarronm:macosx+modifiers

Conversation

Copy link
Copy Markdown
Contributor

Add modifier key handling to key event handlers for macosx backend. Clean up code to use NS foundation constants for keys and simplified convertKeyEvent selector

pelson commented Mar 22, 2013

Copy link
Copy Markdown
Member

Thanks for submitting this @cimarronm - its great to have your contribution!

@mdehoon is our resident OSX backend expert, so it would be good to have his eyes on this change. I'll build this on my own machine this weekend to give it a whirl. @dmcdougall - I know you're also a ObjC wizz - any comments?

mdehoon commented Mar 22, 2013

Copy link
Copy Markdown
Contributor

@cimarronm , thanks for the contribution. I'll have a look over the next couple of days.

Copy link
Copy Markdown
Member

This will break builds for older Macs due to the use of NSDictionary literals. To support older Macs, an approach that's pre-ObjectiveC-2.0 friendly will be needed.

Copy link
Copy Markdown
Member

I've tried this and it seems to work, at least I tried to close the window using a keyboard shortcut and it worked. I had to use rather than , though. It'd be nice to have the keyboard shortcuts consistent with native OS X applications. Having said that, it is consistent with X window manager applications, and with the other backends, so I'd be happy for this to go in.

A portable approach to the dictionary literal issue could possibility utilise this. I think that would work with Objective-C pre 2.0. Perhaps @mdehoon would also be able to advise in this regard.

Copy link
Copy Markdown
Contributor Author

I'll update my branch to not use objc2.0 literals for the pre 2.0 compiler support...code looks much cleaner with the new literals though ;-)

Also, to change to the native OS X feel for closing the window, you can change the keymap.quit to cmd+w (instead of default ctrl+w) in your matplotlibrc. If it makes sense, maybe we could modify the matplotlibrc template to default to cmd+w if the macosx backend is set upon build/install?

pelson commented Mar 26, 2013

Copy link
Copy Markdown
Member

@cimarronm - I think the order of the modifier keys is important: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_tkagg.py#L460

So if I press ctrl+alt+cmd<a key> the string should be the same on all backends. I believe (untested) as it stands, this change would return cmd+alt+ctrl+<a key>. If I'm correct, would you mind changing the order of your if statements?

I also believe that (at least on the TkAgg backend) pressing ctrl+shift+a actually results in an event with the following key ctrl+A - I'm not sure we had much choice about this with Tk. Ideally it would be nice to be consistent on this front, though I suspect that would mean a whole host of complexities relating to key mappings shudder. Perhaps save this one for another PR? @mdboom thoughts?

For reference see http://matplotlib.org/api/backend_bases_api.html#matplotlib.backend_bases.KeyEvent

mdehoon commented Mar 26, 2013

Copy link
Copy Markdown
Contributor

@dmcdougall , @cimarronm : With respect to the dictionary literal issue, it looks like @cimarronm 's updated code solves it. I'd like to try it on Mac OS X 10.5, just to make sure; I can do so in a few days when I have access to that machine.

With respect to cmd+w vs. ctrl+w for closing the window, I think that by default the Mac OS X backend should follow the native Mac OS X behavior, not the X windows behavior.

pelson commented Mar 26, 2013

Copy link
Copy Markdown
Member

With respect to cmd+w vs. ctrl+w for closing the window, I think that by default the Mac OS X backend should follow the native Mac OS X behavior, not the X windows behavior.

From memory, does cmd+w (or was it cmd+q) not close the window anyway on OSX?

mdehoon commented Mar 26, 2013

Copy link
Copy Markdown
Contributor

@pelson : cmd+w, cmd+q, ctrl+w, ctrl+q do nothing on OSX 10.8 with the current matplotlib.

Copy link
Copy Markdown
Contributor Author

@pelson - The order should be correct. Each statement is appending so you would get ctrl+alt+cmd+. I just tested it to print out what I get when I press the modifiers together and get

  1. (all except shift with a) ctrl+alt+cmd+a
  2. (including shift) ctrl+alt+cmd+shift+A

Should I eliminate the shift modifier?

pelson commented Mar 26, 2013

Copy link
Copy Markdown
Member

@pelson - The order should be correct.

Apologies for that - I agree, it all looks good from that perspective.

If the key is coming through after being shifted (e.g. we have A and not a), then I think consistency suggests we can remove the shift key from the string altogether.

mdehoon commented Mar 27, 2013

Copy link
Copy Markdown
Contributor

I tried this on Mac OS X 10.5. It compiles and seems to work fine.

dmcdougall added a commit that referenced this pull request Mar 27, 2013
Fixes issue #1259 - Added modifier key handling for macosx backend
dmcdougall merged commit 1c2e2be into matplotlib:master Mar 27, 2013
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL