def _addSwitch(self, v, cnt):
     control = QCheckBox(v.name)
     control.setChecked(v.value)
     control.setFocusPolicy(Qt.StrongFocus)
     f = control.font()
     f.setPointSizeF(11)
     control.setFont(f)
     control.tag = cnt
     if self.styleName == "mac":
         control.setAttribute(Qt.WA_MacSmallSize, True)
     self.layout.addWidget(control, cnt, 1)
     self.connect(control, SIGNAL("stateChanged(int)"), self.booleanChanged_)
Beispiel #2
0
 def _addSwitch(self, v, cnt):
     control = QCheckBox(v.name)
     control.setChecked(v.value)
     control.setFocusPolicy(Qt.StrongFocus)
     f = control.font()
     f.setPointSizeF(11)
     control.setFont(f)
     control.tag = cnt
     if self.styleName == "mac":
         control.setAttribute(Qt.WA_MacSmallSize, True)
     self.layout.addWidget(control, cnt, 1)
     self.connect(control, SIGNAL("stateChanged(int)"),
                  self.booleanChanged_)
class PlotScalesWidget(QWidget):
    plotScaleChanged = pyqtSignal()

    def __init__(self, type_key, title, select_min_time_value=False):
        QWidget.__init__(self)

        self.__type_key = type_key
        self.__type = None

        self.__double_spinner = self.createDoubleSpinner(minimum=-99999999.0, maximum=99999999.0)
        self.__integer_spinner = self.createIntegerSpinner(minimum=0, maximum=999999999)

        self.__time_map = ReportStepsModel().getList()
        self.__time_index_map = {}
        for index in range(len(self.__time_map)):
            time = self.__time_map[index]
            self.__time_index_map[time] = index

        self.__time_spinner = self.createTimeSpinner(select_minimum_value=select_min_time_value)

        layout = QVBoxLayout()
        self.setLayout(layout)

        self.__checkbox = QCheckBox(title)
        self.__checkbox.setChecked(False)

        self.__stack = QStackedWidget()
        self.__stack.setSizePolicy(QSizePolicy(QSizePolicy.Minimum))
        self.__stack.addWidget(self.__integer_spinner)
        self.__stack.addWidget(self.__double_spinner)
        self.__stack.addWidget(self.__time_spinner)

        layout.addWidget(self.__stack)
        layout.addWidget(self.__checkbox)

        self.__checkbox.stateChanged.connect(self.toggleCheckbox)
        self.setLayout(layout)

    def createDoubleSpinner(self, minimum, maximum):
        spinner = QDoubleSpinBox()
        spinner.setEnabled(False)
        spinner.setMinimumWidth(75)
        spinner.setRange(minimum, maximum)
        spinner.setKeyboardTracking(False)

        spinner.editingFinished.connect(self.plotScaleChanged)
        spinner.valueChanged.connect(self.plotScaleChanged)

        return spinner

    def createIntegerSpinner(self, minimum, maximum):
        spinner = QSpinBox()
        spinner.setEnabled(False)
        spinner.setMinimumWidth(75)
        spinner.setRange(minimum, maximum)
        spinner.setKeyboardTracking(False)

        spinner.editingFinished.connect(self.plotScaleChanged)
        spinner.valueChanged.connect(self.plotScaleChanged)

        return spinner

    def createTimeSpinner(self, select_minimum_value):
        def converter(item):
            return "%s" % (str(item.date()))

        spinner = ListSpinBox(self.__time_map)
        spinner.setEnabled(False)
        spinner.setMinimumWidth(75)

        if select_minimum_value:
            spinner.setValue(0)

        spinner.valueChanged[int].connect(self.plotScaleChanged)
        spinner.editingFinished.connect(self.plotScaleChanged)
        spinner.setStringConverter(converter)

        return spinner


    def getValue(self):
        if self.__type is int:
            return self.__integer_spinner.value()
        elif self.__type is float:
            return self.__double_spinner.value()
        elif self.__type is CTime:
            index = self.__time_spinner.value()
            return self.__time_map[index]
        else:
            raise TypeError("Unsupported spinner type: %s" % self.__type)


    def toggleCheckbox(self):
        checked = self.isChecked()
        self.__double_spinner.setEnabled(checked)
        self.__integer_spinner.setEnabled(checked)
        self.__time_spinner.setEnabled(checked)
        self.plotScaleChanged.emit()


    def isChecked(self):
        return self.__checkbox.isChecked()


    def setChecked(self, checked):
        self.__checkbox.setChecked(checked)


    def setValue(self, value):
        self.setChecked(value is not None)

        if value is not None:
            if self.__type is int:
                self.__integer_spinner.setValue(int(value))
            elif self.__type is float:
                self.__double_spinner.setValue(value)
            elif self.__type is CTime:
                index = self.__time_index_map[value]
                self.__time_spinner.setValue(index)
            else:
                raise TypeError("Unsupported spinner type: %s" % self.__type)


    def setFontSize(self, size):
        font = self.__double_spinner.font()
        font.setPointSize(size)
        self.__double_spinner.setFont(font)

        font = self.__integer_spinner.font()
        font.setPointSize(size)
        self.__integer_spinner.setFont(font)

        font = self.__time_spinner.font()
        font.setPointSize(size)
        self.__time_spinner.setFont(font)

        font = self.__checkbox.font()
        font.setPointSize(size)
        self.__checkbox.setFont(font)


    def setType(self, spinner_type):
        self.__type = spinner_type
        if spinner_type is int:
            self.__stack.setCurrentWidget(self.__integer_spinner)
        elif spinner_type is float:
            self.__stack.setCurrentWidget(self.__double_spinner)
        elif spinner_type is CTime:
            self.__stack.setCurrentWidget(self.__time_spinner)
        else:
            raise TypeError("Unsupported spinner type: %s" % spinner_type)


    def getType(self):
        return self.__type