本文整理汇总了Python中qgis.PyQt.QtWidgets.QApplication类的典型用法代码示例。如果您正苦于以下问题:Python QApplication类的具体用法?Python QApplication怎么用?Python QApplication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QApplication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: constraintsDetails
def constraintsDetails(self):
if not self.table.constraints():
return None
tbl = []
# define the table header
header = (QApplication.translate("DBManagerPlugin", "Name"),
QApplication.translate("DBManagerPlugin", "Type"),
QApplication.translate("DBManagerPlugin", "Column"),
QApplication.translate("DBManagerPlugin", "Status"),
QApplication.translate("DBManagerPlugin", "Validated"),
QApplication.translate("DBManagerPlugin", "Generated"),
QApplication.translate("DBManagerPlugin", "Check condition"),
QApplication.translate("DBManagerPlugin", "Foreign Table"),
QApplication.translate("DBManagerPlugin", "Foreign column"),
QApplication.translate("DBManagerPlugin", "On Delete"))
tbl.append(HtmlTableHeader(header))
# add table contents
for con in self.table.constraints():
tbl.append((con.name, con.type2String(), con.column,
con.status, con.validated, con.generated,
con.checkSource, con.foreignTable,
con.foreignKey, con.foreignOnDelete))
return HtmlTable(tbl, {"class": "header"})
示例2: main
def main():
"""Main function to run the example."""
app = QApplication([])
default_value_parameter = DefaultValueParameter()
default_value_parameter.name = 'Value parameter'
default_value_parameter.help_text = 'Help text'
default_value_parameter.description = 'Description'
default_value_parameter.labels = [
'Setting', 'Do not report', 'Custom']
default_value_parameter.options = [0, 1, None]
parameters = [
default_value_parameter
]
extra_parameters = [
(DefaultValueParameter, DefaultValueParameterWidget)
]
parameter_container = ParameterContainer(
parameters, extra_parameters=extra_parameters)
parameter_container.setup_ui()
widget = QWidget()
layout = QGridLayout()
layout.addWidget(parameter_container)
widget.setLayout(layout)
widget.setGeometry(0, 0, 500, 500)
widget.show()
sys.exit(app.exec_())
示例3: zip_db
def zip_db(self):
force_another_db = False
dbpath=None
if self.db:
use_current_db = utils.Askuser("YesNo",'Vill du göra backup av %s?'%self.db,'Which database?')
if use_current_db.result == 1:
dbpath = self.db
force_another_db = False
elif use_current_db.result == 0:
force_another_db = True
elif use_current_db.result == '':
return
if not self.db or force_another_db:
dbpath = QFileDialog.getOpenFileName(None, 'Ange db som du vill skapa backup utav','',"Spatialite (*.sqlite)")[0]
if dbpath:
QApplication.setOverrideCursor(Qt.WaitCursor)
connection = utils.dbconnection(dbpath)
connection.connect2db()
connection.conn.cursor().execute("begin immediate")
file_path = os.path.realpath(dbpath)
dir_path = os.path.dirname(file_path)
current_dir = dir_path.split(os.sep)[-1]
bkupname = dbpath + datetime.datetime.now().strftime('%Y%m%dT%H%M') + '.zip'
zf = zipfile.ZipFile(bkupname, mode='w')
zf.write(dbpath,os.path.basename(dbpath), compress_type=compression) #compression will depend on if zlib is found or not
zf.close()
connection.conn.rollback()
connection.closedb()
self.iface.messageBar().pushMessage("Information","Database backup was written to " + bkupname, 1,duration=15)
QApplication.restoreOverrideCursor()
示例4: finish
def finish(self, result, context, feedback):
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
if self.iterateParam is None:
# add html results to results dock
for out in self.alg.outputDefinitions():
if isinstance(out, QgsProcessingOutputHtml) and out.name() in result and result[out.name()]:
resultsList.addResult(icon=self.alg.icon(), name=out.description(),
result=result[out.name()])
if not handleAlgorithmResults(self.alg, context, feedback, not keepOpen):
self.resetGUI()
return
self.executed = True
self.setInfo(self.tr('Algorithm \'{0}\' finished').format(self.alg.displayName()), escape_html=False)
QApplication.restoreOverrideCursor()
if not keepOpen:
self.close()
else:
self.resetGUI()
if self.alg.hasHtmlOutputs():
self.setInfo(
self.tr('HTML output has been generated by this algorithm.'
'\nOpen the results dialog to check it.'), escape_html=False)
示例5: spatialInfo
def spatialInfo(self):
ret = []
info = self.db.connector.getSpatialInfo()
if not info:
return
tbl = [
(QApplication.translate("DBManagerPlugin", "Oracle\
Spatial:"),
info[0])
]
ret.append(HtmlTable(tbl))
if not self.db.connector.has_geometry_columns:
ret.append(
HtmlParagraph(
QApplication.translate(
"DBManagerPlugin",
(u"<warning> ALL_SDO_GEOM_METADATA"
u" view doesn't exist!\n"
u"This view is essential for many"
u"GIS applications for enumeration of tables."))))
return ret
示例6: connectionDetails
def connectionDetails(self):
tbl = [
(QApplication.translate("DBManagerPlugin", "Host:"), self.db.connector.host),
(QApplication.translate("DBManagerPlugin", "User:"), self.db.connector.user),
(QApplication.translate("DBManagerPlugin", "Database:"), self.db.connector.dbname)
]
return HtmlTable(tbl)
示例7: getSpatialInfo
def getSpatialInfo(self):
ret = []
info = self.db.connector.getSpatialInfo()
if info is None:
return
tbl = [
(QApplication.translate("DBManagerPlugin", "Library:"), info[0]),
(QApplication.translate("DBManagerPlugin", "Scripts:"), info[3]),
("GEOS:", info[1]),
("Proj:", info[2])
]
ret.append(HtmlTable(tbl))
if info[1] is not None and info[1] != info[2]:
ret.append(HtmlParagraph(QApplication.translate("DBManagerPlugin",
"<warning> Version of installed scripts doesn't match version of released scripts!\n"
"This is probably a result of incorrect PostGIS upgrade.")))
if not self.db.connector.has_geometry_columns:
ret.append(HtmlParagraph(
QApplication.translate("DBManagerPlugin", "<warning> geometry_columns table doesn't exist!\n"
"This table is essential for many GIS applications for enumeration of tables.")))
elif not self.db.connector.has_geometry_columns_access:
ret.append(HtmlParagraph(QApplication.translate("DBManagerPlugin",
"<warning> This user doesn't have privileges to read contents of geometry_columns table!\n"
"This table is essential for many GIS applications for enumeration of tables.")))
return ret
示例8: _opendb
def _opendb(self):
self.gdal_ds = None
if hasattr(gdal, 'OpenEx'):
# GDAL >= 2
self.gdal_ds = gdal.OpenEx(self.dbname, gdal.OF_UPDATE)
if self.gdal_ds is None:
self.gdal_ds = gdal.OpenEx(self.dbname)
if self.gdal_ds is None or self.gdal_ds.GetDriver().ShortName != 'GPKG':
raise ConnectionError(QApplication.translate("DBManagerPlugin", '"{0}" not found').format(self.dbname))
self.has_raster = self.gdal_ds.RasterCount != 0 or self.gdal_ds.GetMetadata('SUBDATASETS') is not None
self.connection = None
self.gdal2 = True
else:
# GDAL 1.X compat. To be removed at some point
self.gdal_ds = ogr.Open(self.dbname, update=1)
if self.gdal_ds is None:
self.gdal_ds = ogr.Open(self.dbname)
if self.gdal_ds is None or self.gdal_ds.GetDriver().GetName() != 'GPKG':
raise ConnectionError(QApplication.translate("DBManagerPlugin", '"{0}" not found').format(self.dbname))
# For GDAL 1.X, we cannot issue direct SQL SELECT to the OGR datasource
# so we need a direct sqlite connection
try:
self.connection = spatialite_connect(str(self.dbname))
except self.connection_error_types() as e:
raise ConnectionError(e)
self.gdal2 = False
示例9: 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)
示例10: runAction
def runAction(self, action):
action = unicode(action)
if action.startswith("vacuumanalyze/"):
if action == "vacuumanalyze/run":
self.runVacuumAnalyze()
return True
elif action.startswith("rule/"):
parts = action.split('/')
rule_name = parts[1]
rule_action = parts[2]
msg = u"Do you want to %s rule %s?" % (rule_action, rule_name)
QApplication.restoreOverrideCursor()
try:
if QMessageBox.question(None, self.tr("Table rule"), msg,
QMessageBox.Yes | QMessageBox.No) == QMessageBox.No:
return False
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
if rule_action == "delete":
self.aboutToChange.emit()
self.database().connector.deleteTableRule(rule_name, (self.schemaName(), self.name))
self.refreshRules()
return True
return Table.runAction(self, action)
示例11: addToLayout
def addToLayout(self):
mgr = QgsProject.instance().layoutManager()
layout = None
layouts = mgr.layouts()
if len(layouts) == 0:
QMessageBox.warning(self,
QApplication.translate("code", "Keine Layouts"),
QApplication.translate("code", "Zuerst ein Layout erstellen"))
return
elif len(layouts) == 1:
layout = layouts[0]
else:
d = VoGISProfilToolLayoutsDialog(self, layouts)
result = d.exec_()
if result == QDialog.Accepted:
layout = mgr.layoutByName(d.ui.cmbLayouts.currentText())
else:
return
u = Util(self.iface)
caption = QApplication.translate("code", "PNG Datei")
file_format = []
file_format.append(["PNG files", "png"])
fileName, fileExt = u.getFileName(caption, file_format, QgsProject.instance().homePath())
if fileName == "":
return
fInfo = QFileInfo(fileName)
self.filePath = fInfo.path()
figure = self.subplot.figure
figure.savefig(fileName, format="png")
image = QgsLayoutItemPicture(layout)
image.setPicturePath(fileName)
image.attemptResize(QgsLayoutSize(200, 200))
layout.addLayoutItem(image)
示例12: exportTxt
def exportTxt(self):
delimiter = self.__getDelimiter()
decimalDelimiter = self.__getDecimalDelimiter()
if delimiter == decimalDelimiter:
msg = QApplication.translate("code", "Gleiches Dezimal- und Spaltentrennzeichen gewählt!")
QMessageBox.warning(self.iface.mainWindow(), "VoGIS-Profiltool", msg)
return
u = Util(self.iface)
caption = QApplication.translate("code", "Textdatei exportieren")
fileName, file_ext = u.getFileName(caption, [["txt", "txt"]], self.filePath)
if fileName == "":
return
fInfo = QFileInfo(fileName)
self.filePath = fInfo.path()
QgsSettings().setValue("vogisprofiltoolmain/savepath", self.filePath)
hekto = (self.ui.IDC_chkHekto.checkState() == Qt.Checked)
attribs = (self.ui.IDC_chkLineAttributes.checkState() == Qt.Checked)
txt = open(fileName, "w")
txt.write(self.profiles[0].writeHeader(self.settings.mapData.rasters.selectedRasters(), hekto, attribs, delimiter))
for p in self.profiles:
#txt.write("=====Profil {0}======{1}".format(p.id, os.linesep))
#txt.write("Segments:{0}{1}".format(len(p.segments), os.linesep))
#for s in p.segments:
# txt.write("Vertices:{0}{1}".format(len(s.vertices), os.linesep))
txt.write(p.toString(hekto,
attribs,
delimiter,
decimalDelimiter
))
txt.close()
示例13: createGeomColumn
def createGeomColumn(self):
""" first check whether everything's fine """
if self.editName.text() == "":
QMessageBox.critical(self, self.tr("DB Manager"), self.tr("field name must not be empty"))
return
name = self.editName.text()
geom_type = self.GEOM_TYPES[self.cboType.currentIndex()]
dim = self.spinDim.value()
try:
srid = int(self.editSrid.text())
except ValueError:
srid = -1
createSpatialIndex = False
# now create the geometry column
QApplication.setOverrideCursor(Qt.WaitCursor)
try:
self.table.addGeometryColumn(name, geom_type, srid, dim, createSpatialIndex)
except DbError as e:
DlgDbError.showError(e, self)
return
finally:
QApplication.restoreOverrideCursor()
self.accept()
示例14: spatialInfo
def spatialInfo(self):
ret = []
if self.table.geomType is None:
return ret
tbl = [
(QApplication.translate("DBManagerPlugin", "Column:"), self.table.geomColumn),
(QApplication.translate("DBManagerPlugin", "Geometry:"), self.table.geomType)
]
# only if we have info from geometry_columns
srid = self.table.srid if self.table.srid is not None else -1
sr_info = self.table.database().connector.getSpatialRefInfo(srid) if srid != -1 else QApplication.translate(
"DBManagerPlugin", "Undefined")
if sr_info:
tbl.append((QApplication.translate("DBManagerPlugin", "Spatial ref:"), u"%s (%d)" % (sr_info, srid)))
# extent
if self.table.extent is not None and self.table.extent[0] is not None:
extent_str = '%.5f, %.5f - %.5f, %.5f' % self.table.extent
else:
extent_str = QApplication.translate("DBManagerPlugin",
'(unknown) (<a href="action:extent/get">find out</a>)')
tbl.append((QApplication.translate("DBManagerPlugin", "Extent:"), extent_str))
ret.append(HtmlTable(tbl))
return ret
示例15: setData
def setData(self, index, value, role):
if role != Qt.EditRole or index.column() != 0:
return False
item = index.internalPointer()
new_value = unicode(value)
if isinstance(item, SchemaItem) or isinstance(item, TableItem):
obj = item.getItemData()
# rename schema or table or view
if new_value == obj.name:
return False
QApplication.setOverrideCursor(Qt.WaitCursor)
try:
obj.rename(new_value)
self._onDataChanged(index)
except BaseError as e:
DlgDbError.showError(e, self.treeView)
return False
finally:
QApplication.restoreOverrideCursor()
return True
return False