Exemple #1
0
def on_ready():
    update_overrides(None, None)
    fs.watch(overrides_directory, update_overrides)
    update_launch_list()
    update_running_list()
    update_visible_list()
    ui.register("", ui_event)
Exemple #2
0
def register_events(register: bool):
    global events_registered
    if register:
        if not events_registered and live_update:
            events_registered = True
            ui.register('', ui_event)
    else:
        events_registered = False
        ui.unregister('', ui_event)
Exemple #3
0
def on_ready():
    global editor_names
    names_csv = setting_editor_names.get()
    editor_names = names_csv.split(", ") if names_csv else default_names

    names_str = '\n'.join({f"app.name: {name}" for name in editor_names})
    mod.apps.draft_editor = f"""{names_str}"""

    ui.register("app_launch", scope.update)
    ui.register("app_close", scope.update)
Exemple #4
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)
Exemple #5
0
class ZshTriggerWatch:
    """
    Whenever a new zsh window is selected, reach out to the zsh completion
    server and have it tell us what its completion list is.
    """
    def win_focus(window):
        if window.title.startswith("zsh:"):
            pid = int(window.title.split(':')[1])
            zsh_pool.trigger(pid)

    def win_title(window):
        if window == ui.active_window():
            if window.title.startswith("zsh:"):
                pid = int(window.title.split(':')[1])
                zsh_pool.trigger(pid)

    ui.register('win_focus', win_focus)
    ui.register('win_title', win_title)
 def enable(self):
     if not self.enabled:
         self.enabled = True
         self.update_focus_indicator()
         ui.register("win_focus", self.update_focus_indicator)
         ui.register("win_resize", self.update_focus_indicator)
         ui.register("win_move", self.move_focus_indicator)
Exemple #7
0
def on_ready():
    update_running_applications_list()
    ui.register("", ui_event)
    for app in ui.apps(background=False):
        if app.name in editor_names:
            return {"draft_editor_running": True}

    return {"draft_editor_running": False}


def handle_app_activate(app):
    if app.name in get_editor_names():
        add_tag("user.draft_editor_app_focused")
    else:
        remove_tag("user.draft_editor_app_focused")


ui.register("app_launch", scope.update)
ui.register("app_close", scope.update)
ui.register("app_activate", handle_app_activate)


original_window = None


@mod.action_class
class Actions:
    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()
Exemple #9
0
    else:
        if re.match(r'Exceed', win.title) is not None:
            vnc_app = "emacs"
    #print(etx_app)
    print(emacs_modes)
    print(emacs_path)
    return_dict = {}
    #return_dict['vnc_app'] = vnc_app
    #print("haca kingo vnc_app")
    #print(emacs_path)3
    return_dict['vnc_app'] = "emacs"
    return_dict['emacs_modes'] = emacs_modes
    return_dict['emacs_path'] = emacs_path
    return return_dict
        
ui.register('win_title', scope.update)
ui.register('win_focus', scope.update)


@mod.action_class
class Actions:
    def term_up(number: int):
        """insert up<num> into terminals. This maps to an alias to cd ../ and the number of directories up matches the number"""
        if number == 1:
            actions.insert("up")
        else:
            actions.insert("up"+str(number))
                
        actions.key("enter")

    def execute_command(command: str):
Exemple #10
0
    # if we made it this far, either it's showing and we need to force an update
    # or we need to hide the gui
    if not is_supported:
        if gui_folders.showing:
            gui_folders.hide()
            gui_files.hide()
    elif is_valid_path and (gui_folders.showing or settings.get(
            "user.file_manager_auto_show_pickers", 0) >= 1):
        gui_folders.freeze()
        gui_files.freeze()

    # todo: figure out what changed in 1320
    # print("hiding: is_valid_path {}, gui_folders.showing {}, title  {}".format(str(is_valid_path), str(gui_folders.showing), str(cached_title)))


ui.register("win_title", update_maps)
ui.register("win_focus", update_maps)

ctx.lists["self.file_manager_directories"] = []
ctx.lists["self.file_manager_files"] = []

current_folder_page = 1


@imgui.open(y=10, x=900, software=False)
def gui_folders(gui: imgui.GUI):
    global current_folder_page, total_folder_pages
    total_folder_pages = math.ceil(
        len(ctx.lists["self.file_manager_directories"]) /
        len(selection_numbers))
    gui.text("Select a directory ({}/{})".format(current_folder_page,
 def __init__(self):
     self.reset()
     ui.register("app_deactivate", lambda app: self.reset())
     ui.register("win_focus", lambda win: self.reset())
Exemple #12
0
def register_events():
    ui.register("win_title", win_event_handler)
    ui.register("win_focus", win_event_handler)
        for expression in regex_shell_tags:
            m = re.match(expression, shell_command)
            if m is not None:
                ctx.tags = [regex_shell_tags[expression]]
                break
            m = re.match(expression, window_title)
            if m is not None:
                ctx.tags = [regex_shell_tags[expression]]
                break


#        if not found_fuzzy:
#            print(f"WARNING: missing tag for shell cmd: {shell_command}")
#            print(f"WARNING: consider updating vim_terminal.py: {shell_command}")
#


def win_title_hook(window):
    # print(f"vim win_title_hook: {window.title}")
    parse_vim_term_title(window)


def win_focus_hook(window):
    # print("vim win_focus_hook")
    parse_vim_term_title(window)


ui.register("win_title", win_title_hook)
ui.register("win_focus", win_focus_hook)
 def __init__(self):
     self.reset()
     ui.register('app_deactivate', lambda app: self.reset())
     ui.register('win_focus', lambda win: self.reset())
Exemple #15
0
 def __init__(self):
     self.show = False
     tracker.register("post:gaze", self.on_gaze)
     ui.register("win_focus", self.on_focus)
     ui.register("app_activate", self.on_focus)
Exemple #16
0
def print_non_natlink(i, o):
    if "natspeak" not in str(o):
        print(i, o)
    shadow_title = ui.active_window().title
    actual_title = GetWindowText(GetForegroundWindow())
    global last_window
    if shadow_title != actual_title:
        if last_window != shadow_title:
            print("Window state mismatch detected")
            print(f"Shadow window title: {shadow_title}")
            print(f"Actual window title: {actual_title}")
            last_window = shadow_title
        else:
            pass
    else:
        last_window = ""


from talon import ui

ui.register('win_focus', print)

ctx.commands = {
    "copy active bundle": copy_bundle,

    # "window {direction}": lambda m: press("win-" + m["direction"]),
    "show window information": utilities.windowinfo,
}

ctx.lists["repeat"] = repeat
ctx.lists["direction"] = directions
Exemple #17
0
 def __init__(self):
     self.reset()
     self.caps = True
     self.space = False
     ui.register("app_deactivate", lambda app: self.reset())
     ui.register("win_focus", lambda win: self.reset())
Exemple #18
0
 def __init__(self):
     ui.register('app_activate', self.update)
     ui.register(
         'win_focus',
         lambda win: win == ui.active_window() and self.update(win.app))
     self.path = []
            app.notify(subtitle=f"hiss quick action set\n{pop_quick_action}")

    def hiss_quick_action_set_last():
        """Sets the quick macro to the previously set action"""
        global hiss_quick_action
        global hiss_quick_action_last
        hiss_quick_action = hiss_quick_action_last
        app.notify(subtitle=f"hiss quick action set\n{pop_quick_action}")

    def hiss_quick_action_run():
        """Runs the quick macro"""
        print(*hiss_quick_action)
        scripting.core.CoreActions.run_command(*hiss_quick_action)


ui.register("app_deactivate",
            lambda app: actions.user.pop_quick_action_clear())
ui.register("win_focus", lambda win: actions.user.pop_quick_action_clear())

pop_quick_action = None
pop_quick_action_last = None
pop_quick_action_history = []


def on_pop(active):
    global pop_quick_action
    if pop_quick_action is None:
        actions.user.pop()
    else:
        actions.user.pop_quick_action_run()

    actions,
    ui,
    Module,
    app,
    clip,
    registry,
    scope,
    speech_system,
)
import os
import re
from itertools import islice
import datetime


ui.register("win_focus", print)
registry.register("", print)
mod = Module()
pattern = re.compile(r"[A-Z][a-z]*|[a-z]+|\d")

# todo: should this be an action that lives elsewhere??
def create_name(text, max_len=20):
    return "_".join(list(islice(pattern.findall(text), max_len))).lower()


@mod.action_class
class Actions:
    def talon_add_context_clipboard_python():
        """Adds os-specific context info to the clipboard for the focused app for .py files. Assumes you've a Module named mod declared."""
        friendly_name = actions.app.name()
        # print(actions.app.executable())
Exemple #21
0
from talon import ui, actions, cron, speech_system, app

job = None


def on_phrase(j):
    global job
    if j.get('phrase'):
        cron.cancel(job)
        job = cron.after('15m', actions.speech.disable)


speech_system.register('post:phrase', on_phrase)


def on_ready():
    global job
    if actions.speech.enabled():
        job = cron.after('15m', actions.speech.disable)


app.register("ready", on_ready)

# https://github.com/nriley/knausj_talon/blob/nriley/misc/screen.py

ui.register('screen_sleep', lambda e: actions.speech.disable())
# ui.register('screen_wake')
Exemple #22
0
        "htop": "user.htop",
        "taskwarrior-tui": "user.taskwarrior_tui",
        "~/.talon/bin/repl": "user.talon_repl",
    }
    # XXX - there's probably a better way to deal with this
    fuzzy_shell_tags = {
        # Match on stuff like fzf running in floating term
        #"term://": "user.readline",
        "root@": "terminal",  # hacky match for docker containers
    }
    print(shell_command)
    if shell_command in shell_tags:
        ctx.tags = [shell_tags[shell_command]]
    else:
        found_fuzzy = False
        for tag in fuzzy_shell_tags:
            if shell_command.startswith(tag):
                ctx.tags = [fuzzy_shell_tags[tag]]
                found_fuzzy = True
                break
        #ctx.tags = ["terminal"]


#        if not found_fuzzy:
#            print(f"WARNING: missing tag for shell cmd: {shell_command}")
#            print(f"WARNING: consider updating vim_terminal.py: {shell_command}")
#

ui.register("win_title", parse_vim_term_title)
ui.register("win_focus", parse_vim_term_title)
Exemple #23
0
        else:
            return ""
    elif str(app.bundle).startswith("com.jetbrains."):
        filename = title.split(" - ")[-1]
        filename = filename.split(" [")[0]
    elif win.doc:
        filename = win.doc
    else:
        return ""
    filename = filename.strip()
    if "." in filename:
        return filename.split(".")[-1]
    return ""


ui.register("", _update_ui_scopes)


# noinspection PyMethodParameters,PyMethodMayBeStatic
@mod.action_class
class Actions:
    def set_language(lang: str):
        """Set lang of language_scope.  (Not the real name of the language, just the file extension.)"""
        global language
        language = lang
        language_scope.update()

    def current_language() -> str:
        """Get current language."""
        print(f"current language is {language}")
        return scope.get("user.language")
 def __init__(self):
     self.job = None
     self.show = False
     tracker.register('post:gaze', self.on_gaze)
     ui.register('win_focus', self.on_focus)
     ui.register('app_activate', self.on_focus)
Exemple #25
0
        self.reset_context()
        self.force_no_space = True


def format_first_letter(text, formatter):
    i = -1
    for i, c in enumerate(text):
        if c.isalpha():
            break
    if i >= 0 and i < len(text):
        text = text[:i] + formatter(text[i]) + text[i + 1:]
    return text


dictation_formatter = DictationFormat()
ui.register("app_deactivate", lambda app: dictation_formatter.reset())
ui.register("win_focus", lambda win: dictation_formatter.reset())


def reformat_last_utterance(formatter):
    text = actions.user.get_last_phrase()
    actions.user.clear_last_phrase()
    text = formatter(text)
    actions.user.add_phrase_to_history(text)
    actions.insert(text)


@mod.action_class
class Actions:
    def dictation_format_reset():
        """Resets the dictation formatter"""
from talon import Module, ui

mod = Module()


@mod.scope
def scope():
    return {"running": {app.name.lower() for app in ui.apps()}}


ui.register("app_launch", scope.update)
ui.register("app_close", scope.update)
Exemple #27
0
ctx.keymap(keymap)


def update_lists():
    global apps
    new = {}
    for app in ui.apps():
        words = app.name.split(' ')
        for word in words:
            if word and not word in new:
                new[word] = app.name
        new[app.name] = app.name
    if set(new.keys()) == set(apps.keys()):
        return
    ctx.set_list('apps', new.keys())
    apps = new


def ui_event(event, arg):
    if event in ('app_activate', 'app_deactivate', 'app_launch', 'app_close'):
        update_lists()


ui.register('', ui_event)
update_lists()


def unload():
    ctx.unload()
    ui.unregister('', update_lists)
Exemple #28
0
 def __init__(self):
     self.reset()
     self.last_utterance = None
     self.paused = False
     ui.register("app_deactivate", lambda app: self.reset())
     ui.register("win_focus", lambda win: self.reset())
Exemple #29
0
    ctx.set_list("running", running.keys())

    new = {}
    for base in "/Applications", "/Applications/Utilities", "/System/Applications", "/System/Applications/Utilities":
        for name in os.listdir(base):
            path = os.path.join(base, name)
            name = name.rsplit(".", 1)[0]
            new[name] = path
            words = name.split(" ")
            for word in words:
                if word and word not in new:
                    if len(name) > 6 and len(word) < 3:
                        continue
                    new[word] = path
    launch = new
    ctx.set_list("launch", launch.keys())


def ui_event(event, arg):
    if event in ("app_activate", "app_launch", "app_close", "win_open",
                 "win_close"):
        # print(event, arg)
        if event in ("win_open", "win_closed"):
            if arg.app.name == "Amethyst":
                return
        update_lists()


ui.register("", ui_event)
update_lists()
        'enter': [enable_talon_speech, disable_dragon_speech],
        'exit': []
    },
    'Microsoft Excel': {
        'enter': [enable_talon_speech, disable_dragon_speech],
        'exit': []
    },
    'TextEdit': {
        'enter': [enable_talon_speech, enable_dragon_speech],
        'exit': [disable_dragon_speech]
    },
}


def on_activate(app):
    print('{0.name} is activated'.format(app))
    if app.name in special_apps:
        for action in special_apps[app.name]['enter']:
            action(None)


def on_deactivate(app):
    print('{0.name} is deactivated'.format(app))
    if app.name in special_apps:
        for action in special_apps[app.name]['exit']:
            action(None)


ui.register('app_deactivate', on_deactivate)
ui.register('app_activate', on_activate)