SLDialog.py 1.35 KiB
# -*- coding: utf-8 -*-

from View.ASubWindow import ASubWindow
from View.ListedSubWindow import ListedSubWindow

from PyQt5.QtGui import (
    QKeySequence,
)

from PyQt5.QtCore import (
    Qt, QVariant, QAbstractTableModel,
)

from PyQt5.QtWidgets import (
    QDialogButtonBox, QComboBox, QUndoStack, QShortcut,
    QDoubleSpinBox,
)

from View.SedimentLayers.Reach.translate import *

_translate = QCoreApplication.translate

class SLDialog(ASubWindow, ListedSubWindow):
    def __init__(self, title="SL", study=None, parent=None):
        self._study = study

        super(SLDialog, self).__init__(
            name=title, ui="SLDialog", parent=parent
        )

        self.setup_combobox()

        self.value = None

    def setup_combobox(self):
        self.combobox_add_items(
            "comboBox",
            [_translate("SedimentLayers", "Not defined")] +
            list(
                map(
                    lambda sl: str(sl),
                    self._study.river.sediment_layers.sediment_layers
                )
            )
        )

    @property
    def sl(self):
        return next(
            filter(
                lambda sl: str(sl) == self.value,
                self._study.river.sediment_layers.sediment_layers
            )
        )

    def accept(self):
        self.value = self.get_combobox_text("comboBox")
        super().accept()