From a760bf2733475bc1a633189bc0e0c80c4fbac673 Mon Sep 17 00:00:00 2001 From: Mike Roberts <42875462+mrob95@users.noreply.github.com> Date: Sat, 15 Sep 2018 15:44:44 +0100 Subject: [PATCH 1/3] caster clipboard commands preserve system clipboard --- caster/lib/ccr/core/nav.py | 55 +++++++++--------- caster/lib/navigation.py | 111 ++++++++++++++++++++++++------------- 2 files changed, 104 insertions(+), 62 deletions(-) diff --git a/caster/lib/ccr/core/nav.py b/caster/lib/ccr/core/nav.py index 245e928c7..72f95dabf 100644 --- a/caster/lib/ccr/core/nav.py +++ b/caster/lib/ccr/core/nav.py @@ -74,11 +74,12 @@ class NavigationNon(MappingRule): R(Key("control:down") + Mouse("left") + Key("control:up"), rdescript="Mouse: Ctrl + Left Click"), "garb []": - R(Mouse("left") + Mouse("left") + Key("c-c") + - Function(navigation.clipboard_to_file, nexus=_NEXUS), + R(Mouse("left") + Mouse("left") + Function( + navigation.stoosh_keep_clipboard, nexus=_NEXUS), rdescript="Highlight @ Mouse + Copy"), "drop []": - R(Mouse("left") + Mouse("left") + Function(navigation.drop, nexus=_NEXUS), + R(Mouse("left") + Mouse("left") + Function( + navigation.drop_keep_clipboard, nexus=_NEXUS), rdescript="Highlight @ Mouse + Paste"), "sure stoosh": R(Key("c-c"), rdescript="Simple Copy"), @@ -185,9 +186,9 @@ class Navigation(MergeRule): "( | []) [( | )]": R(Function(textformat.master_text_nav), rdescript="Keyboard Text Navigation"), - "stoosh []": R(Key("c-c")+Function(navigation.clipboard_to_file, nexus=_NEXUS), rspec="stoosh", rdescript="Copy"), - "cut []": R(Key("c-x")+Function(navigation.clipboard_to_file, nexus=_NEXUS), rspec="cut", rdescript="Cut"), - "spark []": R(Function(navigation.drop, nexus=_NEXUS), rspec="spark", rdescript="Paste"), + "stoosh []": R(Function(navigation.stoosh_keep_clipboard, nexus=_NEXUS), rspec="stoosh", rdescript="Copy"), + "cut []": R(Function(navigation.cut_keep_clipboard, nexus=_NEXUS), rspec="cut", rdescript="Cut"), + "spark []": R(Function(navigation.drop_keep_clipboard, nexus=_NEXUS), rspec="spark", rdescript="Paste"), "deli []": R(Key("del/5"), rspec="deli", rdescript="Delete") * Repeat(extra="nnavi50"), "clear []": R(Key("backspace/5:%(nnavi50)d"), rspec="clear", rdescript="Backspace"), @@ -196,7 +197,7 @@ class Navigation(MergeRule): "shackle": R(Key("home/5, s-end"), rspec="shackle", rdescript="Select Line"), "(tell | tau) ": R(Function(navigation.next_line), rspec="tell dock", rdescript="Complete Line"), - "duple []": R(Key("escape, home, s-end, c-c, end, enter, c-v"), rspec="duple", rdescript="Duplicate Line") * Repeat(extra="nnavi50"), + "duple []": R(Function(navigation.duple_keep_clipboard), rspec="duple", rdescript="Duplicate Line"), "Kraken": R(Key("c-space"), rspec="Kraken", rdescript="Control Space"), # text formatting @@ -212,17 +213,19 @@ class Navigation(MergeRule): } extras = [ + IntegerRefST("nnavi10", 1, 11), IntegerRefST("nnavi50", 1, 50), IntegerRefST("nnavi500", 1, 500), Dictation("textnv"), - Choice("enclosure", { - "prekris": "(~)", - "angle": "<~>", - "curly": "{~}", - "brax": "[~]", - "thin quotes": "'~'", - 'quotes': '"~"', - }), + Choice( + "enclosure", { + "prekris": "(~)", + "angle": "<~>", + "curly": "{~}", + "brax": "[~]", + "thin quotes": "'~'", + 'quotes': '"~"', + }), Choice("capitalization", { "yell": 1, "tie": 2, @@ -230,16 +233,17 @@ class Navigation(MergeRule): "sing": 4, "laws": 5 }), - Choice("spacing", { - "gum": 1, - "gun": 1, - "spine": 2, - "snake": 3, - "pebble": 4, - "incline": 5, - "dissent": 6, - "descent": 6 - }), + Choice( + "spacing", { + "gum": 1, + "gun": 1, + "spine": 2, + "snake": 3, + "pebble": 4, + "incline": 5, + "dissent": 6, + "descent": 6 + }), Choice("semi", { "dock": ";", "doc": ";", @@ -266,6 +270,7 @@ class Navigation(MergeRule): defaults = { "nnavi500": 1, "nnavi50": 1, + "nnavi10": 1, "textnv": "", "capitalization": 0, "spacing": 0, diff --git a/caster/lib/navigation.py b/caster/lib/navigation.py index c8a37945f..2e5667ffe 100644 --- a/caster/lib/navigation.py +++ b/caster/lib/navigation.py @@ -84,44 +84,81 @@ def mouse_alternates(mode, nexus, monitor=1): else: utilities.availability_message(mode.title(), "PIL") - -def clipboard_to_file(nnavi500, nexus, do_copy=False): - if do_copy: +def stoosh_keep_clipboard(nnavi500, nexus): + if nnavi500 == 1: Key("c-c").execute() - - max_tries = 20 - - key = str(nnavi500) - for i in range(0, max_tries): - failure = False - try: - # time for keypress to execute - time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) - nexus.clip[key] = Clipboard.get_system_text() - utilities.save_json_file(nexus.clip, - settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"]) - except Exception: - failure = True - utilities.simple_log() - if not failure: - break - - -def drop(nnavi500, nexus): - key = str(nnavi500) - while True: - failure = False - try: - if key in nexus.clip: - Clipboard.set_system_text(nexus.clip[key]) - Key("c-v").execute() - else: - dragonfly.get_engine().speak("slot empty") - time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) - except Exception: - failure = True - if not failure: - break + else: + max_tries = 20 + cb = Clipboard(from_system=True) + Key("c-c").execute() + key = str(nnavi500) + for i in range(0, max_tries): + failure = False + try: + # time for keypress to execute + time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) + nexus.clip[key] = Clipboard.get_system_text() + utilities.save_json_file(nexus.clip, + settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"]) + except Exception: + failure = True + utilities.simple_log() + if not failure: + break + cb.copy_to_system() + +def cut_keep_clipboard(nnavi500, nexus): + if nnavi500 == 1: + Key("c-x").execute() + else: + max_tries = 20 + cb = Clipboard(from_system=True) + Key("c-x").execute() + key = str(nnavi500) + for i in range(0, max_tries): + failure = False + try: + # time for keypress to execute + time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) + nexus.clip[key] = Clipboard.get_system_text() + utilities.save_json_file(nexus.clip, + settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"]) + except Exception: + failure = True + utilities.simple_log() + if not failure: + break + cb.copy_to_system() + +def drop_keep_clipboard(nnavi500, nexus): + if nnavi500 == 1: + Key("c-v").execute() + else: + key = str(nnavi500) + cb = Clipboard(from_system=True) + while True: + failure = False + try: + if key in nexus.clip: + Clipboard.set_system_text(nexus.clip[key]) + Key("c-v").execute() + else: + dragonfly.get_engine().speak("slot empty") + time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) + except Exception: + failure = True + if not failure: + break + cb.copy_to_system() + +def duple_keep_clipboard(nnavi50): + cb = Clipboard(from_system=True) + Key("escape, home, s-end, c-c, end").execute() + time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) + for i in range(0, nnavi50): + Key("enter, c-v").execute() + time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) + cb.copy_to_system() def erase_multi_clipboard(nexus): From d70de9d8964632d8ca1d3836b7b1e66005c7070c Mon Sep 17 00:00:00 2001 From: Mike Roberts <42875462+mrob95@users.noreply.github.com> Date: Sat, 15 Sep 2018 17:30:48 +0100 Subject: [PATCH 2/3] improved consistency, reliability and readability of loops --- caster/lib/navigation.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/caster/lib/navigation.py b/caster/lib/navigation.py index 2e5667ffe..6632dafe6 100644 --- a/caster/lib/navigation.py +++ b/caster/lib/navigation.py @@ -103,8 +103,8 @@ def stoosh_keep_clipboard(nnavi500, nexus): except Exception: failure = True utilities.simple_log() - if not failure: - break + if not failure: + break cb.copy_to_system() def cut_keep_clipboard(nnavi500, nexus): @@ -126,25 +126,26 @@ def cut_keep_clipboard(nnavi500, nexus): except Exception: failure = True utilities.simple_log() - if not failure: - break + if not failure: + break cb.copy_to_system() def drop_keep_clipboard(nnavi500, nexus): if nnavi500 == 1: Key("c-v").execute() else: + max_tries = 20 key = str(nnavi500) cb = Clipboard(from_system=True) - while True: + for i in range(0, max_tries): failure = False try: if key in nexus.clip: Clipboard.set_system_text(nexus.clip[key]) Key("c-v").execute() + time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) else: dragonfly.get_engine().speak("slot empty") - time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) except Exception: failure = True if not failure: From f5f26bd8f7dfe7490a8389d45082f02cde1ee855 Mon Sep 17 00:00:00 2001 From: Mike Roberts <42875462+mrob95@users.noreply.github.com> Date: Thu, 20 Sep 2018 18:06:31 +0100 Subject: [PATCH 3/3] yapf formatting --- caster/lib/ccr/core/nav.py | 105 ++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 41 deletions(-) diff --git a/caster/lib/ccr/core/nav.py b/caster/lib/ccr/core/nav.py index 72f95dabf..3786f1fcc 100644 --- a/caster/lib/ccr/core/nav.py +++ b/caster/lib/ccr/core/nav.py @@ -76,11 +76,11 @@ class NavigationNon(MappingRule): "garb []": R(Mouse("left") + Mouse("left") + Function( navigation.stoosh_keep_clipboard, nexus=_NEXUS), - rdescript="Highlight @ Mouse + Copy"), + rdescript="Highlight @ Mouse + Copy"), "drop []": R(Mouse("left") + Mouse("left") + Function( navigation.drop_keep_clipboard, nexus=_NEXUS), - rdescript="Highlight @ Mouse + Paste"), + rdescript="Highlight @ Mouse + Paste"), "sure stoosh": R(Key("c-c"), rdescript="Simple Copy"), "sure cut": @@ -160,55 +160,78 @@ class Navigation(MergeRule): mapping = { # "periodic" repeats whatever comes next at 1-second intervals until "cancel" is spoken or 100 tries occur - "periodic": ContextSeeker(forward=[L(S(["cancel"], lambda: None), \ - S(["*"], \ - lambda fnparams: UntilCancelled(Mimic(*filter(lambda s: s != "periodic", fnparams)), 1).execute(), \ - use_spoken=True))]), + "periodic": + ContextSeeker(forward=[L(S(["cancel"], lambda: None), + S(["*"], lambda fnparams: UntilCancelled(Mimic(*filter(lambda s: s != "periodic", fnparams)), 1).execute(), + use_spoken=True))]), # VoiceCoder-inspired -- these should be done at the IDE level - "fill ": R(Key("escape, escape, end"), show=False) + - AsynchronousAction([L(S(["cancel"], Function(context.fill_within_line, nexus=_NEXUS))) - ], time_in_seconds=0.2, repetitions=50, rdescript="Fill" ), - "jump in": AsynchronousAction([L(S(["cancel"], context.nav, ["right", "(~[~{~<"])) - ], time_in_seconds=0.1, repetitions=50, rdescript="Jump: In" ), - "jump out": AsynchronousAction([L(S(["cancel"], context.nav, ["right", ")~]~}~>"])) - ], time_in_seconds=0.1, repetitions=50, rdescript="Jump: Out" ), - "jump back": AsynchronousAction([L(S(["cancel"], context.nav, ["left", "(~[~{~<"])) - ], time_in_seconds=0.1, repetitions=50, rdescript="Jump: Back" ), - "jump back in": AsynchronousAction([L(S(["cancel"], context.nav, ["left", "(~[~{~<"])) - ], finisher=Key("right"), - time_in_seconds=0.1, - repetitions=50, - rdescript="Jump: Back In" ), + "fill ": + R(Key("escape, escape, end"), show=False) + + AsynchronousAction([L(S(["cancel"], Function(context.fill_within_line, nexus=_NEXUS)))], + time_in_seconds=0.2, repetitions=50, rdescript="Fill" ), + "jump in": + AsynchronousAction([L(S(["cancel"], context.nav, ["right", "(~[~{~<"]))], + time_in_seconds=0.1, repetitions=50, rdescript="Jump: In"), + "jump out": + AsynchronousAction([L(S(["cancel"], context.nav, ["right", ")~]~}~>"]))], + time_in_seconds=0.1, repetitions=50, rdescript="Jump: Out"), + "jump back": + AsynchronousAction([L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))], + time_in_seconds=0.1, repetitions=50, rdescript="Jump: Back"), + "jump back in": + AsynchronousAction([L(S(["cancel"], context.nav, ["left", "(~[~{~<"]))], + finisher=Key("right"), time_in_seconds=0.1, repetitions=50, rdescript="Jump: Back In" ), # keyboard shortcuts - 'save': R(Key("c-s"), rspec="save", rdescript="Save"), - 'shock []': R(Key("enter"), rspec="shock", rdescript="Enter")* Repeat(extra="nnavi50"), + 'save': + R(Key("c-s"), rspec="save", rdescript="Save"), + 'shock []': + R(Key("enter"), rspec="shock", rdescript="Enter")* Repeat(extra="nnavi50"), - "( | []) [( | )]": R(Function(textformat.master_text_nav), rdescript="Keyboard Text Navigation"), + "( | []) [( | )]": + R(Function(textformat.master_text_nav), rdescript="Keyboard Text Navigation"), - "stoosh []": R(Function(navigation.stoosh_keep_clipboard, nexus=_NEXUS), rspec="stoosh", rdescript="Copy"), - "cut []": R(Function(navigation.cut_keep_clipboard, nexus=_NEXUS), rspec="cut", rdescript="Cut"), - "spark []": R(Function(navigation.drop_keep_clipboard, nexus=_NEXUS), rspec="spark", rdescript="Paste"), + "stoosh []": + R(Function(navigation.stoosh_keep_clipboard, nexus=_NEXUS), rspec="stoosh", rdescript="Copy"), + "cut []": + R(Function(navigation.cut_keep_clipboard, nexus=_NEXUS), rspec="cut", rdescript="Cut"), + "spark []": + R(Function(navigation.drop_keep_clipboard, nexus=_NEXUS), rspec="spark", rdescript="Paste"), - "deli []": R(Key("del/5"), rspec="deli", rdescript="Delete") * Repeat(extra="nnavi50"), - "clear []": R(Key("backspace/5:%(nnavi50)d"), rspec="clear", rdescript="Backspace"), - SymbolSpecs.CANCEL: R(Key("escape"), rspec="cancel", rdescript="Cancel Action"), + "deli []": + R(Key("del/5"), rspec="deli", rdescript="Delete") * Repeat(extra="nnavi50"), + "clear []": + R(Key("backspace/5:%(nnavi50)d"), rspec="clear", rdescript="Backspace"), + SymbolSpecs.CANCEL: + R(Key("escape"), rspec="cancel", rdescript="Cancel Action"), - "shackle": R(Key("home/5, s-end"), rspec="shackle", rdescript="Select Line"), - "(tell | tau) ": R(Function(navigation.next_line), rspec="tell dock", rdescript="Complete Line"), - "duple []": R(Function(navigation.duple_keep_clipboard), rspec="duple", rdescript="Duplicate Line"), - "Kraken": R(Key("c-space"), rspec="Kraken", rdescript="Control Space"), + "shackle": + R(Key("home/5, s-end"), rspec="shackle", rdescript="Select Line"), + "(tell | tau) ": + R(Function(navigation.next_line), rspec="tell dock", rdescript="Complete Line"), + "duple []": + R(Function(navigation.duple_keep_clipboard), rspec="duple", rdescript="Duplicate Line"), + "Kraken": + R(Key("c-space"), rspec="Kraken", rdescript="Control Space"), # text formatting - "set format ( | | ) (bow|bowel)": R(Function(textformat.set_text_format), rdescript="Set Text Format"), - "clear caster formatting": R(Function(textformat.clear_text_format), rdescript="Clear Caster Formatting"), - "peek format": R(Function(textformat.peek_text_format), rdescript="Peek Format"), - "( | | ) (bow|bowel) [brunt]": R(Function(textformat.master_format_text), rdescript="Text Format"), - "format ": R(Function(textformat.prior_text_format), rdescript="Last Text Format"), - " format ": R(Function(textformat.partial_format_text), rdescript="Partial Text Format"), - "hug ": R(Function(textformat.enclose_selected), rdescript="Enclose text "), - "dredge": R(Key("a-tab"), rdescript="Alt-Tab"), + "set format ( | | ) (bow|bowel)": + R(Function(textformat.set_text_format), rdescript="Set Text Format"), + "clear caster formatting": + R(Function(textformat.clear_text_format), rdescript="Clear Caster Formatting"), + "peek format": + R(Function(textformat.peek_text_format), rdescript="Peek Format"), + "( | | ) (bow|bowel) [brunt]": + R(Function(textformat.master_format_text), rdescript="Text Format"), + "format ": + R(Function(textformat.prior_text_format), rdescript="Last Text Format"), + " format ": + R(Function(textformat.partial_format_text), rdescript="Partial Text Format"), + "hug ": + R(Function(textformat.enclose_selected), rdescript="Enclose text "), + "dredge": + R(Key("a-tab"), rdescript="Alt-Tab"), }