Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Black Mamba - open quickly and other shortcuts
-
Hi all,
I mainly work with Pythonista on the biggest iPad with external keyboard. And I miss some features like Open quickly, registering shortcuts for my scripts, ... so I decided to add them by myself. Hope it will be natively supported in the future.
Here's screen recording of what I can do with external keyboard only. If you would like to try it, feel free to clone all files from pythonista-site-packages-3 repository to your local
site-packages-3
folder. Just download them or usegit
via StaSH.Then you can hit ...
Cmd /
- to toggle commentsCmd N
- to open new tab and to show new file dialogCmd Shift N
- to open just new tabCmd 0
(zero) - to toggle library view (I call it navigator)Cmd W
- to close current tabCmd Shift W
- to close all tabs except current oneCmd O
(letter o) - to quickly open files
If you need more shortcuts for more actions, just let me know and I'll try to add them.
WARNING It works, but it's experimental, dangerous. There's some swizzling, some direct calls to ObjC instances, passing guessed parameter values, etc. It can crash your Pythonista, you can lost data, ... I warned you :) If you will modify this code and Pythonista will crash during startup, just open
pythonista3://
in your browser and fix your changes.Will write more issues, so, Pythonista modules can be enhanced (like
editor
module functions to close tab, open file, etc.). Then I can remove some of these crazy calls.Back to open quickly ... It just supports Python (
.py
) and Markdown (.md
) files. That's because I have no clue yet what should I pass as editor type, when force reload should be used, ... Also some directories are excluded, so, you know why if some files are missing in open quickly dialog. Also the open quickly dialog has hidden title bar -> no close button -> you need to hit Esc (or Ctrl [ on smart keyboard) to close it.Anyway, it's pretty scary, fascinating, ... that we can do all these things directly on iPad. Many thanks to Ole for this wonderful tool. This tool let me play with Python on iPad and I can drive our AWS services directly from iPad as well. I'm not forced to bring MBP everywhere, iPad is enough :) Thanks again.
Enjoy!
-
Ouch, did forget to commit
key_events.py
. Fixed, everything's in place. Sorry. -
I did move these hacks into the
blackmamba
(Pythonista on steroids) package, so, it will not interfere with another packages you already have in thesite-packages-3
folder. -
I'm dumb :) Did spend lot of time in the runtime searching for correct function to call that I completely missed that
editor.open_file
already exists. Open Quickly is no longer limited to Python & Markdown files only.Also I just added
Cmd-Shift-0
(zero) to open Dash with a) selected text as a query, b) if there's no selection, cursor position is used to find identifier around it. -
@zrzka said:
Also I just added Cmd-Shift-0 (zero) to open Dash with a) selected text as a query, b) if there's no selection, cursor position is used to find identifier around it.
Very nice idea!
-
@zrzka, thanks. This is looking pretty cool. Is there a strategy that i can clone the repo into the site-package-3 dir. i cloned it then moved it, i was a little unsure of what i was doing. Maybe this cant be done because of site-packages-3 being a special folder. Not sure. But maybe I should just clone the blackmamba dir and deal with the startup seperately. I just want to be able to update as you update by doing a git pull, rather than moving etc...
I have one suggestion, is to do print statements in your startup file. Just a few to say what's going on. I do that for my simple startup for changing the screen brightness, font size, turning off animations etc...Anyway, just a suggestion. I inserted a print line just saying 'doing some blackmamba stuff'.
-
You can clone it directly into the
site-packages-3
folder in this way ...[site-packages-3]$ pwd ~/Documents/site-packages-3 [site-packages-3]$ ls -la .git (352.0B) 2017-08-12 10:15:40 LICENSE (1.2K) 2017-08-12 10:15:40 Readme.md (2.2K) 2017-08-12 10:15:40 blackmamba (384.0B) 2017-08-12 10:15:40 external_screen.py (5.6K) 2017-08-12 10:15:40 pythonista_startup.py (1.3K) 2017-08-12 10:15:40 [site-packages-3]$ rm -rf .git LICENSE Readme.md blackmamba external_screen.py pythonista_startup.py [site-packages-3]$ ls -la [site-packages-3]$ git clone https://github.com/zrzka/pythonista-site-packages-3.git [site-packages-3]$ ls -la .git (352.0B) 2017-08-12 10:16:16 LICENSE (1.2K) 2017-08-12 10:16:15 Readme.md (2.2K) 2017-08-12 10:16:15 blackmamba (384.0B) 2017-08-12 10:16:15 external_screen.py (5.6K) 2017-08-12 10:16:15 pythonista_startup.py (1.3K) 2017-08-12 10:16:16 [site-packages-3]$
And then you can update it via
git pull
...[site-packages-3]$ pwd ~/Documents/site-packages-3 [site-packages-3]$ git pull [site-packages-3]$
-
Added some comments as requested and I also created
blackmamba.startup
file where all the startup things are done. Then I removedpythonista_startup.py
from GitHub repo, so, it will not interfere with yourpythonista_startup.py
file and did add Installation section to the readme. Just copy & paste the lines from this section to yourpythonista_startup.py
file. This will be stable interface for BM initialization. Alsopythonista_startup.py
file is ignored by git (.gitignore
), feel free to modify it, add your custom routines,git pull
will be happy.Yeah, I know it's akward installation process, but because I still consider it as hack, not going to provide better way to install / update it. And I hope that some of these features will be added to the Pythonista, thus lot of things will be removed, new ones added, ...
-
@zrzka, sorry. I cant see what I am doing wrong. I have done this a few times so all your cmds are not there. But I think you can see from the printout below, the site-packages-3 dir is empty before I do the clone. Bu you can see I only end up with a single folder in the site-packages-3 dir after the clone.
I cant see what I am doing wrong[site-packages-3]$ pwd
~/Documents/site-packages-3
[site-packages-3]$ ls -la[site-packages-3]$ git clone https://github.com/zrzka/pythonista-site-packages-3.git
[site-packages-3]$ ls -la
pythonista-site-packages-3 (256.0B) 2017-08-12 15:39:32
[site-packages-3]$ -
I had probably older StaSH. Did update StaSH and you're right, now
git clone
behaves correctly. So the clone command is:git clone https://github.com/zrzka/pythonista-site-packages-3.git .
(<- space dot at the end)
-
@zrzka , perfect, works great. Thanks for your help. You might want to make a note in your installation instructions about the trailing period. I can see you changed it, but this would trip up newbies like me.
-
Done :) More updates later, going to take week off :)
-
@zrzka , ok. Enjoy. Thanks again.
-
cool,perfect,thanks.
and wish @omz next pythonista update can support it native.
-
@zrzka, hey. I know you are off right now, hope you are having a good break. But when you return could you consider having a (dedicated) key combo (cmd-something) that you can apply to invoke a given wrench menu item. Eg. Maybe the user could pass the name of the wrench item name as a param in the bm.start('StaSh'). I guess it could also be a .py filename. Although that seems a bit more on the wild side. Maybe you have some better ideas than that.
I also mention dedicated, because I think it would get infinitely more complicated to let users to map their own keys.
Anyway thanks again, still only a day or so with what you have done so far and its very useful for me with the Apple iPad Pro keyboard. -
@Phuket2 thanks for the suggestions.
Open Quickly
I would like to reuse Open Quickly dialog (when I refactor it) for:
- Run Quickly (search for just
.py
and run it, basically emulation of open and tapping on play), - Wrench Quickly, same idea, but you can search for wrench items.
UI for mapping keys
I'm not going to provide UI for mapping keys, because it's a lot of work, which can be replaced with something more simpler. I can remove HW shortcuts registration from
bm.start
, can provide something likebm.register_default_key_commands
. And if you don't call this function in yourpythonista_startup.py
file, feel free to map your own shortcuts viabm.register_key_command
. Or call it and add your own afterbm.start()
.Shortcut for the wrench item
Just do this in your
pythonista_startup.py
file:#!python3 import blackmamba.startup as bm import blackmamba.key_commands as bkc import blackmamba.uikit as bui def launch_wrench_item(name): print('Wrench item: {}'.format(name)) def launch_stash(): launch_wrench_item('StaSh') bm.start() bkc.register_key_command( bkc.PYTHONISTA_SCOPE_EDITOR, 'S', bui.UIKeyModifierCommand | bui.UIKeyModifierShift, launch_stash, 'Launch StaSh')
This maps
Cmd-Shift-S
tolaunch_stash
, where you can do whatever you want :) - Run Quickly (search for just
-
Some breaking changes pushed. Check Usage section in the readme. Summary:
external_screen.py
moved toblackmamba/experimental
blackmamba/startup.py
trashedregister_default_key_commands
introduced inblackmamba/__init__.py
- removed scope in
blackmamba/key_commands.py
- usage examples updated
- repository renamed (
pythonista-site-packages-3
->blackmamba
)
If you don't want to check all these changes, just update your
pythonista_startup.py
content:#!python3 import blackmamba as bm bm.register_default_key_commands()
-
@zrzka , hey thanks. The git pull worked perfectly. Thanks for your help to get it setup correctly. Makes a huge difference being able to do that. I haven't added my own keys yet, but will put some thought into it. I am always running 'Check Style' and 'Reformat Code' these days so I am guessing, i just need to find these scripts and run them from function stubs like you do with the hallo example. Anyway, will give it a go later.
Thanks again. This is really fantastic with an external keyboard. I am sure a lot of other apps would be envious of this ability.Oppps, sorry, I missed the post above this...Looks like the wrench keys have been handled. That's great. I will try them now!!!!
-
@Phuket2 wrench item(s) are not handled yet. It's just silly example how to print smth with keyboard shortcut. I'll try to add run script / wrench item today. Then you'll be able to use it.
-
@zrzka , ok. Cool. I had a lame attempt to get it working and started going down a rabbit hole. But for me it will be a big help. Esp the check styles/reformat code. @ccc has beaten me with a big stick so I don't dare to push anything anymore until I have done all the checks :) I find it super annoying and time consuming. But I am happy I am staring to take the time to do things properly. Just a matter of time it will become second nature.
Ok, will keep a look out for the next update :)