Skip to content

cclauss/blackmamba

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Black Mamba

Pythonista on steroids.

Pythonista is a complete development environment for writing Python™ scripts on your iPad or iPhone.

Pythonista is a great tool. But it lacks some features like keyboard shortcuts for specific actions. I'm slow without them. So I decided to write set of scripts to fix all these issues. To speed up my iteration cycle. To make it as fast as possible. And which snake is the speediest one on the planet? Black Mamba. And you know why it's called Black Mamba now :)

Black Mamba Open Quickly...

Black Mamba keyboard shortcuts

It's still an experiment and you can expect breaking changes. I'm trying to avoid them, but I can't promise stable interface for now.

You're welcome to report new issue if you find a bug or would like to have something added. Or pull request which is even better.

Install StaSh - Shell for Pythonista. All following commands are for StaSh.

You can use git way if you'd like to install Black Mamba from the master branch. But it has several drawbacks:

  • It's not officially released, can contain bugs, etc.
  • You can't do this if you already have site-packages-3 folder backed by the git (conflict with .git folder)

Initial installation:

[~/Documents]$ cd site-packages-3
[site-packages-3]$ git clone https://github.com/zrzka/blackmamba.git .

NOTE: Do not miss the space dot at the end of git clone command.

Updates:

[~/Documents]$ cd site-packages-3
[site-packages-3]$ git pull

It's also possible to use PyPI, but it's not recommended now. Two reasons:

  • pip command from StaSh does use XML RPC and responses contain data that are not up to date. In other words, you're not able to install newer version, because pip doesn't see it even if it's available. See #254.
  • And also pip update doesn't work as well. So you have to issue pip remove blackmamba and pip install ... instead of pip update ....

If you'd like to experiment, feel free. I'll keep releasing PyPI versions for sure.

Initial installation:

[~/Documents]$ pip install blackmamba -d ~/Documents/site-packages-3

Updates:

[~/Documents]$ pip update blackmamba

Following examples should be placed in the ~/Documents/site-packages-3/pythonista_startup.py file. Create this file if it doesn't exist.

Also I assume that your file starts with Black Mamba import:

#!python3
import blackmamba as bm

Open/Run Quickly... dialog ignores following folders by default:

  • .git - in any folder
  • .Trash, Examples, site-packages, site-packages-2, site-packages-3 in ~/Documents folder

You can modify it via:

  • bm.settings.OPEN_QUICKLY_IGNORE_FOLDERS - for Open Quickly... dialog
  • bm.settings.RUN_QUICKLY_IGNORE_FOLDERS - for Run Quickly... dialog

Example:

bm.settings.OPEN_QUICKLY_IGNORE_FOLDERS = {
    # '' -> any parent folder
    '': ['.git'],

    # '.' -> ~/Documents parent folder
    '.': ['Pythonista', '.Trash', 'Examples',
          'site-packages-2', 'site-packages', 'stash_extensions'],
          'site-packages-3': ['blackmamba'],

    # 'Development' -> ~/Documents/Development parent folder
    'Development': ['bm-pip-backup']
}

bm.settings.RUN_QUICKLY_IGNORE_FOLDERS = {
    '': ['.git'],
    '.': ['Pythonista', '.Trash', 'Examples',
          'site-packages-2', 'site-packages', 'stash_extensions'],
    'site-packages-3': ['blackmamba'],
    'Development': ['bm-pip-backup']
}
bm.register_default_key_commands()

This registers following keyboard shortcuts you can use with external keyboard. It's optional, you're not forced to register them.

Shortcut Function
Cmd / Comment / uncomment selected line(s)
Cmd W Close current editor tab
Cmd Shift W Close all editor tabs except current one
Cmd N New tab + new file
Cmd T Just new tab
Cmd 0 Show / hide navigator (Library)
Cmd Shift 0 Query selected text in Dash
Cmd Shift O Open Quickly...
Cmd Shift R Run Quickly...
Cmd Shift A Action Quickly...
Ctrl Shift B Analyze & Check Style
Cmd Shift K Clear annotations

WARNING: Run Quickly... and Action Quickly... works only and only if there's no running script. If there's running script, you'll see your script in the editor (new tab), but the script wasn't executed.

How to print Hallo with Cmd Shift H.

def print_hallo():
    print('Hallo')

bm.key_commands.register_key_command(
    'H',
    bm.uikit.UIKeyModifierCommand | bm.uikit.UIKeyModifierShift,
    print_hallo,
    'Print Hallo')

Analyze & Check Style (Ctrl Shift B) runs pyflakes & pep8 code style checks. Analyzer behavior can be modified via following settings variables:

bm.settings.ANALYZER_HUD_DELAY = 1.0

bm.settings.ANALYZER_PEP8_IGNORE = ('W391', )  # Must be a tuple

bm.settings.ANALYZER_PEP8_MAX_LINE_LENGTH = 120

Analyzer always scrolls to the first issue and does not show HUD in case your file contains issues.

#!python3

import blackmamba as bm

################################################################
# Open/Run Quickly... ignore folders                           #
################################################################

# ''           : any parent folder
# '.'          : ~/Documents parent folder
# 'Development': ~/Documents/Development parent folder

bm.settings.OPEN_QUICKLY_IGNORE_FOLDERS = {
    '': ['.git'],
    '.': ['Pythonista', '.Trash', 'Examples',
          'site-packages-2', 'site-packages', 'stash_extensions'],
    'site-packages-3': ['blackmamba'],
    'Development': ['bm-pip-backup']
}

bm.settings.RUN_QUICKLY_IGNORE_FOLDERS = {
    '': ['.git'],
    '.': ['Pythonista', '.Trash', 'Examples',
          'site-packages-2', 'site-packages', 'stash_extensions'],
    'site-packages-3': ['blackmamba'],
    'Development': ['bm-pip-backup']
}

################################################################
# Default Black Mamba external keyboard shortcuts registration #
################################################################

bm.register_default_key_commands()

################################################################
# Analyzer                                                     #
################################################################

bm.settings.ANALYZER_PEP8_IGNORE = ('W391', 'W293')
bm.settings.ANALYZER_PEP8_MAX_LINE_LENGTH = 120

################################################################
# Custom keyboard shortcuts                                    #
################################################################

# Launch StaSh (= custom action title) via Cmd-Shift-S
if bm.ide.action_exists('StaSh'):
    def launch_stash():
        bm.ide.run_action('StaSh')

    bm.key_commands.register_key_command(
        'S',
        bm.uikit.UIKeyModifierCommand | bm.uikit.UIKeyModifierShift,
        launch_stash,
        'Launch StaSh')

# Or you can use run_script instead of action to launch StaSh
#if bm.ide.script_exists('launch_stash.py'):
#    def launch_stash():
#        bm.ide.run_script('launch_stash.py')
#
#    bm.key_commands.register_key_command(
#        'S',
#        bm.uikit.UIKeyModifierCommand | bm.uikit.UIKeyModifierShift,
#        launch_stash,
#        'Launch StaSh')

About

Python packages for Pythonista (iOS)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.6%
  • Shell 0.4%