本文整理汇总了Python中qgis.PyQt.QtWidgets.QAction类的典型用法代码示例。如果您正苦于以下问题:Python QAction类的具体用法?Python QAction怎么用?Python QAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initGui
def initGui(self):
self.action = QAction(
QIcon(":/db_manager/icon"), QApplication.translate("DBManagerPlugin", "DB Manager"), self.iface.mainWindow()
)
self.action.setObjectName("dbManager")
self.action.triggered.connect(self.run)
# Add toolbar button and menu item
if hasattr(self.iface, "addDatabaseToolBarIcon"):
self.iface.addDatabaseToolBarIcon(self.action)
else:
self.iface.addToolBarIcon(self.action)
if hasattr(self.iface, "addPluginToDatabaseMenu"):
self.iface.addPluginToDatabaseMenu(QApplication.translate("DBManagerPlugin", "DB Manager"), self.action)
else:
self.iface.addPluginToMenu(QApplication.translate("DBManagerPlugin", "DB Manager"), self.action)
self.layerAction = QAction(
QIcon(":/db_manager/icon"),
QApplication.translate("DBManagerPlugin", "Update Sql Layer"),
self.iface.mainWindow(),
)
self.layerAction.setObjectName("dbManagerUpdateSqlLayer")
self.layerAction.triggered.connect(self.onUpdateSqlLayer)
self.iface.legendInterface().addLegendLayerAction(
self.layerAction, "", "dbManagerUpdateSqlLayer", QgsMapLayer.VectorLayer, False
)
for l in QgsMapLayerRegistry.instance().mapLayers().values():
self.onLayerWasAdded(l)
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.onLayerWasAdded)
示例2: addAlgorithmEntry
def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, addButton=False):
if actionText is None:
if (QgsGui.higFlags() & QgsGui.HigMenuTextIsTitleCase) and not (alg.flags() & QgsProcessingAlgorithm.FlagDisplayNameIsLiteral):
alg_title = QgsStringUtils.capitalize(alg.displayName(), QgsStringUtils.TitleCase)
else:
alg_title = alg.displayName()
actionText = alg_title + QCoreApplication.translate('Processing', '…')
action = QAction(icon or alg.icon(), actionText, iface.mainWindow())
alg_id = alg.id()
action.setData(alg_id)
action.triggered.connect(lambda: _executeAlgorithm(alg_id))
action.setObjectName("mProcessingUserMenu_%s" % alg_id)
if menuName:
menu = getMenu(menuName, iface.mainWindow().menuBar())
submenu = getMenu(submenuName, menu)
submenu.addAction(action)
if addButton:
global algorithmsToolbar
if algorithmsToolbar is None:
algorithmsToolbar = iface.addToolBar(QCoreApplication.translate('MainWindow', 'Processing Algorithms'))
algorithmsToolbar.setObjectName("ProcessingAlgorithms")
algorithmsToolbar.setToolTip(QCoreApplication.translate('MainWindow', 'Processing Algorithms Toolbar'))
algorithmsToolbar.addAction(action)
示例3: initGui
def initGui(self):
"""startup"""
# run
run_icon = QIcon('%s/%s' % (self.context.ppath,
'images/MetaSearch.png'))
self.action_run = QAction(run_icon, 'MetaSearch',
self.iface.mainWindow())
self.action_run.setWhatsThis(QCoreApplication.translate('MetaSearch',
'MetaSearch plugin'))
self.action_run.setStatusTip(QCoreApplication.translate('MetaSearch',
'Search Metadata Catalogs'))
self.action_run.triggered.connect(self.run)
self.iface.addWebToolBarIcon(self.action_run)
self.iface.addPluginToWebMenu(self.web_menu, self.action_run)
# help
help_icon = QgsApplication.getThemeIcon('/mActionHelpContents.svg')
self.action_help = QAction(help_icon, 'Help', self.iface.mainWindow())
self.action_help.setWhatsThis(QCoreApplication.translate('MetaSearch',
'MetaSearch plugin help'))
self.action_help.setStatusTip(QCoreApplication.translate('MetaSearch',
'Get Help on MetaSearch'))
self.action_help.triggered.connect(self.help)
self.iface.addPluginToWebMenu(self.web_menu, self.action_help)
# prefab the dialog but not open it yet
self.dialog = MetaSearchDialog(self.iface)
示例4: __init__
class D3DataVis:
heatmapDialog = None
def __init__(self, iface):
self.iface = iface
def initGui(self):
""" Initialize the menu and dialog boxes for the D3 heatmap chart """
icon = QIcon(os.path.dirname(__file__) + "/icon.png")
self.heatmapAction = QAction(icon, "Circular Date/Time Heatmap", self.iface.mainWindow())
self.heatmapAction.triggered.connect(self.showHeatmapDialog)
self.heatmapAction.setCheckable(False)
self.iface.addWebToolBarIcon(self.heatmapAction)
# Add a D3 Data Visualization menu item to the Web menu
self.iface.addPluginToWebMenu("D3 Data Visualization", self.heatmapAction)
def unload(self):
self.iface.removePluginWebMenu("D3 Data Visualization", self.heatmapAction)
self.iface.removeWebToolBarIcon(self.heatmapAction)
def showHeatmapDialog(self):
"""Display the circular date/time heatmap dialog box"""
if not self.heatmapDialog:
from .heatmapDialog import HeatmapDialog
self.heatmapDialog = HeatmapDialog(self.iface, self.iface.mainWindow())
self.heatmapDialog.show()
示例5: build_menu_tree
def build_menu_tree(self):
# Main Menu
self.menu.clear()
self.groups_list = GroupsList()
self.ds_list = DataSourcesList()
data_sources = self.ds_list.data_sources.values()
data_sources = sorted(data_sources, key=lambda x: x.alias or x.id)
ds_hide_list = PluginSettings.get_hide_ds_id_list()
for ds in data_sources:
if ds.id in ds_hide_list:
continue
ds.action.triggered.connect(self.insert_layer)
gr_menu = self.groups_list.get_group_menu(ds.group)
gr_menu.addAction(ds.action)
if gr_menu not in self.menu.children():
self.menu.addMenu(gr_menu)
# QMS web service
self.menu.addSeparator()
self.service_actions.append(self.qms_search_action)
self.menu.addAction(self.qms_search_action)
icon_create_service_path = self.plugin_dir + '/icons/mActionCreate.svg'
qms_create_service_action = QAction(self.tr('Add to Search'), self.iface.mainWindow())
qms_create_service_action.setIcon(QIcon(icon_create_service_path))
qms_create_service_action.triggered.connect(self.openURL)
self.menu.addAction(qms_create_service_action)
# Scales, Settings and About actions
self.menu.addSeparator()
icon_set_nearest_scale_path = self.plugin_dir + '/icons/mActionSettings.svg' # TODO change icon
set_nearest_scale_act = QAction(QIcon(icon_set_nearest_scale_path), self.tr('Set proper scale'), self.iface.mainWindow())
set_nearest_scale_act.triggered.connect(self.set_nearest_scale)
self.menu.addAction(set_nearest_scale_act) # TODO: uncomment after fix
self.service_actions.append(set_nearest_scale_act)
icon_scales_path = self.plugin_dir + '/icons/mActionSettings.svg' # TODO change icon
scales_act = QAction(QIcon(icon_scales_path), self.tr('Set SlippyMap scales'), self.iface.mainWindow())
scales_act.triggered.connect(self.set_tms_scales)
#self.menu.addAction(scales_act) # TODO: uncomment after fix
self.service_actions.append(scales_act)
icon_settings_path = self.plugin_dir + '/icons/mActionSettings.svg'
settings_act = QAction(QIcon(icon_settings_path), self.tr('Settings'), self.iface.mainWindow())
self.service_actions.append(settings_act)
settings_act.triggered.connect(self.show_settings_dialog)
self.menu.addAction(settings_act)
icon_about_path = self.plugin_dir + '/icons/mActionAbout.svg'
info_act = QAction(QIcon(icon_about_path), self.tr('About'), self.iface.mainWindow())
self.service_actions.append(info_act)
info_act.triggered.connect(self.info_dlg.show)
self.menu.addAction(info_act)
示例6: registerDatabaseActions
def registerDatabaseActions(self, mainWindow):
Database.registerDatabaseActions(self, mainWindow)
# add a separator
separator = QAction(self)
separator.setSeparator(True)
mainWindow.registerAction(separator, self.tr("&Table"))
action = QAction(self.tr("Run &Vacuum Analyze"), self)
mainWindow.registerAction(action, self.tr("&Table"), self.runVacuumAnalyzeActionSlot)
示例7: initGui
def initGui(self):
self.toolbox = ProcessingToolbox()
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
self.toolbox.hide()
self.resultsDock = ResultsDock()
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.resultsDock)
self.resultsDock.hide()
resultsList.resultAdded.connect(self.resultsDock.fillTree)
self.menu = QMenu(self.iface.mainWindow().menuBar())
self.menu.setObjectName('processing')
self.menu.setTitle(self.tr('Pro&cessing'))
self.toolboxAction = self.toolbox.toggleViewAction()
self.toolboxAction.setObjectName('toolboxAction')
self.toolboxAction.setIcon(
QgsApplication.getThemeIcon("/processingAlgorithm.svg"))
self.toolboxAction.setText(self.tr('&Toolbox'))
self.iface.registerMainWindowAction(self.toolboxAction, 'Ctrl+Alt+T')
self.menu.addAction(self.toolboxAction)
self.modelerAction = QAction(
QgsApplication.getThemeIcon("/processingModel.svg"),
self.tr('Graphical &Modeler...'), self.iface.mainWindow())
self.modelerAction.setObjectName('modelerAction')
self.modelerAction.triggered.connect(self.openModeler)
self.iface.registerMainWindowAction(self.modelerAction, 'Ctrl+Alt+M')
self.menu.addAction(self.modelerAction)
self.historyAction = QAction(
QIcon(os.path.join(cmd_folder, 'images', 'history.svg')),
self.tr('&History...'), self.iface.mainWindow())
self.historyAction.setObjectName('historyAction')
self.historyAction.triggered.connect(self.openHistory)
self.iface.registerMainWindowAction(self.historyAction, 'Ctrl+Alt+H')
self.menu.addAction(self.historyAction)
self.resultsAction = self.resultsDock.toggleViewAction()
self.resultsAction.setObjectName('resultsAction')
self.resultsAction.setIcon(
QgsApplication.getThemeIcon("/processingResult.svg"))
self.resultsAction.setText(self.tr('&Results Viewer'))
self.iface.registerMainWindowAction(self.resultsAction, 'Ctrl+Alt+R')
self.menu.addAction(self.resultsAction)
menuBar = self.iface.mainWindow().menuBar()
menuBar.insertMenu(
self.iface.firstRightStandardMenu().menuAction(), self.menu)
self.menu.addSeparator()
initializeMenus()
createMenus()
示例8: QMatplotlibWidget
class QMatplotlibWidget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.canvas = QMatplotlibCanvas()
self.ax = self.canvas.ax
self.figure = self.canvas.figure
self.toolBar = NavigationToolbar2QT(self.canvas, self)
bgColor = self.palette().color(QPalette.Background).name()
self.figure.set_facecolor(bgColor)
self.layout = QVBoxLayout()
self.layout.setSpacing(2)
self.layout.setMargin(0)
self.layout.addWidget(self.toolBar)
self.layout.addWidget(self.canvas)
self.setLayout(self.layout)
self._setupToolbar()
def _setupToolbar(self):
self.actionToggleGrid = QAction(self.tr('Toggle grid'), self.toolBar)
self.actionToggleGrid.setIcon(
QIcon(os.path.join(pluginPath, 'icons', 'toggleGrid.svg')))
self.actionToggleGrid.setCheckable(True)
self.actionToggleGrid.triggered.connect(self.toggleGrid)
self.toolBar.insertAction(self.toolBar.actions()[7], self.actionToggleGrid)
self.toolBar.insertSeparator(self.toolBar.actions()[8])
def toggleGrid(self):
self.ax.grid()
self.canvas.draw()
def alignLabels(self):
self.figure.autofmt_xdate()
def clear(self):
self.ax.clear()
self.canvas.draw()
def setTitle(self, text):
self.ax.set_title(text)
def setXAxisCaption(self, text):
self.ax.set_xlabel(text)
def setYAxisCaption(self, text):
self.ax.set_ylabel(text)
示例9: menu
def menu(self):
menu = QMenu()
refreshAction = QAction(icon("refresh.svg"), "Refresh", menu)
refreshAction.triggered.connect(self.refreshContent)
menu.addAction(refreshAction)
createBranchAction = QAction(icon("create_branch.png"), "Create branch", menu)
createBranchAction.triggered.connect(self.createBranch)
menu.addAction(createBranchAction)
deleteAction = QAction(QgsApplication.getThemeIcon('/mActionDeleteSelected.svg'), "Delete", menu)
deleteAction.triggered.connect(self.delete)
menu.addAction(deleteAction)
deleteAction.setEnabled(self.parent().childCount() > 1 and self.branch != "master")
return menu
示例10: setAsNonRepoLayer
def setAsNonRepoLayer(layer):
removeLayerActions(layer)
action = QAction("Import to GeoGig...", config.iface.legendInterface())
action.triggered.connect(partial(addLayer, layer))
if layer.type() == QgsMapLayer.RasterLayer or layer.storageType() != 'GPKG':
action.setEnabled(False)
config.iface.legendInterface().addLegendLayerAction(action, u"GeoGig", u"id2", QgsMapLayer.VectorLayer, False)
config.iface.legendInterface().addLegendLayerActionForLayer(action, layer)
_actions[layer.id()] = [action]
try:
repoWatcher.layerUpdated.disconnect(updateInfoActions)
except:
pass #In case it is a layer that was never a repo layer
示例11: selectOutput
def selectOutput(self):
if isinstance(self.parameter, QgsProcessingParameterFolderDestination):
self.selectDirectory()
else:
popupMenu = QMenu()
if not self.default_selection:
if self.parameter.flags() & QgsProcessingParameterDefinition.FlagOptional:
actionSkipOutput = QAction(
self.tr('Skip Output'), self.btnSelect)
actionSkipOutput.triggered.connect(self.skipOutput)
popupMenu.addAction(actionSkipOutput)
if isinstance(self.parameter, QgsProcessingParameterFeatureSink) \
and self.parameter.supportsNonFileBasedOutput():
# use memory layers for temporary layers if supported
actionSaveToTemp = QAction(
self.tr('Create Temporary Layer'), self.btnSelect)
else:
actionSaveToTemp = QAction(
self.tr('Save to a Temporary File'), self.btnSelect)
actionSaveToTemp.triggered.connect(self.saveToTemporary)
popupMenu.addAction(actionSaveToTemp)
actionSaveToFile = QAction(
QCoreApplication.translate('DestinationSelectionPanel', 'Save to File…'), self.btnSelect)
actionSaveToFile.triggered.connect(self.selectFile)
popupMenu.addAction(actionSaveToFile)
if isinstance(self.parameter, QgsProcessingParameterFeatureSink) \
and self.parameter.supportsNonFileBasedOutput():
actionSaveToGpkg = QAction(
QCoreApplication.translate('DestinationSelectionPanel', 'Save to GeoPackage…'), self.btnSelect)
actionSaveToGpkg.triggered.connect(self.saveToGeopackage)
popupMenu.addAction(actionSaveToGpkg)
actionSaveToPostGIS = QAction(
QCoreApplication.translate('DestinationSelectionPanel', 'Save to PostGIS Table…'), self.btnSelect)
actionSaveToPostGIS.triggered.connect(self.saveToPostGIS)
settings = QgsSettings()
settings.beginGroup('/PostgreSQL/connections/')
names = settings.childGroups()
settings.endGroup()
actionSaveToPostGIS.setEnabled(bool(names))
popupMenu.addAction(actionSaveToPostGIS)
actionSetEncoding = QAction(
QCoreApplication.translate('DestinationSelectionPanel', 'Change File Encoding ({})…').format(self.encoding), self.btnSelect)
actionSetEncoding.triggered.connect(self.selectEncoding)
popupMenu.addAction(actionSetEncoding)
popupMenu.exec_(QCursor.pos())
示例12: selectOutput
def selectOutput(self):
if isinstance(self.parameter, QgsProcessingParameterFolderDestination):
self.selectDirectory()
else:
popupMenu = QMenu()
if self.parameter.flags() & QgsProcessingParameterDefinition.FlagOptional:
actionSkipOutput = QAction(
self.tr('Skip output'), self.btnSelect)
actionSkipOutput.triggered.connect(self.skipOutput)
popupMenu.addAction(actionSkipOutput)
if isinstance(self.parameter, QgsProcessingParameterFeatureSink) \
and self.alg.provider().supportsNonFileBasedOutput():
# use memory layers for temporary layers if supported
actionSaveToTemp = QAction(
self.tr('Create temporary layer'), self.btnSelect)
else:
actionSaveToTemp = QAction(
self.tr('Save to a temporary file'), self.btnSelect)
actionSaveToTemp.triggered.connect(self.saveToTemporary)
popupMenu.addAction(actionSaveToTemp)
actionSaveToFile = QAction(
self.tr('Save to file...'), self.btnSelect)
actionSaveToFile.triggered.connect(self.selectFile)
popupMenu.addAction(actionSaveToFile)
actionShowExpressionsBuilder = QAction(
self.tr('Use expression...'), self.btnSelect)
actionShowExpressionsBuilder.triggered.connect(self.showExpressionsBuilder)
popupMenu.addAction(actionShowExpressionsBuilder)
if isinstance(self.parameter, QgsProcessingParameterFeatureSink) \
and self.alg.provider().supportsNonFileBasedOutput():
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 = QgsSettings()
settings.beginGroup('/PostgreSQL/connections/')
names = settings.childGroups()
settings.endGroup()
actionSaveToPostGIS.setEnabled(bool(names))
popupMenu.addAction(actionSaveToPostGIS)
popupMenu.exec_(QCursor.pos())
示例13: __init__
class DBManagerPlugin:
def __init__(self, iface):
self.iface = iface
self.dlg = None
def initGui(self):
self.action = QAction(QIcon(":/db_manager/icon"), QApplication.translate("DBManagerPlugin", "DB Manager"),
self.iface.mainWindow())
self.action.setObjectName("dbManager")
self.action.triggered.connect(self.run)
# Add toolbar button and menu item
if hasattr(self.iface, 'addDatabaseToolBarIcon'):
self.iface.addDatabaseToolBarIcon(self.action)
else:
self.iface.addToolBarIcon(self.action)
if hasattr(self.iface, 'addPluginToDatabaseMenu'):
self.iface.addPluginToDatabaseMenu(QApplication.translate("DBManagerPlugin", "DB Manager"), self.action)
else:
self.iface.addPluginToMenu(QApplication.translate("DBManagerPlugin", "DB Manager"), self.action)
def unload(self):
# Remove the plugin menu item and icon
if hasattr(self.iface, 'removePluginDatabaseMenu'):
self.iface.removePluginDatabaseMenu(QApplication.translate("DBManagerPlugin", "DB Manager"), self.action)
else:
self.iface.removePluginMenu(QApplication.translate("DBManagerPlugin", "DB Manager"), self.action)
if hasattr(self.iface, 'removeDatabaseToolBarIcon'):
self.iface.removeDatabaseToolBarIcon(self.action)
else:
self.iface.removeToolBarIcon(self.action)
if self.dlg is not None:
self.dlg.close()
def run(self):
# keep opened only one instance
if self.dlg is None:
from .db_manager import DBManager
self.dlg = DBManager(self.iface)
self.dlg.destroyed.connect(self.onDestroyed)
self.dlg.show()
self.dlg.raise_()
self.dlg.setWindowState(self.dlg.windowState() & ~Qt.WindowMinimized)
self.dlg.activateWindow()
def onDestroyed(self, obj):
self.dlg = None
示例14: __init__
def __init__(self, parent=None):
QTableView.__init__(self, parent)
self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.item = None
self.dirty = False
# allow copying results
copyAction = QAction(QApplication.translate("DBManagerPlugin", "Copy"), self)
self.addAction(copyAction)
copyAction.setShortcuts(QKeySequence.Copy)
copyAction.triggered.connect(self.copySelectedResults)
self._clear()
示例15: addAlgorithmEntry
def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, addButton=False):
action = QAction(icon or alg.icon(), actionText or alg.displayName(), iface.mainWindow())
action.triggered.connect(lambda: _executeAlgorithm(alg))
action.setObjectName("mProcessingUserMenu_%s" % alg.id())
if menuName:
menu = getMenu(menuName, iface.mainWindow().menuBar())
submenu = getMenu(submenuName, menu)
submenu.addAction(action)
if addButton:
global algorithmsToolbar
if algorithmsToolbar is None:
algorithmsToolbar = iface.addToolBar('ProcessingAlgorithms')
algorithmsToolbar.addAction(action)