本文整理汇总了Python中qgis.utils.iface.mainWindow函数的典型用法代码示例。如果您正苦于以下问题:Python mainWindow函数的具体用法?Python mainWindow怎么用?Python mainWindow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mainWindow函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: createAlgorithmDialog
def createAlgorithmDialog(algOrName, parameters={}):
"""
Creates and returns an algorithm dialog for the specified algorithm, prepopulated
with a given set of parameters. It is the caller's responsibility to execute
and delete this dialog.
:param algOrName: Either an instance of an algorithm, or an algorithm's ID
:param parameters: Initial algorithm parameters dictionary
:returns algorithm results as a dictionary, or None if execution failed
:rtype: Union[dict, None]
"""
if isinstance(algOrName, QgsProcessingAlgorithm):
alg = algOrName.create()
else:
alg = QgsApplication.processingRegistry().createAlgorithmById(algOrName)
if alg is None:
return False
dlg = alg.createCustomParametersWidget(iface.mainWindow())
if not dlg:
dlg = AlgorithmDialog(alg, parent=iface.mainWindow())
dlg.setParameters(parameters)
return dlg
开发者ID:dmarteau,项目名称:QGIS,代码行数:28,代码来源:general.py
示例2: rearrangeToolbars
def rearrangeToolbars(profile):
settings = QSettings()
key = "profilesplugin/Profiles/%s/geometry" % profile
if settings.contains(key):
iface.mainWindow().restoreGeometry(settings.value(key))
else:
toolbars = [el for el in iface.mainWindow().children() if isinstance(el, QToolBar) and el.isVisible()]
toolbars = sorted(toolbars, key=lambda t: (t.geometry().top(), t.geometry().left()))
for toolbar in toolbars:
iface.mainWindow().removeToolBarBreak(toolbar)
for toolbar in toolbars:
iface.mainWindow().insertToolBarBreak(toolbar)
rowWidth = 0
lastY = None
for toolbar in toolbars:
if lastY is None:
lastY = toolbar.geometry().top()
actions = [a for a in toolbar.actions() if a.isVisible()]
toolbarWidth = toolbar.actionGeometry(actions[-1]).right()
rowWidth += toolbarWidth
#print toolbar.objectName(), toolbarWidth, rowWidth
if rowWidth < iface.mainWindow().width():
iface.mainWindow().removeToolBarBreak(toolbar)
else:
lastY += toolbar.geometry().height()
rowWidth = toolbarWidth
toolbar.move(QPoint(rowWidth - toolbarWidth, lastY))
开发者ID:boundlessgeo,项目名称:qgis-profiles-plugin,代码行数:27,代码来源:utils.py
示例3: canvasMoveEvent
def canvasMoveEvent(self, e):
pt = self.toMapCoordinates(e.pos())
mgrsCoord = self.toMgrs(pt)
if mgrsCoord:
iface.mainWindow().statusBar().showMessage("MGRS Coordinate: " + mgrsCoord)
else:
iface.mainWindow().statusBar().showMessage("")
开发者ID:tay7-git,项目名称:mgrs-tools,代码行数:7,代码来源:maptool.py
示例4: triggerResult
def triggerResult(self, result):
alg = QgsApplication.processingRegistry().createAlgorithmById(result.userData)
if alg:
ok, message = alg.canExecute()
if not ok:
dlg = MessageDialog()
dlg.setTitle(self.tr('Missing dependency'))
dlg.setMessage(message)
dlg.exec_()
return
if [d for d in alg.parameterDefinitions() if
d.name() not in ('INPUT', 'OUTPUT')]:
dlg = alg.createCustomParametersWidget(parent=iface.mainWindow())
if not dlg:
dlg = AlgorithmDialog(alg, True, parent=iface.mainWindow())
canvas = iface.mapCanvas()
prevMapTool = canvas.mapTool()
dlg.show()
dlg.exec_()
if canvas.mapTool() != prevMapTool:
try:
canvas.mapTool().reset()
except:
pass
canvas.setMapTool(prevMapTool)
else:
feedback = MessageBarProgress(algname=alg.displayName())
parameters = {}
execute_in_place(alg, parameters, feedback=feedback)
开发者ID:pblottiere,项目名称:QGIS,代码行数:30,代码来源:AlgorithmLocatorFilter.py
示例5: 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)
开发者ID:dmarteau,项目名称:QGIS,代码行数:25,代码来源:menus.py
示例6: _open
def _open(self):
if self.plugin["status"] == "upgradeable":
reply = QMessageBox.question(
iface.mainWindow(),
"Plugin",
"An older version of the plugin is already installed. Do you want to upgrade it?",
QMessageBox.Yes | QMessageBox.No)
if reply != QMessageBox.Yes:
return
elif self.plugin["status"] in ["not installed", "new"]:
pass
else:
reply = QMessageBox.question(
iface.mainWindow(),
"Plugin",
"The plugin is already installed. Do you want to reinstall it?",
QMessageBox.Yes | QMessageBox.No)
if reply != QMessageBox.Yes:
return
def _install():
installer = pyplugin_installer.instance()
installer.installPlugin(self.plugin["id"])
self.plugin["status"] = "installed"
execute(_install)
开发者ID:boundlessgeo,项目名称:qgis-connect-plugin,代码行数:26,代码来源:connect.py
示例7: fetchAvailablePlugins
def fetchAvailablePlugins(self, reloadMode):
""" Fetch plugins from all enabled repositories."""
""" reloadMode = true: Fully refresh data from QSettings to mRepositories """
""" reloadMode = false: Fetch unready repositories only """
QApplication.setOverrideCursor(Qt.WaitCursor)
if reloadMode:
repositories.load()
plugins.clearRepoCache()
plugins.getAllInstalled()
for key in repositories.allEnabled():
if reloadMode or repositories.all()[key]["state"] == 3: # if state = 3 (error or not fetched yet), try to fetch once again
repositories.requestFetching(key)
if repositories.fetchingInProgress():
fetchDlg = QgsPluginInstallerFetchingDialog(iface.mainWindow())
fetchDlg.exec_()
del fetchDlg
for key in repositories.all():
repositories.killConnection(key)
QApplication.restoreOverrideCursor()
# display error messages for every unavailable reposioty, unless Shift pressed nor all repositories are unavailable
keepQuiet = QgsApplication.keyboardModifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier)
if repositories.allUnavailable() and repositories.allUnavailable() != repositories.allEnabled():
for key in repositories.allUnavailable():
if not keepQuiet:
QMessageBox.warning(iface.mainWindow(), self.tr("QGIS Python Plugin Installer"), self.tr("Error reading repository:") + " " + key + "\n\n" + repositories.all()[key]["error"])
if QgsApplication.keyboardModifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier):
keepQuiet = True
# finally, rebuild plugins from the caches
plugins.rebuild()
开发者ID:fritsvanveen,项目名称:QGIS,代码行数:34,代码来源:installer.py
示例8: addRepository
def addRepository(self):
""" add new repository connection """
dlg = QgsPluginInstallerRepositoryDialog(iface.mainWindow())
dlg.checkBoxEnabled.setCheckState(Qt.Checked)
if not dlg.exec_():
return
for i in repositories.all().values():
if dlg.editURL.text().strip() == i["url"]:
QMessageBox.warning(
iface.mainWindow(),
self.tr("QGIS Python Plugin Installer"),
self.tr("Unable to add another repository with the same URL!"),
)
return
settings = QSettings()
settings.beginGroup(reposGroup)
reposName = dlg.editName.text()
reposURL = dlg.editURL.text().strip()
if repositories.all().has_key(reposName):
reposName = reposName + "(2)"
# add to settings
settings.setValue(reposName + "/url", reposURL)
settings.setValue(reposName + "/enabled", bool(dlg.checkBoxEnabled.checkState()))
# refresh lists and populate widgets
plugins.removeRepository(reposName)
self.reloadAndExportData()
开发者ID:jetuk,项目名称:Quantum-GIS,代码行数:26,代码来源:installer.py
示例9: checkingDone
def checkingDone(self):
""" Remove the "Looking for new plugins..." label and display a notification instead if any updates or news available """
if not self.statusLabel:
# only proceed if the label is present
return
# rebuild plugins cache
plugins.rebuild()
# look for news in the repositories
plugins.markNews()
status = ""
# first check for news
for key in plugins.all():
if plugins.all()[key]["status"] == "new":
status = self.tr("There is a new plugin available")
tabIndex = 4 # PLUGMAN_TAB_NEW
# then check for updates (and eventually overwrite status)
for key in plugins.all():
if plugins.all()[key]["status"] == "upgradeable":
status = self.tr("There is a plugin update available")
tabIndex = 3 # PLUGMAN_TAB_UPGRADEABLE
# finally set the notify label
if status:
self.statusLabel.setText(u' <a href="%d">%s</a> ' % (tabIndex, status))
else:
iface.mainWindow().statusBar().removeWidget(self.statusLabel)
self.statusLabel = None
开发者ID:fritsvanveen,项目名称:QGIS,代码行数:26,代码来源:installer.py
示例10: applyButtons
def applyButtons(profile):
if profile.buttons is None:
return
for toolbar in customToolbarsWidgets[::-1]:
toolbar.setVisible(False)
iface.mainWindow().removeToolBar(toolbar)
del toolbar
del customToolbarsWidgets[:]
currentToolbars = [el for el in iface.mainWindow().children()
if isinstance(el, QToolBar)]
customToolbars = defaultdict(list)
toolbars = profile.buttons
for toolbar in currentToolbars:
if toolbar.objectName() in toolbars:
hasVisibleActions = False
actions = toolbar.actions()
for i, action in enumerate(actions):
objectName = action.objectName() or str(i)
if objectName in toolbars[toolbar.objectName()]:
location = toolbars[toolbar.objectName()][objectName]
if location is not None:
newAction = QAction(action.icon(), action.text(), iface.mainWindow())
newAction.triggered.connect(action.trigger)
objectName = "%s_%i" % (location, len(customToolbars[location]))
newAction.setObjectName(objectName)
customToolbars[location].append(newAction)
action.setVisible(False)
else:
hasVisibleActions = True
action.setVisible(True)
else:
if toolbars[toolbar.objectName()]:
action.setVisible(False)
else: #If toolbar definition is empty, means all buttons should be added
hasVisibleActions = True
action.setVisible(True)
if isinstance(action, QWidgetAction) and not isinstance(action.defaultWidget(), QToolButton) and action.defaultWidget() is not None:
action.defaultWidget().setMinimumWidth(300)
#action.defaultWidget().setMaximumWidth(400)
toolbar.setVisible(hasVisibleActions)
else:
toolbar.setVisible(False)
for name, actions in customToolbars.iteritems():
toolbar = iface.mainWindow().addToolBar(name)
toolbar.setObjectName("toolbar_%s" % name)
customToolbarsWidgets.append(toolbar)
for action in actions:
toolbar.addAction(action)
开发者ID:boundlessgeo,项目名称:qgis-profiles-plugin,代码行数:55,代码来源:utils.py
示例11: uninstallPlugin
def uninstallPlugin(self, key, quiet=False):
""" Uninstall given plugin """
if plugins.all().has_key(key):
plugin = plugins.all()[key]
else:
plugin = plugins.localCache[key]
if not plugin:
return
if not quiet:
warning = self.tr("Are you sure you want to uninstall the following plugin?") + "\n(" + plugin["name"] + ")"
if plugin["status"] == "orphan" and not plugin["error"]:
warning += "\n\n" + self.tr("Warning: this plugin isn't available in any accessible repository!")
if (
QMessageBox.warning(
iface.mainWindow(),
self.tr("QGIS Python Plugin Installer"),
warning,
QMessageBox.Yes,
QMessageBox.No,
)
== QMessageBox.No
):
return
# unload the plugin
try:
unloadPlugin(key)
except:
pass
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + plugin["id"]
result = removeDir(pluginDir)
if result:
QMessageBox.warning(iface.mainWindow(), self.tr("Plugin uninstall failed"), result)
else:
# safe remove
try:
unloadPlugin(plugin["id"])
except:
pass
try:
exec("plugins[%s].unload()" % plugin["id"])
exec("del plugins[%s]" % plugin["id"])
except:
pass
try:
exec("del sys.modules[%s]" % plugin["id"])
except:
pass
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
QMessageBox.information(
iface.mainWindow(),
self.tr("Plugin uninstalled successfully"),
self.tr("Plugin uninstalled successfully"),
)
开发者ID:jetuk,项目名称:Quantum-GIS,代码行数:55,代码来源:installer.py
示例12: __init__
def __init__(self, parent=None):
QDockWidget.__init__(self, parent)
self.setObjectName("PythonConsole")
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
#self.setAllowedAreas(Qt.BottomDockWidgetArea)
self.console = PythonConsoleWidget(self)
self.setWidget( self.console )
# try to restore position from stored main window state
if iface and not iface.mainWindow().restoreDockWidget(self):
iface.mainWindow().addDockWidget(Qt.BottomDockWidgetArea, self)
开发者ID:mola,项目名称:Quantum-GIS,代码行数:12,代码来源:console.py
示例13: __init__
def __init__(self, parent=None):
QDockWidget.__init__(self, parent)
self.setObjectName("Python Console")
self.setAllowedAreas(Qt.BottomDockWidgetArea)
self.widget = QWidget()
self.l = QVBoxLayout(self.widget)
self.edit = PythonEdit()
self.l.addWidget(self.edit)
self.setWidget(self.widget)
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
# try to restore position from stored main window state
if not iface.mainWindow().restoreDockWidget(self):
iface.mainWindow().addDockWidget(Qt.BottomDockWidgetArea, self)
开发者ID:RealworldSystems,项目名称:Quantum-GIS,代码行数:13,代码来源:console.py
示例14: addAlgorithmEntry
def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, addButton=False):
action = QAction(icon or alg.getIcon(), actionText or alg.name, iface.mainWindow())
action.triggered.connect(lambda: _executeAlgorithm(alg))
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)
开发者ID:Jesonchang12,项目名称:QGIS,代码行数:14,代码来源:menus.py
示例15: __init__
def __init__(self):
""" Initialize data objects, starts fetching if appropriate, and warn about/removes obsolete plugins """
QObject.__init__(self) # initialize QObject in order to to use self.tr()
repositories.load()
plugins.getAllInstalled()
if repositories.checkingOnStart() and repositories.timeForChecking() and repositories.allEnabled():
# start fetching repositories
self.statusLabel = QLabel(self.tr("Looking for new plugins...") + " ", iface.mainWindow().statusBar())
iface.mainWindow().statusBar().insertPermanentWidget(0, self.statusLabel)
self.statusLabel.linkActivated.connect(self.showPluginManagerWhenReady)
repositories.checkingDone.connect(self.checkingDone)
for key in repositories.allEnabled():
repositories.requestFetching(key)
else:
# no fetching at start, so mark all enabled repositories as requesting to be fetched.
for key in repositories.allEnabled():
repositories.setRepositoryData(key, "state", 3)
# look for obsolete plugins (the user-installed one is newer than core one)
for key in plugins.obsoletePlugins:
plugin = plugins.localCache[key]
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle(self.tr("QGIS Python Plugin Installer"))
msg.addButton(self.tr("Uninstall (recommended)"), QMessageBox.AcceptRole)
msg.addButton(self.tr("I will uninstall it later"), QMessageBox.RejectRole)
msg.setText(
"%s <b>%s</b><br/><br/>%s"
% (
self.tr("Obsolete plugin:"),
plugin["name"],
self.tr(
"QGIS has detected an obsolete plugin that masks its more recent version shipped with this copy of QGIS. This is likely due to files associated with a previous installation of QGIS. Do you want to remove the old plugin right now and unmask the more recent version?"
),
)
)
msg.exec_()
if not msg.result():
# uninstall, update utils and reload if enabled
self.uninstallPlugin(key, quiet=True)
updateAvailablePlugins()
settings = QSettings()
if settings.value("/PythonPlugins/" + key, False, type=bool):
settings.setValue("/PythonPlugins/watchDog/" + key, True)
loadPlugin(key)
startPlugin(key)
settings.remove("/PythonPlugins/watchDog/" + key)
开发者ID:Zakui,项目名称:QGIS,代码行数:49,代码来源:installer.py
示例16: openLink
def openLink(self, url):
if url.toString() == "log":
self.close()
logDock = iface.mainWindow().findChild(QDockWidget, 'MessageLog')
logDock.show()
else:
QDesktopServices.openUrl(url)
开发者ID:cz172638,项目名称:QGIS,代码行数:7,代码来源:MessageDialog.py
示例17: runModel
def runModel(self):
if len(self.model.childAlgorithms()) == 0:
self.bar.pushMessage("", self.tr("Model doesn't contain any algorithm and/or parameter and can't be executed"), level=Qgis.Warning, duration=5)
return
dlg = AlgorithmDialog(self.model.create(), parent=iface.mainWindow())
dlg.exec_()
开发者ID:dwsilk,项目名称:QGIS,代码行数:7,代码来源:ModelerDialog.py
示例18: 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(QCoreApplication.translate('MainWindow', 'Processing Algorithms'))
algorithmsToolbar.setToolTip(QCoreApplication.translate('MainWindow', 'Processing Algorithms Toolbar'))
algorithmsToolbar.addAction(action)
开发者ID:pigreco,项目名称:QGIS,代码行数:16,代码来源:menus.py
示例19: __init__
def __init__(self):
"""
Initialize the STR component class.
"""
super(ComponentUtility, self).__init__()
self.current_profile = current_profile()
self.social_tenure = self.current_profile.social_tenure
self.parties = self.social_tenure.parties
self.spatial_units = self.social_tenure.spatial_units
self.str_model = None
self.str_doc_model = None
if len(self.parties) > 0:
self.party_1 = self.parties[0]
if len(self.spatial_units) > 0:
self.spatial_unit_1 = self.spatial_units[0]
try:
self.str_model, self.str_doc_model = entity_model(
self.social_tenure, False, True
)
except Exception as ex:
QMessageBox.critical(
iface.mainWindow(),
QApplication.translate('ComponentUtility', 'Database Error'),
str(ex)
)
开发者ID:gltn,项目名称:stdm,代码行数:25,代码来源:str_components.py
示例20: __init__
def __init__(self, resourceType):
super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow())
self.setupUi(self)
self.manager = QgsNetworkAccessManager.instance()
self.resourceType = resourceType
if self.resourceType == self.MODELS:
self.folder = ModelerUtils.modelsFolder()
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/'
self.icon = QIcon(os.path.join(pluginPath, 'images', 'model.png'))
elif self.resourceType == self.SCRIPTS:
self.folder = ScriptUtils.scriptsFolder()
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/'
self.icon = QIcon(os.path.join(pluginPath, 'images', 'script.png'))
else:
self.folder = RUtils.RScriptsFolder()
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/'
self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.png'))
self.lastSelectedItem = None
self.updateToolbox = False
self.populateTree()
self.buttonBox.accepted.connect(self.okPressed)
self.buttonBox.rejected.connect(self.cancelPressed)
self.tree.currentItemChanged.connect(self.currentItemChanged)
开发者ID:HeatherHillers,项目名称:QGIS,代码行数:25,代码来源:GetScriptsAndModels.py
注:本文中的qgis.utils.iface.mainWindow函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论