Forum Archive

Keyboard shortcuts (Physical)

shaun-h

I have been wanting to add new keycommands to pythonista so that I can navigate the ui with less touching of the screen, so this one is probably aimed at @omz more as it is a question about internals to pythonista.

I can happily add keycommands to the app, but @omz, if you are happy to share or even if it is possible, I am looking for a way to open the "new file" view by using a keycommand as well as show/hide the file browser list. Do you have any pointers to where I should look for these?

JonB

https://github.com/jsbain/objc_hacks/blob/master/addnewfileshowchooser.py

not entirely clean, but should be usable. show_file_chooser_panel shows the file chooser, optionslly creating a new tab first. add_new_file is equivalent to clicking the new tab button, then clicking the new file button on the resulting empty tab.

I feel like there might be a better way to show the editor, console.hide_output requires the annoying time.sleep which might not be robust (for instance, if the editor has a large file) e

shaun-h

Thanks @JonB I have taken a couple of your scripts and created a script that adds physical keyboard shortcuts to create a new tab, show the new file dialog and show/hide the filebrowser. GitHub link

This has been barely tested and you can't use a method with a name with an _ in it.

shaun-h

@JonB I am hoping you can help, the script I created a while ago that based on your keycommands script no longer works (yours doesn't either). I now get this error

AddKeyCommands.py", line 64, in addKeyCommandToPythonista
aa = getattr(CmdHHandler_obj, me.__name__).method
AttributeError: 'ObjCInstanceMethodProxy' object has no attribute 'method'

I cant work out how to fix it. If you can take a look that would be fantastic.

scj643

I plan on adding this feature to my objc_tools lib like many other features.

scj643

http://nshipster.com/uikeycommand/ Seems subclasses need to be able to become first responders

JonB

The correct way to get an instance method IMP in recent versions is

aa = ObjCInstanceMethod(CmdHHandler_obj, me.__name__).method

Use that on line 64

shaun-h

@scj643 if you want to take a look how it is implemented go right ahead and add it to objc_tools library. A lot of my implementation came from @jonb

Thanks @jonb this working now.