本文整理汇总了Python中qgis.utils.iface.mainWindow方法的典型用法代码示例。如果您正苦于以下问题:Python iface.mainWindow方法的具体用法?Python iface.mainWindow怎么用?Python iface.mainWindow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.utils.iface
的用法示例。
在下文中一共展示了iface.mainWindow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
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)
)
示例2: select_file_dialog
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def select_file_dialog(self, title):
"""
Displays a file dialog for a user to specify a source document
:param title: The title of the file dialog
:type title: String
"""
# Get last path for supporting documents
last_path = last_document_path()
if last_path is None:
last_path = '/home'
files = QFileDialog.getOpenFileNames(
iface.mainWindow(),
title,
last_path,
"Source Documents (*.jpg *.jpeg *.png *.bmp *.tiff *.svg)"
)
return files
示例3: closeEvent
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def closeEvent(self, event):
title = self.tr('Interruption Error')
message = self.tr(
'Are you sure you want to '
'cancel the process?'
)
warning_result = QMessageBox.critical(
iface.mainWindow(),
title,
message,
QMessageBox.Yes,
QMessageBox.No
)
if warning_result:
event.accept()
else:
event.ignore()
示例4: getZoom
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def getZoom():
"""
Returns the current zoom level of the map.
https://developers.google.com/earth-engine/api_docs#map.getzoom, note that in QGIS zoom is a floating point number
Uses:
>>> from ee_plugin import Map
>>> print(Map.getZoom())
"""
# from https://gis.stackexchange.com/questions/268890/get-current-zoom-level-from-qgis-map-canvas
scale = iface.mapCanvas().scale()
dpi = iface.mainWindow().physicalDpiX()
maxScalePerPixel = 156543.04
inchesPerMeter = 39.37
zoom = math.log((dpi * inchesPerMeter * maxScalePerPixel / scale), 2)
return zoom
示例5: runAlgorithm
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def runAlgorithm(self):
alg = RAlgorithm(description_file=None, script=self.editor.text())
if alg.error is not None:
error = QgsError(alg.error, "R")
QgsErrorDialog.show(error,
self.tr("Execution error")
)
return
alg.setProvider(QgsApplication.processingRegistry().providerById("r"))
alg.initAlgorithm()
dlg = alg.createCustomParametersWidget(iface.mainWindow())
if not dlg:
dlg = AlgorithmDialog(alg, parent=iface.mainWindow())
canvas = iface.mapCanvas()
prevMapTool = canvas.mapTool()
dlg.show()
if canvas.mapTool() != prevMapTool:
if canvas.mapTool():
canvas.mapTool().reset()
canvas.setMapTool(prevMapTool)
示例6: _installWith
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def _installWith(system):
if _qtModule:
ans = _qtModule.QMessageBox.question(
iface.mainWindow(),
"Install missing packages?",
"Install missing packages with " + system + "?\r\n"
"(You'll get a notification when finished)",
_qtModule.QMessageBox.Yes | _qtModule.QMessageBox.No,
_qtModule.QMessageBox.Yes)
return ans == _qtModule.QMessageBox.Yes
else:
valid = {"": True, "yes": True, "y": True,
"no": False, "on": False, "n": False}
while True:
choice = input(
"Install missing packages with " + system + " [Y/n]? "
).lower()
if choice in valid:
return valid[choice]
else:
_print("Please respond with 'yes' or 'no' (or 'y' or 'n').")
示例7: pyratToLayer
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def pyratToLayer(layerid=None):
"""Exports a PyRAT-layer into QGIS"""
if type(layerid) is str:
pyrat.data.activateLayer(layerid)
annotation = pyrat.data.getAnnotation()
if 'info' in annotation:
filename = path.join(pyrat.data.tmpdir, annotation['info'] +
".rat")
else:
filename = path.join(pyrat.data.tmpdir, "PyRAT.rat")
filename, s = QFileDialog.getSaveFileName(
iface.mainWindow(),
"Save the PyRAT-Layer",
filename,
"RAT-File (*.rat)")
if not s or filename == "":
return
pyrat.save.rat((filename, "rat"), geo_envi_hdr=True)
iface.addRasterLayer(filename, path.basename(filename).split(".")[0])
示例8: messageShow
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def messageShow(self, progress, count, max):
if not progress:
progressMessageBar = iface.messageBar().createMessage(
"Looping through " + str(max) + " records ...")
progress = QProgressBar()
progress.setMaximum(max)
progress.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
progressMessageBar.layout().addWidget(progress)
iface.messageBar().pushWidget(progressMessageBar, level=1)
iface.mainWindow().repaint()
# return progress
if progress:
progress.setValue(count)
return(progress)
示例9: vector_layer
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def vector_layer(table_name, sql='', key='id', geom_column='', layer_name='', proj_wkt=None):
"""
Returns a QgsVectorLayer based on the specified table name.
"""
if not table_name:
return None
conn = stdm.data.app_dbconn
if conn is None:
return None
if not geom_column:
geom_column = None
ds_uri = conn.toQgsDataSourceUri()
ds_uri.setDataSource("public", table_name, geom_column, sql, key)
if not layer_name:
layer_name = table_name
if proj_wkt is not None:
iface.mainWindow().blockSignals(True)
v_layer = QgsVectorLayer(ds_uri.uri(), layer_name, "postgres")
if proj_wkt is not None:
iface.mainWindow().blockSignals(False)
try:
target_crs = QgsCoordinateReferenceSystem(
proj_wkt, QgsCoordinateReferenceSystem.InternalCrsId
)
v_layer.setCrs(target_crs)
except Exception:
pass
return v_layer
示例10: checkWorkspaces
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def checkWorkspaces(self):
ws = self.getDefaultWorkspace()
if ws is None:
QMessageBox.warning(iface.mainWindow(), 'No workspaces',
"You must have at least one workspace in your catalog\n"
"to perform this operation.",
QMessageBox.Ok)
return False
return True
示例11: run
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def run(self, conversionMap):
"""
Executes conversion itself based on a conversion map.
:param conversionMap: (dict) the conversion map. (SPECIFY FORMAT!)
"""
# task = DbConverter(iface, conversionMap, description=self.tr('DSGTools Dataset Conversion'))
# summaryDlg = TextBrowserDialog(parent=iface.mainWindow())
# summaryDlg.savePushButton.setEnabled(False)
# task.progressChanged.connect(summaryDlg.progressBar.setValue)
# task.taskCompleted.connect(lambda : summaryDlg.setHtml(task.output['log']))
# task.taskCompleted.connect(lambda : summaryDlg.cancelPushButton.setEnabled(False))
# task.taskCompleted.connect(lambda : summaryDlg.savePushButton.setEnabled(True))
# task.conversionUpdated.connect(summaryDlg.addToHtml)
# summaryDlg.cancelPushButton.clicked.connect(partial(self.cancelConversion, task, summaryDlg))
# # to clear log message before repopulating with conversion summary
# task.conversionFinished.connect(summaryDlg.clearHtml)
# QgsApplication.taskManager().addTask(task)
# summaryDlg.show()
# conversion off the thread
conv = DbConverter(iface, conversionMap, description=self.tr('DSGTools Dataset Conversion'))
summaryDlg = TextBrowserDialog(parent=iface.mainWindow())
summaryDlg.cancelPushButton.hide()
summaryDlg.progressBar.hide()
try:
QtWidgets.QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
if not conv.run():
# advise conversion has failed
msg = self.tr("Dataset conversion has finished with some errors. Check conversion log for details.")
iface.messageBar().pushMessage(self.tr('Warning!'), msg, level=Qgis.Warning, duration=5)
else:
self.resetInterface()
QtWidgets.QApplication.restoreOverrideCursor()
summaryDlg.setHtml(conv.output['log'])
except Exception as e:
QtWidgets.QApplication.restoreOverrideCursor()
msg = self.tr("Dataset conversion has failed: '{0}'").format(', '.join(map(str, e.args)))
iface.messageBar().pushMessage(self.tr('Warning!'), msg, level=Qgis.Warning, duration=5)
QgsMessageLog.logMessage(':'.join(e.args), "DSGTools Plugin", Qgis.Critical)
summaryDlg.exec_()
示例12: execute
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def execute(self):
"""
Called whenever the action is triggered
"""
file_path = self.itemData.description_file
if file_path is not None:
dlg = ScriptEditorDialog(file_path, iface.mainWindow())
dlg.show()
else:
QMessageBox.warning(None,
self.tr("Edit Script"),
self.tr("Can not find corresponding script file."))
示例13: _noWritePerms
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def _noWritePerms():
_print("ERROR: The current user does not have "
"write permissions to the target environment.")
if _qtModule:
_qtModule.QMessageBox.critical(
iface.mainWindow(),
"No write permissions",
"You don't have write permissions to install the requested"
" packages in the current python environment. Ask the "
"environment administrator to install the packages or create "
"a new conda environment with the requirements.yml file.")
示例14: _unknownError
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def _unknownError():
if _qtModule:
_qtModule.QMessageBox.critical(
iface.mainWindow(),
"Aborting",
"Errors occured during package installation.\r\n"
"Please look into the console for more details.")
示例15: addMenuEntry
# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mainWindow [as 别名]
def addMenuEntry(self, pyratTool):
"""Adds a PyRAT Tool to the QGIS-Menu"""
menus = pyratTool.gui['menu'].split('|')
submenu = self.pyratMenu
for menu in menus:
if menu not in [action.text() for action in submenu.actions()]:
submenu = submenu.addMenu(menu)
else:
submenu = [action.menu() for action in submenu.actions() if
action.text() == menu][0]
action = QAction(pyratTool.gui['entry'], iface.mainWindow())
action.triggered.connect(lambda:
PyRATBridge.menuAction(self, pyratTool))
submenu.addAction(action)