def createEditBox(self): # create group box self.editBox = QGroupBox() self.editBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) gridLayout = QGridLayout(self.editBox) # create input fields self.operationInput = QLineEdit(self.model.projectData("operation")) self.operationInput.setFixedWidth(self._INPUTS_FIXED_WIDTH) self.operationInput.setClearButtonEnabled(True) self.operationLabel = QLabel() self.operationLabel.setBuddy(self.operationInput) gridLayout.addWidget(self.operationLabel, 0, 0) gridLayout.addWidget(self.operationInput, 0, 1) self.districtInput = QLineEdit(self.model.projectData("district")) self.districtInput.setFixedWidth(self._INPUTS_FIXED_WIDTH) self.districtInput.setClearButtonEnabled(True) self.districtLabel = QLabel() self.districtLabel.setBuddy(self.districtInput) gridLayout.addWidget(self.districtLabel, 0, 2) gridLayout.addWidget(self.districtInput, 0, 3) self.managerInput = QLineEdit(self.model.projectData("manager")) self.managerInput.setFixedWidth(self._INPUTS_FIXED_WIDTH) self.managerInput.setClearButtonEnabled(True) self.managerLabel = QLabel() self.managerLabel.setBuddy(self.managerInput) gridLayout.addWidget(self.managerLabel, 1, 0) gridLayout.addWidget(self.managerInput, 1, 1) self.locationInput = QLineEdit(self.model.projectData("location")) self.locationInput.setFixedWidth(self._INPUTS_FIXED_WIDTH) self.locationInput.setClearButtonEnabled(True) self.locationLabel = QLabel() self.locationLabel.setBuddy(self.locationInput) gridLayout.addWidget(self.locationLabel, 1, 2) gridLayout.addWidget(self.locationInput, 1, 3) lineFrame = QFrame(frameShadow=QFrame.Sunken, frameShape=QFrame.VLine) gridLayout.addWidget(lineFrame, 0, 4, 2, 1) self.taxInput = QCheckBox() self.taxInput.setChecked(self.model.projectData("tax")) self.taxLabel = QLabel() self.taxLabel.setBuddy(self.taxInput) self.taxHint = ToolTipLabel() gridLayout.addWidget(self.taxLabel, 0, 5) gridLayout.addWidget(self.taxInput, 0, 6) gridLayout.addWidget(self.taxHint, 0, 7, Qt.AlignRight) gridLayout.setColumnMinimumWidth(7, 40) rightSpacer = QSpacerItem(20, 0, QSizePolicy.Expanding, QSizePolicy.Fixed) gridLayout.addItem(rightSpacer, 0, 8, 2, 1) self.dataWidget = EnhancedTreeWidget() gridLayout.addWidget(self.dataWidget, 2, 0, 1, 9) return self.editBox
def __init__(self, species=(), item=None, tax=True, last=0, index=QModelIndex(), count=0, length=0): """The constructor initializes the class NewVariantDialog.""" super().__init__() self.item = item self.value = None self.speciesRegistry = species.keys() self.species = -1 self.count = 0 self.tax = tax self.index = index # the last added index self.last = last self.count = count self.length = length self._OXYGEN_PATH_22 = os.path.join("resources", "icons", "oxygen", "22") self._LABEL_MIN_WIDTH = 240 self._piece_unit = " St." self._currency_unit = " " + self.locale().currencySymbol(QLocale.CurrencyIsoCode) self._currency_unit_piece = self._currency_unit + "/" + self._piece_unit.strip() self._spinbox_step = 0.05 self._COMBOBOX_ITEM_LIST = (QApplication.translate("VariantDataDialog", "Fence"), # Zaun QApplication.translate("VariantDataDialog", "Tree shelter")) # Wuchshülle # general things self.generalGroup = QGroupBox() self.variantInput = QComboBox() self.variantInput.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.variantInput.addItems(self._COMBOBOX_ITEM_LIST) self.variantLabel = QLabel() self.variantLabel.setMinimumWidth(self._LABEL_MIN_WIDTH) self.variantLabel.setBuddy(self.variantInput) self.variantHint = ToolTipLabel() self.descriptionInput = QLineEdit() self.descriptionLabel = QLabel() self.descriptionLabel.setBuddy(self.descriptionInput) self.descriptionHint = ToolTipLabel() # create the layout of the general group box generalLayout = QGridLayout(self.generalGroup) generalLayout.setVerticalSpacing(15) generalLayout.addWidget(self.variantLabel, 0, 0, Qt.AlignTop) generalLayout.addWidget(self.variantInput, 0, 1, Qt.AlignTop) generalLayout.addWidget(self.variantHint, 0, 2, Qt.AlignTop) generalLayout.addWidget(self.descriptionLabel, 1, 0, Qt.AlignTop) generalLayout.addWidget(self.descriptionInput, 1, 1, Qt.AlignTop) generalLayout.addWidget(self.descriptionHint, 1, 2, Qt.AlignTop) # plant specific input fields self.plantGroup = QGroupBox() self.speciesInput = QComboBox() self.speciesInput.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.speciesInput.addItems(library.TREESPECIES_DESCRIPTION) self.speciesLabel = QLabel() self.speciesLabel.setMinimumWidth(self._LABEL_MIN_WIDTH) self.speciesLabel.setBuddy(self.speciesInput) self.speciesHint = ToolTipLabel() self.speciesHint.hide() speciesSpacer = QSpacerItem(0, 30, QSizePolicy.Minimum, QSizePolicy.Fixed) self.speciesWarningSymbol = QLabel(pixmap=QPixmap(os.path.join(self._OXYGEN_PATH_22, "dialog-warning.png"))) self.speciesWarningSymbol.hide() self.speciesWarningText = QLabel(wordWrap=True) self.speciesWarningText.hide() warningLayout = QHBoxLayout() warningLayout.setContentsMargins(0, 0, 0, 0) warningLayout.addItem(speciesSpacer) warningLayout.addWidget(self.speciesWarningSymbol, alignment=Qt.AlignTop) warningLayout.addWidget(self.speciesWarningText, alignment=Qt.AlignTop) self.costInput = QDoubleSpinBox() self.costInput.setSuffix(self._currency_unit_piece) self.costInput.setSingleStep(self._spinbox_step) self.costLabel = QLabel() self.costLabel.setBuddy(self.costInput) self.costHint = ToolTipLabel() self.costHint.hide() self.costCalculator = QPushButton() self.preparationInput = QDoubleSpinBox() self.preparationInput.setSuffix(self._currency_unit_piece) self.preparationInput.setSingleStep(self._spinbox_step) self.preparationLabel = QLabel() self.preparationLabel.setBuddy(self.preparationInput) self.preparationHint = ToolTipLabel() self.preparationHint.hide() self.preparationCalculator = QPushButton() self.plantingInput = QDoubleSpinBox() self.plantingInput.setSuffix(self._currency_unit_piece) self.plantingInput.setSingleStep(self._spinbox_step) self.plantingLabel = QLabel() self.plantingLabel.setBuddy(self.plantingInput) self.plantingHint = ToolTipLabel() self.plantingHint.hide() self.plantingCalculator = QPushButton() self.tendingInput = QDoubleSpinBox() self.tendingInput.setSuffix(self._currency_unit_piece) self.tendingInput.setSingleStep(self._spinbox_step) self.tendingLabel = QLabel() self.tendingLabel.setBuddy(self.tendingInput) self.tendingHint = ToolTipLabel() self.tendingHint.hide() self.tendingCalculator = QPushButton() self.mortalityInput = QSpinBox() self.mortalityInput.setSuffix(" %") self.mortalityInput.setMaximum(100) self.mortalityInput.setValue(0) self.mortalityInput.setDisabled(True) self.mortalityLabel = QLabel() self.mortalityLabel.setBuddy(self.mortalityInput) self.mortalityHint = ToolTipLabel() self.mortalityHint.hide() # create the layout of the plant group box plantLayout = QGridLayout(self.plantGroup) plantLayout.addWidget(self.speciesLabel, 0, 0) plantLayout.addWidget(self.speciesInput, 0, 1) plantLayout.addWidget(self.speciesHint, 0, 2) plantLayout.addLayout(warningLayout, 1, 1) plantLayout.addWidget(self.costLabel, 2, 0) plantLayout.addWidget(self.costInput, 2, 1) plantLayout.addWidget(self.costHint, 2, 2) plantLayout.addWidget(self.costCalculator, 2, 3) plantLayout.addWidget(self.preparationLabel, 3, 0) plantLayout.addWidget(self.preparationInput, 3, 1) plantLayout.addWidget(self.preparationHint, 3, 2) plantLayout.addWidget(self.preparationCalculator, 3, 3) plantLayout.addWidget(self.plantingLabel, 4, 0) plantLayout.addWidget(self.plantingInput, 4, 1) plantLayout.addWidget(self.plantingHint, 4, 2) plantLayout.addWidget(self.plantingCalculator, 4, 3) plantLayout.addWidget(self.tendingLabel, 5, 0) plantLayout.addWidget(self.tendingInput, 5, 1) plantLayout.addWidget(self.tendingHint, 5, 2) plantLayout.addWidget(self.tendingCalculator, 5, 3) plantLayout.addWidget(self.mortalityLabel, 6, 0) plantLayout.addWidget(self.mortalityInput, 6, 1) plantLayout.addWidget(self.mortalityHint, 6, 2) # stacked widget for protection group self.fenceWidget = FenceInputWidget(self.tax) self.fenceWidget.length = self.length self.tubeWidget = TubeInputWidget(self.tax) self.protectionGroup = QStackedWidget() self.protectionGroup.addWidget(self.fenceWidget) self.protectionGroup.addWidget(self.tubeWidget) # sales tax hint taxLabel = QLabel("*) " + QApplication.translate("VariantDataDialog", # Bitte beachten Sie, dass Sie den Variantentyp später nicht mehr ändern können. "Keep in mind, that all values must contain uniformly " "the sales tax or not."), wordWrap=True) # create an ok button and abort button within a button box lineFrame = QFrame(frameShadow=QFrame.Sunken, frameShape=QFrame.VLine) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel|QDialogButtonBox.Help, orientation=Qt.Vertical) # create main layout dataLayout = QVBoxLayout() dataLayout.addWidget(self.generalGroup) dataLayout.addWidget(self.plantGroup) dataLayout.addWidget(self.protectionGroup) dataLayout.addWidget(taxLabel) dataLayout.addStretch() layout = QHBoxLayout(self) layout.addLayout(dataLayout) layout.addWidget(lineFrame) layout.addWidget(self.buttonBox) # connect actions self.variantInput.currentIndexChanged.connect(self.variantChanged) self.speciesInput.currentIndexChanged.connect(self.checkSpecies) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.buttonBox.helpRequested.connect(self.help) self.costCalculator.clicked.connect(self.costCalculation) self.preparationCalculator.clicked.connect(self.preparationCalculation) self.plantingCalculator.clicked.connect(self.plantingCalculation) self.tendingCalculator.clicked.connect(self.tendingCalculation) self.tubeWidget.countChanged.connect(self.updateCount) self.fenceWidget.lengthChanged.connect(self.updateLength) # update input fields if self.item: plant = self.item[TreeModel.PlantRole] protection = self.item[TreeModel.ProtectionRole] self.species = plant.species # update input fields self.variantInput.setCurrentIndex(protection.TYPE) self.variantInput.setDisabled(True) self.descriptionInput.setText(self.item[TreeModel.NameRole]) self.speciesInput.setCurrentIndex(plant.species) self.costInput.setValue(plant.cost) self.preparationInput.setValue(plant.preparation) self.plantingInput.setValue(plant.planting) self.tendingInput.setValue(plant.tending) self.mortalityInput.setValue(plant.mortality * 100) # update the protection group self.protectionGroup.currentWidget().setValues(protection) else: self.variantInput.setCurrentIndex(self.last) if self.index.isValid(): self.speciesInput.setCurrentIndex(self.index.data(TreeModel.SpeciesRole)) # check the species and show # a warning, if necessary self.checkSpecies() # translate the graphical user interface self.retranslateUi()
def __init__(self, tax=True): """The constructor initializes the class NewVariantDialog.""" super().__init__() self.count = 0 self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) self._LABEL_MIN_WIDTH = 240 self._piece_unit = " St." self._currency_unit = " " + self.locale().currencySymbol(QLocale.CurrencyIsoCode) self._currency_unit_piece = self._currency_unit + "/" + self._piece_unit.strip() self._spinbox_step = 0.05 # determine the sales tax self.tax = 1.0 + library.SALES_TAX if tax else 1.0 # input fields self.tubeInput = QComboBox() self.tubeInput.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.tubeInput.addItems(library.TREESHELTERS_DESCRIPTION) self.tubeLabel = QLabel() self.tubeLabel.setMinimumWidth(self._LABEL_MIN_WIDTH) self.tubeLabel.setBuddy(self.tubeInput) self.tubeHint = ToolTipLabel() self.tubeHint.hide() self.costInput = QDoubleSpinBox() self.costInput.setSuffix(self._currency_unit_piece) self.costInput.setSingleStep(self._spinbox_step) self.costLabel = QLabel() self.costLabel.setBuddy(self.costInput) self.costHint = ToolTipLabel() self.costHint.hide() self.costCalculator = QPushButton() self.accessoriesInput = QDoubleSpinBox() self.accessoriesInput.setSuffix(self._currency_unit_piece) self.accessoriesInput.setSingleStep(self._spinbox_step) self.accessoriesLabel = QLabel() self.accessoriesLabel.setBuddy(self.accessoriesInput) self.accessoriesHint = ToolTipLabel() self.accessoriesHint.hide() self.accessoriesCalculator = QPushButton() self.installationInput = QDoubleSpinBox() self.installationInput.setSuffix(self._currency_unit_piece) self.installationInput.setSingleStep(self._spinbox_step) self.installationLabel = QLabel() self.installationLabel.setBuddy(self.installationInput) self.installationHint = ToolTipLabel() self.installationHint.hide() self.installationCalculator = QPushButton() self.maintenanceInput = QDoubleSpinBox() self.maintenanceInput.setSuffix(self._currency_unit_piece) self.maintenanceInput.setSingleStep(self._spinbox_step) self.maintenanceLabel = QLabel() self.maintenanceLabel.setBuddy(self.maintenanceInput) self.maintenanceHint = ToolTipLabel() self.maintenanceHint.hide() self.removalInput = QDoubleSpinBox() self.removalInput.setSuffix(self._currency_unit_piece) self.removalInput.setSingleStep(self._spinbox_step) self.removalLabel = QLabel() self.removalLabel.setBuddy(self.removalInput) self.removalHint = ToolTipLabel() self.removalHint.hide() spacerBottom = QSpacerItem(0, 0, QSizePolicy.Minimum, QSizePolicy.Expanding) # create the layout of the plant group box layout = QGridLayout(self) layout.addWidget(self.tubeLabel, 0, 0) layout.addWidget(self.tubeInput, 0, 1) layout.addWidget(self.tubeHint, 0, 2) layout.addWidget(self.costLabel, 1, 0) layout.addWidget(self.costInput, 1, 1) layout.addWidget(self.costHint, 1, 2) layout.addWidget(self.costCalculator, 1, 3) layout.addWidget(self.accessoriesLabel, 2, 0) layout.addWidget(self.accessoriesInput, 2, 1) layout.addWidget(self.accessoriesHint, 2, 2) layout.addWidget(self.accessoriesCalculator, 2, 3) layout.addWidget(self.installationLabel, 3, 0) layout.addWidget(self.installationInput, 3, 1) layout.addWidget(self.installationHint, 3, 2) layout.addWidget(self.installationCalculator, 3, 3) layout.addWidget(self.maintenanceLabel, 4, 0) layout.addWidget(self.maintenanceInput, 4, 1) layout.addWidget(self.maintenanceHint, 4, 2) layout.addWidget(self.removalLabel, 5, 0) layout.addWidget(self.removalInput, 5, 1) layout.addWidget(self.removalHint, 5, 2) layout.addItem(spacerBottom, 7, 0, 1, 3) # connect actions self.tubeInput.currentIndexChanged.connect(self.updateCost) self.costCalculator.clicked.connect(self.costCalculation) self.accessoriesCalculator.clicked.connect(self.accessoriesCalculation) self.installationCalculator.clicked.connect(self.installationCalculation) #self.installationInput.valueChanged.connect(self.updateMaintenanceAndRemoval) # translate the graphical user interface self.retranslateUi()