Example #1
0
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)

        self.strip_tool = QTangoStripTool("Test", legend_pos="right")
        self.stop_button = QtWidgets.QPushButton("STOP")
        self.stop_button.clicked.connect(self.stop)
        self.start_button = QtWidgets.QPushButton("START")
        self.start_button.clicked.connect(self.start)
        l2 = QtWidgets.QHBoxLayout()
        l2.addWidget(self.start_button)
        l2.addWidget(self.stop_button)
        self.stop_thread_flag = False
        self.setLayout(QtWidgets.QVBoxLayout())
        self.layout().addLayout(l2)
        self.layout().addWidget(self.strip_tool)
        self.thread_list = list()
        self.n_points = 100
        self.n_curves = 3

        self.setup_curves()
        st = """QPushButton {{ border-width: 2px;
                      border-color: {1};
                      border-style: solid; 
                      border-radius: 0px;
                      color: {1};}}
                QWidget {{
                              background-color: {0};
                              }}""".format(QTangoColors().backgroundColor,
                                           QTangoColors().secondaryColor0)
        self.setStyleSheet(st)
        self.update()
Example #2
0
    def __init__(self, sizes=None, colors=None, parent=None):
        QtWidgets.QDoubleSpinBox.__init__(self, parent)
        self.setLocale(QtCore.QLocale(QtCore.QLocale.English))

        # 		Setting up event handling:
        self.lineEdit().cursorPositionChanged.connect(self.changeStep)
        self.lineEdit().updateWriteValue.connect(self.editReady)
        self.lineEdit().returnPressed.connect(self.editReady)
        self.setKeyboardTracking(False)
        self.valueChanged.connect(self.valueReady)
        self.editingFinished.connect(self.editReady)

        self.storedCursorPos = 0
        self.lastKey = QtCore.Qt.Key_0
        if colors is None:
            self.attrColors = QTangoColors()
        else:
            self.attrColors = colors
        if sizes is None:
            self.sizes = QTangoSizes()
        else:
            self.sizes = sizes
        s = ''.join(
            ('QDoubleSpinBox { \n', 'background-color: ',
             self.attrColors.backgroundColor, '; \n',
             'selection-background-color: ', self.attrColors.secondaryColor0,
             '; \n', 'selection-color: ',
             self.attrColors.backgroundColor, '; \n', 'border-width: ',
             str(int(self.sizes.barHeight / 10)), 'px; \n', 'border-color: ',
             self.attrColors.secondaryColor0, '; \n',
             'border-top-style: none; \n', 'border-bottom-style: none; \n',
             'border-left-style: double; \n', 'border-right-style: solid; \n',
             'border-radius: 0px; \n', 'padding: 0px; \n', 'margin: 0px; \n',
             'qproperty-buttonSymbols: NoButtons; \n', 'min-width: ',
             str(int(self.sizes.barHeight) * 2.5), 'px; \n', 'max-width: ',
             str(int(self.sizes.barHeight) * 2.5), 'px; \n', 'min-height: ',
             str(int(self.sizes.barHeight)), 'px; \n', 'max-height: ',
             str(int(
                 self.sizes.barHeight)), 'px; \n', 'qproperty-readOnly: 0; \n',
             'color: ', self.attrColors.secondaryColor0, ';} \n'))
        font = self.font()
        font.setFamily(self.sizes.fontType)
        font.setStretch(self.sizes.fontStretch)
        font.setWeight(self.sizes.fontWeight)
        font.setPointSize(int(self.sizes.barHeight * 0.7))
        font.setStyleStrategy(QtGui.QFont.PreferAntialias)
        self.setFont(font)

        self.setStyleSheet(s)
        self.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                           QtWidgets.QSizePolicy.Minimum)
        self.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignBottom)
        self.setMaximum(1e9)
        self.setMinimum(-1e9)
Example #3
0
 def __init__(self, sizes=None, colors=None, parent=None):
     QtWidgets.QWidget.__init__(self, parent)
     if colors is None:
         self.attrColors = QTangoColors()
     else:
         self.attrColors = colors
     if sizes is None:
         self.sizes = QTangoSizes()
     else:
         self.sizes = sizes
     self.cmdButtons = OrderedDict()
     self.layout = None
     self.setupLayout()
Example #4
0
    def __init__(self, title='', sizes=None, colors=None, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        if title is None:
            self.title = ''
        else:
            self.title = title
        if sizes is None:
            self.sizes = QTangoSizes()
        else:
            self.sizes = sizes
        if colors is None:
            self.attrColors = QTangoColors()
        else:
            self.attrColors = colors

        self.setupLayout()
Example #5
0
 def __init__(self, name, horizontal=True, sizes=None, colors=None, parent=None):
     QtGui.QWidget.__init__(self, parent)
     if colors is None:
         self.attrColors = QTangoColors()
     else:
         self.attrColors = colors
     if sizes is None:
         self.sizes = QTangoSizes()
     else:
         self.sizes = sizes
     self.layout = None
     self.name = name
     self.title_bar = None
     self.side_bar = None
     self.layout_bar = None
     self.layout_content = None
     self.setupLayout(horizontal)
Example #6
0
 def __init__(self, sizes=None, colors=None, parent=None):
     QtWidgets.QLabel.__init__(self, parent)
     if colors is None:
         self.attrColors = QTangoColors()
     else:
         self.attrColors = colors
     if sizes is None:
         self.sizes = QTangoSizes()
     else:
         self.sizes = sizes
     self.setText('')
     st = ''.join(('QLabel {min-height: ', str(self.sizes.barHeight / 2), 'px; \n',
                   'max-height: ', str(int(self.sizes.barHeight / 2)), 'px; \n',
                   'min-width: ', str(int(self.sizes.barHeight / 2)), 'px; \n',
                   'max-width: ', str(int(self.sizes.barHeight / 2)), 'px; \n',
                   'border-width: 1px; \n',
                   'border-color: ', self.attrColors.secondaryColor0, '; \n',
                   'border-style: solid; \n',
                   'border-radius: 0px; \n',
                   'padding: 0px; \n',
                   'margin: 0px; \n',
                   'background-color: ', self.attrColors.backgroundColor, ';}'))
     self.setStyleSheet(st)
Example #7
0
 def __init__(self):
     QtWidgets.QFrame.__init__(self)
     QTangoAttributeBase.__init__(self)
     self.setObjectName(self.__class__.__name__)
     self.l1 = QtWidgets.QLabel("test")
     self.l2 = QtWidgets.QLabel("apa")
     self.setLayout(QtWidgets.QHBoxLayout())
     self.layout().addWidget(self.l1)
     self.layout().addWidget(self.l2)
     self.attrColors = QTangoColors()
     st = ''.join(
         ("DummyLabel {\n", 'border-width: 2px; \n', 'border-color: ',
          self.attrColors.secondaryColor0, '; \n',
          'border-style: solid; \n', 'border-radius: 0px; \n',
          'padding: 2px; \n', 'margin: 1px; \n', 'color: ',
          self.attrColors.secondaryColor0, "; \n", 'background-color: ',
          self.attrColors.backgroundColor, ';}\n', "QLabel {\n",
          'border-width: 0px; \n', 'border-color: ',
          self.attrColors.secondaryColor0, '; \n',
          'border-style: solid; \n', 'border-radius: 0px; \n',
          'padding: 2px; \n', 'margin: 1px; \n', 'color: ',
          self.attrColors.secondaryColor0, "; \n", 'background-color: ',
          self.attrColors.backgroundColor, ';}'))
     self.setStyleSheet(st)
Example #8
0
class QTangoWriteAttributeSpinBox2(QtWidgets.QDoubleSpinBox):
    def __init__(self, sizes=None, colors=None, parent=None):
        QtWidgets.QDoubleSpinBox.__init__(self, parent)
        self.setLocale(QtCore.QLocale(QtCore.QLocale.English))

        # 		Setting up event handling:
        self.lineEdit().cursorPositionChanged.connect(self.changeStep)
        self.lineEdit().updateWriteValue.connect(self.editReady)
        self.lineEdit().returnPressed.connect(self.editReady)
        self.setKeyboardTracking(False)
        self.valueChanged.connect(self.valueReady)
        self.editingFinished.connect(self.editReady)

        self.storedCursorPos = 0
        self.lastKey = QtCore.Qt.Key_0
        if colors is None:
            self.attrColors = QTangoColors()
        else:
            self.attrColors = colors
        if sizes is None:
            self.sizes = QTangoSizes()
        else:
            self.sizes = sizes
        s = ''.join(
            ('QDoubleSpinBox { \n', 'background-color: ',
             self.attrColors.backgroundColor, '; \n',
             'selection-background-color: ', self.attrColors.secondaryColor1,
             '; \n', 'selection-color: ', self.attrColors.backgroundColor,
             '; \n', 'border-width: ', str(int(1)), 'px; \n', 'border-color: ',
             self.attrColors.secondaryColor0, '; \n',
             'border-top-style: solid; \n', 'border-bottom-style: solid; \n',
             'border-left-style: double; \n', 'border-right-style: solid; \n',
             'border-radius: 0px; \n', 'padding: 0px; \n', 'margin: 0px; \n',
             'qproperty-buttonSymbols: UpDownArrows; \n', 'min-width: ',
             str(int(self.sizes.barHeight) * 1), 'px; \n', 'max-width: ',
             str(int(self.sizes.barHeight) * 4), 'px; \n', 'min-height: ',
             str(int(self.sizes.barHeight * 1.2)), 'px; \n', 'max-height: ',
             str(int(self.sizes.barHeight *
                     1.2)), 'px; \n', 'qproperty-readOnly: 0; \n', 'color: ',
             self.attrColors.secondaryColor0, ';} \n'))
        font = self.font()
        font.setFamily(self.sizes.fontType)
        font.setStretch(self.sizes.fontStretch)
        font.setWeight(self.sizes.fontWeight)
        font.setPointSize(int(self.sizes.barHeight * 0.7))
        font.setStyleStrategy(QtGui.QFont.PreferAntialias)
        self.setFont(font)

        self.setStyleSheet(s)
        self.setSizePolicy(QtWidgets.QSizePolicy.Maximum,
                           QtWidgets.QSizePolicy.Minimum)
        self.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.setMaximum(1e9)
        self.setMinimum(-1e9)

    def valueReady(self, value):
        logger.debug("Value ready:: {0}".format(value))
        self.lineEdit().setCursorPosition(self.storedCursorPos)

    def editReady(self):
        logger.debug("Edit ready::")
        logger.debug("Cursor pos set to {0}".format(self.storedCursorPos))
        self.lineEdit().setCursorPosition(self.storedCursorPos)

    def stepBy(self, steps):
        logger.debug("In QTangoWriteAttributeSpinBox2.stepBy")
        logger.debug("Step: {0}".format(steps))
        logger.debug("Value: {0}".format(self.value()))
        logger.debug("Text: {0}".format(self.valueFromText(self.text())))
        txt = self.text()
        current_value = self.valueFromText(txt)
        comma_pos = str(txt).find('.')
        self.storedCursorPos = self.lineEdit().cursorPosition()
        pos = comma_pos - self.storedCursorPos + 1
        logger.debug("stepBy::comma pos: {0}".format(comma_pos))
        logger.debug("stepBy::stored pos: {0}".format(self.storedCursorPos))
        logger.debug("stepBy::cursor pos: {0}".format(
            self.lineEdit().cursorPosition()))
        if pos + self.decimals() < 0:
            pos = -self.decimals()
        elif pos > 0:
            pos -= 1
        self.setValue(current_value + 10**pos * steps)

    def changeStep(self):
        logger.debug("In QTangoWriteAttributeSpinBox2.changeStep")
        # Check if the last key was return, then the cursor
        # shouldn't change
        if self.lastKey != QtCore.Qt.Key_Return:
            txt = str(self.text())
            comma_pos = txt.find('.')
            pos = comma_pos - self.storedCursorPos + 1
            logger.debug("stepBy::pos: {0}".format(pos))
            logger.debug("stepBy::comma pos: {0}".format(comma_pos))
            logger.debug("stepBy::stored pos: {0}".format(
                self.storedCursorPos))
            if pos + self.decimals() < 0:
                pos = -self.decimals()
            elif pos > 0:
                pos -= 1

    def keyPressEvent(self, event):
        # Record keypress to check if it was return in changeStep
        if type(event) == QtGui.QKeyEvent:
            self.lastKey = event.key()
        super(QTangoWriteAttributeSpinBox2, self).keyPressEvent(event)

    def setColors(self, attr_color_name, background_color_name):
        main_color = self.attrColors.__getattribute__(background_color_name)
        background_color = self.attrColors.__getattribute__(attr_color_name)
        s = ''.join(
            ('QDoubleSpinBox { \n', 'background-color: ', background_color,
             '; \n', 'selection-background-color: ', main_color, '; \n',
             'selection-color: ', background_color, '; \n',
             'border-width: 1px; \n', 'border-color: ', main_color, '; \n',
             'border-style: solid; \n', 'border-radius: 0px; \n',
             'padding: 0px; \n', 'margin: 0px; \n',
             'qproperty-buttonSymbols: NoButtons; \n', 'min-width: ',
             str(self.sizes.barWidth), 'px; \n', 'max-width: ',
             str(self.sizes.barWidth), 'px; \n', 'min-height: ',
             str(int(self.sizes.barHeight - 2)), 'px; \n', 'max-height: ',
             str(int(self.sizes.barHeight - 2)), 'px; \n',
             'qproperty-readOnly: 0; \n', 'color: ', main_color, ';} \n'))

        self.setStyleSheet(s)