예제 #1
0
 def select_previous_occurrence(verbs: str, text: str):
     actions.edit.find(text)
     actions.key("shift-enter")
     actions.sleep("100ms")
     actions.key("esc")
     if verbs is not None:
         actions.user.perform_selection_action(verbs)
예제 #2
0
 def quick_url_prepare_current():
     """Prepare the browser for inputting the URL in the current tab"""
     focus_browser()
     actions.key("ctrl-l")
     actions.sleep("20ms")
     actions.key("ctrl-a")
     actions.sleep("20ms")
예제 #3
0
    def switcher_launch(path: str):
        """Launch a new application by path"""
        if app.platform == "windows":
            is_valid_path = False
            try:
                current_path = Path(path)
                is_valid_path = current_path.is_file()
                # print("valid path: {}".format(is_valid_path))

            except:
                # print("invalid path")
                is_valid_path = False

            if is_valid_path:
                # print("path: " + path)
                ui.launch(path=path)

            else:
                # print("envelop")
                actions.key("super-s")
                actions.sleep("300ms")
                actions.insert("apps: {}".format(path))
                actions.sleep("150ms")
                actions.key("enter")

        else:
            ui.launch(path=path)
예제 #4
0
    def file_manager_open_directory(path: Union[str, int]):
        """opens the directory that's already visible in the view"""
        if is_terminal:
            actions.user.file_manager_terminal_open_directory(path)
        else:
            if is_windows:
                actions.key("ctrl-l")
                #print("windows")
                if isinstance(path, int):
                    actions.insert(folder_selections[path])
                else:
                    actions.insert(path)

                actions.key("enter")
            elif is_mac:
                actions.key("cmd-shift-g")
                actions.sleep("50ms")
                if isinstance(path, int):
                    actions.insert(folder_selections[path])
                else:
                    actions.insert(path)
                actions.key("enter")
            elif is_linux:
                actions.key("ctrl-l")
                actions.insert(path)
                actions.key("enter")
예제 #5
0
 def tab_duplicate():
     """Limitation: this will not work if the text in your address bar has been manually edited.
     Long-term we want a better shortcut from browsers.
     """
     actions.browser.focus_address()
     actions.sleep("180ms")
     actions.key("alt-enter")
예제 #6
0
    def file_manager_open_directory(path: Union[str, int]):
        """opens the directory that's already visible in the view"""
        if is_terminal:
            actions.user.file_manager_terminal_open_directory(path)
        else:

            if is_windows:
                actions.key("ctrl-l")
                if isinstance(path, int):
                    index = (current_folder_page -
                             1) * len(selection_numbers) + path
                    if index < len(folder_selections):
                        actions.insert(folder_selections[index])
                else:
                    actions.insert(path)

                actions.key("enter")
            elif is_mac:
                actions.key("cmd-shift-g")
                actions.sleep("50ms")
                if isinstance(path, int):
                    index = (current_folder_page -
                             1) * len(selection_numbers) + path
                    if index < len(folder_selections):
                        actions.insert(folder_selections[index])
                else:
                    actions.insert(path)
                actions.key("enter")
            elif is_linux:
                actions.key("ctrl-l")
                actions.insert(path)
                actions.key("enter")
예제 #7
0
 def switcher_focus_app(app: ui.App):
     """Focus application and wait until switch is made"""
     app.focus()
     t1 = time.monotonic()
     while ui.active_app() != app:
         if time.monotonic() - t1 > 1:
             raise RuntimeError(f"Can't focus app: {app.name}")
         actions.sleep(0.1)
예제 #8
0
 def shell_rerun():
     """rerun the most recent command in whichever shell as most recently used"""
     # switch_app(name='iTerm2')
     app = ui.apps(bundle="com.googlecode.iterm2")[0]
     ctrl.key_press("c", ctrl=True, app=app)
     actions.sleep("50ms")
     ctrl.key_press("up", app=app)
     ctrl.key_press("enter", app=app)
예제 #9
0
def quick_url(url: str, go: bool, preparer):
    preparer()
    actions.insert(url)
    actions.sleep("50ms")
    if not go:
        actions.key("right")
    else:
        actions.key("enter")
예제 #10
0
 def switcher_focus_window(window: ui.Window):
     """Focus window and wait until switch is made"""
     window.focus()
     t1 = time.monotonic()
     while ui.active_window() != window:
         if time.monotonic() - t1 > 1:
             raise RuntimeError(f"Can't focus window: {window.title}")
         actions.sleep(0.1)
예제 #11
0
    def paste(text: str):
        """Pastes text and preserves clipboard"""

        with clip.revert():
            clip.set(text)
            actions.edit.paste()
            # sleep here so that clip.revert doesn't revert the clipboard too soon
            actions.sleep("100ms")
예제 #12
0
 def screenshot_window_clipboard():
     '''takes a screenshot of the window and saves it to the clipboard'''
     if "Windows-10" in active_platform:
         engine.mimic("press control alt print screen")
     elif "Darwin" in active_platform:
         actions.key("ctrl-shift-cmd-4")
         actions.sleep("50ms")
         actions.key("space")
예제 #13
0
 def emacs_company_complete(number: int) -> None:
     """Pick & complete a numbered company candidate."""
     # We don't use `voicemacs-company-complete` because it doesn't reliably
     # give visual feedback.
     # emacs_prefix_command("voicemacs-company-complete", number)
     user.emacs_company_highlight(number)
     # Sleep briefly to ensure there's visual feedback
     actions.sleep("100ms")
     user.emacs_command("company-complete")
예제 #14
0
    def move_mouse_to_current_gaze_position():
        """Moves the mouse to where you are currently looking at"""
        global eye_tracker_sleep_timer_delay

        #schedule_putting_eye_tracker_to_sleep(eye_tracker_sleep_timer_delay)

        toggle_control(True)
        actions.sleep("100ms")
        toggle_control(False)
예제 #15
0
def _log(args):
    global text, can
    if "command" not in scope.get("mode"):
        return
    text = f"\"{' '.join(args['text'])}\""
    can.show()
    can.freeze()
    actions.sleep(action_wait)
    cron.after(canvas_hide_wait, hide_canvas)
예제 #16
0
 def german_paste(word:str=None, text:str=None):
     """Searches and copies the definition from wiktionary"""
     if text is None:
         text = actions.user.german_get_text(word)
     actions.key("shift-tab")
     actions.sleep("100ms")
     actions.edit.select_all()
     actions.user.paste(text)
     actions.sleep("50ms")
예제 #17
0
    def search(text: str = None) -> None:
        """Perform some generic "search". Behavior depends on the program.

        Provide `text` to search for some text.

        """
        actions.user.search()
        actions.sleep("500ms")
        if text:
            actions.insert(text)
예제 #18
0
def close_editor(submit_draft: bool):
    remove_tag("user.draft_editor_active")
    actions.edit.select_all()
    selected_text = actions.edit.selected_text()
    actions.edit.delete()
    actions.app.tab_close()
    actions.user.switcher_focus_window(original_window)
    actions.sleep("200ms")
    if submit_draft:
        actions.user.paste(selected_text)
예제 #19
0
def copy_to_code():
    ''' Saves text into code '''
    #select line
    actions.edit.line_start()
    actions.edit.extend_line_end()
    actions.edit.copy()
    actions.sleep("100ms")
    #save wording
    line = clip.text()
    #convert line
    return line
예제 #20
0
 def german_pronounce(word:str=None, back:bool=False):
     """Searches and copies the pronunciation from wiktionary"""
     if word is None:
         word = actions.user.german_anki_get_word()
     actions.key("tab")
     actions.edit.select_all()
     for word in word.split("\n"):
         os.system(f"python /mnt/data/p/wiktionary.py '{word}'")
         actions.edit.paste()
     actions.sleep("100ms")
     if back:
         actions.key("shift-tab")
     return word
예제 #21
0
파일: draft_editor.py 프로젝트: eprev/talon
 def draft_editor_open():
     """Open draft editor"""
     global original_window
     original_window = ui.active_window()
     editor_app = get_editor_app()
     selected_text = actions.edit.selected_text()
     actions.user.switcher_focus_app(editor_app)
     # Wait additional time for talon context to update.
     actions.sleep("200ms")
     actions.app.tab_open()
     if selected_text != "":
         actions.user.paste(selected_text)
     actions.mode.enable("user.draft_editor")
예제 #22
0
 def slow_key(pattern: str):
     """Press some keys slowly"""
     print(pattern)
     keys = pattern.split(" ")
     keys2 = []
     for k in keys:
         chord_rep = k.split(":")
         if len(chord_rep) == 1:
             keys2.append(chord_rep[0])
         elif len(chord_rep) == 2:
             keys2.extend([chord_rep[0]] * int(chord_rep[1]))
     for k in keys2:
         actions.key(k)
         actions.sleep("50ms")
예제 #23
0
    def vscode(command: str):
        """Execute command via command palette. Preserves the clipboard."""
        # Clip is noticeably faster than insert
        original_clipboard = clip.text()
        clip.set_text(f"{command}")
        if not is_mac:
            actions.key("ctrl-shift-p")
        else:
            actions.key("cmd-shift-p")

        actions.edit.paste()
        actions.key("enter")
        actions.sleep("200ms")
        clip.set_text(original_clipboard)
예제 #24
0
def i3wm_window_resize(size, grow=True):
    """resizes the selected window by the specified number of key movements"""
    actions.user.system_command_nb('i3-msg mode "resize"')
    if grow:
        actions.key(f"right:{size}")
        actions.key(f"down:{size}")
    else:
        actions.key(f"left:{size}")
        actions.key(f"up:{size}")
    # escape resize mode
    actions.key("escape")
    actions.sleep("200ms")
    # center window
    actions.user.system_command_nb("i3-msg move position center")
예제 #25
0
    def paste(text: str):
        """Pastes text and preserves clipboard"""

        #        with clip.revert():
        #            clip.set_text(text)
        #            actions.edit.paste()
        #            # sleep here so that clip.revert doesn't revert the clipboard too soon
        #            actions.sleep("100ms")

        old = subprocess.check_output(['xsel', '-o', '-b'])
        clip.set_text(text)
        actions.edit.paste()
        actions.sleep("200ms")
        clip.set_text(old.decode("utf-8"))
예제 #26
0
 def switcher_launch(path: str):
     """Launch a new application by path"""
     if app.platform == "windows":
         if "." not in path:
             actions.key("super-s")
             actions.sleep("300ms")
             actions.insert("apps: {}".format(path))
             actions.sleep("150ms")
             actions.key("enter")
         else:
             # print("path: " + path)
             os.startfile(path)
     else:
         ui.launch(path=path)
예제 #27
0
def get_editor_app() -> ui.App:
    editor_names = get_editor_names()

    for app in ui.apps(background=False):
        if app.name in editor_names:
            return app

    actions.user.system_command("code")
    while True:
        actions.sleep("500ms")

        for app in ui.apps(background=False):
            if app.name in editor_names:
                return app


    raise RuntimeError("Draft editor is not running")
예제 #28
0
    def show_throttled_logs(self, sleep_s: float = 0):
        if sleep_s:
            actions.sleep(sleep_s)

        if self.throttled_logs:
            for log_message in self.throttled_logs:
                self.topic_types["log_messages"][log_message.type].append(
                    log_message)
                self.topic_types["log_messages"][
                    log_message.type][-max_log_length:]
                if self.queued_log_splits:
                    self.revise_log(True)
                else:
                    self.dispatch(
                        "broadcast_update",
                        HudContentEvent("log_messages", log_message.type,
                                        log_message, "append"))
            self.throttled_logs = []
예제 #29
0
 def german_wiktionary_yank_audio():
     """Assuming we are on de.wiktionary.org, yanks the first audio."""
     actions.browser.focus_address()
     actions.sleep("100ms")
     actions.key("ctrl-f")
     actions.insert("Hörbeispiele")
     actions.sleep("50ms")
     actions.key("escape tab enter")
     actions.sleep("500ms")
     actions.browser.focus_address()
     actions.sleep("200ms")
     url = actions.edit.selected_text()
     actions.sleep("200ms")
     actions.browser.go_back()
     print(url)
     if not any(a in url for a in "ogg opus mp3".split()):
         url = None
     return url
예제 #30
0
    def cursorless_command(action_id: str, target: dict):
        """Perform cursorless command on target"""
        if action_id in callback_action_map:
            return callback_action_map[action_id](target)
        elif action_id in makeshift_action_map:
            command, command_options, talon_options = makeshift_action_map[
                action_id]
            return_value = (vscode_command(command, target, command_options)
                            if talon_options.await_command
                            else vscode_command_no_wait(
                                command, target, command_options))

            if talon_options.post_command_sleep_ms:
                actions.sleep(f"{talon_options.post_command_sleep_ms}ms")

            return return_value
        else:
            return actions.user.cursorless_single_target_command(
                action_id, target)