本文整理汇总了Python中qgis.PyQt.QtWidgets.QTabWidget类的典型用法代码示例。如果您正苦于以下问题:Python QTabWidget类的具体用法?Python QTabWidget怎么用?Python QTabWidget使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTabWidget类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initGui
def initGui(self):
layout = QVBoxLayout()
self.tab = QTabWidget()
self.table = QTableView()
self.setLayout(layout)
self.canvas = QgsMapCanvas()
self.canvas.setCanvasColor(Qt.white)
settings = QSettings()
self.canvas.enableAntiAliasing(settings.value("/qgis/enable_anti_aliasing", False, type = bool))
self.canvas.useImageToRender(settings.value("/qgis/use_qimage_to_render", False, type = bool))
self.canvas.mapSettings().setDestinationCrs(self.crs)
action = settings.value("/qgis/wheel_action", 0, type = float)
zoomFactor = settings.value("/qgis/zoom_factor", 2, type = float)
self.canvas.setWheelAction(QgsMapCanvas.WheelAction(action), zoomFactor)
self.panTool = QgsMapToolPan(self.canvas)
self.canvas.setMapTool(self.panTool)
execute(self.createLayers)
model = GeomDiffTableModel(self.data)
self.table.setModel(model)
self.table.resizeColumnsToContents()
self.table.resizeRowsToContents()
self.tab.addTab(self.canvas, "Map view")
self.tab.addTab(self.table, "Table view")
layout.addWidget(self.tab)
self.resize(600, 500)
self.setWindowTitle("Geometry comparison")
示例2: DBManager
#.........这里部分代码省略.........
# hide the placeholder if there're no other registered actions
if len(self._registeredDbActions[menuName]) <= 0:
for i in range(len(menuActions)):
if menuActions[i].isSeparator() and menuActions[i].objectName().endswith("_placeholder"):
menuActions[i].setVisible(False)
break
action.deleteLater()
return True
return False
def unregisterAllActions(self):
if not hasattr(self, '_registeredDbActions'):
return
for menuName in self._registeredDbActions:
for action in list(self._registeredDbActions[menuName]):
self.unregisterAction(action, menuName)
del self._registeredDbActions
def close_tab(self, index):
widget = self.tabs.widget(index)
if widget not in [self.info, self.table, self.preview]:
self.tabs.removeTab(index)
widget.deleteLater()
def setupUi(self):
self.setWindowTitle(self.tr("DB Manager"))
self.setWindowIcon(QIcon(":/db_manager/icon"))
self.resize(QSize(700, 500).expandedTo(self.minimumSizeHint()))
# create central tab widget and add the first 3 tabs: info, table and preview
self.tabs = QTabWidget()
self.info = InfoViewer(self)
self.tabs.addTab(self.info, self.tr("Info"))
self.table = TableViewer(self)
self.tabs.addTab(self.table, self.tr("Table"))
self.preview = LayerPreview(self)
self.tabs.addTab(self.preview, self.tr("Preview"))
self.setCentralWidget(self.tabs)
# display close button for all tabs but the first 3 ones, i.e.
# HACK: just hide the close button where not needed (GS)
self.tabs.setTabsClosable(True)
self.tabs.tabCloseRequested.connect(self.close_tab)
tabbar = self.tabs.tabBar()
for i in range(3):
btn = tabbar.tabButton(i, QTabBar.RightSide) if tabbar.tabButton(i, QTabBar.RightSide) else tabbar.tabButton(i, QTabBar.LeftSide)
btn.resize(0, 0)
btn.hide()
# Creates layout for message bar
self.layout = QGridLayout(self.info)
self.layout.setContentsMargins(0, 0, 0, 0)
spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.layout.addItem(spacerItem, 1, 0, 1, 1)
# init messageBar instance
self.infoBar = QgsMessageBar(self.info)
sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self.infoBar.setSizePolicy(sizePolicy)
self.layout.addWidget(self.infoBar, 0, 0, 1, 1)
# create database tree
self.dock = QDockWidget("Tree", self)
self.dock.setObjectName("DB_Manager_DBView")
示例3: setupUi
def setupUi(self):
self.setWindowTitle(self.tr("DB Manager"))
self.setWindowIcon(QIcon(":/db_manager/icon"))
self.resize(QSize(700, 500).expandedTo(self.minimumSizeHint()))
# create central tab widget and add the first 3 tabs: info, table and preview
self.tabs = QTabWidget()
self.info = InfoViewer(self)
self.tabs.addTab(self.info, self.tr("Info"))
self.table = TableViewer(self)
self.tabs.addTab(self.table, self.tr("Table"))
self.preview = LayerPreview(self)
self.tabs.addTab(self.preview, self.tr("Preview"))
self.setCentralWidget(self.tabs)
# display close button for all tabs but the first 3 ones, i.e.
# HACK: just hide the close button where not needed (GS)
self.tabs.setTabsClosable(True)
self.tabs.tabCloseRequested.connect(self.close_tab)
tabbar = self.tabs.tabBar()
for i in range(3):
btn = tabbar.tabButton(i, QTabBar.RightSide) if tabbar.tabButton(i, QTabBar.RightSide) else tabbar.tabButton(i, QTabBar.LeftSide)
btn.resize(0, 0)
btn.hide()
# Creates layout for message bar
self.layout = QGridLayout(self.info)
self.layout.setContentsMargins(0, 0, 0, 0)
spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.layout.addItem(spacerItem, 1, 0, 1, 1)
# init messageBar instance
self.infoBar = QgsMessageBar(self.info)
sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self.infoBar.setSizePolicy(sizePolicy)
self.layout.addWidget(self.infoBar, 0, 0, 1, 1)
# create database tree
self.dock = QDockWidget("Tree", self)
self.dock.setObjectName("DB_Manager_DBView")
self.dock.setFeatures(QDockWidget.DockWidgetMovable)
self.tree = DBTree(self)
self.dock.setWidget(self.tree)
self.addDockWidget(Qt.LeftDockWidgetArea, self.dock)
# create status bar
self.statusBar = QStatusBar(self)
self.setStatusBar(self.statusBar)
# create menus
self.menuBar = QMenuBar(self)
self.menuDb = QMenu(self.tr("&Database"), self)
self.menuBar.addMenu(self.menuDb)
self.menuSchema = QMenu(self.tr("&Schema"), self)
actionMenuSchema = self.menuBar.addMenu(self.menuSchema)
self.menuTable = QMenu(self.tr("&Table"), self)
actionMenuTable = self.menuBar.addMenu(self.menuTable)
self.menuHelp = None # QMenu(self.tr("&Help"), self)
# actionMenuHelp = self.menuBar.addMenu(self.menuHelp)
self.setMenuBar(self.menuBar)
# create toolbar
self.toolBar = QToolBar("Default", self)
self.toolBar.setObjectName("DB_Manager_ToolBar")
self.addToolBar(self.toolBar)
# create menus' actions
# menu DATABASE
sep = self.menuDb.addSeparator()
sep.setObjectName("DB_Manager_DbMenu_placeholder")
sep.setVisible(False)
self.actionRefresh = self.menuDb.addAction(QIcon(":/db_manager/actions/refresh"), self.tr("&Refresh"),
self.refreshActionSlot, QKeySequence("F5"))
self.actionSqlWindow = self.menuDb.addAction(QIcon(":/db_manager/actions/sql_window"), self.tr("&SQL window"),
self.runSqlWindow, QKeySequence("F2"))
self.menuDb.addSeparator()
self.actionClose = self.menuDb.addAction(QIcon(), self.tr("&Exit"), self.close, QKeySequence("CTRL+Q"))
# menu SCHEMA
sep = self.menuSchema.addSeparator()
sep.setObjectName("DB_Manager_SchemaMenu_placeholder")
sep.setVisible(False)
actionMenuSchema.setVisible(False)
# menu TABLE
sep = self.menuTable.addSeparator()
sep.setObjectName("DB_Manager_TableMenu_placeholder")
sep.setVisible(False)
self.actionImport = self.menuTable.addAction(QIcon(":/db_manager/actions/import"),
self.tr("&Import layer/file"), self.importActionSlot)
self.actionExport = self.menuTable.addAction(QIcon(":/db_manager/actions/export"), self.tr("&Export to file"),
self.exportActionSlot)
self.menuTable.addSeparator()
#self.actionShowSystemTables = self.menuTable.addAction(self.tr("Show system tables/views"), self.showSystemTables)
#self.actionShowSystemTables.setCheckable(True)
#self.actionShowSystemTables.setChecked(True)
#.........这里部分代码省略.........
示例4: setupUi
def setupUi(self):
self.labels = {}
self.widgets = {}
self.checkBoxes = {}
self.showAdvanced = False
self.valueItems = {}
self.dependentItems = {}
self.resize(650, 450)
self.buttonBox = QDialogButtonBox()
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
| QDialogButtonBox.Ok)
tooltips = self._alg.getParameterDescriptions()
self.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding)
self.verticalLayout = QVBoxLayout()
self.verticalLayout.setSpacing(5)
self.verticalLayout.setMargin(20)
hLayout = QHBoxLayout()
hLayout.setSpacing(5)
hLayout.setMargin(0)
descriptionLabel = QLabel(self.tr("Description"))
self.descriptionBox = QLineEdit()
self.descriptionBox.setText(self._alg.name)
hLayout.addWidget(descriptionLabel)
hLayout.addWidget(self.descriptionBox)
self.verticalLayout.addLayout(hLayout)
line = QFrame()
line.setFrameShape(QFrame.HLine)
line.setFrameShadow(QFrame.Sunken)
self.verticalLayout.addWidget(line)
for param in self._alg.parameters:
if param.isAdvanced:
self.advancedButton = QPushButton()
self.advancedButton.setText(self.tr('Show advanced parameters'))
self.advancedButton.clicked.connect(
self.showAdvancedParametersClicked)
advancedButtonHLayout = QHBoxLayout()
advancedButtonHLayout.addWidget(self.advancedButton)
advancedButtonHLayout.addStretch()
self.verticalLayout.addLayout(advancedButtonHLayout)
break
for param in self._alg.parameters:
if param.hidden:
continue
desc = param.description
if isinstance(param, ParameterExtent):
desc += self.tr('(xmin, xmax, ymin, ymax)')
if isinstance(param, ParameterPoint):
desc += self.tr('(x, y)')
label = QLabel(desc)
self.labels[param.name] = label
widget = self.getWidgetFromParameter(param)
self.valueItems[param.name] = widget
if param.name in tooltips.keys():
tooltip = tooltips[param.name]
else:
tooltip = param.description
label.setToolTip(tooltip)
widget.setToolTip(tooltip)
if param.isAdvanced:
label.setVisible(self.showAdvanced)
widget.setVisible(self.showAdvanced)
self.widgets[param.name] = widget
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(widget)
for output in self._alg.outputs:
if output.hidden:
continue
if isinstance(output, (OutputRaster, OutputVector, OutputTable,
OutputHTML, OutputFile, OutputDirectory)):
label = QLabel(output.description + '<'
+ output.__class__.__name__ + '>')
item = QLineEdit()
if hasattr(item, 'setPlaceholderText'):
item.setPlaceholderText(ModelerParametersDialog.ENTER_NAME)
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(item)
self.valueItems[output.name] = item
label = QLabel(' ')
self.verticalLayout.addWidget(label)
label = QLabel(self.tr('Parent algorithms'))
self.dependenciesPanel = self.getDependenciesPanel()
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(self.dependenciesPanel)
self.verticalLayout.addStretch(1000)
self.setLayout(self.verticalLayout)
self.setPreviousValues()
self.setWindowTitle(self._alg.name)
self.verticalLayout2 = QVBoxLayout()
self.verticalLayout2.setSpacing(2)
self.verticalLayout2.setMargin(0)
self.tabWidget = QTabWidget()
self.tabWidget.setMinimumWidth(300)
#.........这里部分代码省略.........
示例5: ModelerParametersDialog
#.........这里部分代码省略.........
self.widgets[param.name] = widget
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(widget)
for output in self._alg.outputs:
if output.hidden:
continue
if isinstance(output, (OutputRaster, OutputVector, OutputTable,
OutputHTML, OutputFile, OutputDirectory)):
label = QLabel(output.description + '<'
+ output.__class__.__name__ + '>')
item = QLineEdit()
if hasattr(item, 'setPlaceholderText'):
item.setPlaceholderText(ModelerParametersDialog.ENTER_NAME)
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(item)
self.valueItems[output.name] = item
label = QLabel(' ')
self.verticalLayout.addWidget(label)
label = QLabel(self.tr('Parent algorithms'))
self.dependenciesPanel = self.getDependenciesPanel()
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(self.dependenciesPanel)
self.verticalLayout.addStretch(1000)
self.setLayout(self.verticalLayout)
self.setPreviousValues()
self.setWindowTitle(self._alg.name)
self.verticalLayout2 = QVBoxLayout()
self.verticalLayout2.setSpacing(2)
self.verticalLayout2.setMargin(0)
self.tabWidget = QTabWidget()
self.tabWidget.setMinimumWidth(300)
self.paramPanel = QWidget()
self.paramPanel.setLayout(self.verticalLayout)
self.scrollArea = QScrollArea()
self.scrollArea.setWidget(self.paramPanel)
self.scrollArea.setWidgetResizable(True)
self.tabWidget.addTab(self.scrollArea, self.tr('Parameters'))
self.webView = QWebView()
html = None
url = None
isText, help = self._alg.help()
if help is not None:
if isText:
html = help
else:
url = QUrl(help)
else:
html = self.tr('<h2>Sorry, no help is available for this '
'algorithm.</h2>')
try:
if html:
self.webView.setHtml(html)
elif url:
self.webView.load(url)
except:
self.webView.setHtml(self.tr('<h2>Could not open help file :-( </h2>'))
self.tabWidget.addTab(self.webView, 'Help')
self.verticalLayout2.addWidget(self.tabWidget)
self.verticalLayout2.addWidget(self.buttonBox)
self.setLayout(self.verticalLayout2)
self.buttonBox.accepted.connect(self.okPressed)
示例6: GeometryDiffViewerDialog
class GeometryDiffViewerDialog(QDialog):
def __init__(self, geoms, crs, parent = None):
super(GeometryDiffViewerDialog, self).__init__(parent)
self.geoms = geoms
self.crs = crs
self.initGui()
def initGui(self):
layout = QVBoxLayout()
self.tab = QTabWidget()
self.table = QTableView()
self.setLayout(layout)
self.canvas = QgsMapCanvas()
self.canvas.setCanvasColor(Qt.white)
settings = QSettings()
self.canvas.enableAntiAliasing(settings.value("/qgis/enable_anti_aliasing", False, type = bool))
self.canvas.useImageToRender(settings.value("/qgis/use_qimage_to_render", False, type = bool))
self.canvas.mapSettings().setDestinationCrs(self.crs)
action = settings.value("/qgis/wheel_action", 0, type = float)
zoomFactor = settings.value("/qgis/zoom_factor", 2, type = float)
self.canvas.setWheelAction(QgsMapCanvas.WheelAction(action), zoomFactor)
self.panTool = QgsMapToolPan(self.canvas)
self.canvas.setMapTool(self.panTool)
execute(self.createLayers)
model = GeomDiffTableModel(self.data)
self.table.setModel(model)
self.table.resizeColumnsToContents()
self.table.resizeRowsToContents()
self.tab.addTab(self.canvas, "Map view")
self.tab.addTab(self.table, "Table view")
layout.addWidget(self.tab)
self.resize(600, 500)
self.setWindowTitle("Geometry comparison")
def createLayers(self):
textGeometries = []
for geom in self.geoms:
text = geom.exportToWkt()
valid = " -1234567890.,"
text = "".join([c for c in text if c in valid])
textGeometries.append(text.split(","))
lines = difflib.Differ().compare(textGeometries[0], textGeometries[1])
self.data = []
for line in lines:
if line.startswith("+"):
self.data.append([None, line[2:]])
if line.startswith("-"):
self.data.append([line[2:], None])
if line.startswith(" "):
self.data.append([line[2:], line[2:]])
types = [("LineString", lineBeforeStyle, lineAfterStyle),
("Polygon", polygonBeforeStyle, polygonAfterStyle)]
layers = []
extent = self.geoms[0].boundingBox()
for i, geom in enumerate(self.geoms):
geomtype = types[int(geom.type() - 1)][0]
style = types[int(geom.type() - 1)][i + 1]
layer = loadLayerNoCrsDialog(geomtype + "?crs=" + self.crs.authid(), "layer", "memory")
pr = layer.dataProvider()
feat = QgsFeature()
feat.setGeometry(geom)
pr.addFeatures([feat])
layer.loadNamedStyle(style)
layer.updateExtents()
layers.append(layer)
QgsMapLayerRegistry.instance().addMapLayer(layer, False)
extent.combineExtentWith(geom.boundingBox())
layer = loadLayerNoCrsDialog("Point?crs=%s&field=changetype:string" % self.crs.authid(), "points", "memory")
pr = layer.dataProvider()
feats = []
for coords in self.data:
coord = coords[0] or coords[1]
feat = QgsFeature()
x, y = coord.strip().split(" ")
x, y = (float(x), float(y))
pt = QgsGeometry.fromPoint(QgsPoint(x, y))
feat.setGeometry(pt)
if coords[0] is None:
changetype = "A"
elif coords[1] is None:
changetype = "R"
else:
changetype = "U"
feat.setAttributes([changetype])
feats.append(feat)
pr.addFeatures(feats)
layer.loadNamedStyle(pointsStyle)
QgsMapLayerRegistry.instance().addMapLayer(layer, False)
layers.append(layer)
self.mapLayers = [QgsMapCanvasLayer(lay) for lay in layers]
self.canvas.setLayerSet(self.mapLayers)
#.........这里部分代码省略.........