def set_debug_enabled(enable): global is_debug_enabled # Respect the enabled-ness of default talon ContextGroup for these Voice Commands # Also, no point in re-registering if not talon.enabled or enable == is_debug_enabled: return if enable: engine.register('', debug_listener) else: engine.unregister('', debug_listener) is_debug_enabled = enable
hist_len = 10 def parse_phrase(phrase): return " ".join(word.split("\\")[0] for word in phrase) def on_phrase(j): phrase = parse_phrase(j.get("phrase", [])) cmd = j["cmd"] if cmd == "p.end" and phrase: with atomic_write(path, overwrite=True) as f: f.write(phrase) engine.register("phrase", on_phrase) template = """ <style type="text/css"> body { width: 400px; padding: 0; margin: 0; } .contents, table, h3 { width: 100%; } table { table-layout: fixed; } td {
from talon.voice import Word, Context, Key, Str, press from talon import app, clip, ui from talon_init import TALON_HOME, TALON_PLUGINS, TALON_USER import string from ..utils import surround, parse_words, parse_word, sentence_text, text, word from talon.engine import engine def engine_update(j): engine.cmd("g.update", name="dragon", enabled=False) engine.register("ready", engine_update) def copy_bundle(m): bundle = ui.active_app().bundle clip.set(bundle) app.notify("Copied app bundle", body="{}".format(bundle)) ctx = Context("standard") ctx.vocab = [ "docker", "talon", "pragma", "pragmas", "vim", "configs", "spotify",
event = m.get("event") except (AttributeError): event = "unknown" new_m = None for handler in APPLIED_HANDLERS: h = handlers[handler] if "topic" not in h or topic in h["topic"]: if "event" not in h or event in h["event"]: if "cond" not in h or h["cond"](m): new_m = h["format"](m) if new_m: print(topic, new_m) engine.register("", listener) def ui_event(event, arg): contexts = [ctx.name for ctx in voice.talon.active] listener( "ui", { "event": event, "arg": arg, "active": ui.active_app(), "contexts": contexts }, ),
from talon.engine import engine def listener(topic, m): if topic == 'cmd' and m['cmd']['cmd'] == 'g.load' and m['success'] == True: print('[grammar reloaded]') else: print(topic, m) engine.register('', listener)
def __init__(self): self.history = defaultdict(int) engine.register("post:phrase", self.on_phrase_post)
macro_stop(None) actions = [] for item in macro: for action, rule in item: if isinstance(action, Key): actions.append('press("{}")'.format(action.data)) elif isinstance(action, Str): actions.append('Str("{}")(None)'.format(action.data)) else: # TODO: other conditions actions.append(str(action)) for action in actions: Str(action)(None) press("enter") engine.register("post:phrase", macro_record) ctx = Context("macro") ctx.keymap( { "macro (start | record)": macro_start, "macro stop": macro_stop, "macro play": macro_play, "macro print": macro_print, } )
from talon.engine import engine def on_status(j): if j['cmd'] == 'mic' and j['status'] == 'on': print('mic turned on, mimic "go to sleep"') engine.mimic('go to sleep') engine.register('status', on_status)
def __init__(self): self.history = [] engine.register('post:phrase', self.on_phrase_post)
if WEBVIEW: webview = webview.Webview() webview.body = '<i>[waiting for phrase]</i>' webview.show() def parse_phrase(phrase): return ' '.join(word.split('\\')[0] for word in phrase) def on_phrase(j): phrase = parse_phrase(j.get('phrase', [])) cmd = j['cmd'] if cmd == 'p.end' and phrase: with atomic_write(path, overwrite=True) as f: f.write(phrase) if WEBVIEW and cmd in ('p.end', 'p.hypothesis') and phrase: body = phrase.replace(' ', ' ') if cmd == 'p.hypothesis': webview.render("<i>{{ phrase }}</i>", phrase=body) else: webview.render("{{ phrase }}", phrase=body) if NOTIFY and cmd == 'p.end' and phrase: app.notify(body=phrase) engine.register('phrase', on_phrase)
def macro_print(m): global macro macro_stop(None) actions = [] for item in macro: for action, rule in item: if isinstance(action, Key): actions.append('press("{}")'.format(action.data)) if isinstance(action, Str): actions.append('Str("{}")(None)'.format(action.data)) else: # TODO: other conditions actions.append(str(action)) for action in actions: Str(action)(None) press('enter') engine.register('post:phrase', macro_record) ctx = Context('macro') ctx.keymap({ 'macro (start | record)': macro_start, 'macro stop': macro_stop, 'macro play': macro_play, 'macro print': macro_print, })
from talon.engine import engine def on_status(topic, j): if j["cmd"] == "mic" and j["status"] == "on": print('mic turned on, mimic "go to sleep"') engine.mimic("go to sleep") engine.register("status", on_status)
] remove_words = [ # r'(\left-parenthesis\left paren', # r'(\left-parenthesis\left parenthesis', # r')\right-parenthesis\right paren', # r')\right-parenthesis\right parenthesis', # r'[\left-square-bracket\left bracket', # r']\right-square-bracket\right bracket', ] def on_ready(j): if add_words: engine.cmd('w.add', words=add_words) if remove_words: engine.cmd('w.remove', words=remove_words) engine.register('ready', on_ready) """ # miscellaneous 'chuck': 'shock' 'aldo': 'algo' 'GPUs': 'gpus' 'docker file': 'dockerfile' 'deck': 'deque' 'compose a bull': 'composable' 'jace on': 'json' # linux 'H top': 'htop' 'IO top': 'iotop' 'T mucks': 'tmux'
def __init__(self): self.visible = True self.history = [] engine.register("post:phrase", self.on_phrase_post)
def __init__(self): self.history = [] engine.register('post:phrase', self.on_phrase_post) self.canvas = Canvas.from_screen(ui.main_screen()) self.canvas.register('draw', self.draw)
history.append(phrase) history = history[-hist_len:] # todo: dynamic rect? @imgui.open(y=0, x=0, software=True) def gui(gui: imgui.GUI): global history gui.text("Command History") gui.line() text = history[:] for line in text: gui.text(line) engine.register('post:phrase', on_phrase_post) mod = Module() @mod.action_class class Actions: def history_enable(): """Enables the history""" gui.show() def history_disable(): """Disables the history""" gui.hide() def history_clear():
def __init__(self): self.history = [] self.macro_history = [] self.timer = cron.after('15s', self.auto_hide) self.auto_hidden = False engine.register('post:phrase', self.on_phrase_post)