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
def __init__(self, title, parent=None): QDialog.__init__(self, parent) self.setWindowTitle(title) layout = QVBoxLayout() self.selector = QgsProjectionSelector(self) buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close) layout.addWidget(self.selector) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.accept) buttonBox.rejected.connect(self.reject)
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
def setupUi(self): self.valueItems = {} self.dependentItems = {} self.resize(650, 450) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.infoText = QTextEdit() numbers = self.getAvailableValuesOfType(ParameterNumber, OutputNumber) text = self.tr( 'You can refer to model values in your formula, using ' 'single-letter variables, as follows:\n', 'CalculatorModelerParametersDialog') ichar = 97 if numbers: for number in numbers: text += chr(ichar) + '->' + self.resolveValueDescription( number) + '\n' ichar += 1 else: text += self.tr('\n - No numerical variables are available.', 'CalculatorModelerParametersDialog') self.infoText.setText(text) self.infoText.setEnabled(False) self.formulaText = QLineEdit() if hasattr(self.formulaText, 'setPlaceholderText'): self.formulaText.setPlaceholderText( self.tr('[Enter your formula here]', 'CalculatorModelerParametersDialog')) if self._algName is not None: alg = self.model.algs[self._algName] self.formulaText.setText(alg.params[FORMULA]) self.setWindowTitle( self.tr('Calculator', 'CalculatorModelerParametersDialog')) self.verticalLayout = QVBoxLayout() self.verticalLayout.setSpacing(2) self.verticalLayout.setMargin(0) self.verticalLayout.addWidget(self.infoText) self.verticalLayout.addWidget(self.formulaText) self.verticalLayout.addWidget(self.buttonBox) self.setLayout(self.verticalLayout) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) QMetaObject.connectSlotsByName(self)
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) 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) self.buttonBox.rejected.connect(self.cancelPressed) QMetaObject.connectSlotsByName(self)
def setupUi(self): self.setWindowTitle(self.tr('Parameter definition')) self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setSpacing(40) self.verticalLayout.setMargin(20) self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.setSpacing(2) self.horizontalLayout.setMargin(0) self.label = QLabel(self.tr('Parameter name')) self.horizontalLayout.addWidget(self.label) self.nameTextBox = QLineEdit() self.horizontalLayout.addWidget(self.nameTextBox) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout2 = QHBoxLayout(self) self.horizontalLayout2.setSpacing(2) self.horizontalLayout2.setMargin(0) self.horizontalLayout3 = QHBoxLayout(self) self.horizontalLayout3.setSpacing(2) self.horizontalLayout3.setMargin(0) self.horizontalLayout4 = QHBoxLayout(self) self.horizontalLayout4.setSpacing(2) self.horizontalLayout4.setMargin(0) if isinstance(self.param, Parameter): self.nameTextBox.setText(self.param.description) if self.paramType == ModelerParameterDefinitionDialog.PARAMETER_BOOLEAN or \ isinstance(self.param, ParameterBoolean): self.state = QCheckBox() self.state.setText(self.tr('Checked')) self.state.setChecked(False) if self.param is not None: self.state.setChecked(True if self.param.value else False) self.horizontalLayout3.addWidget(self.state) self.verticalLayout.addLayout(self.horizontalLayout3) elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_TABLE_FIELD or \ isinstance(self.param, ParameterTableField): self.horizontalLayout3.addWidget(QLabel(self.tr('Parent layer'))) self.parentCombo = QComboBox() idx = 0 for param in self.alg.inputs.values(): if isinstance(param.param, (ParameterVector, ParameterTable)): self.parentCombo.addItem(param.param.description, param.param.name) if self.param is not None: if self.param.parent == param.param.name: self.parentCombo.setCurrentIndex(idx) idx += 1 self.horizontalLayout3.addWidget(self.parentCombo) self.verticalLayout.addLayout(self.horizontalLayout3) elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_VECTOR or \ isinstance(self.param, ParameterVector): self.horizontalLayout3.addWidget(QLabel(self.tr('Shape type'))) self.shapetypeCombo = QComboBox() self.shapetypeCombo.addItem(self.tr('Any')) self.shapetypeCombo.addItem(self.tr('Point')) self.shapetypeCombo.addItem(self.tr('Line')) self.shapetypeCombo.addItem(self.tr('Polygon')) if self.param is not None: self.shapetypeCombo.setCurrentIndex(self.param.shapetype[0] + 1) self.horizontalLayout3.addWidget(self.shapetypeCombo) self.verticalLayout.addLayout(self.horizontalLayout3) elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE or \ isinstance(self.param, ParameterMultipleInput): self.horizontalLayout3.addWidget(QLabel(self.tr('Data type'))) self.datatypeCombo = QComboBox() self.datatypeCombo.addItem(self.tr('Vector (any)')) self.datatypeCombo.addItem(self.tr('Vector (point)')) self.datatypeCombo.addItem(self.tr('Vector (line)')) self.datatypeCombo.addItem(self.tr('Vector (polygon)')) self.datatypeCombo.addItem(self.tr('Raster')) self.datatypeCombo.addItem(self.tr('Table')) if self.param is not None: self.datatypeCombo.setCurrentIndex(self.param.datatype + 1) self.horizontalLayout3.addWidget(self.datatypeCombo) self.verticalLayout.addLayout(self.horizontalLayout3) elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_NUMBER or \ isinstance(self.param, ParameterNumber): self.horizontalLayout3.addWidget(QLabel(self.tr('Min/Max values'))) self.minTextBox = QLineEdit() self.maxTextBox = QLineEdit() if self.param is not None: self.minTextBox.setText(unicode(self.param.min)) self.maxTextBox.setText(unicode(self.param.max)) self.horizontalLayout3.addWidget(self.minTextBox) self.horizontalLayout3.addWidget(self.maxTextBox) self.verticalLayout.addLayout(self.horizontalLayout3) self.horizontalLayout4.addWidget(QLabel(self.tr('Default value'))) self.defaultTextBox = QLineEdit() self.defaultTextBox.setText(self.tr('0')) if self.param is not None: default = self.param.default if self.param.isInteger: default = int(math.floor(default)) self.defaultTextBox.setText(unicode(default)) self.horizontalLayout4.addWidget(self.defaultTextBox) self.verticalLayout.addLayout(self.horizontalLayout4) elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_STRING or \ isinstance(self.param, ParameterString): self.horizontalLayout3.addWidget(QLabel(self.tr('Default value'))) self.defaultTextBox = QLineEdit() if self.param is not None: self.defaultTextBox.setText(self.param.default) self.horizontalLayout3.addWidget(self.defaultTextBox) self.verticalLayout.addLayout(self.horizontalLayout3) elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_FILE or \ isinstance(self.param, ParameterFile): self.horizontalLayout3.addWidget(QLabel(self.tr('Type'))) self.fileFolderCombo = QComboBox() self.fileFolderCombo.addItem(self.tr('File')) self.fileFolderCombo.addItem(self.tr('Folder')) if self.param is not None: self.fileFolderCombo.setCurrentIndex( 1 if self.param.isFolder else 0) self.horizontalLayout3.addWidget(self.fileFolderCombo) self.verticalLayout.addLayout(self.horizontalLayout3) elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or \ isinstance(self.param, ParameterPoint): self.horizontalLayout3.addWidget(QLabel(self.tr('Default value'))) self.defaultTextBox = QLineEdit() if self.param is not None: self.defaultTextBox.setText(self.param.default) self.horizontalLayout3.addWidget(self.defaultTextBox) self.verticalLayout.addLayout(self.horizontalLayout3) self.horizontalLayout2.addWidget(QLabel(self.tr('Required'))) self.yesNoCombo = QComboBox() self.yesNoCombo.addItem(self.tr('Yes')) self.yesNoCombo.addItem(self.tr('No')) self.horizontalLayout2.addWidget(self.yesNoCombo) if self.param is not None: self.yesNoCombo.setCurrentIndex(1 if self.param.optional else 0) self.verticalLayout.addLayout(self.horizontalLayout2) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.buttonBox.setObjectName('buttonBox') self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.verticalLayout.addWidget(self.buttonBox) self.setLayout(self.verticalLayout)