Пример #1
0
    def add_action(
        self,
        icon_path,
        text,
        callback,
        enabled_flag=True,
        add_to_menu=True,
        add_to_toolbar=True,
        status_tip=True,
        whats_this=None,
        parent=None,
    ):
        """ Add a toolbar icon to the toolbar.

        @param icon_path: Path to the icon for this action. Can be a resource
        path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
                @param icon_path: Path to the icon for this action. Can be a resource
            path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
        @type icon_path: str
        @param text: Text that should be shown in menu items for this action.
        @type text: str
        @param callback: Function to be called when the action is triggered.
        @type callback: function
        @param enabled_flag: A flag indicating if the action should be enabled
            by default. Defaults to True.
        @type enabled_flag: bool
        @param add_to_menu: Flag indicating whether the action should also
            be added to the menu. Defaults to True.
        @type add_to_menu: bool
        @param add_to_toolbar: Flag indicating whether the action should also
            be added to the toolbar. Defaults to True.
        @type add_to_toolbar: bool
        @param status_tip: Optional text to show in a popup when mouse pointer
            hovers over the action.
        @type status_tip: str
        @param whats_this: Optional text to show in the status bar when the
            mouse pointer hovers over the action.
        @param parent: Parent widget for the new action. Defaults None.
        @type parent: QWidget
        @return action: The action that was created.
            Note that the action is also added to self.actions list.
        @rtype action: QAction
        """
        icon = QIcon(icon_path)
        action = QAction(icon, text, parent)
        action.triggered.connect(callback)
        action.setEnabled(enabled_flag)

        if status_tip is not None:
            action.setWhatsThis(whats_this)

        if add_to_toolbar:
            self.main_toolbar.addAction(action)

        if add_to_menu:
            iface.addPluginToMenu(self.menu, action)

        self.actions.append(action)
        return action
Пример #2
0
def addUpdatePluginMenu(menu, username, reponame):
    global actions
    import inspect
    frm = inspect.stack()[1]
    mod = inspect.getmodule(frm[0])
    folder = os.path.dirname(mod.__file__)
    icon = QtGui.QIcon(os.path.join(os.path.dirname(__file__), "plugin.png"))
    action = QtGui.QAction(icon, "Update plugin...", iface.mainWindow())
    action.triggered.connect(lambda: updatePlugin(username, reponame, folder))
    actions[menu] = action
    iface.addPluginToMenu(menu, action)
Пример #3
0
    def initGui(self):
        '''
        Here wew add the main menu entry, used to enable the map tool to 
        capture coordinates
        '''
        mapToolIcon = QIcon(
            os.path.join(os.path.dirname(__file__), "icons", "w3w.png"))
        self.toolAction = QAction(mapToolIcon, "what3words map tool",
                                  iface.mainWindow())
        self.toolAction.triggered.connect(self.setTool)

        #checkable = true, so it indicates whether the maptool is active or not
        self.toolAction.setCheckable(True)

        iface.addToolBarIcon(self.toolAction)
        iface.addPluginToMenu("what3words", self.toolAction)
        '''And here we add another tool to zoom to a w3w address'''
        zoomToIcon = QIcon(':/images/themes/default/mActionZoomIn.svg')
        self.zoomToAction = QAction(zoomToIcon, "Zoom to 3 word address",
                                    iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        iface.addPluginToMenu("what3words", self.zoomToAction)

        #Standard plugin menus provided by the qgiscommons library
        addSettingsMenu("what3words", iface.addPluginToMenu)
        addHelpMenu("what3words", iface.addPluginToMenu)
        addAboutMenu("what3words", iface.addPluginToMenu)
        '''
        This plugin uses a maptool. When another maptool is selected, our 
        plugin maptool will be disconnected, and we need to update the menu 
        entry, so it does not show itself as enabled. When the new tool is set, 
        it will fire a signal. We connect it to our unsetTool method, which 
        will handle this.
        '''
        iface.mapCanvas().mapToolSet.connect(self.unsetTool)
        '''
        We use a docked widget. We create it here and hide it, so when it is 
        called by the user, it is just set to visible and will be displayed in 
        its corresponding location in the app window.
        '''
        self.zoomToDialog = W3WCoordInputDialog(iface.mapCanvas(),
                                                iface.mainWindow())
        iface.addDockWidget(Qt.TopDockWidgetArea, self.zoomToDialog)
        self.zoomToDialog.hide()
        '''Add the Processing provider if Processing is availabel and loaded'''
        if processingOk:
            Processing.addProvider(self.provider)
Пример #4
0
    def add_action(
        self,
        icon_path: str,
        text: str,
        callback: Callable,
        enabled_flag: bool = True,
        add_to_menu: bool = True,
        add_to_toolbar: bool = True,
        status_tip: Optional[str] = None,
        whats_this: Optional[str] = None,
        parent: Optional[QWidget] = None,
    ) -> QAction:
        """Add a toolbar icon to the toolbar.

        :param icon_path: Path to the icon for this action. Can be a resource
            path (e.g. ':/plugins/foo/bar.png') or a normal file system path.

        :param text: Text that should be shown in menu items for this action.

        :param callback: Function to be called when the action is triggered.

        :param enabled_flag: A flag indicating if the action should be enabled
            by default. Defaults to True.

        :param add_to_menu: Flag indicating whether the action should also
            be added to the menu. Defaults to True.

        :param add_to_toolbar: Flag indicating whether the action should also
            be added to the toolbar. Defaults to True.

        :param status_tip: Optional text to show in a popup when mouse pointer
            hovers over the action.

        :param parent: Parent widget for the new action. Defaults None.

        :param whats_this: Optional text to show in the status bar when the
            mouse pointer hovers over the action.

        :returns: The action that was created. Note that the action is also
            added to self.actions list.
        :rtype: QAction
        """

        icon = QIcon(icon_path)
        action = QAction(icon, text, parent)
        # noinspection PyUnresolvedReferences
        action.triggered.connect(callback)
        action.setEnabled(enabled_flag)

        if status_tip is not None:
            action.setStatusTip(status_tip)

        if whats_this is not None:
            action.setWhatsThis(whats_this)

        if add_to_toolbar:
            # Adds plugin icon to Plugins toolbar
            iface.addToolBarIcon(action)

        if add_to_menu:
            iface.addPluginToMenu(self.menu, action)

        self.actions.append(action)

        return action
    def init(self) -> None:
        self.baseRasterLayerComboBox.setFilters(
            QgsMapLayerProxyModel.RasterLayer)
        self.segmentsLayerComboBox.setFilters(QgsMapLayerProxyModel.LineLayer)

        self.baseRasterLayerButton.clicked.connect(
            self.onBaseRasterInputButtonClicked)
        self.baseRasterLayerComboBox.layerChanged.connect(
            self.onBaseRasterLayerComboBoxChanged)
        self.segmentsLayerButton.clicked.connect(
            self.onSegmentsLayerButtonClicked)
        self.segmentsLayerComboBox.layerChanged.connect(
            self.onSegmentsLayerComboBoxChanged)
        self.outputLayerButton.clicked.connect(self.onOutputLayerButtonClicked)
        self.outputLayerLineEdit.textChanged.connect(
            self.onOutputLayerLineEditChanged)
        self.its4landButton.clicked.connect(self.onIts4landButtonClicked)
        self.addLengthAttributeCheckBox.toggled.connect(
            self.onAddLengthAttributeCheckBoxToggled)
        self.processButton.clicked.connect(self.onProcessButtonClicked)

        self.modePolygonsRadio.toggled.connect(self.onModePolygonsRadioToggled)
        self.modeVerticesRadio.toggled.connect(self.onModeVerticesRadioToggled)
        self.modeLinesRadio.toggled.connect(self.onModeLinesRadioToggled)
        self.modeManualRadio.toggled.connect(self.onModeManualRadioToggled)

        self.weightComboBox.fieldChanged.connect(self.onWeightComboBoxChanged)

        self.acceptButton.clicked.connect(self.onAcceptButtonClicked)
        self.rejectButton.clicked.connect(self.onRejectButtonClicked)
        self.editButton.toggled.connect(self.onEditButtonToggled)
        self.updateEditsButton.clicked.connect(self.onUpdateEditsButtonClicked)
        self.finishButton.clicked.connect(self.onFinishButtonClicked)

        self.weightComboBox.setFilters(QgsFieldProxyModel.Numeric)

        set_label_icon(self.its4landLabel, 'its4landLogo.png')
        set_button_icon(self.acceptButton, 'accept.png')
        set_button_icon(self.editButton, 'edit.png')
        set_button_icon(self.rejectButton, 'reject.png')
        set_button_icon(self.finishButton, 'finishFlag.png')

        self.action = QAction(create_icon('icon.png'), 'ITS4LAND Settings',
                              iface.mainWindow())
        self.action.setWhatsThis('Settings')
        self.action.setStatusTip('ITS4LAND Settings')
        self.action.setObjectName('its4landButton')
        self.action.triggered.connect(self.onIts4landButtonClicked)

        iface.addPluginToMenu('&BoundaryDelineation', self.action)

        # TODO enable to row below for faster debugging
        # self.its4landWindow.show()

        if self.baseRasterLayerComboBox.currentLayer():
            self.baseRasterLayerComboBox.layerChanged.emit(
                self.baseRasterLayerComboBox.currentLayer())

        if self.segmentsLayerComboBox.currentLayer():
            self.segmentsLayerComboBox.layerChanged.emit(
                self.segmentsLayerComboBox.currentLayer())

        self.createShortcut(SC_MODE_POLYGONS, self.modePolygonsRadio,
                            self.onShortcutModePolygons)
        self.createShortcut(SC_MODE_LINES, self.modeLinesRadio,
                            self.onShortcutModeLines)
        self.createShortcut(SC_MODE_VERTICES, self.modeVerticesRadio,
                            self.onShortcutModeVertices)
        self.createShortcut(SC_MODE_MANUAL, self.modeManualRadio,
                            self.onShortcutModeManual)
        self.createShortcut(SC_ACCEPT, self.acceptButton,
                            self.onShortcutAccept)
        self.createShortcut(SC_REJECT, self.rejectButton,
                            self.onShortcutReject)
        self.createShortcut(SC_EDIT, self.editButton, self.onShortcutEdit)
        self.createShortcut(SC_UPDATE, self.updateEditsButton,
                            self.onShortcutUpdate)

        try:
            from PyQt5.QtWebKitWidgets import QWebView

            helpView = QWebView()
            helpView.setUrl(QUrl('https://its4land.com/automate-it-wp5/'))
            self.helpWrapper.addWidget(helpView)
        except Exception as err:
            print(err)
            pass