Пример #1
0
    def __init__(self, parent, name, conv, grid, ordinal, browse=False, width=None):
        ParaWidget.__init__(self, parent)
        self.name = name
        self.v2tx = conv[0]
        self.tx2v = conv[1]
        self.grid = grid
        self.ordinal = ordinal
        self.browse = browse

        self.label = QLabel(self)
        self.edit = QLineEdit()
        if width:
            self.edit.setFixedWidth(width)
        self.button = QPushButton()
        self.err_label = QLabel(self)
        self.err_label.setStyleSheet(Style.error())
        self.err_label.setVisible(False)

        self.edit.textChanged.connect(self.parameter_changed)
        self.edit.editingFinished.connect(self.parameter_finished)
        self.button.clicked.connect(self.button_clicked)

        grid.addWidget(self.label, ordinal, 1)
        grid.addWidget(self.edit, ordinal, 2)
        if self.browse:
            grid.addWidget(self.button, ordinal, 3)
        grid.addWidget(self.err_label, ordinal + 1, 1, 1, 3)

        self.on_switch_language()
        self.on_switch_configuration()
Пример #2
0
 def parameter_changed(self, text):
     try:
         value = self.tx2v(text)
         setattr(self.paras, self.name, value)
         self.accepted = True
         self.err_label.setText("")
         self.err_label.setVisible(False)
         self.edit.setStyleSheet(Style.default())
         self.label.setStyleSheet(Style.default())
         self.edit.setToolTip(None)
     except ValueError as err:
         self.accepted = False
         self.err_label.setText(str(err))
         self.err_label.setVisible(True)
         self.edit.setStyleSheet(Style.error())
         self.label.setStyleSheet(Style.error())
Пример #3
0
 def parameter_finished(self):
     try:
         value = self.tx2v(self.edit.text())
         setattr(self.paras, self.name, value)
         self.paras.save_configuration()
         self.accepted = True
         self.err_label.setText("")
         self.err_label.setVisible(False)
         value = self.v2tx(getattr(self.paras, self.name))
         self.edit.setText(value)
         self.edit.setStyleSheet(Style.default())
         self.label.setStyleSheet(Style.default())
     except ValueError as err:
         self.accepted = False
         self.err_label.setText(str(err))
         self.err_label.setVisible(True)
         self.edit.setStyleSheet(Style.error())
         self.label.setStyleSheet(Style.error())