def _scan_directory(data, nexus): ''' Adds a scan of the directory to DATA ''' global DATA directory = data["path"] languageFilters = {} scanned_directory = {} try: for base, dirs, files in os.walk(directory): # traverse base directory, and list directories as dirs and files as files for fname in files: extension = "." + fname.split(".")[-1] if not extension in languageFilters: languageFilters[extension] = LanguageFilter(extension) if extension in settings.SETTINGS["pita"]["extensions"]: # scanned_file is a list scanned_file = _scan_single_file(base + "/" + fname, languageFilters[extension], nexus) # scanned_directory["absolute path to file"] = that list scanned_directory[base.replace("\\", "/") + "/" + fname] = scanned_file except Exception: utilities.simple_log(True) if "directories" not in DATA: DATA["directories"] = {} DATA["directories"][directory] = scanned_directory utilities.save_json_file(DATA, settings.SETTINGS["paths"]["PITA_JSON_PATH"])
def add_recorded_macro(data): # use a response window to get a spec for the new macro: handled by calling function commands = [] for i in data["selected_indices"]: commands.append(control.nexus().preserved[i]) spec = data["word"] # clean the results for l in commands: for w in l: if "\\" in w: w = w.split("\\")[0] recorded_macros = None if spec != "" and len(commands) > 0: extras = None defaults = None if data["repeatable"]: spec += " [times <n>]" extras = [IntegerRef("n", 1, 50)] defaults = {"n":1} recorded_macros = utilities.load_json_file(settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) recorded_macros[spec] = commands utilities.save_json_file(recorded_macros, settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) # immediately make a new compound rule and add to a set grammar control.nexus().macros_grammar.unload() rule = RecordedRule(commands=commands, spec=spec, name="recorded_rule_" + spec, extras=extras, defaults=defaults) control.nexus().macros_grammar.add_rule(rule) control.nexus().macros_grammar.load() # clear the dictation cache control.nexus().preserved = None
def rescan_current_file(): global DATA try: filename, folders, title = utilities.get_window_title_info() current_file_path = guess_file_based_on_window_title(filename, folders) scanned_file = _scan_single_file(current_file_path[1], LanguageFilter("." + filename.split(".")[-1])) # find out exact match in DATA file_was_found=False break_outer = False for d in DATA["directories"]: for f in DATA["directories"][d]: if f == current_file_path[1]: DATA["directories"][d][f] = scanned_file utilities.save_json_file(DATA, settings.SETTINGS["paths"]["PITA_JSON_PATH"]) break_outer = True file_was_found=True break if break_outer: break if not file_was_found: if not "uncategorized" in DATA["directories"]: DATA["directories"]["uncategorized"]={} DATA["directories"]["uncategorized"][current_file_path[1]]=scanned_file utilities.save_json_file(DATA, settings.SETTINGS["paths"]["PITA_JSON_PATH"]) except Exception: utilities.simple_log()
def remove_word(n, sticky): n = int(n) del control.nexus().sticky[n - 1] utilities.save_json_file(control.nexus().sticky, settings.SETTINGS["paths"]["S_LIST_JSON_PATH"]) if utilities.window_exists(None, settings.S_LIST_VERSION): control.nexus().comm.get_com("sticky_list").remove_symbol(n) else: enable_sticky_list(sticky)
def add_symbol(sticky): sticky_key="sticky_key" navigation.clipboard_to_file(sticky_key, True) time.sleep(0.1) control.nexus().sticky.append(control.nexus().clip[sticky_key]) utilities.save_json_file(control.nexus().sticky, settings.SETTINGS["paths"]["S_LIST_JSON_PATH"]) if utilities.window_exists(None, settings.S_LIST_VERSION): control.nexus().comm.get_com("sticky_list").add_symbol(control.nexus().clip[sticky_key]) else: enable_sticky_list(sticky)
def refresh(self, *args): aliases = utilities.load_json_file(settings.SETTINGS["paths"]["ALIAS_PATH"]) if not ChainAlias.json_path in aliases: aliases[ChainAlias.json_path] = {} if len(args)>0 and args[0]!="": aliases[ChainAlias.json_path][args[0]] = args[1] utilities.save_json_file(aliases, settings.SETTINGS["paths"]["ALIAS_PATH"]) mapping = {} for spec in aliases[ChainAlias.json_path]: mapping[spec] = R(Text(str(aliases[ChainAlias.json_path][spec])),rdescript="Chain Alias: "+spec) mapping["chain alias"] = R(Function(self.chain_alias), rdescript="Create Chainable Alias") mapping["delete chain aliases"] = R(Function(lambda: delete_all(self, ChainAlias.json_path)), rdescript="Delete Vanilla Aliases") self.reset(mapping)
def refresh(self, *args): '''args: spec, text''' aliases = utilities.load_json_file(settings.SETTINGS["paths"]["ALIAS_PATH"]) if not VanillaAlias.json_path in aliases: aliases[VanillaAlias.json_path] = {} if len(args)>0: aliases[VanillaAlias.json_path][args[0]] = args[1] utilities.save_json_file(aliases, settings.SETTINGS["paths"]["ALIAS_PATH"]) mapping = {} for spec in aliases[VanillaAlias.json_path]: mapping[spec] = R(Text(str(aliases[VanillaAlias.json_path][spec])),rdescript="Alias: "+spec) mapping["vanilla alias <s>"] = R(Function(lambda s: self.vanilla_alias(s)), rdescript="Create Vanilla Alias") mapping["delete vanilla aliases"] = R(Function(lambda: delete_all(self, VanillaAlias.json_path)), rdescript="Delete Vanilla Aliases") self.reset(mapping)
def refresh(self, *args): '''args: spec, list of lists of strings''' # get mapping recorded_macros = utilities.load_json_file(settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) if len(args)>0: recorded_macros[args[0]] = args[1] utilities.save_json_file(recorded_macros, settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) mapping = {} for spec in recorded_macros: sequences = recorded_macros[spec] mapping[spec] = R(Playback([(sequence, 0.0) for sequence in sequences])*Repeat(extra="n"), rdescript="Recorded Macro: "+spec) mapping["record from history"] = R(Function(self.record_from_history), rdescript="Record From History") mapping["delete recorded macros"] = R(Function(self.delete_recorded_macros), rdescript="Delete Recorded Macros") # reload with new mapping self.reset(mapping)
def clipboard_to_file(nnavi500, do_copy=False): if do_copy: Key("c-c").execute() key = str(nnavi500) while True: failure = False try: time.sleep(0.05) # time for keypress to execute win32clipboard.OpenClipboard() control.nexus().clip[key] = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() utilities.save_json_file(control.nexus().clip, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"]) except Exception: failure = True if not failure: break
def clipboard_to_file(nnavi500, nexus, do_copy=False): if do_copy: Key("c-c").execute() max_tries = 20 key = str(nnavi500) for i in range(0, max_tries): failure = False try: time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"]/1000.) # time for keypress to execute win32clipboard.OpenClipboard() nexus.clip[key] = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() utilities.save_json_file(nexus.clip, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"]) except Exception: failure = True utilities.simple_log() if not failure: break
def erase_multi_clipboard(): control.nexus().clip = {} utilities.save_json_file(control.nexus().clip, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
def save_config(self): if self.use_real_config: utilities.save_json_file(self._config, settings.SETTINGS["paths"]["CCR_CONFIG_PATH"])
def delete_recorded_macros(self): utilities.save_json_file({}, settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) self.refresh()
def erase_multi_clipboard(nexus): nexus.clip = {} utilities.save_json_file(nexus.clip, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
def erase_multi_clipboard(nexus): nexus.clip = {} utilities.save_json_file( nexus.clip, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
def clear(): control.nexus().sticky=[] utilities.save_json_file(control.nexus().sticky, settings.SETTINGS["paths"]["S_LIST_JSON_PATH"]) if utilities.window_exists(None, settings.S_LIST_VERSION): control.nexus().comm.get_com("sticky_list").clear()
def save_settings(self): self.settings["remaining"] = self.remaining self.settings["active"] = self.active utilities.save_json_file(self.settings, settings.SETTINGS["paths"]["DISPEL_JSON_PATH"])
def delete_recorded_rules(): utilities.save_json_file({}, settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) control.nexus().macros_grammar.unload() while len(control.nexus().macros_grammar.rules) > 0: rule = control.nexus().macros_grammar.rules[0] control.nexus().macros_grammar.remove_rule(rule)
def delete_all(alias, path): aliases = utilities.load_json_file(settings.SETTINGS["paths"]["ALIAS_PATH"]) aliases[path] = {} utilities.save_json_file(aliases, settings.SETTINGS["paths"]["ALIAS_PATH"]) alias.refresh()