本文整理汇总了Python中qgis.PyQt.QtWidgets.QDialog.setLayout方法的典型用法代码示例。如果您正苦于以下问题:Python QDialog.setLayout方法的具体用法?Python QDialog.setLayout怎么用?Python QDialog.setLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.QtWidgets.QDialog
的用法示例。
在下文中一共展示了QDialog.setLayout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: widget_dialog
# 需要导入模块: from qgis.PyQt.QtWidgets import QDialog [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QDialog import setLayout [as 别名]
def widget_dialog(self, widget):
dlg = QDialog()
widget.setParent(dlg)
layout = QVBoxLayout()
layout.addWidget(widget)
layout.setMargin(6)
button_box = QDialogButtonBox(QDialogButtonBox.Close)
button_box.rejected.connect(dlg.close)
layout.addWidget(button_box)
dlg.setLayout(layout)
return dlg
示例2: editAuthCfgId
# 需要导入模块: from qgis.PyQt.QtWidgets import QDialog [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QDialog import setLayout [as 别名]
def editAuthCfgId(self):
dlg = QDialog(self)
dlg.setWindowModality(Qt.WindowModal)
layout = QVBoxLayout()
selector = QgsAuthConfigSelect(self)
if self.editAuthCfg.text():
selector.setConfigId(self.editAuthCfg.text())
layout.addWidget(selector)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close)
buttonBox.accepted.connect(dlg.accept)
buttonBox.rejected.connect(dlg.reject)
layout.addWidget(buttonBox)
dlg.setLayout(layout)
if dlg.exec_():
self.editAuthCfg.setText(selector.configId())
del dlg
示例3: on_copy
# 需要导入模块: from qgis.PyQt.QtWidgets import QDialog [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QDialog import setLayout [as 别名]
def on_copy(self):
select_group_dialog = QDialog(self)
select_group_dialog.resize(300, 400)
select_group_dialog.setWindowTitle(self.tr("Choose source group"))
layout = QVBoxLayout(select_group_dialog)
select_group_dialog.setLayout(layout)
groups_list_view = QTableView(self)
layout.addWidget(groups_list_view)
groups_list_view.setModel(self.ds_model)
groups_list_view.setColumnHidden(DSManagerModel.COLUMN_VISIBILITY, True)
groups_list_view.setSelectionMode(QTableView.NoSelection)
groups_list_view.setAlternatingRowColors(True)
groups_list_view.setShowGrid(False)
if hasattr(groups_list_view.horizontalHeader(), "setResizeMode"):
# Qt4
groups_list_view.horizontalHeader().setResizeMode(DSManagerModel.COLUMN_GROUP_DS, QHeaderView.Stretch)
groups_list_view.verticalHeader().setResizeMode(QHeaderView.ResizeToContents)
else:
# Qt5
groups_list_view.horizontalHeader().setSectionResizeMode(DSManagerModel.COLUMN_GROUP_DS, QHeaderView.Stretch)
groups_list_view.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
groups_list_view.verticalHeader().hide()
groups_list_view.clicked.connect(
lambda index: select_group_dialog.accept() \
if self.ds_model.isGroup(index) and \
index.column() == DSManagerModel.COLUMN_GROUP_DS \
else None
)
if select_group_dialog.exec_() == QDialog.Accepted:
group_info = self.ds_model.data(groups_list_view.currentIndex(), Qt.UserRole)
group_info.id += "_copy"
edit_dialog = GroupEditDialog()
edit_dialog.setWindowTitle(self.tr('Create group from existing'))
edit_dialog.fill_group_info(group_info)
if edit_dialog.exec_() == QDialog.Accepted:
self.feel_list()
self.ds_model.resetModel()
示例4: on_copy
# 需要导入模块: from qgis.PyQt.QtWidgets import QDialog [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QDialog import setLayout [as 别名]
def on_copy(self):
self.ds_model.sort(DSManagerModel.COLUMN_GROUP_DS)
select_data_sources_dialog = QDialog(self)
select_data_sources_dialog.resize(400, 400)
select_data_sources_dialog.setWindowTitle(self.tr("Choose source service"))
layout = QVBoxLayout(select_data_sources_dialog)
select_data_sources_dialog.setLayout(layout)
list_view = QTreeView(self)
layout.addWidget(list_view)
list_view.setModel(self.ds_model)
#list_view.expandAll()
list_view.setColumnHidden(DSManagerModel.COLUMN_VISIBILITY, True)
list_view.setAlternatingRowColors(True)
if hasattr(list_view.header(), "setResizeMode"):
# Qt4
list_view.header().setResizeMode(DSManagerModel.COLUMN_GROUP_DS, QHeaderView.ResizeToContents)
else:
# Qt5
list_view.header().setSectionResizeMode(DSManagerModel.COLUMN_GROUP_DS, QHeaderView.ResizeToContents)
list_view.clicked.connect(
lambda index: select_data_sources_dialog.accept() \
if not self.ds_model.isGroup(index) and \
index.column() == DSManagerModel.COLUMN_GROUP_DS \
else None
)
if select_data_sources_dialog.exec_() == QDialog.Accepted:
data_source = self.ds_model.data(list_view.currentIndex(), Qt.UserRole)
data_source.id += "_copy"
edit_dialog = DsEditDialog()
edit_dialog.setWindowTitle(self.tr('Create service from existing'))
edit_dialog.fill_ds_info(data_source)
if edit_dialog.exec_() == QDialog.Accepted:
self.feel_list()
self.ds_model.resetModel()
示例5: installFromZipFile
# 需要导入模块: from qgis.PyQt.QtWidgets import QDialog [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QDialog import setLayout [as 别名]
def installFromZipFile(self, filePath):
if not os.path.isfile(filePath):
return
settings = QgsSettings()
settings.setValue(settingsGroup + '/lastZipDirectory',
QFileInfo(filePath).absoluteDir().absolutePath())
with zipfile.ZipFile(filePath, 'r') as zf:
pluginName = os.path.split(zf.namelist()[0])[0]
pluginFileName = os.path.splitext(os.path.basename(filePath))[0]
pluginsDirectory = qgis.utils.home_plugin_path
if not QDir(pluginsDirectory).exists():
QDir().mkpath(pluginsDirectory)
pluginDirectory = QDir.cleanPath(os.path.join(pluginsDirectory, pluginName))
# If the target directory already exists as a link,
# remove the link without resolving
QFile(pluginDirectory).remove()
password = None
infoString = None
success = False
keepTrying = True
while keepTrying:
try:
# Test extraction. If fails, then exception will be raised and no removing occurs
unzip(filePath, pluginsDirectory, password)
# Removing old plugin files if exist
removeDir(pluginDirectory)
# Extract new files
unzip(filePath, pluginsDirectory, password)
keepTrying = False
success = True
except Exception as e:
success = False
if 'password' in str(e):
infoString = self.tr('Aborted by user')
if 'Bad password' in str(e):
msg = self.tr('Wrong password. Please enter a correct password to the zip file.')
else:
msg = self.tr('The zip file is encrypted. Please enter password.')
# Display a password dialog with QgsPasswordLineEdit
dlg = QDialog()
dlg.setWindowTitle(self.tr('Enter password'))
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal)
buttonBox.rejected.connect(dlg.reject)
buttonBox.accepted.connect(dlg.accept)
lePass = QgsPasswordLineEdit()
layout = QVBoxLayout()
layout.addWidget(QLabel(msg))
layout.addWidget(lePass)
layout.addWidget(buttonBox)
dlg.setLayout(layout)
keepTrying = dlg.exec_()
password = lePass.text()
else:
infoString = self.tr("Failed to unzip the plugin package\n{}.\nProbably it is broken".format(filePath))
keepTrying = False
if success:
updateAvailablePlugins()
loadPlugin(pluginName)
plugins.getAllInstalled()
plugins.rebuild()
self.exportPluginsToManager()
if settings.contains('/PythonPlugins/' + pluginName):
if settings.value('/PythonPlugins/' + pluginName, False, bool):
startPlugin(pluginName)
reloadPlugin(pluginName)
else:
unloadPlugin(pluginName)
loadPlugin(pluginName)
else:
if startPlugin(pluginName):
settings.setValue('/PythonPlugins/' + pluginName, True)
msg = "<b>%s</b>" % self.tr("Plugin installed successfully")
else:
msg = "<b>%s:</b> %s" % (self.tr("Plugin installation failed"), infoString)
level = Qgis.Info if success else Qgis.Critical
iface.pluginManagerInterface().pushMessage(msg, level)
示例6: upload_data
# 需要导入模块: from qgis.PyQt.QtWidgets import QDialog [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QDialog import setLayout [as 别名]
def upload_data(self):
if self.check_login():
if self.local_data_sources.count() == 0:
return
if self.db_connections.count() == 0:
QMessageBox.warning(self, self.tr("No database available"), self.tr("Please create a database in the 'Account' tab."))
return
if not self.ui.cbUploadDatabase.currentIndex() >= 0:
QMessageBox.warning(self, self.tr("No database selected"), self.tr("Please select a database to upload data."))
return
db_name = self.ui.cbUploadDatabase.currentText()
if not self.db_connections.isPortOpen(db_name):
uri = self.db_connections.cloud_layer_uri(db_name, "", "")
host = str(uri.host())
port = uri.port()
QMessageBox.critical(self, self.tr("Network Error"),
self.tr("Could not connect to database server ({0}) on port {1}. Please contact your system administrator or internet provider to open port {1} in the firewall".format(host, port)))
return
# disable update of local data sources during upload, as there are
# temporary layers added and removed
self.do_update_local_data_sources = False
self.statusBar().showMessage(self.tr("Uploading data..."))
self.setCursor(Qt.WaitCursor)
self.ui.btnUploadData.hide()
self.ui.spinner.start()
self.ui.progressWidget.show()
# Map<data_source, {schema: schema, table: table, layers: layers}>
data_sources_items = {}
for row in range(0, self.ui.tblLocalLayers.rowCount()):
data_source = unicode(
self.ui.tblLocalLayers.item(
row, self.COLUMN_DATA_SOURCE).text())
layers = self.local_data_sources.layers(data_source)
if layers is not None:
schema_name = unicode(
self.ui.tblLocalLayers.cellWidget(
row, self.COLUMN_SCHEMA_NAME).currentText())
table_name = unicode(
self.ui.tblLocalLayers.item(
row, self.COLUMN_TABLE_NAME).text())
data_sources_items[data_source] = {
u'schema': unicode(schema_name), u'table': unicode(table_name), u'layers': layers}
login_info = self.api.check_login(version_info=self._version_info())
try:
self.maxSize = login_info['max_storage']
self.maxDBs = login_info['max_dbs']
except:
self.maxSize = 50
self.maxDBs = 5
try:
self.data_upload.upload(self.db_connections.db(unicode(db_name)), data_sources_items, unicode(self.maxSize))
upload_ok = True
except Exception as e:
ErrorReportDialog(self.tr("Upload errors occurred"), self.tr("Upload errors occurred. Not all data could be uploaded."), str(e) + "\n" + traceback.format_exc(), self.user, self).exec_()
upload_ok = False
self.ui.spinner.stop()
self.ui.progressWidget.hide()
self.ui.btnUploadData.show()
self.unsetCursor()
self.statusBar().showMessage("")
# Refresh local layers
self.do_update_local_data_sources = True
self.update_local_layers()
# Refresh used space after upload
self.db_size(self.db_connections)
if upload_ok:
# Show save project dialog
save_dialog = QDialog(self)
save_dialog.setWindowTitle(self.tr("Save Project"))
save_dialog.setLayout(QVBoxLayout())
header = QWidget()
header.setLayout(QVBoxLayout())
label = QLabel(self.tr("Upload complete. The local layers in the project were replaced with the layers uploaded to the qgiscloud database."))
label.setWordWrap(True)
header.layout().addWidget(label)
label = QLabel(self.tr("Choose were to save the modified project:"))
label.setWordWrap(True)
header.layout().addWidget(label)
save_dialog.layout().setContentsMargins(0, 0, 0, 0)
save_dialog.layout().addWidget(header)
initialPath = QgsProject.instance().fileName()
if not initialPath:
initialPath = QSettings().value("/UI/lastProjectDir", ".")
fd = QFileDialog(None, self.tr("Save Project"), initialPath, "%s (*.qgz *.qgs)" % self.tr("QGIS Project Files"))
fd.setParent(save_dialog, Qt.Widget)
fd.setOption(QFileDialog.DontUseNativeDialog)
fd.setAcceptMode(QFileDialog.AcceptSave)
save_dialog.layout().addWidget(fd)
header.layout().setContentsMargins(fd.layout().contentsMargins())
fd.accepted.connect(save_dialog.accept)
#.........这里部分代码省略.........