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 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: # Create a copy of the string without Unicode characters. ascii_str = str(spec) sequences = recorded_macros[spec] delay = settings.SETTINGS["miscellaneous"][ "history_playback_delay_secs"] # It appears that the associative string (ascii_str) must be ascii, but the sequences within Playback must be Unicode. mapping[ascii_str] = R(Playback([(sequence, delay) for sequence in sequences]), rdescript="Recorded Macro: " + ascii_str) 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 load_recorded_rules(): recorded_macros = utilities.load_json_file(settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) for spec in recorded_macros: commands = recorded_macros[spec]# this is a list of lists rule = RecordedRule(commands=commands, spec=spec, name="recorded_rule_" + spec, extras=[IntegerRef("n", 1, 50)], defaults={"n":1}) control.nexus().macros_grammar.add_rule(rule) if len(control.nexus().macros_grammar.rules) > 0: control.nexus().macros_grammar.load()
def __init__(self): self.minute = 60 self.hour = 3600 # self.settings = utilities.load_json_file(settings.SETTINGS["paths"]["DISPEL_JSON_PATH"]) self.PERIOD = 25 # number of minutes self.DELAY_AMOUNT = 5 self.remaining = 0 self.active = False self.load() # load saved settings from last run if self.active: self.resume()
def load_recorded_rules(): recorded_macros = utilities.load_json_file( settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"]) for spec in recorded_macros: commands = recorded_macros[spec] # this is a list of lists rule = RecordedRule(commands=commands, spec=spec, name="recorded_rule_" + spec, extras=[IntegerRef("n", 1, 50)], defaults={"n": 1}) control.nexus().macros_grammar.add_rule(rule) if len(control.nexus().macros_grammar.rules) > 0: control.nexus().macros_grammar.load()
def __init__(self): self.minute = 60 self.hour = 3600 # self.settings = utilities.load_json_file( settings.SETTINGS["paths"]["DISPEL_JSON_PATH"]) self.PERIOD = 25 # number of minutes self.DELAY_AMOUNT = 5 self.remaining = 0 self.active = False self.load() # load saved settings from last run if self.active: self.resume()
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 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 Aliases") self.reset(mapping)
def refresh(self, *args): '''args: spec, text''' aliases = utilities.load_json_file(settings.SETTINGS["paths"]["ALIAS_PATH"]) if not Alias.json_path in aliases: aliases[Alias.json_path] = {} if len(args) > 0: aliases[Alias.json_path][args[0]] = args[1] utilities.save_json_file(aliases, settings.SETTINGS["paths"]["ALIAS_PATH"]) mapping = {} for spec in aliases[Alias.json_path]: mapping[spec] = R( Text(str(aliases[Alias.json_path][spec])), rdescript="Alias: " + spec) mapping["alias <s>"] = R( Function(lambda s: self.alias(s)), rdescript="Create Alias") mapping["delete aliases"] = R( Function(lambda: delete_all(self, Alias.json_path)), rdescript="Delete Aliases") self.reset(mapping)
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 load_config(self): if self.use_real_config: self._config = utilities.load_json_file( settings.SETTINGS["paths"]["CCR_CONFIG_PATH"]) else: self._config = {}
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()
def initialize_clipboard(nexus): if len(nexus.clip) == 0: nexus.clip = utilities.load_json_file( settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
class SListUsageRule(MappingRule): mapping = { "L add [<sticky>]": R(Function(add_symbol), rdescript="Add Selected To Sticky List"), "L get <n> [<sticky>]": R(Function(get_symbol), rdescript="Retrieve From Sticky List"), "L remove <n> [<sticky>]": R(Function(remove_word), rdescript="Remove From Sticky List"), "L clear": Function(clear), "L run": R(Function(do_enable), rdescript="Run Sticky List"), "L kill": R(Function(kill), rdescript="Shutdown Sticky List"), } extras = [ IntegerRef("n", 1, 200), Dictation("text"), Choice("sticky", {"run": 1}), ] defaults = {"n": 1, "text": "", "sticky": 0 } control.nexus().sticky = utilities.load_json_file(settings.SETTINGS["paths"]["S_LIST_JSON_PATH"]) r = SListUsageRule() grammar = Grammar('SListUsageRule') grammar.add_rule(r) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None
def initialize_clipboard(): if len(control.nexus().clip) == 0: control.nexus().clip = utilities.load_json_file(settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
def load_config(self): if self.use_real_config: self._config = utilities.load_json_file(settings.SETTINGS["paths"]["CCR_CONFIG_PATH"]) else: self._config = {}
(1) add its filetype extension to SETTINGS["pita"]["extensions"] in lib/settings.py (2) add its keywords, long comment and short comment syntax in lib/pita/filters.py ''' import os import re from caster.asynch.hmc import h_launch from caster.lib import utilities, settings, control from caster.lib.pita import filters from caster.lib.pita.filters import LanguageFilter if control.nexus().dep.NATLINK: import natlink _d = utilities.load_json_file(settings.SETTINGS["paths"]["PITA_JSON_PATH"]) DATA = _d if _d != {} else {"directories": {}} def scan_directory(): h_launch.launch(settings.QTYPE_DIRECTORY, _scan_directory, 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]))
import os import re from caster.asynch.hmc import h_launch from caster.lib import utilities, settings from caster.lib.dfplus.state.actions import AsynchronousAction from caster.lib.dfplus.state.short import L, S from caster.lib.pita import filters from caster.lib.pita.filters import LanguageFilter if not settings.WSR: import natlink _d = utilities.load_json_file(settings.SETTINGS["paths"]["PITA_JSON_PATH"]) DATA = _d if _d != {} else {"directories":{}} def scan_directory(nexus): on_complete = AsynchronousAction.hmc_complete(lambda data: _scan_directory(data, nexus), nexus) h_launch.launch(settings.QTYPE_DIRECTORY) AsynchronousAction([L(S(["cancel"], on_complete))], time_in_seconds=0.5, repetitions=300, blocking=False).execute() 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)[1]
class SListUsageRule(MappingRule): mapping = { "L add [<sticky>]": R(Function(add_symbol, nexus=_NEXUS), rdescript="Add Selected To Sticky List"), "L get <n> [<sticky>]": R(Function(get_symbol, nexus=_NEXUS), rdescript="Retrieve From Sticky List"), "L remove <n> [<sticky>]": R(Function(remove_word, nexus=_NEXUS), rdescript="Remove From Sticky List"), "L clear": Function(clear, nexus=_NEXUS), "L run": R(Function(do_enable), rdescript="Run Sticky List"), "L kill": R(Function(kill, nexus=_NEXUS), rdescript="Shutdown Sticky List"), } extras = [ IntegerRefST("n", 1, 200), Dictation("text"), Choice("sticky", {"run": 1}), ] defaults = {"n": 1, "text": "", "sticky": 0 } _NEXUS.sticky = utilities.load_json_file(settings.SETTINGS["paths"]["S_LIST_JSON_PATH"]) grammar = Grammar('SListUsageRule') grammar.add_rule(SListUsageRule()) grammar.load() def unload(): global grammar if grammar: grammar.unload() grammar = None