def _bring_add(self, launch_type, key): # Add current program or highlighted text to bring me if launch_type == "program": path = utilities.get_active_window_path() if not path: # dragonfly.get_engine().speak("program not detected") printer.out("Program path for bring me not found ") elif launch_type == 'file': files = utilities.get_selected_files(folders=False) path = files[0] if files else None # or allow adding multiple files elif launch_type == 'folder': files = utilities.get_selected_files(folders=True) path = files[ 0] if files else None # or allow adding multiple folders else: Key("a-d/5").execute() fail, path = context.read_selected_without_altering_clipboard() if fail == 2: # FIXME: A better solution would be to specify a number of retries and the time interval. time.sleep(0.1) _, path = context.read_selected_without_altering_clipboard() if not path: printer.out("Selection for bring me not found ") Key("escape").execute() if not path: # logger.warn('Cannot add %s as %s to bringme: cannot get path', launch, key) return config_copy = self._config.get_copy() config_copy[launch_type][str(key)] = path self._refresh(config_copy)
def enclose_selected(enclosure): ''' Encloses selected text in the appropriate enclosures By using the system Clipboard as a buffer ( doesn't delete previous contents) ''' (err, selected_text) = context.read_selected_without_altering_clipboard(True) if err == 0: opener = enclosure.split('~')[0] closer = enclosure.split('~')[1] enclosed_text = opener + selected_text + closer # Attempt to paste enclosed text without altering clipboard if not context.paste_string_without_altering_clipboard(enclosed_text): print("failed to paste {}".format(enclosed_text))
def grep_this(path, filetype): c = None tries = 0 while c is None: tries += 1 results = context.read_selected_without_altering_clipboard() error_code = results[0] if error_code == 0: c = results[1] break if tries > 5: return False grep = "D:/PROGRAMS/NON_install/AstroGrep/AstroGrep.exe" Popen([ grep, "/spath=\"" + str(path) + "\"", "/stypes=\"" + str(filetype) + "\"", "/stext=\"" + str(c) + "\"", "/s" ])
def text_manipulation_copy(application): """ the wait time can also be modified up or down further by going into context.read_selected_without_altering_clipboard and changing the sleep time which is apparently slightly different than the pause time. the sleep time is set to a positive number, so can be reduced here I am using "wait time" to mean the sum of the sleep and pause time right after pressing control c """ # double hashmarks below indicate an alternative to using the functions in lib.context ## previous_item_on_the_clipboard = pyperclip.paste() ## Key("c-c").execute() ## Pause(copy_pause_time_dict[application]).execute() ## selected_text = pyperclip.paste() err, selected_text = context.read_selected_without_altering_clipboard(same_is_okay=True, pause_time=copy_pause_time_dict[application]) if err != 0: # I'm not discriminating between err = 1 and err = 2 print("failed to copy text") return return selected_text
def _read_highlighted(max_tries): for i in range(0, max_tries): result = context.read_selected_without_altering_clipboard(True) if result[0] == 0: return result[1] return None
def github_checkoutupdate_pull_request(new): # Function to fetch a PR try: Key("c-l/20").execute() url = read_selected_without_altering_clipboard() if url[0] == 0: split_string = url[1].split("/pull/") repo_url = split_string[0] pr_name = split_string[1].split("/")[0] CONFIG = load_toml_file( settings.SETTINGS["paths"]["GIT_REPO_LOCAL_REMOTE_PATH"]) if not CONFIG: # logger.warn("Could not load bringme defaults") raise Exception( "Could not load " + settings.SETTINGS["paths"]["GIT_REPO_LOCAL_REMOTE_PATH"]) items = rebuild_local_remote_items(CONFIG) if repo_url in items: local_directory = items[repo_url][0] local_directory = local_directory.replace("\\", "\\\\") directory_command = "cd " + local_directory TERMINAL_PATH = settings.SETTINGS["paths"]["TERMINAL_PATH"] AHK_PATH = settings.SETTINGS["paths"]["AHK_PATH"] ahk_installed = os.path.isfile(AHK_PATH) print "AHK_PATH = " + AHK_PATH if TERMINAL_PATH != "": load_terminal = True # set default value # ready fetch command string to be appended to fetch_command = "" # find the equivalent ahk script with the same name as this one ahk_script = __file__.replace(".pyc", ".ahk").replace( ".py", ".ahk") pattern_match = "MINGW64" # the string we expect to find in the title of git bash when loaded # if autohotkey is installed if ahk_installed: # open the script which checks that git bash window is open or not p = Popen( [AHK_PATH, ahk_script, "exists", pattern_match], stdout=PIPE) # retrieve the output from the ahk script stdout, stderr = p.communicate() # terminates the ahk script if not already done so p.terminate() # if an existing git bash window has been activated if stdout == pattern_match + " activated": # set the first portion of the fetch command fetch_command += directory_command + " && " load_terminal = False print "Msg:" + ahk_script + " has activated window: " + pattern_match # if an existing git bash window is not already open elif stdout == pattern_match + " does not exist": print "Msg:" + ahk_script + " has found no window: " + pattern_match print "Load new instance of: " + pattern_match else: print "Error:" + ahk_script + " neither returned 'activated' nor 'does not exist'" print "Fallback: load new instance of :" + pattern_match if load_terminal: # open up a new git bash terminal terminal = Popen(TERMINAL_PATH, cwd=local_directory) # if autohotkey is installed if ahk_installed: # open the script which checks that git bash windoow is ready or not for input p = Popen([ AHK_PATH, ahk_script, "create", pattern_match ], stdout=PIPE) # retrieve the output from the AHK script stdout, stderr = p.communicate() # terminates the ahk script if not already done so p.terminate() # if the git bash terminal is not ready if stdout != pattern_match + " ready": raise Exception( "Error: git terminal took too long to load for script:" + ahk_script) else: # otherwise await the default number of seconds for the terminal to load time.sleep( settings.SETTINGS["gitbash"]["loading_time"]) else: # Remove any text that's there in the existing terminal Key("end/10, c-u/10").execute() # adds to the fetch command string that which will fetch from the particular repository in question fetch_command += "git fetch " + repo_url + ".git pull/" + pr_name + "/head" # if fetching from a new pull request if new: branch_name_base = repo_url.replace( "https://github.com/", "") checkout_command = "git checkout -b " + branch_name_base + "/pull/" + pr_name + " FETCH_HEAD" # type in the full command into the git bash window Text(fetch_command + " && " + checkout_command).execute() else: # otherwise if it is an update to an existing pull request branch_name_base = repo_url.replace( "https://github.com/", "") checkout_command = "git checkout " + branch_name_base + "/pull/" + pr_name # type in the full command into the git bash window Text(fetch_command + " && " + checkout_command).execute() Key("enter").execute( ) # checkout is safe enough so will run this merge_command = "git merge FETCH_HEAD" # allow time for the fetch commands complete before typing in the next one time.sleep( settings.SETTINGS["gitbash"]["fetching_time"]) Text(merge_command).execute() else: raise Exception( 'TERMINAL_PATH in <user_dir>/.caster/data/settings.toml is not set' ) else: raise Exception( "Repository URL: " + repo_url + " not found in " + settings.SETTINGS["paths"]["GIT_REPO_LOCAL_REMOTE_PATH"]) except Exception as e: print(e)
def store_and_next(): Key("c-d").execute() _, origin = context.read_selected_without_altering_clipboard(False) stored_values.append(origin) Key("left,right,tab").execute()
def get_output(): get_notepad() Key("c-a").execute() output = context.read_selected_without_altering_clipboard(True)[1] Key("backspace").execute() return output
def _execute(self, data=None): _, orig = context.read_selected_without_altering_clipboard(False) text = orig.replace(" ", self.space) if orig else "" control.nexus().temp = text.replace("\n", "") if self.remove_cr else text return True
def _execute(self, data=None): global _TEMP _, orig = context.read_selected_without_altering_clipboard(False) text = orig.replace(" ", self.space) if orig else "" _TEMP = text.replace("\n", "") if self.remove_cr else text return True