Wed, 21 Sep 2022 16:24:54 +0200
Reformatted source code with 'Black'.
# -*- coding: utf-8 -*- # Copyright (c) 2012 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog for entering the create parameters. """ from PyQt6.QtCore import pyqtSlot from PyQt6.QtWidgets import QDialog, QDialogButtonBox from .Ui_CreateParametersDialog import Ui_CreateParametersDialog class CreateParametersDialog(QDialog, Ui_CreateParametersDialog): """ Class implementing a dialog for entering the create parameters. """ PyramidStarterGH = "gh:Pylons/pyramid-cookiecutter-starter" PyramidStarter = "pyramid-cookiecutter-starter" PyramidStarterZip = "pyramid-cookiecutter-starter.zip" def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super().__init__(parent) self.setupUi(self) self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) self.__okButton.setEnabled(False) self.templateCombo.addItems( [ "", CreateParametersDialog.PyramidStarter, CreateParametersDialog.PyramidStarterGH, CreateParametersDialog.PyramidStarterZip, ] ) self.templateLanguageCombo.addItem("Jinja2", "jinja") self.templateLanguageCombo.addItem("Chameleon", "chameleon") self.templateLanguageCombo.addItem("Mako", "mako") self.backendCombo.addItem(self.tr("No Database"), "none") self.backendCombo.addItem("SQLAlchemy", "sqlalchemy") self.backendCombo.addItem("ZODB", "zodb") self.starterGroupBox.setEnabled(False) msh = self.minimumSizeHint() self.resize(max(self.width(), msh.width()), msh.height()) @pyqtSlot(str) def on_templateCombo_currentTextChanged(self, text): """ Private slot to handle changes of the selected scaffold. @param text text of the combo box @type str """ self.__updateUi() def __updateUi(self): """ Private slot to update the dialog. """ template = self.templateCombo.currentText() self.__okButton.setEnabled(bool(template)) self.starterGroupBox.setEnabled( CreateParametersDialog.PyramidStarter in template ) self.versionEdit.setEnabled(template == CreateParametersDialog.PyramidStarterGH) def getData(self): """ Public method to get the data. @return tuple giving the template name, an optional template version, a flag indicating to overwrite existing files and a dictionary containing additional context data @rtype tuple of (str, str, bool) """ template = self.templateCombo.currentText() contextData = ( { "project_name": self.projectEdit.text(), "repo_name": ( self.projectEdit.text() .lower() .strip() .replace(" ", "_") .replace(":", "_") .replace("-", "_") .replace("!", "_") ), "template_language": self.templateLanguageCombo.currentData(), "backend": self.backendCombo.currentData(), } if CreateParametersDialog.PyramidStarter in template else {} ) version = ( self.versionEdit.text() if template == CreateParametersDialog.PyramidStarterGH else "" ) return (template, version, self.overwriteCheckBox.isChecked(), contextData)