Example #1
0
def drop_keep_clipboard(nnavi500, nexus, capitalization, spacing):
    # Maintain standard spark functionality for non-strings
    if capitalization == 0 and spacing == 0 and nnavi500 == 1:
        Key("c-v").execute()
        return
    # Get clipboard text
    if nnavi500 > 1:
        key = str(nnavi500)
        if key in nexus.clip:
            text = nexus.clip[key]
        else:
            dragonfly.get_engine().speak("slot empty")
            text = None
    else:
        text = Clipboard.get_system_text()
    # Format if necessary, and paste
    if text is not None:
        cb = Clipboard(from_system=True)
        if capitalization != 0 or spacing != 0:
            text = textformat.TextFormat.formatted_text(
                capitalization, spacing, text)
        Clipboard.set_system_text(text)
        time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.)
        Key("c-v").execute()
        time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.)
        # Restore the clipboard contents.
        cb.copy_to_system()
Example #2
0
def stoosh_keep_clipboard(nnavi500, nexus):
    if nnavi500 == 1:
        Key("c-c").execute()
    else:
        max_tries = 20
        cb = Clipboard(from_system=True)
        Key("c-c").execute()
        key = str(nnavi500)
        for i in range(0, max_tries):
            failure = False
            try:
                # time for keypress to execute
                time.sleep(
                    settings.SETTINGS["miscellaneous"]["keypress_wait"] /
                    1000.)
                nexus.clip[key] = Clipboard.get_system_text()
                utilities.save_toml_file(
                    nexus.clip,
                    settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
            except Exception:
                failure = True
                utilities.simple_log()
            if not failure:
                break
        cb.copy_to_system()
Example #3
0
def bring_add(launch, key):
    '''
    Add current program or highlighted text to bring me
    '''
    key = str(key)
    if launch == "program":
        path = utilities.get_active_window_path()
        if not path:
            # dragonfly.get_engine().speak("program not detected")
            print("Program path for bring me not found ")
    # elif launch == 'file':
    # no way to add file via pyperclip
    else:
        Key("a-d/5").execute()
        fail, path = context.read_selected_without_altering_clipboard()
        if fail == 2:
            #FIXME
            time.sleep(0.1)
            _, path = context.read_selected_without_altering_clipboard()
            if not path:
                # dragonfly.get_engine().speak("nothing selected")
                print("Selection for bring me not found ")
        Key("escape").execute()
    if not path:
        #logger.warn('Cannot add %s as %s to bringme: cannot get path', launch, key)
        return
    CONFIG[launch][key] = path
    utilities.save_toml_file(CONFIG,
                             settings.SETTINGS["paths"]["BRINGME_PATH"])
    refresh()
Example #4
0
def ACP(command, label=None):
    """Utilize the Palette UI to execute commands."""
    if not label:
        label = "Atom: Unlabeled Palette Command: " + command
    return R(Key("cs-p") + Pause(str(atom_palette_wait)) + Text(command) +
             Key("enter"),
             rdescript=label)
Example #5
0
class PythonNon(MappingRule):
    mapping = {
        "try catch":
        R(Text("try:") + Key("enter:2/10, backspace") +
          Text("except Exception:") + Key("enter"),
          rdescript="Python: Try Catch"),
    }
Example #6
0
def next_line(semi):
    semi = str(semi)
    Key("escape").execute()
    time.sleep(0.25)
    Key("end").execute()
    time.sleep(0.25)
    Text(semi).execute()
    Key("enter").execute()
Example #7
0
class PrologNon(MappingRule):
    mapping = {
        "Rule":
        R(Text("() :-.") + Key("left/6"), rdescript="Prolog: rule"),
        SymbolSpecs.IF:
        R(Text("( ") + Key("enter") + Text(";") + Key("enter") + Text(")"),
          rdescript="Prolog: IF"),
    }
Example #8
0
def duple_keep_clipboard(nnavi50):
    cb = Clipboard(from_system=True)
    Key("escape, home, s-end, c-c, end").execute()
    time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.)
    for i in range(0, nnavi50):
        Key("enter, c-v").execute()
        time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.)
    cb.copy_to_system()
Example #9
0
def findNthToken(text, n, direction):
    Key("c-f").execute()
    Text("%(text)s").execute({"text": text})
    if direction == "reverse":
        print("yeah? %(n)d")
        Key("s-enter:%(n)d").execute()
    else:
        Key("enter:%(n)d").execute()
        print("no? %(n)d")
    Key('escape').execute()
Example #10
0
class EclipseCCR(MergeRule):
    pronunciation = "eclipse jump"

    mwith = [Navigation().get_pronunciation()]

    mapping = {
            #Line Ops
            "configure":                                R(Paste(ec_con.analysis_chars)+Key("left:2/5, c-f/20, backslash, rbracket, enter") + \
                                                          Function(ec_con.analyze_for_configure), rdescript="Eclipse: Configure"),
            "jump in [<n>]":                            R(Key("c-f, a-o")+Paste(r"[\(\[\{\<]")+Function(ec_con.regex_on)+ \
                                                          Key("enter:%(n)d/5, escape, right") , rdescript="Eclipse: Jump In"),
            "jump out [<n>]":                           R(Key("c-f, a-o")+Paste(r"[\)\] \}\>]")+Function(ec_con.regex_on)+ \
                                                          Key("enter:%(n)d/5, escape, right") , rdescript="Eclipse: Jump Out"),
            "jump back [<n>]":                          R(Key("c-f/5, a-b")+Paste(r"[\)\]\}\>]")+Function(ec_con.regex_on)+ \
                                                          Key("enter:%(n)d/5, escape, left") , rdescript="Eclipse: Jump Back"),
            "[go to] line <n>":                         R(Key("c-l") + Pause("50") + Text("%(n)d") + Key("enter")+ Pause("50"),
                                                          rdescript="Eclipse: Go To Line"),
            "shackle <n> [<back>]":                     R(Key("c-l")+Key("right, cs-left")+ \
                                                          Function(ec_con.lines_relative), rdescript="Eclipse: Select Relative Lines"),

        }
    extras = [
        Dictation("text"),
        IntegerRefST("n", 1, 1000),
        Boolean("back"),
    ]
    defaults = {"n": 1, "back": False}
Example #11
0
class Alphabet(MergeRule):
    pronunciation = "alphabet"

    mapping = {
        "<letter>": R(Key("%(letter)s"), rdescript="Spell"),
        "big <letter>": R(Key("s-%(letter)s")),
    }
    extras = [
        letter_choice("letter"),
    ]
    defaults = {}
Example #12
0
def begin_end(environment):
    if type(environment) in [str, unicode]:
        back_curl("begin", environment).execute()
        Key("enter:2").execute()
        back_curl("end", environment).execute()
        Key("up").execute()
    elif type(environment) in [tuple, list]:
        back_curl("begin", environment[0]).execute()
        Text(environment[1]).execute()
        Key("enter:2").execute()
        back_curl("end", environment[0]).execute()
        Key("up").execute()
Example #13
0
class SQLDeveloperRule(MergeRule):
    pronunciation = "sequel developer"

    mapping = {
        "run this query": R(Key("f9"), rdescript="SQL Dev: Run Query"),
        "format code": R(Key("c-f7"), rdescript="SQL Dev: Format Code"),
        "comment line": R(Key("c-slash"), rdescript="SQL Dev: Comment Line"),
    }
    extras = [
        Dictation("text"),
        IntegerRefST("n", 1, 1000),
    ]
    defaults = {"n": 1}
Example #14
0
class CMDRule(MergeRule):
    pronunciation = "command prompt"

    mapping = {
        "C drive": R(Text(r"cd C:/") + Key("enter"), rdescript="CMD: Go To C:"),
        "CD up": R(Text("cd ..") + Key("enter"), rdescript="CMD: Up Directory"),
        "CD": R(Text("cd "), rdescript="CMD: Navigate Directory"),
        "list": R(Text("dir") + Key("enter"), rdescript="CMD: List Files"),
        "make directory": R(Text("mkdir "), rdescript="CMD: Make directory"),
        "exit": R(Text("exit") + Key("enter"), rdescript="CMD: Exit"),
    }
    extras = []
    defaults = {}
Example #15
0
def letters(big, dict1, dict2, letter):
    '''used with alphabet.txt'''
    d1 = str(dict1)
    if d1 != "":
        Text(d1).execute()
    if big:
        Key("shift:down").execute()
    letter.execute()
    if big:
        Key("shift:up").execute()
    d2 = str(dict2)
    if d2 != "":
        Text(d2).execute()
Example #16
0
class PythonNon(MappingRule):
    mapping = {
        "with":
        R(Text("with "), rdescript="Python: With"),
        "open file":
        R(Text("open('filename','r') as f:"), rdescript="Python: Open File"),
        "read lines":
        R(Text("content = f.readlines()"), rdescript="Python: Read Lines"),
        "try catch":
        R(Text("try:") + Key("enter:2/10, backspace") +
          Text("except Exception:") + Key("enter"),
          rdescript="Python: Try Catch"),
    }
Example #17
0
class LyxRule(MergeRule):
    pronunciation = "lyx"

    mapping = {
        "new file":
        R(Key("c-n"), rdescript="LyX: new file"),
        "open file":
        R(Key("c-o"), rdescript="LyX: open file"),
        "save as":
        R(Key("cs-s"), rdescript="LyX: save as"),
        "math mode":
        R(Key("c-m"), rdescript="LyX: math mode"),
        "display mode":
        R(Key("cs-m"), rdescript="LyX: display mode"),
        "view PDF":
        R(Key("c-r"), rdescript="LyX: view PDF"),
        "update PDF":
        R(Key("cs-r"), rdescript="LyX: update PDF"),
        "move line up [<n>]":
        R(Key("a-up"), rdescript="LyX: move line up") * Repeat(extra="n"),
        "move line down [<n>]":
        R(Key("a-down"), rdescript="LyX: move line down") * Repeat(extra="n"),
        "insert <environment>":
        R(Key("a-i, h, %(environment)s"), rdescript="LyX: insert environment"),
    }
    extras = [
        IntegerRefST("n", 1, 10),
        Choice(
            "environment", {
                "(in line formula | in line)": "i",
                "(display formula | display)": "d",
                "(equation array environment | equation array)": "e",
                "(AMS align environment | AMS align)": "a",
                "AMS align at [environment]": "t",
                "AMS flalign [environment]": "f",
                "(AMS gathered environment | AMS gather)": "g",
                "(AMS multline [environment]| multiline)": "m",
                "array [environment]": "y",
                "(cases [environment] | piecewise)": "c",
                "(aligned [environment] | align)": "l",
                "aligned at [environment]": "v",
                "gathered [environment]": "h",
                "split [environment]": "s",
                "delimiters": "r",
                "matrix": "x",
                "macro": "o",
            }),
    ]
    defaults = {
        "n": 1,
    }
Example #18
0
 def analyze_for_configure(self):
     '''solves the problem of the editor not being smart about toggles by using text
     to see which toggles are active'''
     '''regex toggle check'''
     Key("escape").execute()  # get out of Find
     result = CONTEXT.read_nmax_tries(10)
     if result == self.analysis_chars:
         self.regex = False
         Key("backspace").execute()
     elif result == self.analysis_chars[1]:
         self.regex = True
         Key("delete, backspace").execute()
     else:
         print("Eclipse configuration failed (%s)" % result)
Example #19
0
class FlashDevelopCCR(MergeRule):
    pronunciation = "flash develop test"
    mwith = [Navigation().get_pronunciation()]

    mapping = {
        "[go to] line <n>":
        R(Key("c-g") + Pause("50") + Text("%(n)d") + Key("enter"),
          rdescript="FlashDevelop: Go To Line"),
    }
    extras = [
        Dictation("text"),
        IntegerRefST("n", 1, 1000),
    ]
    defaults = {"n": 1}
Example #20
0
def quote():
    e, text = context.read_selected_without_altering_clipboard(False)
    if text:
        Text("``" + text + "\'\'").execute()
    else:
        Text("``\'\'").execute()
        Key("left:2").execute()
Example #21
0
def master_text_nav(mtn_mode, mtn_dir, nnavi500, extreme):
    '''
    (<mtn_dir> | <mtn_mode> [<mtn_dir>]) [(<nnavi500> | <extreme>)]
    mtn_mode: "shin" s, "queue" cs, "fly" c, (default None)
    mtn_dir: 0-up, 1-down, 2-left, 3-right, (default right)
    nnavi500: number of keypresses (default 1)
    extreme: home/end (default None)
    '''

    k = None
    if mtn_mode is None:
        if extreme is not None:
            if mtn_dir == "left":
                k = "home"
            elif mtn_dir == "right":
                k = "end"
            elif mtn_dir == "up":
                k = "c-home"
            elif mtn_dir == "down":
                k = "c-end"
        else:
            k = str(mtn_dir) + "/5:" + str(nnavi500)
    elif extreme is None:
        k = str(mtn_mode) + "-" + str(mtn_dir) + "/5:" + str(nnavi500)
    else:
        mtn_dir = str(mtn_dir)
        way = "end" if mtn_dir in ["right", "down"] else "home"
        k = str(mtn_mode) + "-" + str(way)
    Key(k).execute()
    time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.)
Example #22
0
def refresh(_NEXUS):
    ''' should be able to add new scripts on the fly and then call this '''
    unload()
    global grammar
    grammar = Grammar("si/kuli")

    def refresh_sick_command():
        server_proxy.terminate()
        refresh(_NEXUS)

    mapping = {
        "launch sick IDE": Function(launch_IDE),
        "launch sick server": Function(launch_server),
        "refresh sick you Lee": Function(refresh_sick_command),
        "sick shot": Key("cs-2"),
    }

    rule = MergeRule(name="sik", mapping=mapping)
    gfilter.run_on(rule)
    grammar.add_rule(rule)
    grammar.load()
    # start server
    try:
        # if the server is already running, this should go off without a hitch
        start_server_proxy()
    except Exception:
        launch_server()
        seconds5 = 5
        control.nexus().timer.add_callback(server_proxy_timer_fn, seconds5)
Example #23
0
def read_selected_without_altering_clipboard(same_is_okay=False):
    '''Returns a tuple:
    (0, "text from system") - indicates success
    (1, None) - indicates no change
    (2, None) - indicates clipboard error
    '''
    time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] /
               1000.)  # time for previous keypress to execute
    cb = Clipboard(from_system=True)
    temporary = None
    prior_content = None
    try:

        prior_content = Clipboard.get_system_text()
        Clipboard.set_system_text("")

        Key("c-c").execute()
        time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] /
                   1000.)  # time for keypress to execute
        temporary = Clipboard.get_system_text()
        cb.copy_to_system()

    except Exception:
        utilities.simple_log(False)
        return 2, None
    if prior_content == temporary and not same_is_okay:
        return 1, None
    return 0, temporary
Example #24
0
    def lines_relative(self, back, n):
        if back:  #backward
            try:
                num = CONTEXT.read_nmax_tries(10)
                txt = str(int(num) - int(n) + 1)  # +1 to include current line
                Text(txt).execute()
            except ValueError:
                utilities.simple_log()
                return
            Key("enter").execute()
        else:  #forward
            Key("escape, end, home, home").execute(
            )  # end-home-home to include all of current line

        # forward or backward
        Key("s-down:" + str(int(n)) + "/5, s-left").execute()
Example #25
0
File: dev.py Project: mrob95/caster
class StackTest(MappingRule):
    '''test battery for the ContextStack'''

    mapping = {
        "close last tag":
        ContextSeeker([
            L(S(["cancel"], None),
              S(["html spoken"], close_last_spoken, use_spoken=True),
              S(["span", "div"], close_last_rspec, use_rspec=True))
        ]),
        "html":
        R(Text("<html>"), rspec="html spoken"),
        "divider":
        R(Text("<div>"), rspec="div"),
        "span":
        R(Text("<span>"), rspec="span"),
        "backward seeker [<text>]":
        ContextSeeker([
            L(S(["ashes"], Text("ashes1 [%(text)s] ")),
              S(["bravery"], Text("bravery1 [%(text)s] "))),
            L(S(["ashes"], Text("ashes2 [%(text)s] ")),
              S(["bravery"], Text("bravery2 [%(text)s] ")))
        ]),
        "forward seeker [<text>]":
        ContextSeeker(forward=[
            L(S(["ashes"], Text("ashes1 [%(text)s] ")),
              S(["bravery"], Text("bravery1 [%(text)s] "))),
            L(S(["ashes"], Text("ashes2 [%(text)s] ")),
              S(["bravery"], Text("bravery2 [%(text)s] ")))
        ]),
        "asynchronous test":
        AsynchronousAction([
            L(S(["ashes", "charcoal"], print_time, None),
              S(["bravery"], Text, "bravery1"))
        ],
                           time_in_seconds=0.2,
                           repetitions=20,
                           finisher=Text(FINISHER_TEXT),
                           blocking=False),
        "ashes":
        RegisteredAction(Text("ashes _ "), rspec="ashes"),
        "bravery":
        RegisteredAction(Text("bravery _ "), rspec="bravery"),
        "charcoal <text> [<n>]":
        R(Text("charcoal _ %(text)s"), rspec="charcoal"),
        "test confirm action":
        ConfirmAction(Key("a"),
                      rdescript="Confirm Action Test",
                      instructions="some words here"),
        "test box action":
        BoxAction(lambda data: _abc(data),
                  rdescript="Test Box Action",
                  box_type=settings.QTYPE_DEFAULT,
                  log_failure=True),
    }
    extras = [Dictation("text"), Dictation("text2"), IntegerRefST("n", 1, 5)]
    defaults = {"text": "", "text2": ""}
Example #26
0
def misc(misc_lyx_commands):
    if type(misc_lyx_commands) in [str, int]:
        Text(misc_lyx_commands).execute()
    elif type(misc_lyx_commands) in [list, tuple]:
        for i in range(len(misc_lyx_commands)):
            if i % 2 == 0:
                Text(misc_lyx_commands[i]).execute()
            else:
                Key(misc_lyx_commands[i]).execute()
Example #27
0
def add_modkeys(rule):
    release = R(Key("shift:up, ctrl:up, alt:up"), rdescript="Mod Keys Up")

    if not hasattr(rule, "marked") and\
    rule.get_pronunciation()[0:6] != "Merged": # don't augment merged rules-- they'd get it twice
        for spec in rule.mapping_actual().keys():
            rule.mapping_actual(
            )[spec] = release + rule.mapping_actual()[spec] + release
        rule.marked = True
Example #28
0
def insert(element):
    if type(element) in [str, int]:
        Text(element).execute()
    elif type(element) in [list, tuple]:
        for i in range(len(element)):
            if i % 2 == 0:
                Text(element[i]).execute()
            else:
                Key(element[i]).execute()
Example #29
0
class MineNon(MappingRule):
    mapping = {
        # "switch <exec_path>":
        #     R(Function(window_switcher.switch_window)),
        # "switch notepad":
        # 	R(Playback([(["switch", "to", "notepad"], 0.0)])),
        # "switch kindle":
        # 	R(Playback([(["switch", "to", "kindle"], 0.0)])),
        # "switch spot if I":
        # 	R(Playback([(["switch", "to", "spotify"], 0.0)])),
        # "switch file man":
        # 	R(Playback([(["switch", "to", "fman"], 0.0)])),

        # "open spot if I":
        # 	R(Playback([(["open", "spotify"], 0.0)])),
        # "open file man":
        # 	R(Playback([(["open", "fman"], 0.0)])),
        "show work [spaces]":
        R(Key("w-tab")),
        "(create | new) work [space]":
        R(Key("wc-d")),
        "close work [space]":
        R(Key("wc-f4")),
        "next work [space] [<n>]":
        R(Key("wc-right")) * Repeat(extra="n"),
        "(previous | prior) work [space] [<n>]":
        R(Key("wc-left")) * Repeat(extra="n"),

        # "normal mode":
        # 	R(Playback([(["switch", "to", "normal", "mode"], 0.0)])),
        # "command mode":
        # 	R(Playback([(["switch", "to", "command", "mode"], 0.0)])),
        # "dictation mode":
        # 	R(Playback([(["switch", "to", "dictation", "mode"], 0.0)])),
    }

    extras = [
        window_switcher.get_choice(),
        IntegerRefST("n", 1, 5),
    ]
    defaults = {
        "n": 1,
    }
Example #30
0
def insert(element):
    if type(element) is str:
        n_markers = 0
        to_enter = element
    else:
        n_markers = element[1]
        to_enter = element[0]
    Text(to_enter).execute()
    for _ in range(n_markers):
        Key("s-f4").execute()