예제 #1
0
    def __init__(self, iface):
        """Constructor.

        :param iface: An interface instance that will be passed to this class
            which provides the hook by which you can manipulate the QGIS
            application at run time.
        :type iface: QgsInterface
        """
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir,
            'i18n',
            '{}.qm'.format(locale))

        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Declare instance attributes
        self.plugin_name = self.tr('&Menu Builder')
        # reference to plugin actions
        self.actions = []
        # used to store active menus
        self.menus = []

        # Create the dialog (after translation) and keep reference
        self.dlg = MenuBuilderDialog(self)
예제 #2
0
    def __init__(self, iface):
        """Constructor.

        :param iface: An interface instance that will be passed to this class
            which provides the hook by which you can manipulate the QGIS
            application at run time.
        :type iface: QgsInterface
        """
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir,
            'i18n',
            '{}.qm'.format(locale))

        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Declare instance attributes
        self.plugin_name = self.tr('&Menu Builder')
        # reference to plugin actions
        self.actions = []
        # used to store active menus
        self.menus = []

        # Create the dialog (after translation) and keep reference
        self.dlg = MenuBuilderDialog(self)
예제 #3
0
class MenuBuilder:
    """QGIS Plugin Implementation."""

    def __init__(self, iface):
        """Constructor.

        :param iface: An interface instance that will be passed to this class
            which provides the hook by which you can manipulate the QGIS
            application at run time.
        :type iface: QgsInterface
        """
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir,
            'i18n',
            '{}.qm'.format(locale))

        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Declare instance attributes
        self.plugin_name = self.tr('&Menu Builder')
        # reference to plugin actions
        self.actions = []
        # used to store active menus
        self.menus = []

        # Create the dialog (after translation) and keep reference
        self.dlg = MenuBuilderDialog(self)

    # noinspection PyMethodMayBeStatic
    def tr(self, message):
        """Get the translation for a string using Qt translation API.

        We implement this ourselves since we do not inherit QObject.

        :param message: String for translation.
        :type message: str, QString

        :returns: Translated version of message.
        :rtype: QString
        """
        # noinspection PyTypeChecker,PyArgumentList,PyCallByClass
        return QCoreApplication.translate('MenuBuilder', message)

    def initGui(self):
        """Create the plugin entries inside the QGIS GUI."""
        # create the configure entry
        icon = QIcon(':/plugins/MenuBuilder/resources/settings.svg')
        configure = QAction(icon, self.tr('&Configure Menus'), self.iface.mainWindow())
        configure.triggered.connect(self.run_configure)
        configure.setEnabled(True)
        configure.setStatusTip(self.tr("Configure menus with drag&drop from qgisbrowser"))
        configure.setWhatsThis(self.tr("Configure menus with drag&drop from qgisbrowser"))
        self.iface.addPluginToMenu(self.plugin_name, configure)
        self.actions.append(configure)

        # restore previous session if exists
        try:
            self.dlg.restore_session()
        except Exception as exc:
            QMessageBox(
                QMessageBox.Warning,
                "Restoring MenuBuilder last session",
                exc.message.decode(self.dlg.pgencoding),
                QMessageBox.Ok,
                self.dlg
            ).exec_()

    def unload(self):
        """Removes the plugin menu item and icon from QGIS GUI."""
        for action in self.actions:
            self.iface.removePluginMenu(self.plugin_name, action)
        for menu in self.menus:
            menu.deleteLater()
        self.iface.removeDockWidget(self.dlg.dock_widget)

    def run_configure(self):
        # show the configure dialog
        self.dlg.show()
        # reload browser content
        self.dlg.browser.reload()
        self.dlg.update_database_list()
        # Run the dialog event loop
        self.dlg.exec_()
예제 #4
0
class MenuBuilder:
    """QGIS Plugin Implementation."""

    def __init__(self, iface):
        """Constructor.

        :param iface: An interface instance that will be passed to this class
            which provides the hook by which you can manipulate the QGIS
            application at run time.
        :type iface: QgsInterface
        """
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir,
            'i18n',
            '{}.qm'.format(locale))

        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Declare instance attributes
        self.plugin_name = self.tr('&Menu Builder')
        # reference to plugin actions
        self.actions = []
        # used to store active menus
        self.menus = []

        # Create the dialog (after translation) and keep reference
        self.dlg = MenuBuilderDialog(self)

    # noinspection PyMethodMayBeStatic
    def tr(self, message):
        """Get the translation for a string using Qt translation API.

        We implement this ourselves since we do not inherit QObject.

        :param message: String for translation.
        :type message: str, QString

        :returns: Translated version of message.
        :rtype: QString
        """
        # noinspection PyTypeChecker,PyArgumentList,PyCallByClass
        return QCoreApplication.translate('MenuBuilder', message)

    def initGui(self):
        """Create the plugin entries inside the QGIS GUI."""
        # create the configure entry
        icon = QIcon(':/plugins/MenuBuilder/resources/settings.svg')
        configure = QAction(icon, self.tr('&Configure Menus'), self.iface.mainWindow())
        configure.triggered.connect(self.run_configure)
        configure.setEnabled(True)
        configure.setStatusTip(self.tr("Configure menus with drag&drop from qgisbrowser"))
        configure.setWhatsThis(self.tr("Configure menus with drag&drop from qgisbrowser"))
        self.iface.addPluginToMenu(self.plugin_name, configure)
        self.actions.append(configure)

        # restore previous session if exists
        try:
            self.dlg.restore_session()
        except Exception as exc:
            QMessageBox(
                QMessageBox.Warning,
                "Restoring MenuBuilder last session",
                exc.message.decode(self.dlg.pgencoding),
                QMessageBox.Ok,
                self.dlg
            ).exec_()

    def unload(self):
        """Removes the plugin menu item and icon from QGIS GUI."""
        for action in self.actions:
            self.iface.removePluginMenu(self.plugin_name, action)
        for menu in self.menus:
            menu.deleteLater()
        self.iface.removeDockWidget(self.dlg.dock_widget)

    def run_configure(self):
        # show the configure dialog
        self.dlg.show()
        self.dlg.update_database_list()
        # Run the dialog event loop
        self.dlg.exec_()