Beispiel #1
0
 def replay_save(choice: int):
     """Save the selected recording to a preconfigured directory"""
     global rr
     file_name = rr.save_recording_by_index(choice)
     if not file_name:
         return
     if settings.get("user.replay_paste_name_on_save") != 0:
         clip.set_text(file_name)
         actions.user.insert_cursor_paste('"[|]":', "")
Beispiel #2
0
 def code_public_function(text: str):
     result = "def {}():".format(
         actions.user.formatted_text(
             text, settings.get("user.code_public_function_formatter")
         )
     )
     actions.user.paste(result)
     actions.edit.left()
     actions.edit.left()
Beispiel #3
0
 def __init__(self, count=30):
     """Specify the number of default recording to list in the picker"""
     self.gui_open = False
     self.recordings_list = []
     self.count = count
     self.recordings = pathlib.Path(TALON_HOME, "recordings/")
     self.last_saved_recording = None
     if settings.get("speech.record_all") != 1:
         app.notify("Recording appears to be disabled")
Beispiel #4
0
    def code_private_function(text: str):
        """Inserts private function declaration"""
        result = "def _{}():".format(
            actions.user.formatted_text(
                text, settings.get("user.code_private_function_formatter")))

        actions.user.paste(result)
        actions.edit.left()
        actions.edit.left()
Beispiel #5
0
 def wait_mode_change(self, wanted):
     timeout = settings.get("user.vim_mode_change_timeout")
     if self.nvrpc.init_ok:
         while wanted != self.nvrpc.get_active_mode()["mode"][0]:
             print("%s vs %s" %
                   (wanted, self.nvrpc.get_active_mode()["mode"]))
             time.sleep(0.01)
     else:
         time.sleep(timeout)
Beispiel #6
0
    def code_default_function(text: str):
        """Inserts function definition"""
        result = "function {} {{".format(
            actions.user.formatted_text(
                text, settings.get("user.code_public_function_formatter")))

        actions.insert("\n\n}")
        actions.key("up:2")
        actions.user.code_insert_function(result, None)
    def code_private_function_async(text: str):
        """Inserts async private function declaration"""
        result = "async {}".format(
            actions.user.formatted_text(
                text, settings.get("user.code_private_function_formatter")
            )
        )

        actions.user.code_insert_function(result, None)
Beispiel #8
0
    def code_private_static_function(text: str):
        """Inserts private static function"""
        result = "private static void {}".format(
            actions.user.formatted_text(
                text, settings.get("user.code_private_function_formatter")
            )
        )

        actions.user.code_insert_function(result, None)
Beispiel #9
0
def get_file_map(current_path):
    files = [
        f.name
        for f in islice(current_path.iterdir(),
                        settings.get("user.file_manager_file_limit", 1000))
        if f.is_file()
    ]
    spoken_forms = create_spoken_forms([p for p in files])
    return dict(zip(spoken_forms, [f for f in files]))
Beispiel #10
0
 def replay_save_last_played():
     """Insert some info from the last self.count recordings"""
     global rr
     file_name = rr.save_last_played()
     if not file_name:
         return
     if settings.get("user.replay_paste_name_on_save") != 0:
         clip.set_text(file_name)
         actions.user.insert_cursor_paste('"[|]":', "")
Beispiel #11
0
    def code_public_function(text: str):
        result = "function {}".format(
            actions.user.formatted_text(
                text, settings.get("user.code_public_function_formatter")
            )
        )

        actions.insert("\n\nend")
        actions.key("up:2")
        actions.user.code_insert_function(result, None)
Beispiel #12
0
    def code_default_function(text: str):
        """Inserts function definition"""

        result = "def {}".format(
            actions.user.formatted_text(
                text,
                settings.get("user.code_public_function_formatter")
            )
        )
        actions.user.paste(result)
Beispiel #13
0
def get_file_map(current_path):
    files = [
        f.name
        for f in islice(current_path.iterdir(),
                        settings.get("user.file_manager_file_limit", 1000))
        if is_file(f)
    ]
    files.sort(key=str.casefold)
    return actions.user.create_spoken_forms_from_list(
        files, words_to_exclude=words_to_exclude)
Beispiel #14
0
 def mouse_scroll_up_continuous():
     """Scrolls up continuously"""
     global continuous_scoll_mode
     continuous_scoll_mode = "scroll up continuous"
     mouse_scroll(-80)()
     
     if scroll_job is None:
         start_scroll() 
     if settings.get("user.mouse_hide_mouse_gui") == 0:
         gui_wheel.show()
Beispiel #15
0
def get_directory_map(current_path):
    directories = [
        f.name
        for f in islice(current_path.iterdir(),
                        settings.get("user.file_manager_folder_limit", 1000))
        if f.is_dir()
    ]
    # print(len(directories))
    spoken_forms = create_spoken_forms(directories)
    return dict(zip(spoken_forms, directories))
Beispiel #16
0
    def enable(self, persisted=False):
        if not self.enabled:
            self.enabled = True
            self.display_state.register("broadcast_update",
                                        self.broadcast_update)

            # Only reset the talon HUD environment after a user action
            # And only set the visible tag
            self.current_talon_hud_environment = settings.get(
                "user.talon_hud_environment", "")

            if persisted:
                self.set_current_flow("enabled")
                self.current_flow = "enable"
                ctx.tags = [
                    "user.talon_hud_available", "user.talon_hud_visible",
                    "user.talon_hud_choices_visible"
                ]

            # Connect the events relating to non-content communication
            self.event_dispatch.register("persist_preferences",
                                         self.debounce_widget_preferences)
            self.event_dispatch.register("hide_context_menu",
                                         self.hide_context_menu)
            self.event_dispatch.register("deactivate_poller",
                                         self.deactivate_poller)
            self.event_dispatch.register("show_context_menu",
                                         self.move_context_menu)
            self.event_dispatch.register("synchronize_poller",
                                         self.synchronize_widget_poller)

            # Reload the preferences just in case a screen change happened in between the hidden state
            if persisted or self.current_flow in ["repair", "initialize"]:
                reload_theme = self.widget_manager.reload_preferences(
                    True, self.current_talon_hud_environment)
                if reload_theme != self.theme.name:
                    self.switch_theme(reload_theme, True)

            for widget in self.widget_manager.widgets:
                if widget.preferences.enabled and not widget.enabled:
                    widget.enable()
            self.synchronize_pollers()

            ui.register("screen_change", self.reload_preferences)
            settings.register("user.talon_hud_environment",
                              self.hud_environment_change)
            self.determine_active_setup_mouse()
            if persisted:
                self.preferences.persist_preferences({"enabled": True})
                self.set_current_flow("manual")

            # Make sure context isn't updated in this thread because of automatic reloads
            cron.cancel(self.update_context_debouncer)
            self.update_context_debouncer = cron.after("50ms",
                                                       self.update_context)
Beispiel #17
0
    def code_insert_function(text: str, selection: str):

        formatted_text = actions.user.formatted_text(
            text, settings.get("user.code_private_function_formatter"))

        if selection:
            result = formatted_text + "({})".format(selection)
        else:
            result = formatted_text + "()"
        actions.user.paste(result)
        actions.edit.left()
Beispiel #18
0
    def adjust_mode(self, valid_mode_ids, no_preserve=False, auto=True):
        if auto is True and settings.get("user.vim_adjust_modes") == 0:
            return

        cur = self.current_mode_id()
        print("Current mode is {}".format(cur))
        if type(valid_mode_ids) != list:
            valid_mode_ids = [valid_mode_ids]
        if cur not in valid_mode_ids:
            # Just favor the first mode
            self.set_mode(valid_mode_ids[0], no_preserve=no_preserve)
Beispiel #19
0
    def code_private_function(text: str):
        """Inserts private function declaration"""
        result = "local function {}".format(
            actions.user.formatted_text(
                text, settings.get("user.code_private_function_formatter")
            )
        )

        actions.insert("\n\nend")
        actions.key("up:2")
        actions.user.code_insert_function(result, None)
Beispiel #20
0
    def code_private_function(text: str):
        result = "{} <- function () {{\n\n}}".format(
            actions.user.formatted_text(
                text, settings.get("user.code_private_function_formatter")))

        actions.user.paste(result)
        actions.edit.up()
        actions.edit.up()
        actions.edit.line_end()
        actions.edit.left()
        actions.edit.left()
        actions.edit.left()
Beispiel #21
0
 def __init__(self, mod):
     self.arch_index = 0
     self.architectures = ["x86", "x64"]
     for arch in self.architectures:
         mod.tag(arch, desc="Tag for enabling {arch} architecture")
     self.architecture = settings.get("user.debug_default_architecture")
     if self.architecture:
         ctx.tags = [f"user.{self.architecture}"]
     else:
         print("Just encountered bug!!!")
         # it seems like sometimes the above isn't set yet...
         ctx.tags = ["user.x64"]
Beispiel #22
0
def code_function(name: str, privacy=None):
    formatted_name = actions.user.formatted_text(
        name, settings.get("user.code_{}_function_formatter".format(privacy)))

    if privacy:
        result = "{} function {}".format(privacy, formatted_name)
    else:
        result = "function {}".format(formatted_name)

    actions.user.paste("{}():  {{\n}}".format(result))
    actions.edit.up()
    actions.edit.line_end()
    actions.edit.left()
    actions.edit.left()
Beispiel #23
0
    def smart_insert(txt: str):
        """context-aware insertion"""

        # delete whatever is currently selected
        actions.key(" ")
        actions.key("backspace")

        with ClipScanner() as clip:

            # scan left side of the cursor
            clip.clear()
            actions.edit.extend_left()
            before = clip.get_selection()
            if before != "":
                actions.edit.extend_right()

            # scan right side of the cursor
            clip.clear()
            actions.edit.extend_right()
            after = clip.get_selection()
            if after != "":
                actions.edit.extend_left()

        squeeze_into_word = False
        if before != "" and unicodedata.category(before)[0] == 'L' \
          and after != "" and unicodedata.category(after)[0] == 'L':
            squeeze_into_word = True

        if before != "" \
          and (unicodedata.category(before)[0] == 'L' or before in _space_after) \
          and txt[0] not in _no_space_before \
          and not squeeze_into_word:
            actions.insert(' ')

        if before in _capitalize_after or before == "":
            txt = txt[0].upper() + txt[1:]

        if settings.get("user.german_unicode") == 0:
            ascii = txt
            for c in _ascii_replace:
                ascii = ascii.replace(c, _ascii_replace[c])
            actions.insert(ascii)
        else:
            actions.insert(txt)

        if (after != "" and (txt[-1] in _space_after
                             or unicodedata.category(txt[-1])[0] == 'L')
                and after not in ' \n\t' and after not in _no_space_before
                and not squeeze_into_word):
            actions.insert(' ')
Beispiel #24
0
def handle_hexdump_count(cmd, number, register, clip=False, copy=False):
    count = settings.get("user.debug_default_hexdump_count")
    if number:
        count = number

    actions.auto_insert(f"{cmd} ")
    if len(register):
        actions.auto_insert(f"${register} {count}\n")
    elif clip:
        if copy:
            actions.edit.copy()
        actions.edit.paste()
        actions.auto_insert(f" {count}\n")
    else:
        actions.user.insert_cursor(f"[|] {count}")
Beispiel #25
0
    def __init__(self):
        self.init_ok = False
        self.nvim = None

        if settings.get("user.vim_use_rpc") == 0:
            return

        self.rpc_path = self.get_active_rpc()
        if self.rpc_path is not None:
            try:
                self.nvim = pynvim.attach("socket", path=self.rpc_path)
            except RuntimeError:
                return
            self.init_ok = True
        else:
            return
Beispiel #26
0
    def open_recordings(self, data):
        if settings.get("speech.record_all", False) == False:
            actions.user.hud_add_log("warning", "Recordings aren't currently enabled!\n" + \
            "Enable them in the talon menu to create recordings")

        if not os.path.exists(str(TALON_HOME) + "/recordings"):
            actions.user.hud_add_log("error",
                                     "No recordings have been made yet!")
        else:
            recordings_folder = str(TALON_HOME)
            recordings_folder += "/recordings"
            if platform.system() == "Windows":
                os.startfile(recordings_folder)
            elif platform.system() == "Darwin":
                subprocess.Popen(["open", recordings_folder])
            else:
                subprocess.Popen(["xdg-open", recordings_folder])
Beispiel #27
0
    def personal_info(record: str):
        """Insert some info from the personal info database"""
        global pi
        global personal_info_list
        record_data = pi.db[record]
        if type(record_data) == list:
            if len(record_data) > 1:

                auto_index = settings.get("user.personal_info_auto_select")
                personal_info_list = record_data
                if auto_index <= len(record_data):
                    record_data = record_data[auto_index]
                else:
                    raise_personal_info()
            else:
                record_data = record_data[0]
        actions.insert(f"{record_data}")
Beispiel #28
0
def code_function(name: str, is_public: bool):
    formatter_privacy = "public" if is_public else "private"
    formatted_name = actions.user.formatted_text(
        name,
        settings.get(
            "user.code_{}_function_formatter".format(formatter_privacy)))

    if is_public == "public":
        result = "pub fn {}".format(formatted_name)
    else:
        result = "fn {}".format(formatted_name)

    actions.user.paste("{}() {{\n}}".format(result))
    actions.edit.up()
    actions.edit.line_end()
    actions.edit.left()
    actions.edit.left()
    actions.edit.left()
Beispiel #29
0
    def __init__(self, mod):
        self.datatypes = ["c_basic_datatypes", "c_stdint_datatypes"]

        default = "c_basic_datatypes"
        if settings.get("user.use_stdint_datatypes"):
            default = "c_stdint_datatypes"

        index = 0
        for type in self.datatypes:
            if default == type:
                break
            index += 1
        self.datatype_index = index

        for datatype in self.datatypes:
            mod.tag(datatype, desc="Tag for enabling {datatype} datatype")
        self.datatype = self.datatypes[self.datatype_index]
        ctx.tags = [f"user.{self.datatype}"]
Beispiel #30
0
    def start(self, current_flow="initialize"):
        self.set_current_flow(current_flow)
        self.current_talon_hud_environment = settings.get(
            "user.talon_hud_environment", "")
        if (self.preferences.prefs["enabled"]):
            self.enable()
            ctx.tags = [
                "user.talon_hud_available", "user.talon_hud_visible",
                "user.talon_hud_choices_visible"
            ]

            if actions.sound.active_microphone() == "None":
                actions.user.hud_add_log(
                    "warning",
                    "Microphone is set to \"None\"!\n\nNo voice commands will be registered."
                )
        self.set_current_flow("manual")
        self.distribute_content()