本文整理汇总了Python中qgis.utils.iface.messageBar函数的典型用法代码示例。如果您正苦于以下问题:Python messageBar函数的具体用法?Python messageBar怎么用?Python messageBar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了messageBar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: applyProfile
def applyProfile(profile, defaultProfile):
if profile.menus is None:
applyMenus(defaultProfile)
if profile.buttons is None:
applyButtons(defaultProfile)
if profile.panels is None:
applyPanels(defaultProfile)
if profile.plugins is None:
applyPlugins(defaultProfile)
pluginErrors = applyPlugins(profile)
applyMenus(profile)
applyButtons(profile)
applyPanels(profile)
rearrangeToolbars(profile.name)
if pluginErrors:
widget = iface.messageBar().createMessage("Error", tr('Profile {} has been applied with errors'.format(profile.name)))
showButton = QPushButton(widget)
showButton.setText("View more")
def showMore():
dlg = QgsMessageOutput.createMessageOutput()
dlg.setTitle('Profile errors')
dlg.setMessage("<br><br>".join(pluginErrors), QgsMessageOutput.MessageHtml)
dlg.showMessage()
showButton.pressed.connect(showMore)
widget.layout().addWidget(showButton)
iface.messageBar().pushWidget(widget, QgsMessageBar.WARNING,
duration = 5)
else:
iface.messageBar().pushMessage(tr('Profiles'),
tr('Profile {} has been correctly applied'.format(profile.name)),
level=QgsMessageBar.INFO,
duration=5)
示例2: canvasReleaseEvent
def canvasReleaseEvent(self, e):
pt = self.toMapCoordinates(e.pos())
mgrsCoord = self.toMgrs(pt)
if mgrsCoord:
clipboard = QApplication.clipboard()
clipboard.setText(mgrsCoord)
iface.messageBar().pushMessage("", "Coordinate %s copied to clipboard" % mgrsCoord, level=QgsMessageBar.INFO, duration=3)
示例3: updatePublishedStyle
def updatePublishedStyle(layer):
global _currentMessageBarLayer
track = pluginSetting("TrackLayers")
if track and isTrackedLayer(layer):
if iface.messageBar().currentItem() is None:
_resetCurrentMessageBarLayer()
if _currentMessageBarLayer != layer:
_currentMessageBarLayer = layer
widget = iface.messageBar().createMessage("",
"This layer was uploaded to a geoserver catalog. Do you want to update the published style?")
updateButton = QtWidgets.QPushButton(widget)
updateButton.setText("Update")
def updateStyle():
url = getTrackingInfo(layer)
catalog = Catalog(url)
wrapper = CatalogWrapper(catalog)
wrapper.publishStyle(layer)
iface.messageBar().popWidget()
_resetCurrentMessageBarLayer()
updateButton.pressed.connect(updateStyle)
widget.layout().addWidget(updateButton)
stopTrackingButton = QtWidgets.QPushButton(widget)
stopTrackingButton.setText("Stop tracking this layer")
def stopTracking():
removeTrackedLayer(layer)
iface.messageBar().popWidget()
_resetCurrentMessageBarLayer()
stopTrackingButton.pressed.connect(stopTracking)
widget.layout().addWidget(stopTrackingButton)
iface.messageBar().pushWidget(widget, Qgis.Info)
iface.messageBar().currentItem().geoserverLayer = layer
示例4: loadConfiguration
def loadConfiguration(self):
''' Function to load last conf get from settings
'''
if not self.project:
return
# from th eproject, get JSON filename to load
currentVehicleClassesJson = self.project.value('/FleetComposition/fleetComposition', self.gui.defaultVehicleClassesFileName)
# check if json is relative path or absolute
if not os.path.isabs(currentVehicleClassesJson):
currentVehicleClassesJson = os.path.join(self.projectPath, currentVehicleClassesJson)
# load json conf
try:
with open(currentVehicleClassesJson) as confFile:
# loaded in and OrderedDict to allow maintaining the order of classes
# contained in the json file. This will be reflected in the order
# shown in the sunburst visualization/editor
self.vehicleClassesDict = json.load(confFile, object_pairs_hook=collections.OrderedDict)
self.configurationLoaded.emit(True)
except Exception as ex:
self.vehicleClassesDict = None
QgsMessageLog.logMessage(traceback.format_exc(), 'QTraffic', QgsMessageLog.CRITICAL)
iface.messageBar().pushMessage(self.tr("Error loading Conf JSON file. Please check the log"), QgsMessageBar.CRITICAL)
return
示例5: exportVectorLayer
def exportVectorLayer(layer):
'''accepts a QgsVectorLayer or a string with a filepath'''
settings = QtCore.QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" )
if isinstance(layer, QgsMapLayer):
filename = unicode(layer.source())
destFilename = unicode(layer.name())
else:
filename = unicode(layer)
destFilename = unicode(os.path.splitext(os.path.basename(filename))[0])
if (not filename.lower().endswith("shp")):
if not isinstance(layer, QgsMapLayer):
layer = QgsVectorLayer(filename, "layer", "ogr")
if not layer.isValid() or layer.type() != QgsMapLayer.VectorLayer:
raise Exception ("Error reading file {} or it is not a valid vector layer file".format(filename))
output = utils.tempFilenameInTempFolder(destFilename + ".shp")
provider = layer.dataProvider()
writer = QgsVectorFileWriter(output, systemEncoding, layer.pendingFields(), provider.geometryType(), layer.crs() )
for feat in layer.getFeatures():
writer.addFeature(feat)
del writer
iface.messageBar().pushMessage("Warning", "Layer had to be exported to shapefile for importing. Data might be lost.",
level = QgsMessageBar.WARNING,
duration = 5)
return output
else:
return filename
示例6: prepareAlgorithm
def prepareAlgorithm(self, alg):
algInstance = alg.algorithm
for param in algInstance.parameters:
if not param.hidden:
if param.name in alg.params:
value = self.resolveValue(alg.params[param.name], param)
else:
if iface is not None:
iface.messageBar().pushMessage(self.tr("Warning"),
self.tr("Parameter %s in algorithm %s in the model is run with default value! Edit the model to make sure that this is correct.") % (param.name, alg.name),
QgsMessageBar.WARNING, 4)
value = param.default
# We allow unexistent filepaths, since that allows
# algorithms to skip some conversion routines
if not param.setValue(value) and not isinstance(param,
ParameterDataObject):
raise GeoAlgorithmExecutionException(
self.tr('Wrong value %s for %s %s', 'ModelerAlgorithm')
% (value, param.__class__.__name__, param.name))
for out in algInstance.outputs:
if not out.hidden:
if out.name in alg.outputs:
name = self.getSafeNameForOutput(alg.name, out.name)
modelOut = self.getOutputFromName(name)
if modelOut:
out.value = modelOut.value
else:
out.value = None
return algInstance
示例7: useLayerExtent
def useLayerExtent(self):
CANVAS_KEY = "Use canvas extent"
extentsDict = {}
extentsDict[CANVAS_KEY] = {
"extent": iface.mapCanvas().extent(),
"authid": iface.mapCanvas().mapSettings().destinationCrs().authid(),
}
extents = [CANVAS_KEY]
layers = dataobjects.getAllLayers()
for layer in layers:
authid = layer.crs().authid()
if ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF) and authid is not None:
layerName = u"{} [{}]".format(layer.name(), authid)
else:
layerName = layer.name()
extents.append(layerName)
extentsDict[layerName] = {"extent": layer.extent(), "authid": authid}
(item, ok) = QInputDialog.getItem(self, self.tr("Select extent"), self.tr("Use extent from"), extents, False)
if ok:
self.setValueFromRect(extentsDict[item]["extent"])
if extentsDict[item]["authid"] != iface.mapCanvas().mapSettings().destinationCrs().authid():
iface.messageBar().pushMessage(
self.tr("Warning"),
self.tr(
"The projection of the chosen layer is not the same as canvas projection! The selected extent might not be what was intended."
),
QgsMessageBar.WARNING,
8,
)
示例8: get_layers
def get_layers(self, resource=None):
"""Prefix the layer name with ws name"""
lyrs = super().get_layers(resource)
# Start patch:
layers = {}
result = []
for l in lyrs:
try:
layers[l.name].append(l)
except KeyError:
layers[l.name] = [l]
# Prefix all names
noAscii = False
for name, ls in list(layers.items()):
try:
if len(ls) == 1:
l = ls[0]
l.name = self.get_namespaced_name(l.name)
result.append(l)
else:
i = 0
res = self._get_res(ls[0].name)
for l in ls:
l.name = "%s:%s" % (res[i].workspace.name, l.name)
i += 1
result.append(l)
except UnicodeDecodeError:
noAscii = True
if noAscii:
iface.messageBar().pushMessage("Warning", "Some layers contain non-ascii characters and could not be loaded",
level = QgsMessageBar.WARNING,
duration = 10)
return result
示例9: prepareAlgorithm
def prepareAlgorithm(self, alg):
algInstance = alg.algorithm
for param in algInstance.parameterDefinitions():
if not param.flags() & QgsProcessingParameterDefinition.FlagHidden:
if param.name() in alg.params:
value = self.resolveValue(alg.params[param.name()], param)
else:
if iface is not None:
iface.messageBar().pushMessage(self.tr("Warning"),
self.tr("Parameter {0} in algorithm {1} in the model is run with default value! Edit the model to make sure that this is correct.").format(param.name(), alg.displayName()),
QgsMessageBar.WARNING, 4)
value = param.defaultValue()
# We allow unexistent filepaths, since that allows
# algorithms to skip some conversion routines
# TODO
#if not param.checkValueIsAcceptable(value) and not isinstance(param,
# ParameterDataObject):
# raise GeoAlgorithmExecutionException(
# self.tr('Wrong value {0} for {1} {2}', 'ModelerAlgorithm').format(
# value, param.__class__.__name__, param.name()
# )
# )
for out in algInstance.outputs:
if not out.flags() & QgsProcessingParameterDefinition.FlagHidden:
if out.name() in alg.outputs:
name = self.getSafeNameForOutput(alg.modeler_name, out.name())
modelOut = self.getOutputFromName(name)
if modelOut:
out.value = modelOut.value
else:
out.value = None
return algInstance
示例10: OeQ_pop_status
def OeQ_pop_status():
global OeQ_StatusWidget
if bool(OeQ_StatusWidget):
try:
iface.messageBar().popWidget(OeQ_StatusWidget)
except:
pass
示例11: prepareAlgorithm
def prepareAlgorithm(self, alg):
algInstance = alg.algorithm()
for param in algInstance.parameterDefinitions():
if not param.flags() & QgsProcessingParameterDefinition.FlagHidden:
if param.name() in alg.params:
value = self.resolveValue(alg.params[param.name()], param)
else:
if iface is not None:
iface.messageBar().pushMessage(self.tr("Warning"),
self.tr("Parameter {0} in algorithm {1} in the model is run with default value! Edit the model to make sure that this is correct.").format(param.name(), alg.displayName()),
QgsMessageBar.WARNING, 4)
value = param.defaultValue()
# note to self - these are parameters, not outputs
for out in algInstance.outputDefinitions():
if not out.flags() & QgsProcessingParameterDefinition.FlagHidden:
if out.name() in alg.outputs:
name = self.getSafeNameForOutput(alg.childId(), out.name())
modelOut = self.getOutputFromName(name)
if modelOut:
out.value = modelOut.value
else:
out.value = None
return algInstance
示例12: mergeInto
def mergeInto(self, mergeInto, branch):
conflicts = self.repo.merge(branch, mergeInto)
if conflicts:
ret = QMessageBox.warning(iface.mainWindow(), "Conflict(s) found while syncing",
"There are conflicts between local and remote changes.\n"
"Do you want to continue and fix them?",
QMessageBox.Yes | QMessageBox.No)
if ret == QMessageBox.No:
self.repo.closeTransaction(conflicts[0].transactionId)
return
dlg = ConflictDialog(conflicts)
dlg.exec_()
solved, resolvedConflicts = dlg.solved, dlg.resolvedConflicts
if not solved:
self.repo.closeTransaction(conflicts[0].transactionId)
return
for conflict, resolution in zip(conflicts, list(resolvedConflicts.values())):
if resolution == ConflictDialog.LOCAL:
conflict.resolveWithLocalVersion()
elif resolution == ConflictDialog.REMOTE:
conflict.resolveWithRemoteVersion()
elif resolution == ConflictDialog.DELETE:
conflict.resolveDeletingFeature()
else:
conflict.resolveWithNewFeature(resolution)
user, email = config.getUserInfo()
if user is None:
return
self.repo.commitAndCloseMergeAndTransaction(user, email, "Resolved merge conflicts", conflicts[0].transactionId)
iface.messageBar().pushMessage("GeoGig", "Branch has been correctly merged",
level=QgsMessageBar.INFO, duration=5)
repoWatcher.repoChanged.emit(self.repo)
示例13: updateStyle
def updateStyle():
url = getTrackingInfo(layer)
catalog = Catalog(url)
wrapper = CatalogWrapper(catalog)
wrapper.publishStyle(layer)
iface.messageBar().popWidget()
_resetCurrentMessageBarLayer()
示例14: display_information_message_bar
def display_information_message_bar(
title=None, message=None, more_details=None,
button_text=tr('Show details ...'), duration=8):
"""
Display an information message bar.
:param title: The title of the message bar.
:type title: str
:param message: The message inside the message bar.
:type message: str
:param more_details: The message inside the 'Show details' button.
:type more_details: str
:param button_text: The text of the button if 'more_details' is not empty.
:type button_text: str
:param duration: The duration for the display, default is 8 seconds.
:type duration: int
"""
widget = iface.messageBar().createMessage(title, message)
if more_details:
button = QPushButton(widget)
button.setText(button_text)
button.pressed.connect(
lambda: display_information_message_box(
title=title, message=more_details))
widget.layout().addWidget(button)
iface.messageBar().pushWidget(widget, QgsMessageBar.INFO, duration)
示例15: run
def run(self):
print "into thread"
print self.lyr
wkr = Import(self.lyr)
self.msg_bar_item = QgsMessageBarItem("", "Import des entités", self.progress_bar)
iface.messageBar().pushItem(self.msg_bar_item)
wkr.progress.connect(self.update_progress_bar)
wkr.run()