Beispiel #1
0
def copypaste_delete_until_phrase(direction, phrase, number_of_lines_to_search, before_after, occurrence_number, dictation_versus_character):
    if direction == "up" or direction == "down":
        number_of_lines_to_search, direction = deal_with_up_down_directions(direction, number_of_lines_to_search)
    application = get_application()  
    if not before_after:
        # default to delete all the way through the phrase not just up until it
        if direction == "left":
            before_after = "before"
        if direction == "right":
            before_after = "after"

    selected_text = select_text_and_return_it(direction, number_of_lines_to_search, application)
    if not selected_text:
        return 
    phrase = str(phrase)
    new_text = delete_until_phrase(selected_text, phrase, direction, before_after, occurrence_number, dictation_versus_character)
        
    if new_text is None: 
        # do NOT use `if not new_text` because that will pick up the case where new_text="" which
        # occurs if the phrase is at the beginning of the line
        # phrase not found
        # deal_with_phrase_not_found(selected_text, temp_for_previous_clipboard_item, application, direction)
        deal_with_phrase_not_found(selected_text, application, direction)
        return

    if new_text == "":
        # phrase is at the beginning of the line
        Key("del").execute()
        return
    else:
        text_manipulation_paste(new_text, application)

        if direction == "right":
            offset = len(new_text)
            Key("left:%d" %offset).execute()
Beispiel #2
0
class WindowManagementRule(MappingRule):
    mapping = {
        'maximize':
            R(Function(utilities.maximize_window)),
        'minimize':
            R(Function(utilities.minimize_window)),

        # Workspace management
        "show work [spaces]":
            R(Key("w-tab")),
        "(create | new) work [space]":
            R(Key("wc-d")),
        "close work [space]":
            R(Key("wc-f4")),
        "close all work [spaces]":
            R(Function(virtual_desktops.close_all_workspaces)),
        "next work [space] [<n>]":
            R(Key("wc-right"))*Repeat(extra="n"),
        "(previous | prior) work [space] [<n>]":
            R(Key("wc-left"))*Repeat(extra="n"),

        "go work [space] <n>":
            R(Function(virtual_desktops.go_to_desktop_number)),
        "send work [space] <n>":
            R(Function(virtual_desktops.move_current_window_to_desktop)),
        "move work [space] <n>":
            R(Function(virtual_desktops.move_current_window_to_desktop, follow=True)),
    }

    extras = [
        IntegerRefST("n", 1, 20, default=1),
    ]
Beispiel #3
0
def back_curl(first, second):
    # Return \first{second}, if second is empty then end inside the brackets for user input
    if str(second) != "":
        return (Text("\\") + Text(str(first)) + Key("lbrace, rbrace, left") +
                Text(str(second)) + Key("right"))
    if str(second) == "":
        return (Text("\\") + Text(str(first)) + Key("lbrace, rbrace, left"))
    def find(self, back, go, text=None, punctuation=None, a=None, b=None, c=None):
        '''set direction'''

        key = "b" if back else "o"
        Key("a-" + key).execute()
        '''figure out what to search for'''
        if text is not None:
            text = str(text)
            '''simple vowel-removal regex'''
            if self.regex:
                text = re.sub("[aeiouAEIOU]+", r".*", text)
                if text.endswith(r".*"):
                    text = text[:-2]
        elif punctuation is not None:
            text = str(punctuation)
            self.regex_off()
        elif a is not None:
            a = str(a)
            b = str(b) if b is not None else ""
            c = str(c) if c is not None else ""
            text = a + b + c
            self.regex_off()
        Text(text).execute()
        '''"go" indicates that we should keep looking'''
        if go:
            u = UntilCancelled(Key("enter"), 2)
            u.show = False
            u.execute()
        else:
            Key("enter, escape").execute()
Beispiel #5
0
def _text_to_clipboard(keystroke, nnavi500):
    if nnavi500 == 1:
        Key(keystroke).execute()
    else:
        max_tries = 20
        cb = Clipboard(from_system=True)
        Key(keystroke).execute()
        key = str(nnavi500)
        global _CLIP
        for i in range(0, max_tries):
            failure = False
            try:
                # time for keypress to execute
                time.sleep(
                    settings.SETTINGS["miscellaneous"]["keypress_wait"] /
                    1000.)
                _CLIP[key] = unicode(Clipboard.get_system_text())
                utilities.save_json_file(
                    _CLIP, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
            except Exception:
                failure = True
                utilities.simple_log()
            if not failure:
                break
        cb.copy_to_system()
Beispiel #6
0
def _text_to_clipboard(keystroke, nnavi500):
    if nnavi500 == 1:
        Key(keystroke).execute()
    else:
        max_tries = 20
        cb = Clipboard(from_system=True)
        Key(keystroke).execute()
        key = str(nnavi500)
        for i in range(0, max_tries):
            failure = False
            try:
                # time for keypress to execute
                time.sleep(
                    settings.settings([u'miscellaneous', u'keypress_wait']) /
                    1000.)
                _NavClipBoard.get_instance(
                ).clip[key] = Clipboard.get_system_text()
                utilities.save_json_file(
                    _NavClipBoard.get_instance().clip,
                    settings.settings([u'paths', u'SAVED_CLIPBOARD_PATH']))
            except Exception:
                failure = True
                utilities.simple_log()
            if not failure:
                break
        cb.copy_to_system()
Beispiel #7
0
class PrologNon(MappingRule):
    mapping = {
        "Rule":
        R(Text("() :-.") + Key("left/6")),
        SymbolSpecs.IF:
        R(Text("( ") + Key("enter") + Text(";") + Key("enter") + Text(")")),
    }
class HardwareRule(MappingRule):
    mapping = {
        # Windows 10 changes volume by increments 2
        "volume <volume_mode> [<n_volume>]":
        R(Key("%(volume_mode)s") * Repeat(extra="n_volume")),
        "media <multimedia_control> [<n_media>]":
        R(Key("%(multimedia_control)s") * Repeat(extra="n_media")),
        "change monitor":
        R(Key("w-p") + Pause("100") + Function(change_monitor))
    }
    extras = [
        IntegerRefST("n_media", 1, 15),
        IntegerRefST("n_volume", 1, 50),
        Choice("multimedia_control", {
            "next": "tracknext",
            "back": "trackprev",
            "play|pause": "playpause",
        }),
        Choice("volume_mode", {
            "mute|unmute": "volumemute",
            "up": "volumeup",
            "down": "volumedown",
        })
    ]
    defaults = {
        "n_volume": 1,
        "n_media": 1,
        "volume_mode": "setsysvolume",
    }
Beispiel #9
0
def drop_keep_clipboard(nnavi500, 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 _CLIP:
            text = _CLIP[key]
        else:
            get_current_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([u'miscellaneous', u'keypress_wait'])/1000.)
        Key("c-v").execute()
        time.sleep(settings.settings([u'miscellaneous', u'keypress_wait'])/1000.)
        # Restore the clipboard contents.
        cb.copy_to_system()
Beispiel #10
0
    def _bring_add(self, launch_type, key):
        # Add current program or highlighted text to bring me
        if launch_type == "program":
            path = utilities.get_active_window_path()
            if not path:
                # dragonfly.get_engine().speak("program not detected")
                printer.out("Program path for bring me not found ")
        elif launch_type == 'file':
            files = utilities.get_selected_files(folders=False)
            path = files[0] if files else None  # or allow adding multiple files
        elif launch_type == 'folder':
            files = utilities.get_selected_files(folders=True)
            path = files[
                0] if files else None  # or allow adding multiple folders
        else:
            Key("a-d/5").execute()
            fail, path = context.read_selected_without_altering_clipboard()
            if fail == 2:
                # FIXME: A better solution would be to specify a number of retries and the time interval.
                time.sleep(0.1)
                _, path = context.read_selected_without_altering_clipboard()
                if not path:
                    printer.out("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_copy = self._config.get_copy()
        config_copy[launch_type][str(key)] = path
        self._refresh(config_copy)
Beispiel #11
0
class CppSnippetExample(MappingRule):
    pronunciation = "sublime snippet"
    mapping = {
        "<snippet>":
        R(Function(insert_snippet)),
        "<snippet_variants> [<n>]":
        R(Function(insert_snippet_with_variants)),
        "variant <n>":
        R(Key("c-z") + Function(insert_variant)),
        "display variants":
        R(Key("c-z") + Function(display_variants)),
        "small test":
        R(
            Function(send_sublime,
                     c="insert_snippe",
                     data={
                         "contents": "${1:$PARAK}=2",
                         "PARAK": "y"
                     })) + R(Text("hello")),
        "small jerry":
        R(Function(send_sublime, c="prev_field", data={})),
    }
    extras = [
        IntegerRefST("n", 1, 10),
        Choice("snippet",
               {k: v
                for k, v in snippets.items() if isinstance(v, str)}),
        Choice("snippet_variants",
               {k: v
                for k, v in snippets.items() if not isinstance(v, str)}),
    ]
    defaults = {}
Beispiel #12
0
class CppSnippetExampleExperimental(MappingRule):
    pronunciation = "sublime snippet"
    mapping = {
        "<snippet>":
            R(Function(insert_snippet)),
        "<snippet_variants> [<n>]":
            R(Function(insert_snippet_with_variants)),
        "variant <n>":
            R(Key("c-z") + Function(insert_variant)),
        "display variants":
            R(Key("c-z") + Function(display_variants)),
        "apply <transformation>":
            R(Key("c-z") + Function(transform_last_snippet)),
        "small test":
            R(Function(send_sublime,c = "insert_snippet",data = {"contents":"${1:${PARAK:y}}=2 + ${PARAK:z}","PARAK":"x"})),
        "small jerry":
            R(Function(send_sublime,c = "prev_field",data = {})),
        "jerry":
            R(Function(store_and_next)),
        "<snippet> over":
            R(Function(insert_snippet_with_defaults)),
        "<snippet_variants> [<n>] over":
            R(Function(insert_snippet_with_variants_and_defaults)),



    }
    extras = [
        IntegerRefST("n",1,10),
        Choice("snippet",{k:v for k,v in snippets.items() if  isinstance(v,str)}),
        Choice("snippet_variants",{k:v for k,v in snippets.items() if  not isinstance(v,str)}),
        Choice("transformation",transformations),
    ]
    defaults = {}
Beispiel #13
0
 def _execute(self, data=None):
     output = _TEMP
     Paste(output).execute()
     if output:
         Key(self.action_if_text).execute()
     else:
         Key(self.action_if_no_text).execute()
     return True
Beispiel #14
0
 def _execute(self, data=None):
     output = control.nexus().temp
     Paste(output).execute()
     if output:
         Key(self.action_if_text).execute()
     else:
         Key(self.action_if_no_text).execute()
     return True
Beispiel #15
0
class TmuxRule(MappingRule):
    mapping = {
        "pane close": R(Key("c-b, x")),
        "pane split vertical": R(Key("c-b, percent")),
        "pane split horizontal": R(Key("c-b, quote")),
        "window move": R(Key("c-b, p")),
        "window rename": R(Key("c-b, comma")),
    }
Beispiel #16
0
def next_line(semi):
    semi = str(semi)
    Key("escape").execute()
    time.sleep(0.05)
    Key("end").execute()
    time.sleep(0.05)
    Text(semi).execute()
    Key("enter").execute()
Beispiel #17
0
def duple_keep_clipboard(nnavi50):
    cb = Clipboard(from_system=True)
    Key("escape, home, s-end, c-c, end").execute()
    time.sleep(settings.settings([u'miscellaneous', u'keypress_wait'])/1000.)
    for i in range(0, nnavi50):
        Key("enter, c-v").execute()
        time.sleep(settings.settings([u'miscellaneous', u'keypress_wait'])/1000.)
    cb.copy_to_system()
Beispiel #18
0
class MainRule(MappingRule):

    mapping = {
        # it is this section that you want to fiddle around with if you're new: mapping, extras, and defaults

        # in the next line, there are two things to observe:
        # the first is the use of parentheses and the pipe symbol (|)
        # --this lets me use either "lock dragon" or "deactivate" to trigger that command.
        # The next is the playback action, which lets me tell Dragon to simulate me speaking some words.
        '(lock Dragon | deactivate)':
        Playback([(["go", "to", "sleep"], 0.0)]),

        # Here I'm using BringApp-- this is the same as typing what goes in between the parentheses
        # into the Windows command prompt, without the quotes and commas, like:
        # explorer C:\NatLink\NatLink\MacroSystem
        # -- (which would open Windows Explorer at the specified location). Anything you can do with the command line can be done this way
        # IMPORTANT: If you don't have Dragonfly  6.6  or later, lines 40 and 46  will cause this file to crash and should be commented out
        "open natlink folder":
        BringApp("explorer", r"C:\NatLink\NatLink\MacroSystem"),

        # here I'm using the Key action to press some keys -- see the documentation here: http://dragonfly.readthedocs.org/en/latest/actions.html?highlight=key#module-dragonfly.actions.action_key
        "remax":
        Key("a-space/10,r/10,a-space/10,x"),

        # here I'm chaining a bunch of different actions together to do a complex task
        "(show | open) documentation":
        BringApp(
            'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe')
        + WaitWindow(executable="chrome.exe") + Key('c-t') +
        WaitWindow(title="New Tab") +
        Text('http://dragonfly.readthedocs.org/en/latest') + Key('enter'),

        # here I'm just saying one word to trigger some other words
        "hotel":
        Text("hotels are not cheap"),

        # If you need to do more complicated tasks, or use external resources, a function might be what you need.
        # note that here, I'm using extras: "n" and "text"
        # The angle brackets <> meaning I'm using an extra, and the square brackets [] mean that I don't have to speak that word, it's optional.
        # Advice: if you use an optional extra, like I am with "text", you should set a default value  in the defaults section down below.
        # To trigger the following command, you would have to say the word "function" followed by a number between 1 and 1000.
        '[use] function <n> [<text>]':
        Function(my_function, extra={'n', 'text'}),
    }
    extras = [
        IntegerRefST("n", 1, 1000),
        Dictation("text"),
        Choice("choice", {
            "alarm": "alarm",
            "custom grid": "CustomGrid",
            "element": "e"
        }),
    ]
    defaults = {
        "n": 1,
        "text": "",
    }
Beispiel #19
0
def _find_nth_token(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()
Beispiel #20
0
class NPPRule(MergeRule):
    pronunciation = "notepad plus plus"

    mapping = {
        "(line | zeile) <n>": R(Key("c-g") + Text("%(n)d") + Key("enter")),
        "(save | speichern)": R(Key("c-s")),
        "(save as | speichern als)": R(Key("ca-s")),
    }
    extras = [IntegerRefST("n", 1, 1000)]
    defaults = {"n": 1}
class NPPRule(MappingRule):

    mapping = {
        "stylize <n2>":
        R(
            Mouse("right") + Key("down:6/5, right") +
            (Key("down") * Repeat(extra="n2")) + Key("enter")),
        "remove style":
        R(Mouse("right") + Key("down:6/5, right/5, down:5/5, enter")),
        "preview in browser":
        R(Key("cas-r")),

        # requires function list plug-in:
        "function list":
        R(Key("cas-l")),
        "open":
        R(Key("c-o")),
        "go [to] line <n>":
        R(Key("c-g/10") + Text("%(n)s") + Key("enter")),
    }
    extras = [
        Dictation("text"),
        IntegerRefST("n", 1, 1000),
        IntegerRefST("n2", 1, 10),
    ]
    defaults = {"n": 1}
Beispiel #22
0
def previous_line(semi):
    semi = str(semi)
    Key("escape").execute()
    time.sleep(0.05)
    Key("end").execute()
    time.sleep(0.05)
    Text(semi).execute()
    time.sleep(0.05)
    Key("up").execute()
    time.sleep(0.05)
    Key("enter").execute()
def deal_with_phrase_not_found(selected_text, application, direction):
    # Approach 1: unselect text by pressing left and then right, works in Tex studio
    if application == "texstudio":
        Key("left, right").execute()  # unselect text
        if direction == "right":
            Key("left:%d" % len(selected_text)).execute()
    # Approach 2: unselect text by pressing opposite arrow key, does not work in Tex studio
    else:
        if direction == "left":
            Key("right").execute()
        if direction == "right":
            Key("left").execute()
Beispiel #24
0
class FoxitRule(MappingRule):
    mapping = {
        "next tab [<n>]": R(Key("c-tab")) * Repeat(extra="n"),
        "prior tab [<n>]": R(Key("cs-tab")) * Repeat(extra="n"),
        "close tab [<n>]": R(Key("c-f4/20")) * Repeat(extra="n"),
    }
    extras = [
        Dictation("text"),
        Dictation("mim"),
        IntegerRefST("n", 1, 1000),
    ]
    defaults = {"n": 1, "mim": ""}
Beispiel #25
0
def insert_snippet(item):
    print("Item", item)
    use_keys = False
    if use_keys:
        Key("cs-p").execute()
        Text("Snippet: voice_cpp_" + item).execute()
        Key("enter").execute()
    else:
        y = r'subl --command "insert_snippet {\"contents\":\"' + snippets[
            item] + r'\"}'
        subprocess.call(y, shell=True)
        subprocess.call("subl", shell=True)
Beispiel #26
0
class SQLDeveloperRule(MappingRule):

    mapping = {
        "run this query": R(Key("f9")),
        "format code": R(Key("c-f7")),
        "comment line": R(Key("c-slash")),
    }
    extras = [
        Dictation("text"),
        IntegerRefST("n", 1, 1000),
    ]
    defaults = {"n": 1}
Beispiel #27
0
class PythonNon(MappingRule):
    mapping = {
        "with":
            R(Text("with ")),
        "open file":
            R(Text("open('filename','r') as f:")),
        "read lines":
            R(Text("content = f.readlines()")),
        "try catch":
            R(
                Text("try:") + Key("enter:2/10, backspace") + Text("except Exception:") +
                Key("enter")),
    }
Beispiel #28
0
class RustNon(MappingRule):
    mapping = {
        "macro format string": R(Text("format!()") + Key("left")),
        "macro panic": R(Text("panic!()") + Key("left")),
        "macro assertion": R(Text("assert_eq!()") + Key("left")),
        "ternary": R(Text("if TOKEN == TOKEN { TOKEN } else { TOKEN }")),
        "function [<return>]": R(Text("fn TOKEN(TOKEN)%(return)s{}")),
        "infinite loop": R(Text("loop {}") + Key("left")),
    }
    extras = [
        Choice("return", {"return": " -> TOKEN "}),
    ]
    defaults = {"return": " "}
Beispiel #29
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()
Beispiel #30
0
def action_lines(action,
                 ln1,
                 ln2,
                 go_to_line="c-g",
                 select_line_down="s-down",
                 wait="",
                 upon_arrival=""):
    num_lines = max(int(ln2) - int(ln1) + 1, int(ln1) -
                    int(ln2) + 1) if ln2 else 1
    top_line = min(int(ln2), int(ln1)) if ln2 else int(ln1)
    command = Key(go_to_line) + Text(str(top_line)) + Key(
        "enter%s, %s%s%s:%s, %s" %
        (wait, upon_arrival, select_line_down, wait, str(num_lines), action))
    command.execute()