Skip to main content

Breathe

Build Status codecov

A convenient API for creating dragonfly grammars with automatic CCR (continuous command recognition).

  • Very quick start-up
  • Command activity can be controlled either using dragonfly contexts or using "enable" and "disable" commands.
  • All commands which match the current context may be chained together in any order in the same utterance.

Installation

pip install dfly-breathe

Instructions

  • If you are creating a command set from scratch, start by cloning the Breathe skeleton project, which will give you a file structure to start with.

Adding commands

from dragonfly import *
from breathe import Breathe, CommandContext

Breathe.add_commands(
    # Commands will be active either when we are editing a python file
    # or after we say "enable python". pass None for the commands to be global.
    context = AppContext(title=".py") | CommandContext("python"),
    mapping = {
        "for each"              : Text("for  in :") + Key("left:5"),
        "for loop"              : Text("for i in range():") + Key("left:2"),
        "from import"           : Text("from  import ") + Key("home, right:5"),
        "function"              : Text("def ():") + Key("left:3"),
        "(iffae | iffy)"        : Text("if :") + Key("left"),
        "iffae not"             : Text("if not :") + Key("left"),
        "import"                : Text("import "),
        "lambda"                : Text("lambda :") + Key("left"),
        "while loop"            : Text("while :") + Key("left"),
        "shell iffae"           : Text("elif :") + Key("left"),
        "shells"                : Text("else:"),
        "return"                : Text("return "),
        # ------------------------------------------------
        "method <snaketext>"    : Text("def %(snaketext)s(self):") + Key("left:2"),
        "function [<snaketext>]": Text("def %(snaketext)s():") + Key("left:2"),
        "selfie [<snaketext>]"  : Text("self.%(snaketext)s"),
        "pointer [<snaketext>]" : Text(".%(snaketext)s"),
        "classy [<classtext>]"  : Text("class %(classtext)s:") + Key("left"),
    },
    extras = [
        Dictation("snaketext", default="").lower().replace(" ", "_"),
        Dictation("classtext", default="").title().replace(" ", ""),
    ]
)

For full details of the available contexts, actions and extras you can use, see the dragonfly documentation.

Loading command files

Breathe provides the command "rebuild everything" for reloading all of your commands, allowing you to modify commands without restarting the engine. In order for this to work, your command files need to be loaded by giving your directory structure to Breathe.load_modules().

For example, given a directory set up like this:

|   _main.py
|   __init__.py
+---my_commands
|   |   __init__.py
|   +---apps
|   |       chrome.py
|   |       notepad.py
|   |       __init__.py
|   +---core
|   |       alphabet.py
|   |       keys.py
|   |       __init__.py
|   +---language
|   |       c.py
|   |       python.py
|   |       __init__.py

Inside _main.py, the file which will be loaded by the engine, we load all of our command files by passing a dictionary with keys representing folder names and values being either a single module to import, a list of modules to import, or another dictionary. Like so:

from breathe import Breathe

Breathe.load_modules(
    {
        "my_commands": {
            "apps": ["chrome", "notepad"],
            "language": ["python", "c"],
            "core": ["keys", "alphabet"],
        }
    }
)

Given this setup, calling the "rebuild everything" command will reload all of your command files, making any changes available.

Custom top level commands

Advanced feature, if you are just getting started you should ignore this.

Top level commands allow you to embed sequences of breathe CCR commands inside other commands. This gives finer control over the way in which commands are recognised and executed.

Top level commands should be added in a separate add_commands call with the top_level option set to True. A couple of new elements - Exec and CommandsRef - are required to control them.

For example in the following, the first command implements "greedy" dictation by creating a top level command which recognises between zero and twelve of the commands which are active in the current context, followed by a dictation command which will consume the rest of the utterance. The second allows an arbitrary sequence of commands to be repeated a given number of times.

from dragonfly import *
from breathe import Breathe, CommandsRef, Exec

Breathe.add_commands(
    None,
    {
        "[<sequence_of_commands>] dictate <text>":
            Exec("sequence_of_commands") + Text("%(text)s"),
        "<sequence_of_commands> and repeat that <n> times":
            Exec("sequence_of_commands") * Repeat("n"),
    },
    [
        Dictation("text"),
        IntegerRef("n", 1, 100),
        CommandsRef("sequence_of_commands", 12)
    ],
    top_level=True
)

Examples

Metadata

Release files for dfly-breathe 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dfly-breathe 0.2.4
File Size Uploaded Provenance Actions
dfly-breathe-0.2.4.tar.gz 12.2 kB Without provenance Details for dfly-breathe-0.2.4.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for dfly-breathe 0.2.4
File Interpreter ABI Platform Actions
dfly_breathe-0.2.4-py3-none-any.whl Python 3 none any Details for dfly_breathe-0.2.4-py3-none-any.whl
dfly_breathe-0.2.4-py2-none-any.whl Python 2 none any Details for dfly_breathe-0.2.4-py2-none-any.whl

Total release size: 44.5 kB

Release files / dfly-breathe-0.2.4.tar.gz

Download URL dfly-breathe-0.2.4.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
85bb1425439130c644c379a948084cab2fea3ecc235300fb317372f28b186440
BLAKE2b-256 checksum
How to use checksums
84ba0db9aab615f317bcf8a849de2bab2dc4f0ce64983a2fbafcb4cb5f732256
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release files / dfly_breathe-0.2.4-py3-none-any.whl

Download URL dfly_breathe-0.2.4-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15eb25884c2e838c59e857b50ad8462206e555b9a308cce93f4d0b9e3ce7d241
BLAKE2b-256 checksum
How to use checksums
1aed80bd7ad6483302f448ed7fa084163c61f4ab6fa46d0aacaec1ff45e945a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release files / dfly_breathe-0.2.4-py2-none-any.whl

Download URL dfly_breathe-0.2.4-py2-none-any.whl
Size 16.2 kB
Tags Python 2
SHA-256 checksum
How to use checksums
1e5be5706118b767737a2461a06eb349eb03bd428e6e10eb41a4f9b73855db76
BLAKE2b-256 checksum
How to use checksums
6f7508f4af56b4507a21f97bba5d72d6cf2f3565eb57d1dc98ac8010453588c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Security for dfly-breathe 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page