Beispiel #1
0
    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 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
Beispiel #3
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)

        # initialize class attributes
        self._INPUTS_FIXED_WIDTH = 180
        self._BUTTON_MIN_WIDTH = 80
        self._OXYGEN_PATH_32 = os.path.join("resources", "icons", "oxygen",
                                            "32")

        # locale and language settings
        self.language = self.locale().name()[:2]
        self.qtTl = QTranslator()
        self.appTl = QTranslator()
        self.switchTranslator(self.qtTl, "qtbase", self.language)
        self.switchTranslator(self.appTl, "wuchshuellenrechner", self.language)

        # TODO(th)
        self.model = TreeModel()

        # setup gui
        self.setMinimumSize(1200, 760)

        self.createActions()
        self.createMainMenu()

        # plot widget
        self.plotWidget = VariantPlotView()
        self.plotWidget.setModel(self.model)

        # create vertical splitter
        splitter = QSplitter(Qt.Vertical)
        splitter.setContentsMargins(11, 11, 11, 11)
        splitter.addWidget(self.createEditBox())
        splitter.addWidget(self.plotWidget)

        self.setCentralWidget(splitter)

        self.dataWidget.setModel(self.model)

        selectionModel = QItemSelectionModel(self.model)
        self.dataWidget.setSelectionModel(selectionModel)
        self.plotWidget.setSelectionModel(selectionModel)

        self.retranslateUi()

        self.model.dataChanged.connect(self.updateInputs)
        self.model.itemsInserted.connect(self.taxInput.setDisabled)
        self.model.allItemsRemoved.connect(self.taxInput.setEnabled)
        self.operationInput.textChanged.connect(self.updateOperation)
        self.districtInput.textChanged.connect(self.updateDistrict)
        self.managerInput.textChanged.connect(self.updateManager)
        self.locationInput.textChanged.connect(self.updateLocation)
        self.taxInput.stateChanged.connect(self.updateTax)

    def updateOperation(self, value):
        self.model.setProjectData("operation", value)

    def updateDistrict(self, value):
        self.model.setProjectData("district", value)

    def updateManager(self, value):
        self.model.setProjectData("manager", value)

    def updateLocation(self, value):
        self.model.setProjectData("location", value)

    def updateTax(self):
        self.model.setProjectData("tax", self.taxInput.isChecked())
        self.dataWidget.tax = self.taxInput.isChecked()

    def updateInputs(self):
        self.operationInput.setText(self.model.projectData("operation"))
        self.districtInput.setText(self.model.projectData("district"))
        self.managerInput.setText(self.model.projectData("manager"))
        self.locationInput.setText(self.model.projectData("location"))

        self.taxInput.setChecked(self.model.projectData("tax"))

    def loadLanguage(self, language):
        if not self.language == language:
            self.language = language

            locale = QLocale(language)
            QLocale.setDefault(locale)

            self.switchTranslator(self.qtTl, "qtbase", language)
            self.switchTranslator(self.appTl, "wuchshuellenrechner", language)

            # update gui
            self.retranslateUi()
            self.dataWidget.retranslateUi()

    def switchTranslator(self, translator, filename, language):
        app = QApplication.instance()

        # remove the old translator and
        # try to load a new language file
        app.removeTranslator(translator)
        if translator.load(QLocale(), filename, "_", "language"):
            app.installTranslator(translator)

    def setTaxEnabled(self, enable):
        # enable buttons and the view element
        self.removeButton.setEnabled(enable)
        self.modifyButton.setEnabled(enable)
        self.view.setEnabled(enable)

    def setDisabled(self, disable):
        # internaly call the setEnabled function
        # therefore negate the boolean value
        self.setEnabled(not disable)

    def aboutAction(self):
        aboutDialog = AboutDialog()
        aboutDialog.exec()

    def clear(self):
        # first clear the model
        self.model.clear()

        # update fields with model's default values
        self.operationInput.setText(self.model.projectData("operation"))
        self.districtInput.setText(self.model.projectData("district"))
        self.managerInput.setText(self.model.projectData("manager"))
        self.locationInput.setText(self.model.projectData("location"))

        self.taxInput.setEnabled(True)
        self.taxInput.setChecked(self.model.projectData("tax"))

        # reset the tree view
        self.dataWidget.clear()

        # reset the chart and result view
        # actually this is necassary
        self.plotWidget.clear()

    def closeAction(self):
        if self.model.changed:
            question = QMessageBox()
            question.setIcon(QMessageBox.Question)
            question.setWindowTitle(
                "Berechnung speichern? - Wuchshüllenrechner")
            question.setText(
                "Möchten Sie die Änderungen an dieser Berechnung speichern?")
            question.setInformativeText(
                "Die Änderungen gehen verloren, wenn Sie nicht speichern.")
            question.setStandardButtons(QMessageBox.Save | QMessageBox.Discard
                                        | QMessageBox.Cancel)
            question.setDefaultButton(QMessageBox.Save)
            reply = question.exec()

            if not reply == QMessageBox.Cancel:
                if reply == QMessageBox.Save:
                    if self.saveAction():
                        self.close()
                else:
                    self.close()
        else:
            self.close()

    def newAction(self):
        if self.model.changed:
            question = QMessageBox()
            question.setIcon(QMessageBox.Question)
            question.setWindowTitle(
                "Berechnung speichern? - Wuchshüllenrechner")
            question.setText(
                "Möchten Sie die Änderungen an dieser Berechnung speichern?")
            question.setInformativeText(
                "Die Änderungen gehen verloren, wenn Sie nicht speichern.")
            question.setStandardButtons(QMessageBox.Save | QMessageBox.Discard
                                        | QMessageBox.Cancel)
            question.setDefaultButton(QMessageBox.Save)
            reply = question.exec()

            if not reply == QMessageBox.Cancel:
                if reply == QMessageBox.Save:
                    if self.saveAction():
                        # clear all
                        self.clear()
                else:
                    # clear all
                    self.clear()

    def checkSaveState(self):
        if self.model.changed:
            question = QMessageBox(self)
            question.setWindowModality(Qt.WindowModal)  # check for mac only
            question.setIcon(QMessageBox.Warning)
            question.setStandardButtons(QMessageBox.Save | QMessageBox.Discard
                                        | QMessageBox.Cancel)
            question.setDefaultButton(QMessageBox.Save)
            question.setWindowTitle(
                QApplication.translate("MainWindow", "Wuchshüllenrechner"))
            question.setText("<b>" + QApplication.translate(
                "MainWindow", "Do you want to save the changes you made<br>"
                "to the current calculation?") + "</b>")
            question.setInformativeText(
                QApplication.translate(
                    "MainWindow",
                    "Your changes will be lost if you don't save them."))

            reply = question.exec()
            if reply == QMessageBox.Save:
                if self.saveAction():
                    #self.model.clear()
                    self.clear()
                    return True
                else:
                    return False
            elif reply == QMessageBox.Discard:
                #self.model.clear()
                self.clear()
                return True
            else:
                return False

        # always clear
        self.clear()

        return True

    def loadExample(self, example=""):
        # create the path
        exampleFile = os.path.join("examples", example.strip() + ".xml")

        # if all is save, open the example file
        if self.checkSaveState():
            self.model.readFile(exampleFile)

    def mapleAction(self):
        self.loadExample("great_maple")

    def douglasAction(self):
        self.loadExample("douglas_fir")

    def openAction(self):
        # first check save state of the current calculation
        if self.checkSaveState():
            dialog = QFileDialog(self)
            dialog.setWindowModality(Qt.WindowModal)  # check for mac only
            dialog.setWindowTitle(
                QApplication.translate("MainWindow", "Open Calculation"))
            dialog.setDirectory(os.path.expanduser("~"))
            dialog.setNameFilter(
                QApplication.translate("MainWindow",
                                       "XML files (*.xml);;All Files (*)"))

            dialog.exec()
            filename = dialog.selectedFiles()
            if filename:
                self.model.readFile(filename.pop())

    def saveAction(self):
        if self.model.file:
            return self.model.saveFile()
        else:
            return self.saveAsAction()

    def saveAsAction(self):
        dialog = QFileDialog(self)
        dialog.setWindowModality(Qt.WindowModal)  # check for mac only
        dialog.setAcceptMode(QFileDialog.AcceptSave)
        dialog.setWindowTitle(
            QApplication.translate("MainWindow", "Save Calculation"))
        dialog.setDirectory(os.path.expanduser("~"))
        dialog.setNameFilter(
            QApplication.translate("MainWindow",
                                   "XML files (*.xml);;All Files (*)"))

        dialog.exec()
        filename = dialog.selectedFiles()
        if filename:
            self.model.saveFile(filename.pop())
            return True
        else:
            return False

    def exportAction(self):
        dialog = QFileDialog(self)
        dialog.setWindowModality(Qt.WindowModal)  # check for mac only
        dialog.setAcceptMode(QFileDialog.AcceptSave)
        dialog.setWindowTitle(
            QApplication.translate("MainWindow", "Export Calculation"))
        dialog.setDirectory(os.path.expanduser("~"))
        dialog.setNameFilter(
            QApplication.translate(
                "MainWindow",
                "PNG files (*.png);;JPG files (*.jpg);;TIFF files (*.tif)"))

        if dialog.exec():
            filename = dialog.selectedFiles()
            self.plotWidget.plotWidget.plotWidget.export(filename.pop())

    def helpAction(self):
        # create the documentation path with
        # the current locale settings
        docFile = os.path.join("doc",
                               "documentation_" + self.language + ".pdf")

        # on every platfrom a different
        # start operation is needed
        if sys.platform == "win32":
            os.startfile(docFile)
        elif sys.platform == "darwin":
            subprocess.call(("open", docFile))
        elif sys.platform.startswith("linux"):
            subprocess.call(("xdg-open", docFile))

    def scientificAction(self):
        scientificDialog = ScientificBasisDialog()
        scientificDialog.exec()

    def germanAction(self):
        # update language menu
        self.languageEnglish.setChecked(False)
        self.languageGerman.setChecked(True)

        # update gui
        self.loadLanguage("de")

    def englishAction(self):
        # update language menu
        self.languageGerman.setChecked(False)
        self.languageEnglish.setChecked(True)

        # update gui
        self.loadLanguage("en")

    def createActions(self):
        # all actions for the calculation menu
        # create the new calculation action
        self.calculationNew = QAction(self,
                                      icon=QIcon(
                                          os.path.join(self._OXYGEN_PATH_32,
                                                       "document-new.png")),
                                      shortcut=QKeySequence.New,
                                      triggered=self.newAction)

        # create the open calculation action
        self.calculationOpen = QAction(
            self,
            icon=QIcon(os.path.join(self._OXYGEN_PATH_32,
                                    "document-open.png")),
            shortcut=QKeySequence.Open,
            triggered=self.openAction)

        # create the open calculation example actions
        # for great maple and douglas fir
        self.examplesMaple = QAction(self, triggered=self.mapleAction)
        self.examplesDouglas = QAction(self, triggered=self.douglasAction)

        # create the save calculation action
        self.calculationSave = QAction(
            self,
            icon=QIcon(os.path.join(self._OXYGEN_PATH_32,
                                    "document-save.png")),
            shortcut=QKeySequence.Save,
            triggered=self.saveAction)

        # create the save as action
        self.calculationSaveAs = QAction(self,
                                         icon=QIcon(
                                             os.path.join(
                                                 self._OXYGEN_PATH_32,
                                                 "document-save-as.png")),
                                         shortcut=QKeySequence.SaveAs,
                                         triggered=self.saveAsAction)

        # create the print calculation action
        #self.calculationPrint = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "document-print.png")),
        #        shortcut=QKeySequence.Print, triggered=self.printAction)

        # create the export calculation action
        self.calculationExport = QAction(
            self,
            icon=QIcon(
                os.path.join(self._OXYGEN_PATH_32, "document-export.png")),
            shortcut=QKeySequence(Qt.CTRL + Qt.Key_E),
            triggered=self.exportAction)

        # create the quit calculation action
        self.calculationQuit = QAction(self,
                                       icon=QIcon(
                                           os.path.join(
                                               self._OXYGEN_PATH_32,
                                               "application-exit.png")),
                                       shortcut=QKeySequence.Quit,
                                       triggered=self.closeAction)

        # all actions for the language menu
        # create the german and the english language actions
        self.languageGerman = QAction(self,
                                      checkable=True,
                                      triggered=self.germanAction)
        self.languageEnglish = QAction(self,
                                       checkable=True,
                                       triggered=self.englishAction)

        # update the language menu
        if self.language == "de":
            self.languageGerman.setChecked(True)
        elif self.language == "en":
            self.languageEnglish.setChecked(True)

        # create the help contents action
        self.helpContents = QAction(self,
                                    icon=QIcon(
                                        os.path.join(self._OXYGEN_PATH_32,
                                                     "help-contents.png")),
                                    triggered=self.helpAction)

        # create the scientific basis action
        self.scientificBasis = QAction(self,
                                       icon=QIcon(
                                           os.path.join(
                                               self._OXYGEN_PATH_32,
                                               "applications-science.png")),
                                       triggered=self.scientificAction)

        # create the help about action
        self.helpAbout = QAction(self,
                                 icon=QIcon(
                                     os.path.join(self._OXYGEN_PATH_32,
                                                  "dialog-information.png")),
                                 triggered=self.aboutAction)

    def createMainMenu(self):
        # create main menu bar
        self.menu = self.menuBar()

        # create file menu
        self.calculationMenu = QMenu(self)
        self.calculationMenu.addAction(self.calculationNew)
        self.calculationMenu.addAction(self.calculationOpen)

        self.examplesMenu = QMenu(self,
                                  icon=QIcon(
                                      os.path.join(self._OXYGEN_PATH_32,
                                                   "folder-documents.png")))
        self.examplesMenu.addAction(self.examplesMaple)
        self.examplesMenu.addAction(self.examplesDouglas)
        self.calculationMenu.addMenu(self.examplesMenu)
        self.calculationMenu.addSeparator()

        self.calculationMenu.addAction(self.calculationSave)
        self.calculationMenu.addAction(self.calculationSaveAs)
        self.calculationMenu.addAction(self.calculationExport)
        self.calculationMenu.addSeparator()

        #self.calculationMenu.addAction(self.calculationPrint)
        #self.calculationMenu.addSeparator()

        self.calculationMenu.addAction(self.calculationQuit)

        self.menu.addMenu(self.calculationMenu)

        # create language menu
        self.languageMenu = QMenu(self)
        self.languageMenu.addAction(self.languageGerman)
        self.languageMenu.addAction(self.languageEnglish)
        self.menu.addMenu(self.languageMenu)

        # create help menu
        self.helpMenu = QMenu(self)
        self.helpMenu.addAction(self.helpContents)
        self.helpMenu.addAction(self.scientificBasis)
        self.helpMenu.addSeparator()
        self.helpMenu.addAction(self.helpAbout)
        self.menu.addMenu(self.helpMenu)

    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 retranslateUi(self):
        # main window title
        self.setWindowTitle(
            QApplication.translate("MainWindow",
                                   "Wuchshüllenrechner"))  # Wuchshüllenrechner

        # all menu actions
        # first the calculation menu
        self.calculationMenu.setTitle(
            QApplication.translate("MainWindow",
                                   "&Calculation"))  # Kalkulation
        self.calculationNew.setText(
            QApplication.translate("MainWindow", "&New"))  # &Neu
        self.calculationOpen.setText(
            QApplication.translate("MainWindow", "&Open"))  # Ö&ffnen
        self.calculationSave.setText(
            QApplication.translate("MainWindow", "&Save"))  # &Speichern
        self.calculationSaveAs.setText(
            QApplication.translate("MainWindow",
                                   "&Save as"))  # &Speichern unter
        #self.calculationPrint.setText(QApplication.translate("MainWindow", "&Print"))           # &Drucken
        self.calculationExport.setText(
            QApplication.translate("MainWindow", "&Export"))  # &Exportieren
        self.calculationQuit.setText(
            QApplication.translate("MainWindow", "E&xit"))  # &Beenden

        # now the examples menu
        self.examplesMenu.setTitle(
            QApplication.translate("MainWindow", "E&xamples"))  # &Beispiele
        self.examplesMaple.setText(
            QApplication.translate("MainWindow",
                                   "&Calculation example for great &maple")
        )  # Berechnungsbeispiel für Berg-&Ahorn
        self.examplesDouglas.setText(
            QApplication.translate("MainWindow",
                                   "&Calculation example for &douglas fir")
        )  # Berechnungsbeispiel für Küsten-Douglasie

        # the language menu
        self.languageMenu.setTitle(
            QApplication.translate("MainWindow", "&Language"))  # &Sprache
        self.languageGerman.setText(
            QApplication.translate("MainWindow", "&German"))  # &Deutsch
        self.languageEnglish.setText(
            QApplication.translate("MainWindow", "&English"))  # &Englisch

        # the help menu
        self.helpMenu.setTitle(QApplication.translate("MainWindow",
                                                      "&Help"))  # &Hilfe
        self.helpContents.setText(
            QApplication.translate("MainWindow",
                                   "Help &Contents"))  # &Hilfe anzeigen
        self.scientificBasis.setText(
            QApplication.translate("MainWindow",
                                   "Specialist &articles"))  # &Fachbeiträge
        self.helpAbout.setText(
            QApplication.translate(
                "MainWindow",
                "&About Wuchshüllenrechner"))  # Über &Wuchshüllenrechner

        # the edit box for data collection
        self.editBox.setTitle(
            QApplication.translate("MainWindow",
                                   "Data collection"))  # Datenerfassung
        self.operationLabel.setText(
            QApplication.translate("MainWindow", "Forestry &operation") +
            ":")  # Forst&betrieb
        self.districtLabel.setText(
            QApplication.translate("MainWindow", "Forest &district") +
            ":")  # Forst&revier
        self.managerLabel.setText(
            QApplication.translate("MainWindow", "&District manager") +
            ":")  # &Revierleiter
        self.locationLabel.setText(
            QApplication.translate("MainWindow", "&Location") +
            ":")  # &Waldort
        self.taxLabel.setText(
            QApplication.translate("MainWindow", "&Sales tax") +
            ":")  # Mehrwert&steuer
        self.taxHint.setToolTip(
            QApplication.translate(
                "MainWindow",
                "Wirkt sich auf Vorgabewerte aus und kann nach\nAnlegen einer "
                "Variante nicht geändert werden."))

        # update the data widget
        self.dataWidget.retranslateUi()

        # update the chart and result view
        self.plotWidget.retranslateUi()
Beispiel #4
0
    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()
Beispiel #5
0
class VariantDataDialog(QDialog):
    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 updateCount(self, count):
        # TODO
        self.count = count

    def updateLength(self, length):
        # TODO
        self.length = length

    def retranslateUi(self):
        # dialog title
        self.setWindowTitle(QApplication.translate("VariantDataDialog", "Edit protection"))                         # Schutz bearbeiten

        # variant selection
        self.generalGroup.setTitle(QApplication.translate("VariantDataDialog", "Selection of protection"))          # Auswahl des Schutzes
        self.variantLabel.setText(QApplication.translate("VariantDataDialog", "Protection type") + ":")             # Schutztyp
        self.descriptionLabel.setText(QApplication.translate("VariantDataDialog", "Protection description") + ":")     # Schutzbeschreibung
        self.variantHint.setToolTip(QApplication.translate("VariantDataDialog",                                     # Bitte beachten Sie, dass Sie den Variantentyp später nicht mehr ändern können.
                "Keep in mind, that you can't change the variant type "
                "at a later time."))
        self.descriptionHint.setToolTip(QApplication.translate("VariantDataDialog",                                 # Geben Sie eine Beschreibung der Variante ein, um sie später identifizieren zu können.
                "Please describe the variant. The description helps you "
                "identify it."))

        # plant input
        self.plantGroup.setTitle(QApplication.translate("VariantDataDialog", "Cost of plants and planting"))        # Kosten Pflanze und Pflanzung
        self.speciesLabel.setText(QApplication.translate("VariantDataDialog", "Tree species") + ":")                # Baumart
        self.speciesHint.setToolTip("Text")
        self.speciesWarningText.setText(QApplication.translate("VariantDataDialog",
                "A fence with the selected species exists already!"))                                               # Es existiert bereits ein Zaun mit der ausgewählten Baumart!
        self.costLabel.setText(QApplication.translate("VariantDataDialog", "Unit cost") + "*:")                     # Stückkosten
        self.costHint.setToolTip("Text")
        self.costCalculator.setText(QApplication.translate("VariantDataDialog", "Calculation help"))                # Umrechnungshilfe
        self.preparationLabel.setText(QApplication.translate("VariantDataDialog", "Cost of preparation") + "*:")    # Kulturvorbereitung
        self.preparationHint.setToolTip("Text")
        self.preparationCalculator.setText(QApplication.translate("VariantDataDialog", "Calculation help"))         # Umrechnungshilfe
        self.plantingLabel.setText(QApplication.translate("VariantDataDialog", "Cost of planting") + "*:")          # Pflanzungskosten
        self.plantingHint.setToolTip("Text")
        self.plantingCalculator.setText(QApplication.translate("VariantDataDialog", "Calculation help"))            # Umrechnungshilfe
        self.tendingLabel.setText(QApplication.translate("VariantDataDialog", "Cost of tending (5 years)") + "*:")  # Kultursicherung
        self.tendingHint.setToolTip("Text")
        self.tendingCalculator.setText(QApplication.translate("VariantDataDialog", "Calculation help"))             # Umrechnungshilfe
        self.mortalityLabel.setText(QApplication.translate("MainWindow", "Decreased &mortality over fence") + ":")  # &Mortalitätsrate
        self.mortalityHint.setToolTip("Text")

    def help(self):
        # create the documentation path with
        # the current locale settings
        docFile = os.path.join("doc", "documentation_"
                + self.locale().name()[:2] + ".pdf")

        # on every platfrom a different
        # start operation is needed
        if sys.platform == "win32":
            os.startfile(docFile)
        elif sys.platform == "darwin":
            subprocess.call(("open", docFile))
        elif sys.platform.startswith("linux"):
            subprocess.call(("xdg-open", docFile))

    def variantChanged(self, index):
        # check for species
        self.checkSpecies()

        # update the visible status of the mortality input
        if index == Tube.TYPE:
            self.mortalityInput.setValue(10)
            self.mortalityInput.setEnabled(True)
        else:
            self.mortalityInput.setValue(0)
            self.mortalityInput.setDisabled(True)

        # set up the protection group
        self.protectionGroup.setCurrentIndex(index)

    def accept(self):
        # check name input field
        if not self.descriptionInput.text():
            warning = QMessageBox(self)
            warning.setWindowModality(Qt.WindowModal)  # check for mac only
            warning.setIcon(QMessageBox.Warning)
            warning.setStandardButtons(QMessageBox.Ok)
            warning.setWindowTitle(QApplication.translate("VariantDataDialog", "Wuchshüllenrechner"))
            warning.setText("<b>" + QApplication.translate("VariantDataDialog",
                    "The variant description is missing!") + "</b>")
            warning.setInformativeText(QApplication.translate("VariantDataDialog",
                    "Please describe your new variant."))

            warning.exec()
        else:
            # return the input values
            plant = Plant()
            plant.species = self.speciesInput.currentIndex()
            plant.cost = self.costInput.value()
            plant.preparation = self.preparationInput.value()
            plant.planting = self.plantingInput.value()
            plant.tending = self.tendingInput.value()
            plant.mortality = self.mortalityInput.value() / 100 if self.mortalityInput.value() > 0 else 0

            protection = self.protectionGroup.currentWidget().values()

            if not self.item:
                if protection.TYPE == Fence.TYPE:
                    color = QColor(255, 0, 0).name()
                else:
                    color = QColor(random.randint(0, 256), random.randint(0, 256),
                            random.randint(0, 256)).name()
            else:
                color = self.item[TreeModel.ColorRole]

            self.value = {
                TreeModel.NameRole : self.descriptionInput.text(),
                TreeModel.ColorRole : color,
                TreeModel.StatusRole : True,
                TreeModel.PlantRole : plant,
                TreeModel.ProtectionRole : protection
            }

            super().accept()

    def checkSpecies(self):
        species = self.speciesInput.currentIndex()

        # only for fence variants
        if self.variantInput.currentIndex() == Fence.TYPE:
            if not species == self.species and species in self.speciesRegistry:
                # first disable the OK button
                self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
                self.speciesWarningSymbol.show()
                self.speciesWarningText.show()
            else:
                self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True)
                self.speciesWarningSymbol.hide()
                self.speciesWarningText.hide()
        else:
            self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True)
            self.speciesWarningSymbol.hide()
            self.speciesWarningText.hide()

    def costCalculation(self):
        value = self.unitCostCalculator()
        if value > 0:
            self.costInput.setValue(value)

    def preparationCalculation(self):
        value = self.unitCostCalculator()
        if value > 0:
            self.preparationInput.setValue(value)

    def plantingCalculation(self):
        value = self.unitCostCalculator()
        if value > 0:
            self.plantingInput.setValue(value)

    def tendingCalculation(self):
        value = self.unitCostCalculator()
        if value > 0:
            self.tendingInput.setValue(value)

    def unitCostCalculator(self):
        dialog = UnitCostDialog(self.count)
        dialog.exec()

        # TODO
        self.count = dialog.count
        self.tubeWidget.count = self.count

        return dialog.value
Beispiel #6
0
    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()
Beispiel #7
0
class TubeInputWidget(QGroupBox):
    """Acquires a new plant protection variant for the cost calculation.

    The dialog contains two input fields to acquire a new plant protection variant.
    First there is a input field for the name of the new variant. The second
    input field asks about the used plant protection. The user cannot change
    the variant type at a later time.
    This class has no attributes or return values.

    """

    countChanged = pyqtSignal(int)

    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()

    def retranslateUi(self):
        # group title
        self.setTitle(QApplication.translate("TubeInputWidget", "Cost of tree shelter and maintenance"))            # Kosten Wuchshülle und Unterhaltung

        # tree shelter
        self.tubeLabel.setText(QApplication.translate("TubeInputWidget", "Tree shelter type") + ":")                # Wuchshüllentyp
        self.tubeHint.setToolTip("Text")
        self.costLabel.setText(QApplication.translate("TubeInputWidget", "Unit cost") + "*:")                       # Stückkosten
        self.costHint.setToolTip("Text")
        self.costCalculator.setText(QApplication.translate("TubeInputWidget", "Calculation help"))                  # Umrechnungshilfe
        self.accessoriesLabel.setText(QApplication.translate("TubeInputWidget", "Cost of accessories") + "*:")      # Stückkosten
        self.accessoriesHint.setToolTip("Text")
        self.accessoriesCalculator.setText(QApplication.translate("TubeInputWidget", "Calculation help"))           # Umrechnungshilfe
        self.installationLabel.setText(QApplication.translate("TubeInputWidget", "Cost of installation") + "*:")    # Installationskosten
        self.installationHint.setToolTip("Text")
        self.installationCalculator.setText(QApplication.translate("TubeInputWidget", "Calculation help"))          # Umrechnungshilfe
        self.maintenanceLabel.setText(QApplication.translate("TubeInputWidget", "Cost of maintenance") + "*:")      # Unterhaltungskosten
        self.maintenanceHint.setToolTip("Text")
        self.removalLabel.setText(QApplication.translate("TubeInputWidget", "Cost of removal") + "*:")              # Entsorgungskosten
        self.removalHint.setToolTip("Text")

    def setValues(self, protection):
        self.tubeInput.setCurrentIndex(protection.model)
        self.costInput.setValue(protection.cost)
        self.accessoriesInput.setValue(protection.accessories)
        self.installationInput.setValue(protection.installation)
        self.maintenanceInput.setValue(protection.maintenance)
        self.removalInput.setValue(protection.removal)

    def values(self):
        protection = Tube()
        protection.model = self.tubeInput.currentIndex()
        protection.cost = self.costInput.value()
        protection.accessories = self.accessoriesInput.value()
        protection.installation = self.installationInput.value()
        protection.maintenance =  self.maintenanceInput.value()
        protection.removal = self.removalInput.value()

        return protection

    def updateCost(self, index):
        # update tube cost
        self.costInput.setValue(library.TREESHELTERS_COST[index] * self.tax)

        # search the stake cost
        height = library.TREESHELTERS_HEIGHT[index]
        if height > 0:
            for i, stake in enumerate(library.STAKES_HEIGHT):
                if stake > height:
                    cost = library.STAKES_COST[i] * self.tax
                    break
        else:
            cost = 0

        self.accessoriesInput.setValue(cost)

        # installation cost
        if self.tubeInput.currentIndex():
            self.installationInput.setValue(library.TREESHELTERS_INSTALLATION * self.tax)
        else:
            self.installationInput.setValue(0)

        # removal cost
        if not self.tubeInput.currentIndex() in library.TREESHELTERS_NO_REMOVAL:
            self.removalInput.setValue(library.TREESHELTERS_REMOVAL * self.tax)
        else:
            self.removalInput.setValue(0)

    def updateMaintenanceAndRemoval(self, value):
        # 1/3 rule
        if not (self.maintenanceInput.value() and self.removalInput.value()):
            self.maintenanceInput.setValue(value)
            self.removalInput.setValue(value)

    def costCalculation(self):
        value = self.unitCostCalculator()
        if value > 0:
            self.costInput.setValue(value)

    def accessoriesCalculation(self):
        value = self.unitCostCalculator()
        if value > 0:
            self.accessoriesInput.setValue(value)

    def installationCalculation(self):
        value = self.unitCostCalculator()
        if value > 0:
            self.installationInput.setValue(value)

    def unitCostCalculator(self):
        dialog = UnitCostDialog(self.count)
        dialog.exec()

        # TODO
        self.count = dialog.count
        self.countChanged.emit(self.count)

        return dialog.value
Beispiel #8
0
class FenceInputWidget(QGroupBox):
    """Acquires a new plant protection variant for the cost calculation.

    The dialog contains two input fields to acquire a new plant protection variant.
    First there is a input field for the name of the new variant. The second
    input field asks about the used plant protection. The user cannot change
    the variant type at a later time.
    This class has no attributes or return values.

    """

    lengthChanged = pyqtSignal(int)

    def __init__(self, tax=True):
        """The constructor initializes the class NewVariantDialog."""
        super().__init__()

        self._LABEL_MIN_WIDTH = 240
        self._piece_unit = " St."
        self._length_unit = " Lfm."
        self._currency_unit = " " + self.locale().currencySymbol(QLocale.CurrencyIsoCode)
        self._currency_unit_length = self._currency_unit + "/" + self._length_unit.strip()
        self._spinbox_step = 0.05
        self.length = 0

        # determine the sales tax
        self.tax = 1.0 + library.SALES_TAX if tax else 1.0

        # input fields
        self.fenceInput = QComboBox()
        self.fenceInput.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        self.fenceInput.addItems(library.FENCE_DESCRIPTION)
        self.fenceLabel = QLabel()
        self.fenceLabel.setMinimumWidth(self._LABEL_MIN_WIDTH)
        self.fenceLabel.setBuddy(self.fenceInput)
        self.fenceHint = ToolTipLabel()
        self.fenceHint.hide()

        self.installationInput = QDoubleSpinBox()
        self.installationInput.setSuffix(self._currency_unit_length)
        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_length)
        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_length)
        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.fenceLabel, 0, 0)
        layout.addWidget(self.fenceInput, 0, 1)
        layout.addWidget(self.fenceHint, 0, 2)
        layout.addWidget(self.installationLabel, 1, 0)
        layout.addWidget(self.installationInput, 1, 1)
        layout.addWidget(self.installationHint, 1, 2)
        layout.addWidget(self.installationCalculator, 1, 3)
        layout.addWidget(self.maintenanceLabel, 2, 0)
        layout.addWidget(self.maintenanceInput, 2, 1)
        layout.addWidget(self.maintenanceHint, 2, 2)
        layout.addWidget(self.removalLabel, 3, 0)
        layout.addWidget(self.removalInput, 3, 1)
        layout.addWidget(self.removalHint, 3, 2)
        layout.addItem(spacerBottom, 4, 0, 1, 3)

        # connect actions
        self.installationCalculator.clicked.connect(self.installationCalculation)
        self.fenceInput.currentIndexChanged.connect(self.updateCost)

        # translate the graphical user interface
        self.retranslateUi()

    def retranslateUi(self):
        # group title
        self.setTitle(QApplication.translate("FenceInputWidget", "Cost of fence and maintenance"))                  # Kosten Zaun und Unterhaltung

        # fence
        self.fenceLabel.setText(QApplication.translate("FenceInputWidget", "Fence type") + ":")                     # Zauntyp
        self.fenceHint.setToolTip("Text")
        self.installationLabel.setText(QApplication.translate("FenceInputWidget", "Cost of installation") + "*:")   # Installationskosten
        self.installationHint.setToolTip("Text")
        self.installationCalculator.setText(QApplication.translate("FenceInputWidget", "Calculation help"))         # Umrechnungshilfe
        self.maintenanceLabel.setText(QApplication.translate("FenceInputWidget", "Cost of maintenance") + "*:")     # Unterhaltungskosten
        self.maintenanceHint.setToolTip("Text")
        self.removalLabel.setText(QApplication.translate("FenceInputWidget", "Cost of removal") + "*:")             # Abbaukosten
        self.removalHint.setToolTip("Text")

    def setValues(self, protection):
        self.fenceInput.setCurrentIndex(protection.model)
        self.installationInput.setValue(protection.installation / 3)
        self.maintenanceInput.setValue(protection.installation / 3)
        self.removalInput.setValue(protection.installation / 3)

    def values(self):
        protection = Fence()
        protection.model = self.fenceInput.currentIndex()
        protection.installation = self.installationInput.value() + self.maintenanceInput.value() + self.removalInput.value()

        return protection

    def updateCost(self, index):
        cost = library.FENCE_COST[index] * self.tax / 3

        self.installationInput.setValue(cost)
        self.maintenanceInput.setValue(cost)
        self.removalInput.setValue(cost)

    def installationCalculation(self):
        value = self.unitCostCalculator()
        if value > 0:
            self.installationInput.setValue(value)

    def unitCostCalculator(self):
        dialog = UnitCostDialog(self.length, False)
        dialog.exec()

        # TODO
        self.length = dialog.count
        self.lengthChanged.emit(self.length)

        return dialog.value
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)

        # initialize class attributes
        self._INPUTS_FIXED_WIDTH = 180
        self._BUTTON_MIN_WIDTH = 80
        self._OXYGEN_PATH_32 = os.path.join("resources", "icons", "oxygen", "32")

        # locale and language settings
        self.language = self.locale().name()[:2]
        self.qtTl = QTranslator()
        self.appTl = QTranslator()
        self.switchTranslator(self.qtTl, "qtbase", self.language)
        self.switchTranslator(self.appTl, "wuchshuellenrechner", self.language)

        # TODO(th)
        self.model = TreeModel()

        # setup gui
        self.setMinimumSize(1200, 760)

        self.createActions()
        self.createMainMenu()

        # plot widget
        self.plotWidget = VariantPlotView()
        self.plotWidget.setModel(self.model)

        # create vertical splitter
        splitter = QSplitter(Qt.Vertical)
        splitter.setContentsMargins(11, 11, 11, 11)
        splitter.addWidget(self.createEditBox())
        splitter.addWidget(self.plotWidget)

        self.setCentralWidget(splitter)

        self.dataWidget.setModel(self.model)

        selectionModel = QItemSelectionModel(self.model)
        self.dataWidget.setSelectionModel(selectionModel)
        self.plotWidget.setSelectionModel(selectionModel)

        self.retranslateUi()


        self.model.dataChanged.connect(self.updateInputs)
        self.model.itemsInserted.connect(self.taxInput.setDisabled)
        self.model.allItemsRemoved.connect(self.taxInput.setEnabled)
        self.operationInput.textChanged.connect(self.updateOperation)
        self.districtInput.textChanged.connect(self.updateDistrict)
        self.managerInput.textChanged.connect(self.updateManager)
        self.locationInput.textChanged.connect(self.updateLocation)
        self.taxInput.stateChanged.connect(self.updateTax)

    def updateOperation(self, value):
        self.model.setProjectData("operation", value)

    def updateDistrict(self, value):
        self.model.setProjectData("district", value)

    def updateManager(self, value):
        self.model.setProjectData("manager", value)

    def updateLocation(self, value):
        self.model.setProjectData("location", value)

    def updateTax(self):
        self.model.setProjectData("tax", self.taxInput.isChecked())
        self.dataWidget.tax = self.taxInput.isChecked()

    def updateInputs(self):
        self.operationInput.setText(self.model.projectData("operation"))
        self.districtInput.setText(self.model.projectData("district"))
        self.managerInput.setText(self.model.projectData("manager"))
        self.locationInput.setText(self.model.projectData("location"))

        self.taxInput.setChecked(self.model.projectData("tax"))

    def loadLanguage(self, language):
        if not self.language == language:
            self.language = language

            locale = QLocale(language)
            QLocale.setDefault(locale)

            self.switchTranslator(self.qtTl, "qtbase", language)
            self.switchTranslator(self.appTl, "wuchshuellenrechner", language)

            # update gui
            self.retranslateUi()
            self.dataWidget.retranslateUi()

    def switchTranslator(self, translator, filename, language):
        app = QApplication.instance()

        # remove the old translator and
        # try to load a new language file
        app.removeTranslator(translator)
        if translator.load(QLocale(), filename, "_", "language"):
            app.installTranslator(translator)

    def setTaxEnabled(self, enable):
        # enable buttons and the view element
        self.removeButton.setEnabled(enable)
        self.modifyButton.setEnabled(enable)
        self.view.setEnabled(enable)

    def setDisabled(self, disable):
        # internaly call the setEnabled function
        # therefore negate the boolean value
        self.setEnabled(not disable)

    def aboutAction(self):
        aboutDialog = AboutDialog()
        aboutDialog.exec()

    def clear(self):
        # first clear the model
        self.model.clear()

        # update fields with model's default values
        self.operationInput.setText(self.model.projectData("operation"))
        self.districtInput.setText(self.model.projectData("district"))
        self.managerInput.setText(self.model.projectData("manager"))
        self.locationInput.setText(self.model.projectData("location"))

        self.taxInput.setEnabled(True)
        self.taxInput.setChecked(self.model.projectData("tax"))

        # reset the tree view
        self.dataWidget.clear()

        # reset the chart and result view
        # actually this is necassary
        self.plotWidget.clear()

    def closeAction(self):
        if self.model.changed:
            question = QMessageBox()
            question.setIcon(QMessageBox.Question)
            question.setWindowTitle("Berechnung speichern? - Wuchshüllenrechner")
            question.setText("Möchten Sie die Änderungen an dieser Berechnung speichern?")
            question.setInformativeText("Die Änderungen gehen verloren, wenn Sie nicht speichern.")
            question.setStandardButtons(QMessageBox.Save|QMessageBox.Discard|QMessageBox.Cancel)
            question.setDefaultButton(QMessageBox.Save)
            reply = question.exec()

            if not reply == QMessageBox.Cancel:
                if reply == QMessageBox.Save:
                    if self.saveAction():
                        self.close()
                else:
                    self.close()
        else:
            self.close()

    def newAction(self):
        if self.model.changed:
            question = QMessageBox()
            question.setIcon(QMessageBox.Question)
            question.setWindowTitle("Berechnung speichern? - Wuchshüllenrechner")
            question.setText("Möchten Sie die Änderungen an dieser Berechnung speichern?")
            question.setInformativeText("Die Änderungen gehen verloren, wenn Sie nicht speichern.")
            question.setStandardButtons(QMessageBox.Save|QMessageBox.Discard|QMessageBox.Cancel)
            question.setDefaultButton(QMessageBox.Save)
            reply = question.exec()

            if not reply == QMessageBox.Cancel:
                if reply == QMessageBox.Save:
                    if self.saveAction():
                        # clear all
                        self.clear()
                else:
                    # clear all
                    self.clear()

    def checkSaveState(self):
        if self.model.changed:
            question = QMessageBox(self)
            question.setWindowModality(Qt.WindowModal)  # check for mac only
            question.setIcon(QMessageBox.Warning)
            question.setStandardButtons(QMessageBox.Save|QMessageBox.Discard|QMessageBox.Cancel)
            question.setDefaultButton(QMessageBox.Save)
            question.setWindowTitle(QApplication.translate("MainWindow", "Wuchshüllenrechner"))
            question.setText("<b>" + QApplication.translate("MainWindow",
                    "Do you want to save the changes you made<br>"
                    "to the current calculation?") + "</b>")
            question.setInformativeText(QApplication.translate("MainWindow",
                    "Your changes will be lost if you don't save them."))

            reply = question.exec()
            if reply == QMessageBox.Save:
                if self.saveAction():
                    #self.model.clear()
                    self.clear()
                    return True
                else:
                    return False
            elif reply == QMessageBox.Discard:
                #self.model.clear()
                self.clear()
                return True
            else:
                return False

        # always clear
        self.clear()

        return True

    def loadExample(self, example=""):
        # create the path
        exampleFile = os.path.join("examples", example.strip() + ".xml")

         # if all is save, open the example file
        if self.checkSaveState():
            self.model.readFile(exampleFile)

    def mapleAction(self):
        self.loadExample("great_maple")

    def douglasAction(self):
        self.loadExample("douglas_fir")

    def openAction(self):
        # first check save state of the current calculation
        if self.checkSaveState():
            dialog = QFileDialog(self)
            dialog.setWindowModality(Qt.WindowModal)    # check for mac only
            dialog.setWindowTitle(QApplication.translate("MainWindow", "Open Calculation"))
            dialog.setDirectory(os.path.expanduser("~"))
            dialog.setNameFilter(QApplication.translate("MainWindow",
                    "XML files (*.xml);;All Files (*)"))

            dialog.exec()
            filename = dialog.selectedFiles()
            if filename:
                self.model.readFile(filename.pop())

    def saveAction(self):
        if self.model.file:
            return self.model.saveFile()
        else:
            return self.saveAsAction()

    def saveAsAction(self):
        dialog = QFileDialog(self)
        dialog.setWindowModality(Qt.WindowModal)    # check for mac only
        dialog.setAcceptMode(QFileDialog.AcceptSave)
        dialog.setWindowTitle(QApplication.translate("MainWindow", "Save Calculation"))
        dialog.setDirectory(os.path.expanduser("~"))
        dialog.setNameFilter(QApplication.translate("MainWindow",
                "XML files (*.xml);;All Files (*)"))

        dialog.exec()
        filename = dialog.selectedFiles()
        if filename:
            self.model.saveFile(filename.pop())
            return True
        else:
            return False

    def exportAction(self):
        dialog = QFileDialog(self)
        dialog.setWindowModality(Qt.WindowModal)    # check for mac only
        dialog.setAcceptMode(QFileDialog.AcceptSave)
        dialog.setWindowTitle(QApplication.translate("MainWindow", "Export Calculation"))
        dialog.setDirectory(os.path.expanduser("~"))
        dialog.setNameFilter(QApplication.translate("MainWindow",
                "PNG files (*.png);;JPG files (*.jpg);;TIFF files (*.tif)"))

        if dialog.exec():
            filename = dialog.selectedFiles()
            self.plotWidget.plotWidget.plotWidget.export(filename.pop())

    def helpAction(self):
        # create the documentation path with
        # the current locale settings
        docFile = os.path.join("doc", "documentation_" + self.language + ".pdf")

        # on every platfrom a different
        # start operation is needed
        if sys.platform == "win32":
            os.startfile(docFile)
        elif sys.platform == "darwin":
            subprocess.call(("open", docFile))
        elif sys.platform.startswith("linux"):
            subprocess.call(("xdg-open", docFile))

    def scientificAction(self):
        scientificDialog = ScientificBasisDialog()
        scientificDialog.exec()

    def germanAction(self):
        # update language menu
        self.languageEnglish.setChecked(False)
        self.languageGerman.setChecked(True)

        # update gui
        self.loadLanguage("de")

    def englishAction(self):
        # update language menu
        self.languageGerman.setChecked(False)
        self.languageEnglish.setChecked(True)

        # update gui
        self.loadLanguage("en")

    def createActions(self):
        # all actions for the calculation menu
        # create the new calculation action
        self.calculationNew = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "document-new.png")),
                shortcut=QKeySequence.New, triggered=self.newAction)

        # create the open calculation action
        self.calculationOpen = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "document-open.png")),
                shortcut=QKeySequence.Open, triggered=self.openAction)

        # create the open calculation example actions
        # for great maple and douglas fir
        self.examplesMaple = QAction(self, triggered=self.mapleAction)
        self.examplesDouglas = QAction(self, triggered=self.douglasAction)

        # create the save calculation action
        self.calculationSave = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "document-save.png")),
                shortcut=QKeySequence.Save, triggered=self.saveAction)

        # create the save as action
        self.calculationSaveAs = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "document-save-as.png")),
                shortcut=QKeySequence.SaveAs, triggered=self.saveAsAction)

        # create the print calculation action
        #self.calculationPrint = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "document-print.png")),
        #        shortcut=QKeySequence.Print, triggered=self.printAction)

        # create the export calculation action
        self.calculationExport = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "document-export.png")),
                shortcut=QKeySequence(Qt.CTRL + Qt.Key_E), triggered=self.exportAction)

        # create the quit calculation action
        self.calculationQuit = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "application-exit.png")),
                shortcut=QKeySequence.Quit, triggered=self.closeAction)

        # all actions for the language menu
        # create the german and the english language actions
        self.languageGerman = QAction(self, checkable=True, triggered=self.germanAction)
        self.languageEnglish = QAction(self, checkable=True, triggered=self.englishAction)

        # update the language menu
        if self.language == "de":
            self.languageGerman.setChecked(True)
        elif self.language == "en":
            self.languageEnglish.setChecked(True)

        # create the help contents action
        self.helpContents = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "help-contents.png")),
                triggered=self.helpAction)

        # create the scientific basis action
        self.scientificBasis = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "applications-science.png")),
                triggered=self.scientificAction)

        # create the help about action
        self.helpAbout = QAction(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "dialog-information.png")),
                triggered=self.aboutAction)

    def createMainMenu(self):
        # create main menu bar
        self.menu = self.menuBar()

        # create file menu
        self.calculationMenu = QMenu(self)
        self.calculationMenu.addAction(self.calculationNew)
        self.calculationMenu.addAction(self.calculationOpen)

        self.examplesMenu = QMenu(self, icon=QIcon(os.path.join(self._OXYGEN_PATH_32, "folder-documents.png")))
        self.examplesMenu.addAction(self.examplesMaple)
        self.examplesMenu.addAction(self.examplesDouglas)
        self.calculationMenu.addMenu(self.examplesMenu)
        self.calculationMenu.addSeparator()

        self.calculationMenu.addAction(self.calculationSave)
        self.calculationMenu.addAction(self.calculationSaveAs)
        self.calculationMenu.addAction(self.calculationExport)
        self.calculationMenu.addSeparator()

        #self.calculationMenu.addAction(self.calculationPrint)
        #self.calculationMenu.addSeparator()

        self.calculationMenu.addAction(self.calculationQuit)

        self.menu.addMenu(self.calculationMenu)

        # create language menu
        self.languageMenu = QMenu(self)
        self.languageMenu.addAction(self.languageGerman)
        self.languageMenu.addAction(self.languageEnglish)
        self.menu.addMenu(self.languageMenu)

        # create help menu
        self.helpMenu = QMenu(self)
        self.helpMenu.addAction(self.helpContents)
        self.helpMenu.addAction(self.scientificBasis)
        self.helpMenu.addSeparator()
        self.helpMenu.addAction(self.helpAbout)
        self.menu.addMenu(self.helpMenu)

    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 retranslateUi(self):
        # main window title
        self.setWindowTitle(QApplication.translate("MainWindow", "Wuchshüllenrechner"))     # Wuchshüllenrechner

        # all menu actions
        # first the calculation menu
        self.calculationMenu.setTitle(QApplication.translate("MainWindow", "&Calculation"))     # Kalkulation
        self.calculationNew.setText(QApplication.translate("MainWindow", "&New"))               # &Neu
        self.calculationOpen.setText(QApplication.translate("MainWindow", "&Open"))             # Ö&ffnen
        self.calculationSave.setText(QApplication.translate("MainWindow", "&Save"))             # &Speichern
        self.calculationSaveAs.setText(QApplication.translate("MainWindow", "&Save as"))        # &Speichern unter
        #self.calculationPrint.setText(QApplication.translate("MainWindow", "&Print"))           # &Drucken
        self.calculationExport.setText(QApplication.translate("MainWindow", "&Export"))         # &Exportieren
        self.calculationQuit.setText(QApplication.translate("MainWindow", "E&xit"))             # &Beenden

        # now the examples menu
        self.examplesMenu.setTitle(QApplication.translate("MainWindow", "E&xamples"))           # &Beispiele
        self.examplesMaple.setText(QApplication.translate("MainWindow",
                "&Calculation example for great &maple"))                                       # Berechnungsbeispiel für Berg-&Ahorn
        self.examplesDouglas.setText(QApplication.translate("MainWindow",
                "&Calculation example for &douglas fir"))                                       # Berechnungsbeispiel für Küsten-Douglasie

        # the language menu
        self.languageMenu.setTitle(QApplication.translate("MainWindow", "&Language"))           # &Sprache
        self.languageGerman.setText(QApplication.translate("MainWindow", "&German"))            # &Deutsch
        self.languageEnglish.setText(QApplication.translate("MainWindow", "&English"))          # &Englisch

        # the help menu
        self.helpMenu.setTitle(QApplication.translate("MainWindow", "&Help"))                   # &Hilfe
        self.helpContents.setText(QApplication.translate("MainWindow", "Help &Contents"))       # &Hilfe anzeigen
        self.scientificBasis.setText(QApplication.translate("MainWindow", "Specialist &articles")) # &Fachbeiträge
        self.helpAbout.setText(QApplication.translate("MainWindow",
                "&About Wuchshüllenrechner"))                                                   # Über &Wuchshüllenrechner

        # the edit box for data collection
        self.editBox.setTitle(QApplication.translate("MainWindow", "Data collection"))          # Datenerfassung
        self.operationLabel.setText(QApplication.translate("MainWindow",
                "Forestry &operation") + ":")                                                   # Forst&betrieb
        self.districtLabel.setText(QApplication.translate("MainWindow",
                "Forest &district") + ":")                                                      # Forst&revier
        self.managerLabel.setText(QApplication.translate("MainWindow",
                "&District manager") + ":")                                                     # &Revierleiter
        self.locationLabel.setText(QApplication.translate("MainWindow",
                "&Location") + ":")                                                             # &Waldort
        self.taxLabel.setText(QApplication.translate("MainWindow",
                "&Sales tax") + ":")                                                            # Mehrwert&steuer
        self.taxHint.setToolTip(QApplication.translate("MainWindow",
                "Wirkt sich auf Vorgabewerte aus und kann nach\nAnlegen einer "
                "Variante nicht geändert werden."))

        # update the data widget
        self.dataWidget.retranslateUi()

        # update the chart and result view
        self.plotWidget.retranslateUi()