Пример #1
0
    def contextMenuEvent(self, ev):
        index = self.indexAt(ev.pos())
        if not index.isValid():
            return

        if index != self.currentIndex():
            self.itemChanged(index)

        item = self.currentItem()

        menu = QMenu(self)

        if isinstance(item, (Table, Schema)):
            menu.addAction(self.tr("Rename"), self.rename)
            menu.addAction(self.tr("Delete"), self.delete)

            if isinstance(item, Table) and item.canBeAddedToCanvas():
                menu.addSeparator()
                menu.addAction(self.tr("Add to canvas"), self.addLayer)

        elif isinstance(item, DBPlugin):
            if item.database() is not None:
                menu.addAction(self.tr("Re-connect"), self.reconnect)
            menu.addAction(self.tr("Remove"), self.delete)

        elif not index.parent().isValid() and item.typeName() == "spatialite":
            menu.addAction(self.tr("New Connection..."), self.newConnection)

        if not menu.isEmpty():
            menu.exec_(ev.globalPos())

        menu.deleteLater()
Пример #2
0
    def showPopupMenu(self, point):
        item = self.algorithmTree.itemAt(point)
        if isinstance(item, TreeAlgorithmItem):
            alg = item.alg
            popupmenu = QMenu()
            executeAction = QAction(self.tr('Execute'), self.algorithmTree)
            executeAction.triggered.connect(self.executeAlgorithm)
            popupmenu.addAction(executeAction)
            if alg.canRunInBatchMode and not alg.allowOnlyOpenedLayers:
                executeBatchAction = QAction(
                    self.tr('Execute as batch process'),
                    self.algorithmTree)
                executeBatchAction.triggered.connect(
                    self.executeAlgorithmAsBatchProcess)
                popupmenu.addAction(executeBatchAction)
            popupmenu.addSeparator()
            editRenderingStylesAction = QAction(
                self.tr('Edit rendering styles for outputs'),
                self.algorithmTree)
            editRenderingStylesAction.triggered.connect(
                self.editRenderingStyles)
            popupmenu.addAction(editRenderingStylesAction)
            actions = Processing.contextMenuActions
            if len(actions) > 0:
                popupmenu.addSeparator()
            for action in actions:
                action.setData(alg, self)
                if action.isEnabled():
                    contextMenuAction = QAction(action.name,
                                                self.algorithmTree)
                    contextMenuAction.triggered.connect(action.execute)
                    popupmenu.addAction(contextMenuAction)

            popupmenu.exec_(self.algorithmTree.mapToGlobal(point))
Пример #3
0
 def showSnippets(self, evt):
     popupmenu = QMenu()
     for name, snippet in self.snippets.iteritems():
         action = QAction(self.tr(name), self.btnSnippets)
         action.triggered[()].connect(lambda snippet=snippet: self.editor.insert(snippet))
         popupmenu.addAction(action)
     popupmenu.exec_(QCursor.pos())
Пример #4
0
 def contextMenuEvent(self, e):
     menu = QMenu(self)
     subMenu = QMenu(menu)
     titleHistoryMenu = QCoreApplication.translate("PythonConsole", "Command History")
     subMenu.setTitle(titleHistoryMenu)
     subMenu.addAction(
         QCoreApplication.translate("PythonConsole", "Show"),
         self.showHistory, 'Ctrl+Shift+SPACE')
     subMenu.addSeparator()
     subMenu.addAction(
         QCoreApplication.translate("PythonConsole", "Save"),
         self.writeHistoryFile)
     subMenu.addSeparator()
     subMenu.addAction(
         QCoreApplication.translate("PythonConsole", "Clear File"),
         self.clearHistory)
     subMenu.addAction(
         QCoreApplication.translate("PythonConsole", "Clear Session"),
         self.clearHistorySession)
     menu.addMenu(subMenu)
     menu.addSeparator()
     copyAction = menu.addAction(
         QCoreApplication.translate("PythonConsole", "Copy"),
         self.copy, QKeySequence.Copy)
     pasteAction = menu.addAction(
         QCoreApplication.translate("PythonConsole", "Paste"),
         self.paste, QKeySequence.Paste)
     copyAction.setEnabled(False)
     pasteAction.setEnabled(False)
     if self.hasSelectedText():
         copyAction.setEnabled(True)
     if QApplication.clipboard().text():
         pasteAction.setEnabled(True)
     menu.exec_(self.mapToGlobal(e.pos()))
Пример #5
0
    def contextMenuEvent(self, ev):
        index = self.indexAt(ev.pos())
        if not index.isValid():
            return

        if index != self.currentIndex():
            self.itemChanged(index)

        item = self.currentItem()

        menu = QMenu(self)

        if isinstance(item, (Table, Schema)):
            menu.addAction(self.tr("Rename"), self.rename)
            menu.addAction(self.tr("Delete"), self.delete)

            if isinstance(item, Table) and item.canBeAddedToCanvas():
                menu.addSeparator()
                menu.addAction(self.tr("Add to canvas"), self.addLayer)

        elif isinstance(item, DBPlugin):
            if item.database() is not None:
                menu.addAction(self.tr("Re-connect"), self.reconnect)
            menu.addAction(self.tr("Remove"), self.delete)

        elif not index.parent().isValid() and item.typeName() == "spatialite":
            menu.addAction(self.tr("New Connection..."), self.newConnection)

        if not menu.isEmpty():
            menu.exec_(ev.globalPos())

        menu.deleteLater()
Пример #6
0
 def showSnippets(self, evt):
     popupmenu = QMenu()
     for name, snippet in self.snippets.iteritems():
         action = QAction(self.tr(name), self.btnSnippets)
         action.triggered[(
         )].connect(lambda snippet=snippet: self.editor.insert(snippet))
         popupmenu.addAction(action)
     popupmenu.exec_(QCursor.pos())
Пример #7
0
 def showPopupMenu(self, point):
     item = self.tree.currentItem()
     if isinstance(item, TreeLogEntryItem):
         if item.isAlg:
             popupmenu = QMenu()
             createTestAction = QAction(self.tr('Create test'), self.tree)
             createTestAction.triggered.connect(self.createTest)
             popupmenu.addAction(createTestAction)
             popupmenu.exec_(self.tree.mapToGlobal(point))
Пример #8
0
 def showPopupMenu(self, point):
     item = self.tree.currentItem()
     if isinstance(item, TreeLogEntryItem):
         if item.isAlg:
             popupmenu = QMenu()
             createTestAction = QAction(self.tr('Create test'), self.tree)
             createTestAction.triggered.connect(self.createTest)
             popupmenu.addAction(createTestAction)
             popupmenu.exec_(self.tree.mapToGlobal(point))
Пример #9
0
 def contextMenuEvent(self, e):
     menu = QMenu(self)
     iconRun = QgsApplication.getThemeIcon("console/iconRunConsole.png")
     iconClear = QgsApplication.getThemeIcon("console/iconClearConsole.png")
     iconHideTool = QgsApplication.getThemeIcon(
         "console/iconHideToolConsole.png")
     iconSettings = QgsApplication.getThemeIcon(
         "console/iconSettingsConsole.png")
     menu.addAction(
         iconHideTool,
         QCoreApplication.translate("PythonConsole", "Hide/Show Toolbar"),
         self.hideToolBar)
     menu.addSeparator()
     showEditorAction = menu.addAction(
         QCoreApplication.translate("PythonConsole", "Show Editor"),
         self.showEditor)
     menu.addSeparator()
     runAction = menu.addAction(
         iconRun,
         QCoreApplication.translate("PythonConsole", "Enter Selected"),
         self.enteredSelected, QKeySequence(Qt.CTRL + Qt.Key_E))
     clearAction = menu.addAction(
         iconClear,
         QCoreApplication.translate("PythonConsole", "Clear Console"),
         self.clearConsole)
     menu.addSeparator()
     copyAction = menu.addAction(
         QCoreApplication.translate("PythonConsole", "Copy"), self.copy,
         QKeySequence.Copy)
     selectAllAction = menu.addAction(
         QCoreApplication.translate("PythonConsole", "Select All"),
         self.selectAll, QKeySequence.SelectAll)
     menu.addSeparator()
     menu.addAction(
         iconSettings,
         QCoreApplication.translate("PythonConsole", "Options..."),
         self.parent.openSettings)
     runAction.setEnabled(False)
     clearAction.setEnabled(False)
     copyAction.setEnabled(False)
     selectAllAction.setEnabled(False)
     showEditorAction.setEnabled(True)
     if self.hasSelectedText():
         runAction.setEnabled(True)
         copyAction.setEnabled(True)
     if not self.text(3) == '':
         selectAllAction.setEnabled(True)
         clearAction.setEnabled(True)
     if self.parent.tabEditorWidget.isVisible():
         showEditorAction.setEnabled(False)
     menu.exec_(self.mapToGlobal(e.pos()))
Пример #10
0
 def contextMenuEvent(self, event):
     if isinstance(self.element, ModelerOutput):
         return
     popupmenu = QMenu()
     removeAction = popupmenu.addAction('Remove')
     removeAction.triggered.connect(self.removeElement)
     editAction = popupmenu.addAction('Edit')
     editAction.triggered.connect(self.editElement)
     if isinstance(self.element, Algorithm):
         if not self.element.active:
             removeAction = popupmenu.addAction('Activate')
             removeAction.triggered.connect(self.activateAlgorithm)
         else:
             deactivateAction = popupmenu.addAction('Deactivate')
             deactivateAction.triggered.connect(self.deactivateAlgorithm)
     popupmenu.exec_(event.screenPos())
Пример #11
0
    def showPopupMenu(self):
        popupmenu = QMenu()

        if not (isinstance(self.param, ParameterMultipleInput) and
                self.param.datatype == ParameterMultipleInput.TYPE_FILE):
            selectLayerAction = QAction(
                self.tr('Select from open layers'), self.pushButton)
            selectLayerAction.triggered.connect(self.showLayerSelectionDialog)
            popupmenu.addAction(selectLayerAction)

        selectFileAction = QAction(
            self.tr('Select from filesystem'), self.pushButton)
        selectFileAction.triggered.connect(self.showFileSelectionDialog)
        popupmenu.addAction(selectFileAction)

        popupmenu.exec_(QCursor.pos())
Пример #12
0
 def contextMenuEvent(self, event):
     if isinstance(self.element, ModelerOutput):
         return
     popupmenu = QMenu()
     removeAction = popupmenu.addAction('Remove')
     removeAction.triggered.connect(self.removeElement)
     editAction = popupmenu.addAction('Edit')
     editAction.triggered.connect(self.editElement)
     if isinstance(self.element, Algorithm):
         if not self.element.active:
             removeAction = popupmenu.addAction('Activate')
             removeAction.triggered.connect(self.activateAlgorithm)
         else:
             deactivateAction = popupmenu.addAction('Deactivate')
             deactivateAction.triggered.connect(self.deactivateAlgorithm)
     popupmenu.exec_(event.screenPos())
Пример #13
0
    def showPopupMenu(self):
        popupmenu = QMenu()

        if not (isinstance(self.param, ParameterMultipleInput)
                and self.param.datatype == ParameterMultipleInput.TYPE_FILE):
            selectLayerAction = QAction(self.tr('Select from open layers'),
                                        self.pushButton)
            selectLayerAction.triggered.connect(self.showLayerSelectionDialog)
            popupmenu.addAction(selectLayerAction)

        selectFileAction = QAction(self.tr('Select from filesystem'),
                                   self.pushButton)
        selectFileAction.triggered.connect(self.showFileSelectionDialog)
        popupmenu.addAction(selectFileAction)

        popupmenu.exec_(QCursor.pos())
Пример #14
0
 def contextMenuEvent(self, e):
     menu = QMenu(self)
     iconRun = QgsApplication.getThemeIcon("console/iconRunConsole.png")
     iconClear = QgsApplication.getThemeIcon("console/iconClearConsole.png")
     iconHideTool = QgsApplication.getThemeIcon("console/iconHideToolConsole.png")
     iconSettings = QgsApplication.getThemeIcon("console/iconSettingsConsole.png")
     menu.addAction(iconHideTool,
                    QCoreApplication.translate("PythonConsole", "Hide/Show Toolbar"),
                    self.hideToolBar)
     menu.addSeparator()
     showEditorAction = menu.addAction(
         QCoreApplication.translate("PythonConsole", "Show Editor"),
         self.showEditor)
     menu.addSeparator()
     runAction = menu.addAction(iconRun,
                                QCoreApplication.translate("PythonConsole", "Enter Selected"),
                                self.enteredSelected,
                                QKeySequence(Qt.CTRL + Qt.Key_E))
     clearAction = menu.addAction(iconClear,
                                  QCoreApplication.translate("PythonConsole", "Clear Console"),
                                  self.clearConsole)
     menu.addSeparator()
     copyAction = menu.addAction(
         QCoreApplication.translate("PythonConsole", "Copy"),
         self.copy, QKeySequence.Copy)
     selectAllAction = menu.addAction(
         QCoreApplication.translate("PythonConsole", "Select All"),
         self.selectAll, QKeySequence.SelectAll)
     menu.addSeparator()
     menu.addAction(iconSettings,
                    QCoreApplication.translate("PythonConsole", "Options..."),
                    self.parent.openSettings)
     runAction.setEnabled(False)
     clearAction.setEnabled(False)
     copyAction.setEnabled(False)
     selectAllAction.setEnabled(False)
     showEditorAction.setEnabled(True)
     if self.hasSelectedText():
         runAction.setEnabled(True)
         copyAction.setEnabled(True)
     if not self.text(3) == '':
         selectAllAction.setEnabled(True)
         clearAction.setEnabled(True)
     if self.parent.tabEditorWidget.isVisible():
         showEditorAction.setEnabled(False)
     menu.exec_(self.mapToGlobal(e.pos()))
Пример #15
0
    def selectExtent(self):
        popupmenu = QMenu()
        useLayerExtentAction = QAction(self.tr('Use layer/canvas extent'),
                                       self.btnSelect)
        selectOnCanvasAction = QAction(self.tr('Select extent on canvas'),
                                       self.btnSelect)

        popupmenu.addAction(useLayerExtentAction)
        popupmenu.addAction(selectOnCanvasAction)

        selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
        useLayerExtentAction.triggered.connect(self.useLayerExtent)

        if self.canUseAutoExtent():
            useMincoveringExtentAction = QAction(
                self.tr('Use min covering extent from input layers'),
                self.btnSelect)
            useMincoveringExtentAction.triggered.connect(
                self.useMinCoveringExtent)
            popupmenu.addAction(useMincoveringExtentAction)

        popupmenu.exec_(QCursor.pos())
Пример #16
0
    def selectExtent(self):
        popupmenu = QMenu()
        useLayerExtentAction = QAction(
            self.tr('Use layer/canvas extent'), self.btnSelect)
        selectOnCanvasAction = QAction(
            self.tr('Select extent on canvas'), self.btnSelect)

        popupmenu.addAction(useLayerExtentAction)
        popupmenu.addAction(selectOnCanvasAction)

        selectOnCanvasAction.triggered.connect(self.selectOnCanvas)
        useLayerExtentAction.triggered.connect(self.useLayerExtent)

        if self.canUseAutoExtent():
            useMincoveringExtentAction = QAction(
                self.tr('Use min covering extent from input layers'),
                self.btnSelect)
            useMincoveringExtentAction.triggered.connect(
                self.useMinCoveringExtent)
            popupmenu.addAction(useMincoveringExtentAction)

        popupmenu.exec_(QCursor.pos())
Пример #17
0
    def showPopupMenu(self, point):
        item = self.algorithmTree.itemAt(point)
        if isinstance(item, TreeAlgorithmItem):
            alg = item.alg
            popupmenu = QMenu()
            executeAction = QAction(self.tr('Execute'), self.algorithmTree)
            executeAction.triggered.connect(self.executeAlgorithm)
            popupmenu.addAction(executeAction)
            if alg.canRunInBatchMode and not alg.allowOnlyOpenedLayers:
                executeBatchAction = QAction(
                    self.tr('Execute as batch process'),
                    self.algorithmTree)
                executeBatchAction.triggered.connect(
                    self.executeAlgorithmAsBatchProcess)
                popupmenu.addAction(executeBatchAction)
            popupmenu.addSeparator()
            editRenderingStylesAction = QAction(
                self.tr('Edit rendering styles for outputs'),
                self.algorithmTree)
            editRenderingStylesAction.triggered.connect(
                self.editRenderingStyles)
            popupmenu.addAction(editRenderingStylesAction)

        if isinstance(item, (TreeAlgorithmItem, TreeActionItem)):
            data = item.alg if isinstance(item, TreeAlgorithmItem) else item.action
            actions = Processing.contextMenuActions
            if len(actions) > 0:
                popupmenu.addSeparator()
            for action in actions:
                action.setData(data, self)
                if action.isEnabled():
                    contextMenuAction = QAction(action.name,
                                                self.algorithmTree)
                    contextMenuAction.triggered.connect(action.execute)
                    popupmenu.addAction(contextMenuAction)

            popupmenu.exec_(self.algorithmTree.mapToGlobal(point))
Пример #18
0
    def selectOutput(self):
        if isinstance(self.output, OutputDirectory):
            self.selectDirectory()
        else:
            popupMenu = QMenu()

            actionSaveToTempFile = QAction(self.tr('Save to a temporary file'),
                                           self.btnSelect)
            actionSaveToTempFile.triggered.connect(self.saveToTemporaryFile)
            popupMenu.addAction(actionSaveToTempFile)

            actionSaveToFile = QAction(self.tr('Save to file...'),
                                       self.btnSelect)
            actionSaveToFile.triggered.connect(self.selectFile)
            popupMenu.addAction(actionSaveToFile)

            if isinstance(self.output, OutputVector) \
                    and self.alg.provider.supportsNonFileBasedOutput():
                actionSaveToMemory = QAction(self.tr('Save to memory layer'),
                                             self.btnSelect)
                actionSaveToMemory.triggered.connect(self.saveToMemory)
                popupMenu.addAction(actionSaveToMemory)
                actionSaveToSpatialite = QAction(
                    self.tr('Save to Spatialite table...'), self.btnSelect)
                actionSaveToSpatialite.triggered.connect(self.saveToSpatialite)
                popupMenu.addAction(actionSaveToSpatialite)
                actionSaveToPostGIS = QAction(
                    self.tr('Save to PostGIS table...'), self.btnSelect)
                actionSaveToPostGIS.triggered.connect(self.saveToPostGIS)
                settings = QSettings()
                settings.beginGroup('/PostgreSQL/connections/')
                names = settings.childGroups()
                settings.endGroup()
                actionSaveToPostGIS.setEnabled(bool(names))
                popupMenu.addAction(actionSaveToPostGIS)

            popupMenu.exec_(QCursor.pos())
Пример #19
0
    def selectOutput(self):
        if isinstance(self.output, OutputDirectory):
            self.selectDirectory()
        else:
            popupMenu = QMenu()

            actionSaveToTempFile = QAction(
                self.tr('Save to a temporary file'), self.btnSelect)
            actionSaveToTempFile.triggered.connect(self.saveToTemporaryFile)
            popupMenu.addAction(actionSaveToTempFile)

            actionSaveToFile = QAction(
                self.tr('Save to file...'), self.btnSelect)
            actionSaveToFile.triggered.connect(self.selectFile)
            popupMenu.addAction(actionSaveToFile)

            if isinstance(self.output, OutputVector) \
                    and self.alg.provider.supportsNonFileBasedOutput():
                actionSaveToMemory = QAction(
                    self.tr('Save to memory layer'), self.btnSelect)
                actionSaveToMemory.triggered.connect(self.saveToMemory)
                popupMenu.addAction(actionSaveToMemory)
                actionSaveToSpatialite = QAction(
                    self.tr('Save to Spatialite table...'), self.btnSelect)
                actionSaveToSpatialite.triggered.connect(self.saveToSpatialite)
                popupMenu.addAction(actionSaveToSpatialite)
                actionSaveToPostGIS = QAction(
                    self.tr('Save to PostGIS table...'), self.btnSelect)
                actionSaveToPostGIS.triggered.connect(self.saveToPostGIS)
                settings = QSettings()
                settings.beginGroup('/PostgreSQL/connections/')
                names = settings.childGroups()
                settings.endGroup()
                actionSaveToPostGIS.setEnabled(bool(names))
                popupMenu.addAction(actionSaveToPostGIS)

            popupMenu.exec_(QCursor.pos())
Пример #20
0
 def contextMenuEvent(self, event):
     menu = QMenu(self)
     menu.addAction(self.copyLine)
     menu.addAction(self.copyAll)
     menu.exec_(event.globalPos())