示例#1
0
    def initGui(self):
        """Register event filter and add toolbar icon."""
        self.contextManager = LayerTreeContextMenuManager()
        self.contextManager.addProvider(PathfinderEventFilter())

        # setting up keyboard shortcut actions
        self.copy_action1 = QAction(tr('Copy Path'), self.iface.mainWindow())
        self.copy_action2 = QAction(tr('Copy Path (\\\\)'),
                                    self.iface.mainWindow())
        self.show_action = QAction(tr('Show in Explorer'),
                                   self.iface.mainWindow())

        # register shortcuts
        self.iface.registerMainWindowAction(self.copy_action1, 'Ctrl+E')
        self.iface.registerMainWindowAction(self.copy_action2, 'Ctrl+Shift+E')
        self.iface.registerMainWindowAction(self.show_action, 'Ctrl+R')

        # shortcuts won't work unless actions are added to this menu
        self.iface.addPluginToMenu('&pathfinder', self.copy_action1)
        self.iface.addPluginToMenu('&pathfinder', self.copy_action2)
        self.iface.addPluginToMenu('&pathfinder', self.show_action)

        # bind actions
        self.copy_action1.triggered.connect(lambda: self.on_key_pressed(0))
        self.copy_action2.triggered.connect(lambda: self.on_key_pressed(1))
        self.show_action.triggered.connect(lambda: self.on_key_pressed(2))

        # register settings dialog
        self.settings_dialog = QAction(
            QIcon(':/plugins/pathfinder/icons/copy.svg'),
            tr('pathfinder Settings'), self.iface.mainWindow())

        self.settings_dialog.triggered.connect(self.show_settings_dialog)
        self.iface.addToolBarIcon(self.settings_dialog)
示例#2
0
    def on_curr_changed(self, key: str, value: str) -> None:
        """Enable/Disable corresponding custom character lineedit if necessary and forward
        key and value to on_changed().

        :param key: The name of the setting.
        :param value: The new value of the setting.
        """
        getattr(self, f'{key}_custom').setEnabled(value == tr('Other'))
        self.on_changed(key, value)
示例#3
0
def get_char(s: str) -> str:
    """Return the character equivalent to ``s`` or its respective custom character.

    :param s: either 'quote_char' or 'separ_char'
    :return: representation of s or its respective custom character
    """

    settings = QSettings()
    settings.beginGroup('pathfinder')

    defs = PathfinderMaps.DEFAULTS
    maps = PathfinderMaps.MAPPINGS

    if settings.value(s) == tr('Other'):
        return settings.value(f'{s}_custom', defs[f'{s}_custom'])
    else:
        try:
            return maps[s][settings.value(s, defs[s])]
        except KeyError:
            # after switching languages, the values of some named characters can't be retrieved.
            # For now, we will reset these values to their default.
            # TODO: find way to make these settings persistent across languages
            settings.setValue(s, defs[s])
            return maps[s][settings.value(s)]
示例#4
0
class PathfinderMaps:
    # platform specific commands to open the system's *most likely* file explorer
    COMMANDS = {'Windows': 'explorer', 'Linux': 'xdg-open', 'Darwin': 'open'}

    # map combobox label to actual character
    MAPPINGS = {
        'quote_char': {
            '\"': '\"',
            '\'': '\'',
            '´': '´',
            '`': '`',
            tr('Space'): ' ',
            tr('None'): '',
        },
        'separ_char': {
            tr('Space'): ' ',
            tr('Tab'): '\t',
            tr('New Line'): '\n',
            ',': ',',
            ';': ';',
        }
    }

    # reasonable defaults for pathfinder settings
    DEFAULTS = {
        'quote_char': '"',
        'separ_char': tr('Space'),
        'quote_char_custom': '',
        'separ_char_custom': '',
        'prefix': '',
        'postfix': '',
        'single_path_quote': 0,
        'single_path_affix': 0,
        'incl_file_name': 2,
        'incl_layer_name': 0,
        'incl_subset_str': 0,
        'show_notification': 0,
        'paths_on_new_line': 0,
        'original_vrt_ds': 0
    }
示例#5
0
 def notify(self, text: str) -> None:
     """Show QGIS notification."""
     if self.settings.value('show_notification', type=bool):
         iface.messageBar().pushMessage(tr('Copied to clipboard'), html.escape(text), level=0)