Ejemplo n.º 1
0
    def refresh(self, *args):
        '''args: spec, text'''
        aliases = utilities.load_toml_file(
            settings.SETTINGS["paths"]["ALIAS_PATH"])
        if not Alias.toml_path in aliases:
            aliases[Alias.toml_path] = {}
        if len(args) > 0:
            aliases[Alias.toml_path][args[0]] = args[1]
            utilities.save_toml_file(aliases,
                                     settings.SETTINGS["paths"]["ALIAS_PATH"])
        mapping = {}
        for spec in aliases[Alias.toml_path]:
            mapping[spec] = R(
                Function(context.paste_string_without_altering_clipboard,
                         content=str(aliases[Alias.toml_path][spec])))
            # R(
            #     Text(str(aliases[Alias.toml_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.toml_path)),
            rdescript="Delete Aliases")
        self.reset(mapping)
Ejemplo n.º 2
0
def bring_add(launch, key):
    '''
    Add current program or highlighted text to bring me
    '''
    key = str(key)
    if launch == "program":
        path = utilities.get_active_window_path()
        if not path:
            # dragonfly.get_engine().speak("program not detected")
            print("Program path for bring me not found ")
    # elif launch == 'file':
    # no way to add file via pyperclip
    else:
        Key("a-d/5").execute()
        fail, path = context.read_selected_without_altering_clipboard()
        if fail == 2:
            #FIXME
            time.sleep(0.1)
            _, path = context.read_selected_without_altering_clipboard()
            if not path:
                # dragonfly.get_engine().speak("nothing selected")
                print("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[launch][key] = path
    utilities.save_toml_file(CONFIG, settings.SETTINGS["paths"]["BRINGME_PATH"])
    refresh()
Ejemplo n.º 3
0
    def refresh(self, *args):
        '''args: spec, list of lists of strings'''

        # get mapping
        recorded_macros = utilities.load_toml_file(
            settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"])
        if len(args) > 0:
            recorded_macros[args[0]] = args[1]
            utilities.save_toml_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)
Ejemplo n.º 4
0
def bring_add(launch, key):
    '''
    Add current program or highlighted text to bring me
    '''
    key = str(key)
    if launch == "program":
        path = utilities.get_active_window_path()
        if not path:
            # dragonfly.get_engine().speak("program not detected")
            print("Program path for bring me not found ")
    # elif launch == 'file':
    # no way to add file via pyperclip
    else:
        Key("a-d/5").execute()
        fail, path = context.read_selected_without_altering_clipboard()
        if fail == 2:
            #FIXME
            time.sleep(0.1)
            _, path = context.read_selected_without_altering_clipboard()
            if not path:
                # dragonfly.get_engine().speak("nothing selected")
                print("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[launch][key] = path
    utilities.save_toml_file(CONFIG,
                             settings.SETTINGS["paths"]["BRINGME_PATH"])
    refresh()
Ejemplo n.º 5
0
def stoosh_keep_clipboard(nnavi500, nexus):
    if nnavi500 == 1:
        Key("c-c").execute()
    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_toml_file(
                    nexus.clip,
                    settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
            except Exception:
                failure = True
                utilities.simple_log()
            if not failure:
                break
        cb.copy_to_system()
Ejemplo n.º 6
0
def bring_remove(key):
    '''
    Remove item from bring me
    '''
    key = str(key)
    for section in CONFIG.keys():
        if key in CONFIG[section]:
            del CONFIG[section][key]
            utilities.save_toml_file(CONFIG, settings.SETTINGS["paths"]["BRINGME_PATH"])
            refresh()
            return
Ejemplo n.º 7
0
def bring_remove(key):
    '''
    Remove item from bring me
    '''
    key = str(key)
    for section in CONFIG.keys():
        if key in CONFIG[section]:
            del CONFIG[section][key]
            utilities.save_toml_file(
                CONFIG, settings.SETTINGS["paths"]["BRINGME_PATH"])
            refresh()
            return
Ejemplo n.º 8
0
 def refresh(self, *args):
     aliases = utilities.load_toml_file(settings.SETTINGS["paths"]["ALIAS_PATH"])
     if not ChainAlias.toml_path in aliases:
         aliases[ChainAlias.toml_path] = {}
     if len(args) > 0 and args[0] != "":
         aliases[ChainAlias.toml_path][args[0]] = args[1]
         utilities.save_toml_file(aliases, settings.SETTINGS["paths"]["ALIAS_PATH"])
     mapping = {}
     for spec in aliases[ChainAlias.toml_path]:
         mapping[spec] = R(
             Text(str(aliases[ChainAlias.toml_path][spec])),
             rdescript="Chain Alias: " + spec)
     mapping["chain alias [<s>]"] = R(
         Function(lambda s: self.alias(s)), rdescript="Create Chainable Alias")
     mapping["delete chain aliases"] = R(
         Function(lambda: delete_all(self, ChainAlias.toml_path)),
         rdescript="Delete Aliases")
     self.reset(mapping)
Ejemplo n.º 9
0
 def refresh(self, *args):
     aliases = utilities.load_toml_file(
         settings.SETTINGS["paths"]["ALIAS_PATH"])
     if not ChainAlias.toml_path in aliases:
         aliases[ChainAlias.toml_path] = {}
     if len(args) > 0 and args[0] != "":
         aliases[ChainAlias.toml_path][args[0]] = args[1]
         utilities.save_toml_file(aliases,
                                  settings.SETTINGS["paths"]["ALIAS_PATH"])
     mapping = {}
     for spec in aliases[ChainAlias.toml_path]:
         mapping[spec] = R(Text(str(aliases[ChainAlias.toml_path][spec])),
                           rdescript="Chain Alias: " + spec)
     mapping["chain alias [<s>]"] = R(Function(lambda s: self.alias(s)),
                                      rdescript="Create Chainable Alias")
     mapping["delete chain aliases"] = R(
         Function(lambda: delete_all(self, ChainAlias.toml_path)),
         rdescript="Delete Aliases")
     self.reset(mapping)
Ejemplo n.º 10
0
def stoosh_keep_clipboard(nnavi500, nexus):
    if nnavi500 == 1:
        Key("c-c").execute()
    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_toml_file(
                    nexus.clip, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
            except Exception:
                failure = True
                utilities.simple_log()
            if not failure:
                break
        cb.copy_to_system()
Ejemplo n.º 11
0
def erase_multi_clipboard(nexus):
    nexus.clip = {}
    utilities.save_toml_file(nexus.clip,
                             settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
Ejemplo n.º 12
0
 def delete_recorded_macros(self):
     utilities.save_toml_file({}, settings.SETTINGS["paths"]["RECORDED_MACROS_PATH"])
     self.refresh()
Ejemplo n.º 13
0
def erase_multi_clipboard(nexus):
    nexus.clip = {}
    utilities.save_toml_file(
        nexus.clip, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
Ejemplo n.º 14
0
def delete_all(alias, path):
    aliases = utilities.load_toml_file(settings.SETTINGS["paths"]["ALIAS_PATH"])
    aliases[path] = {}
    utilities.save_toml_file(aliases, settings.SETTINGS["paths"]["ALIAS_PATH"])
    alias.refresh()
Ejemplo n.º 15
0
 def save_config(self):
     if self.use_real_config:
         utilities.save_toml_file(self._config,
                                  settings.SETTINGS["paths"]["CCR_CONFIG_PATH"])
Ejemplo n.º 16
0
def delete_all(alias, path):
    aliases = utilities.load_toml_file(
        settings.SETTINGS["paths"]["ALIAS_PATH"])
    aliases[path] = {}
    utilities.save_toml_file(aliases, settings.SETTINGS["paths"]["ALIAS_PATH"])
    alias.refresh()
Ejemplo n.º 17
0
 def save_config(self):
     if self.use_real_config:
         utilities.save_toml_file(
             self._config, settings.SETTINGS["paths"]["CCR_CONFIG_PATH"])
Ejemplo n.º 18
0
 def save_config(self):
     if self.use_real_config:
         utilities.save_toml_file(self._config, CCR_PATH)