コード例 #1
0
ファイル: user_shortcuts.py プロジェクト: sisalik/automate
def register_selected_shortcut(name, old_clipboard):
    """Retrieve the text/filename from the clipboard and register it as a new command."""
    clipboard = QtGui.QApplication.clipboard()
    clipboard.dataChanged.disconnect()
    clipboard_timer.stop()

    urls = clipboard.mimeData().urls()
    text = clipboard.text()
    if list(old_clipboard.formats()):  # Check if the old clipboard MIME object contains any data
        CommandHandler.main_gui.call(clipboard.setMimeData, [old_clipboard])  # Restore the old clipboard contents

    if text:  # The clipboard contains text
        shortcut = unicode(text)
    elif urls:  # The clipboard contains a file
        shortcut = unicode(urls[0].toString())[8:].replace("/", "\\")
    else:
        message("Unable to register the selection as a shortcut", "Error")
        return

    shortcuts_dict = load_shortcuts()  # Load shortcuts from the config file
    if name.decode("utf-8") not in shortcuts_dict:
        keyword = "registered"
    else:
        keyword = "updated"
        CommandHandler.remove(name)  # Delete the existing command
    register_shortcut(name, shortcut)  # Register the new command
    shortcuts_dict.update({name.decode("utf-8"): shortcut})  # Update with new shortcut
    save_shortcuts(shortcuts_dict)  # Write back to the file
    message("Shortcut %s: [i]%s[/i]\nTarget: [i]%s[/i]" % (keyword, name.decode("utf-8"), shortcut), "Success")
コード例 #2
0
ファイル: user_shortcuts.py プロジェクト: sisalik/automate
def remove_shortcut(name=None):
    if name is None:  # Register subcommands
        shortcuts_dict = load_shortcuts()
        return [key.encode("utf-8") for key in shortcuts_dict]
    elif name == "":
        message("Press tab to select a shortcut to remove", "Error")
    else:
        if CommandHandler.remove(name):
            shortcuts_dict = load_shortcuts()  # Load shortcuts from the config file
            shortcuts_dict.pop(name.decode("utf-8"))  # Remove shortcut
            save_shortcuts(shortcuts_dict)  # Write back to the file
            message("Shortcut removed: [i]%s[/i]" % name.decode("utf-8"), "Success")
        else:
            message("Unable to remove shortcut: [i]%s[/i]" % name.decode("utf-8"), "Error")