from talon.voice import Context, ContextGroup, talon from talon import app def set_enabled(enable): if enable: talon.enable() app.icon_color(0, 0.7, 0, 1) else: talon.disable() app.icon_color(1, 0, 0, 1) lib.menu_check(b'!Enable Speech Recognition', enable) def on_menu(item): if item == '!Enable Speech Recognition': set_enabled(not talon.enabled) app.register('menu', on_menu) set_enabled(talon.enabled) sleep_group = ContextGroup('sleepy') sleepy = Context('sleepy', group=sleep_group) sleepy.keymap({ 'talon sleep': lambda m: set_enabled(False), 'talon wake': lambda m: set_enabled(True), }) sleep_group.load()
from talon import actions, app def on_ready(): actions.speech.disable() actions.speech.set_microphone('Yeti Stereo Microphone Analog Stereo') app.register('launch', on_ready)
global cached_path # on windows, we get events from the clock # and such, so this check is important if not window.app.exe or window != ui.active_window(): return path = actions.user.file_manager_current_path() if not "user.file_manager" in registry.tags: actions.user.file_manager_hide_pickers() clear_lists() elif path: if cached_path != path: update_lists() elif cached_path: clear_lists() actions.user.file_manager_hide_pickers() cached_path = path def register_events(): ui.register("win_title", win_event_handler) ui.register("win_focus", win_event_handler) # prevent scary errors in the log by waiting for talon to be fully loaded # before registering the events app.register("launch", register_events)
global show_enabled_contexts_only global selected_context if gui_context_help.showing: if selected_context == None: refresh_context_command_map(show_enabled_contexts_only) else: update_active_contexts_cache(registry.active_contexts()) def help_hide(): """Hides the help""" reset() # print("help_hide - alphabet gui_alphabet: {}".format(gui_alphabet.showing)) # print( # "help_hide - gui_context_help showing: {}".format(gui_context_help.showing) # ) gui_alphabet.hide() gui_context_help.hide() refresh_context_command_map() register_events(False) actions.mode.disable("user.help") def commands_updated(_): update_title() app.register("ready", refresh_context_command_map)
self.prev_mouse_pos = pos for widget in self.widgets: if widget.enabled: widget.mouse_move(self.prev_mouse_pos) def create_hud(): global hud preferences = HeadUpDisplayUserPreferences() from user.talon_hud.knausj_bindings import KnausjStatePoller poller = KnausjStatePoller() hud = HeadUpDisplay(hud_content, preferences, poller) app.register('ready', create_hud) @mod.action_class class Actions: def enable_hud(): """Enables the HUD""" global hud hud.enable() def disable_hud(): """Disables the HUD""" global hud hud.disable() def add_hud_log(type: str, message: str):
if file_extension and file_extension in extension_lang_map: result = extension_lang_map[file_extension] print("code.language: " + result) return result # create a mode for each defined language for __, lang in extension_lang_map.items(): mod.mode(lang) # Create a mode for the automated language detection. This is active when no lang is forced. mod.mode("auto_lang") # Auto lang is enabled by default app.register("ready", lambda: actions.user.code_clear_language_mode()) @mod.action_class class Actions: def code_set_language_mode(language: str): """Sets the active language mode, and disables extension matching""" actions.user.code_clear_language_mode() actions.mode.disable("user.auto_lang") actions.mode.enable("user.{}".format(language)) app.notify("Enabled {} mode".format(language)) # forced_language = True # app.notify("Enabled {} mode".format(language)) def code_clear_language_mode(): """Clears the active language mode, and re-enables code.language: extension matching"""
global cached_path # on windows, we get events from the clock # and such, so this check is important if not window.app.exe or window != ui.active_window(): return path = actions.user.file_manager_current_path() if not "user.file_manager" in registry.tags: actions.user.file_manager_hide_pickers() clear_lists() elif path: if cached_path != path: update_lists() elif cached_path: clear_lists() actions.user.file_manager_hide_pickers() cached_path = path def register_events(): ui.register("win_title", win_event_handler) ui.register("win_focus", win_event_handler) # prevent scary errors in the log by waiting for talon to be fully loaded # before registering the events app.register("ready", register_events)
global show_enabled_contexts_only global selected_context if gui_context_help.showing: if selected_context == None: refresh_context_command_map(show_enabled_contexts_only) else: update_active_contexts_cache(registry.active_contexts()) def help_hide(): """Hides the help""" reset() # print("help_hide - alphabet gui_alphabet: {}".format(gui_alphabet.showing)) # print( # "help_hide - gui_context_help showing: {}".format(gui_context_help.showing) # ) gui_alphabet.hide() gui_context_help.hide() refresh_context_command_map() register_events(False) actions.mode.disable("user.help") def commands_updated(_): update_title() app.register("launch", refresh_context_command_map)
if gui_enabled: actions.self.command_history_disable() else: actions.self.command_history_enable() def command_history_enable(): """Shows the command_history""" global gui_enabled gui_enabled = True reset_gui_timer() def command_history_disable(): """Hides the command_history""" global gui_enabled gui_enabled = False gui.hide() def command_history_clear(): """Clear the command_history""" global history, history_lock with history_lock: history = [] def command_history_set_size(n: int): """Set number of items displayed in the command history.""" context.settings["user.command_history_items"] = n # Enable command history by default. app.register("launch", lambda: actions.self.command_history_enable())
# print("narrow many", repr(digit)) # print(str(digit_list)) for d in digit_list: GridActions.grid_narrow(int(d)) def grid_narrow(digit: Union[int, str]): """Choose a field of the grid and narrow the selection down""" # print("narrow one", repr(digit)) mg.narrow(int(digit)) def grid_go_back(): """Sets the grid state back to what it was before the last command""" mg.go_back() def grid_close(): """Close the active grid""" if len(ctx.tags) > 0 or mg.active: ctx.tags = [] mg.reset()(None) mg.stop() def check_shimmer_setting_at_startup(): if shimmer_effect_enabled.get(): mg.start() mg.reset() mg.stop() app.register("launch", check_shimmer_setting_at_startup)
from talon import actions, app def set_microphone(): actions.speech.set_microphone('Audient iD14') app.register('launch', set_microphone)
# Text formatters actions.user.hud_add_documentation( "Text formatting", "gives a list with examples of commands that can change text with a different format.", documentation_dir + "/text_formatters.txt") # Talon draft usage actions.user.hud_add_documentation( "Talon draft window", "shows all the available commands used for the draft window, which can be used to dictate and edit text outside of the current program.", documentation_dir + "/talon_draft_usage.txt") # Browser documentation actions.user.hud_add_documentation( "Browser usage", "shows the commands and explanations related to web browser usage", documentation_dir + "/browser_usage_documentation.txt") # Basic browser usage actions.user.hud_add_walkthrough( "Basic browser usage", documentation_dir + "/basic_browser_usage_walkthrough.json") # Media usage actions.user.hud_add_walkthrough( "Music and video controls", documentation_dir + "/music_and_video_walkthrough.json") app.register("ready", talon_hud_ready)
if tags is not None: for tag in tags: new_tags.append(tag) modes = [] scopemodes = scope.get("mode") if scopemodes is not None: for mode in scopemodes: modes.append(mode) text = "<*app: " + scope.get("app")["name"] + "/> " + scope.get( "win")["title"] + "/>\n<*Tags:/>\n" + "\n".join( sorted(new_tags)) + "\n<*Modes:/> " + " - ".join(sorted(modes)) return text def append_poller(): actions.user.hud_add_poller("scope", ScopePoller()) app.register("ready", append_poller) mod = Module() @mod.action_class class Actions: def hud_toolkit_scope(): """Start debugging the Talon scope in the Talon HUD""" actions.user.hud_activate_poller("scope")
def register_language_poller(): actions.user.hud_add_poller("programming_toggle", ProgrammingLanguagePoller()) default_option = actions.user.hud_create_button( "Add code language", add_statusbar_programming_icon, "text_navigation") activated_option = actions.user.hud_create_button( "Remove code language", remove_statusbar_programming_icon, "text_navigation") status_option = actions.user.hud_create_status_option( "programming_toggle", default_option, activated_option) actions.user.hud_publish_status_option("programming_option", status_option) app.register("ready", register_language_poller) def load_languages(languages_file): languages = {} languages_header = "Language,Extension,Icon" if not os.path.exists(languages_file): language_defaults = [ "bash,.sh,programming_bash", "c,,programming_c", "cplusplus,.cpp,programming_cplusplus", "csharp,.cs,programming_cplusplus", "objectivec,,programming_objectivec", "haskel,.hs,programming_haskel", "swift,,programming_swift", "rust,.rs,programming_rust", "r,.r,programming_r", "php,.php,programming_php", "ruby,.rb,programming_ruby", "python,.py,programming_python", "lua,.lua,programming_lua",
voice_commands_remaining.remove(said_word) if len(step.voice_commands) > 0 and len(voice_commands_remaining) == 0 and not "skip step" in step.voice_commands and not "continue" in step.voice_commands: cron.cancel(self.next_step_job) self.next_step_job = cron.after("1500ms", self.next_step) hud_walkthrough = WalkthroughPoller() hud_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) def load_walkthrough(): global hud_walkthrough actions.user.hud_add_walkthrough("Head up display", hud_directory + "/docs/hud_walkthrough.json") actions.user.hud_add_poller("walkthrough_step", hud_walkthrough) hud_walkthrough.load_state() app.register("ready", load_walkthrough) @mod.action_class class Actions: def hud_add_walkthrough(title: str, filename: str): """Add a walk through through a file""" global hud_walkthrough hud_walkthrough.add_walkthrough_file(title, filename) def hud_add_lazy_walkthrough(title: str, get_walkthrough: Callable[[], list[HudWalkThroughStep]]): """Add a walk through through a file""" global hud_walkthrough hud_walkthrough.add_lazy_walkthrough(title, get_walkthrough) def hud_create_walkthrough_step(content: str, context_hint: str = "", tags: list[str] = None, modes: list[str] = None, app: str = "", restore_callback: Callable[[Any, Any], None] = None):
winreg.SetValueEx(Registrykey, value_name, 0, winreg.REG_EXPAND_SZ, hidden_cursor) winreg.CloseKey(Registrykey) ctypes.windll.user32.SystemParametersInfoA(win32con.SPI_SETCURSORS, 0, None, 0) except WindowsError: print("Unable to show_cursor({})".format(str(show))) else: ctrl.cursor_visible(show) if setting_mouse_enable_on_startup.get() >= 1: app.register("ready", mouse_wake) def on_pop(active): if setting_mouse_enable_pop_stops_scroll.get() >= 1 and (gaze_job or scroll_job): stop_scroll() elif (not eye_zoom_mouse.zoom_mouse.enabled and eye_mouse.mouse.attached_tracker is not None): print("Triggering non-zoom click") if setting_mouse_enable_pop_click.get() >= 1: ctrl.mouse_click(button=0, hold=16000) def mouse_scroll(amount): def scroll():
if len(name) > 6 and len(word) < 3: continue launch[word] = path ctx.lists["user.launch"] = launch def ui_event(event, arg): if event in ("app_launch", "app_close"): update_lists() # Currently update_launch_list only does anything on mac, so we should make sure # to initialize user launch to avoid getting "List not found: user.launch" # errors on other platforms. ctx.lists["user.launch"] = {} # Talon starts faster if you don't use the `talon.ui` module during launch def on_ready(): update_overrides(None, None) fs.watch(overrides_directory, update_overrides) update_launch_list() ui.register("", ui_event) # NOTE: please update this from "launch" to "ready" in Talon v0.1.5 app.register("launch", on_ready) # app.register("ready", on_ready)
widget.disable() widget.show_animations = show_animations self.widget_manager.widgets = [] self.widget_manager = None preferences = HeadUpDisplayUserPreferences("", CURRENT_TALON_HUD_VERSION) hud = HeadUpDisplay(preferences) def hud_start(): global hud actions.user.hud_internal_register("HeadUpDisplay", hud) app.register('ready', hud_start) @mod.action_class class Actions: def hud_enable(): """Enables the HUD""" global hud hud.enable(True) def hud_disable(): """Disables the HUD""" global hud hud.disable(True) def hud_persist_preferences():
"microphone_list", PartialMicrophonePoller("microphone_list", microphone_poller)) # Add the toggles to the status bar default_option = actions.user.hud_create_button( "Add microphone", add_statusbar_one_click_toggle, "microphone_on") activated_option = actions.user.hud_create_button( "Remove microphone", remove_statusbar_one_click_toggle, "microphone_on") status_option = actions.user.hud_create_status_option( "microphone_toggle", default_option, activated_option) actions.user.hud_publish_status_option("microphone_toggle_option", status_option) app.register("ready", register_microphone_pollers) mod = Module() @mod.action_class class Actions: def show_microphone_options(): """Show the microphone options in a choice panel""" show_microphone_selection() def hud_add_single_click_mic_toggle(): """Add a single click toggle on the status bar""" add_statusbar_one_click_toggle() def hud_remove_single_click_mic_toggle():
lib.nvgBeginPath(vg) lib.nvgMoveTo(vg, x + ob, wavemid - waveheight / 2 + 5) lib.nvgLineTo(vg, x + ot, wavemid + waveheight / 2 - 5) lib.nvgStroke(vg) font = None timeline = AudioTimeline() def on_noise(noise): with timeline.lock: timeline.events.append([len(timeline.history), noise]) def on_overlay(vg, width, height): global font if font is None: font = lib.nvgCreateFont( vg, 'courier'.encode('utf8'), '/Library/Fonts/Courier New Bold.ttf'.encode('utf8')) lib.nvgFontFaceId(vg, font) lib.nvgFontSize(vg, 18) timeline.draw(vg, 0, height * 4 / 5, width, height / 5) noise.register('noise', on_noise) record.register('record', timeline.append) app.register('overlay', on_overlay)
if gui.showing: gui.hide() else: gui.show() def microphone_select(index: int): """Selects a micropohone""" # print(str(index) + " " + str(len(microphone_device_list))) if 1 <= index and index <= len(microphone_device_list): microphone = microphone_device_list[index - 1].name for item in manager.menu.items: # print(item.name + " " + microphone) if microphone in item.name: # manager.menu_click(item) actions.speech.set_microphone(item.name) app.notify("Activating {}".format(item.name)) break gui.hide() ctx.register("devices_changed", devices_changed) def on_launch(): update_microphone_list() app.register("launch", on_launch)
def format_time_ms(self, time_ms: float, threshold: float = 0.0) -> str: content = "" if time_ms <= threshold: return content if time_ms >= 7500: if time_ms >= 20000: content += "<!!" else: content += "<!" content += "{:.1f}".format(time_ms / 1000) + "s" if time_ms >= 7500: content += "/>" return content def register_poller(): actions.user.hud_add_poller("speech", SpeechPoller()) app.register("ready", register_poller) mod = Module() @mod.action_class class Action: def hud_toolkit_speech(): """Start displaying the phrase debugging tools""" actions.user.hud_activate_poller("speech")
def on_ready(): ctx.lists["self.things_tag"] = actions.user.create_spoken_forms_from_map( {tag.title: tag.uuid for tag in tags} ) ctx.lists[ "self.things_tag_with_shortcut" ] = actions.user.create_spoken_forms_from_map( {tag.title: tag.uuid for tag in tags if tag.shortcut is not None} ) ctx.lists["self.things_project"] = actions.user.create_spoken_forms_from_map( {project.title: project.uuid for project in projects} ) # NOTE: please update this from "launch" to "ready" in Talon v0.1.5 app.register("ready", on_ready) @mod.action_class class Actions: def tag_todo(things_tags: str): """Tag todo with a list of tags""" tag_list = [tag_map[tag_uuid] for tag_uuid in things_tags.split(",")] tags_with_shortcuts = [tag for tag in tag_list if tag.shortcut is not None] tags_without_shortcuts = [tag for tag in tag_list if tag.shortcut is None] for tag in tags_with_shortcuts: actions.key(f"ctrl-{tag.shortcut}") for tag in tags_without_shortcuts: actions.key(f"cmd-shift-t")
{"topic_types": copy.copy(self.topic_types)}, "dump") def destroy(self): pass hud_content = HeadUpDisplayContent() def on_ready(): global hud_content actions.user.hud_internal_register("HeadUpDisplayContent", hud_content) app.register('ready', on_ready) @mod.action_class class Actions: def hud_add_log(type: str, message: str): """Adds a log to the HUD""" global hud_content hud_content.append_to_log_messages(type, message) def hud_edit_log(prefix_split: str, throttle_remaining: int = 0, discard_remaining: int = 0, type: str = "command"): """Edits a log message to be split up into multiple with optional discarding of the remainder""" global hud_content