def _text_to_clipboard(keystroke, nnavi500): if nnavi500 == 1: Key(keystroke).execute() else: max_tries = 20 cb = Clipboard(from_system=True) Key(keystroke).execute() key = str(nnavi500) global _CLIP for i in range(0, max_tries): failure = False try: # time for keypress to execute time.sleep( settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) _CLIP[key] = unicode(Clipboard.get_system_text()) utilities.save_json_file( _CLIP, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"]) except Exception: failure = True utilities.simple_log() if not failure: break cb.copy_to_system()
def fix_dragon_double(): try: lr = _DBL_FIX_HISTORY[len(_DBL_FIX_HISTORY) - 1] lu = " ".join(lr) Key("left/5:" + str(len(lu)) + ", del").execute() except Exception: utilities.simple_log(False)
def paste_string_without_altering_clipboard(content, pause_time="1"): ''' True - indicates success False - indicates clipboard error ''' time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) # time for previous keypress to execute cb = Clipboard(from_system=True) max_tries = 20 for i in range(0, max_tries): failure = False try: Clipboard.set_system_text(unicode(content)) Pause(pause_time).execute() Key("c-v").execute() time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) # time for keypress to execute cb.copy_to_system() except Exception: print("Clipboard Write Attempts " + str(i)) # Debugging failure = True utilities.simple_log(False) if i is max_tries: return False if not failure: break return True
def main(argv): help_message = 'legion.py -t <tirg> [-m <monitor>] [-d <dimensions>] [-a <autoquit>]' tirg = None monitor = 1 dimensions = None auto_quit = False try: opts, args = getopt.getopt(argv, "ht:a:d:m:", ["tirg=", "dimensions=", "autoquit="]) except getopt.GetoptError: print(help_message) sys.exit(2) try: for opt, arg in opts: if opt == '-h': print(help_message) sys.exit() elif opt in ("-t", "--tirg"): tirg = arg elif opt == '-m': monitor = arg elif opt in ("-d", "--dimensions"): # wxh+x+y dimensions = Dimensions(*[int(n) for n in arg.split("_")]) elif opt in ("-a", "--autoquit"): auto_quit = arg in ("1", "t") if dimensions is None: r = monitors[int(monitor) - 1].rectangle dimensions = Dimensions(int(r.dx), int(r.dy), int(r.x), int(r.y)) lg = LegionGrid(grid_size=dimensions, tirg=tirg, auto_quit=auto_quit) except Exception: utilities.simple_log(True)
def _run_filters(self, merge_pair): for filter_fn in self._filters: try: filter_fn(merge_pair) except Exception: utilities.simple_log() print("Filter function '" + filter_fn.__name__ + "' failed.")
def read_selected_without_altering_clipboard(same_is_okay=False, pause_time="0"): '''Returns a tuple: (0, "text from system") - indicates success (1, None) - indicates no change (2, None) - indicates clipboard error ''' time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) # time for previous keypress to execute cb = Clipboard(from_system=True) temporary = None prior_content = None try: prior_content = Clipboard.get_system_text() Clipboard.set_system_text("") Key("c-c").execute() Pause(pause_time).execute() time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) # time for keypress to execute temporary = Clipboard.get_system_text() cb.copy_to_system() except Exception: utilities.simple_log(False) return 2, None if prior_content == temporary and not same_is_okay: return 1, None return 0, temporary
def fix_dragon_double(nexus): try: lr = nexus.history[len(nexus.history) - 1] lu = " ".join(lr) Key("left/5:" + str(len(lu)) + ", del").execute() except Exception: utilities.simple_log(False)
def _text_to_clipboard(keystroke, nnavi500): if nnavi500 == 1: Key(keystroke).execute() else: max_tries = 20 cb = Clipboard(from_system=True) Key(keystroke).execute() key = str(nnavi500) for i in range(0, max_tries): failure = False try: # time for keypress to execute time.sleep( settings.settings([u'miscellaneous', u'keypress_wait']) / 1000.) _NavClipBoard.get_instance( ).clip[key] = Clipboard.get_system_text() utilities.save_json_file( _NavClipBoard.get_instance().clip, settings.settings([u'paths', u'SAVED_CLIPBOARD_PATH'])) except Exception: failure = True utilities.simple_log() if not failure: break cb.copy_to_system()
def refresh(): global _grammar _grammar.unload() while len(_grammar.rules) > 0: _grammar.remove_rule(_grammar.rules[0]) try: rule = generate_rule(settings.SETTINGS["paths"]["CONFIGDEBUGTXT_PATH"]) _grammar.add_rule(rule) _grammar.load() except Exception: utilities.simple_log()
def read_selected_without_altering_clipboard(same_is_okay=False, pause_time="0"): '''Returns a tuple: (0, "text from system") - indicates success (1, None) - indicates no change (2, None) - indicates clipboard error ''' temporary = None prior_content = None max_tries = 20 error_code = 0 try: prior_content = GetClipboard() except Exception: print("ERROR: failed to obtain clipboard") pass cr.Reset() Key("c-c").execute() for i in range(0, max_tries): failure = True time.sleep(0.1) if cr.Update(): #if True: try: temporary = GetClipboard() failure = False except Exception: print("clipboard exception") utilities.simple_log(False) if not failure: break print("Clipboard Read Attempts " + str(i)) # Debugging if i is max_tries: temporary = None error_code = 2 if not prior_content is None: try: SetClipboard(prior_content) except Exception: print("ERROR: failed to restore clipboard") pass if prior_content == temporary and not same_is_okay: return 1, None return error_code, temporary
def lines_relative(self, back, n): if back: #backward try: num = context.read_nmax_tries(10) txt = str(int(num) - int(n) + 1) # +1 to include current line Text(txt).execute() except ValueError: utilities.simple_log() return Key("enter").execute() else: #forward Key("escape, end, home, home").execute( ) # end-home-home to include all of current line # forward or backward Key("s-down:" + str(int(n)) + "/5, s-left").execute()
def check_for_response(): try: _data = self.nexus().comm.get_com("hmc").get_message() except Exception: if log_failure: utilities.simple_log() _["tries"] += 1 if _["tries"] > 9: return True # try 10 times max if there's no Homonculus response else: return False if _data is None: return False try: _data.append( _["dragonfly_data"]) # pass dragonfly data into receiver function _["dragonfly_data"] = None receiver(_data) except Exception: if log_failure: utilities.simple_log() return True
def navigate_to_character(direction3, target, fill=False): try: look_left = str(direction3) == "left" # make sure nothing is highlighted to boot if not fill: # (except when doing "fill" -- if at end of line, there is no space for this ) Key("right, left" if look_left else "left, right").execute() if look_left: Key("cs-left").execute() else: Key("cs-right").execute() context = read_nmax_tries(5, .01) if context is None: return False # if we got to this point, we have a copy result index = _find_index_in_context(target, context, look_left) if index != -1: # target found '''move the cursor to the left of the target if looking left, to the right of the target if looking right:''' Key("left" if look_left else "right").execute() '''number of times to press left or right before the highlight (the target may be a part of a fully highlighted word): ''' nt = index if look_left else len(context) - index - 1 # pylint: disable=no-member if nt != 0: Key("right/5:" + str(nt) if look_left else "left/5:" + str(nt)).execute() '''highlight only the target''' if _target_is_character(target): Key("s-right" if look_left else "s-left").execute() else: Key("cs-right" if look_left else "cs-left").execute() return True else: # reset cursor Key("left" if look_left else "right").execute() return False except Exception: utilities.simple_log()
def paste_string_without_altering_clipboard(content, pause_time="1"): ''' True - indicates success False - indicates clipboard error ''' time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) # time for previous keypress to execute cb = Clipboard(from_system=True) try: Clipboard.set_system_text(unicode(content)) Pause(pause_time).execute() Key("c-v").execute() time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] / 1000.) # time for keypress to execute cb.copy_to_system() except Exception: utilities.simple_log(False) return False return True
def main(argv): help_message = 'legion.py -t <tirg> [-m <monitor>] [-d <dimensions>] [-a <autoquit>]' tirg = None monitor = 1 dimensions = None auto_quit = False error_code = windll.shcore.SetProcessDpiAwareness( 2) #enable 1-1 pixel mapping if error_code == -2147024891: raise OSError("Failed to set app awareness") try: opts, args = getopt.getopt(argv, "ht:a:d:m:", ["tirg=", "dimensions=", "autoquit="]) except getopt.GetoptError: print(help_message) sys.exit(2) try: for opt, arg in opts: if opt == '-h': print(help_message) sys.exit() elif opt in ("-t", "--tirg"): tirg = arg elif opt == '-m': monitor = arg elif opt in ("-d", "--dimensions"): # wxh+x+y dimensions = Dimensions(*[int(n) for n in arg.split("_")]) elif opt in ("-a", "--autoquit"): auto_quit = arg in ("1", "t") if dimensions is None: r = monitors[int(monitor) - 1].rectangle dimensions = Dimensions(int(r.dx), int(r.dy), int(r.x), int(r.y)) lg = LegionGrid(grid_size=dimensions, tirg=tirg, auto_quit=auto_quit) except Exception: utilities.simple_log(True)
def bring_test(): print(settings.SETTINGS["paths"]["BASE_PATH"].replace("/", "\\")) try: BringApp("explorer", settings.SETTINGS["paths"]["BASE_PATH"]).execute() except Exception: utilities.simple_log()
"csharp.csharp": ("CSharp", ), "dart.dart": ("Dart", ), "voice_dev_commands.voice_dev_commands": ("VoiceDevCommands"), "go.go": ("Go", ), "haxe.haxe": ("Haxe", ), "html.html": ("HTML", ), "java.java": ("Java", ), "javascript.javascript": ("Javascript", ), "latex.latex": ("LaTeX", ), "markdown.markdown": ("Markdown", ), "matlab.matlab": ("Matlab", ), "python.python": ("Python", ), "r.r": ("Rlang", ), "rust.rust": ("Rust", ), "sql.sql": ("SQL", ), "prolog.prolog": ("Prolog", ), "vhdl.vhdl": ("VHDL", ), } for module_name, class_name_tup in command_sets.iteritems(): for class_name in class_name_tup: try: module = __import__(module_name, globals(), locals(), [class_name]) # attempts to import the class globals()[class_name] = module # make the name available globally except Exception as e: print("Ignoring ccr rule '{}'. Failed to load with: ".format( class_name)) utilities.simple_log()
def _execute(self, fname): try: fn = getattr(self._server_proxy, fname) fn() except Exception: utilities.simple_log()