コード例 #1
0
ファイル: simpleShowFrame.py プロジェクト: sbalcar/linPrefMod
    def __showFormLeft(self):

        self.user1Form = SimpleShowForm(self.userProfileModelStructured,
                                        self.aggrLevel, self.linPrefModelConf,
                                        self.clickOnFormular)

        # layoutForm:QVBoxLayout
        layoutForm = QVBoxLayout()
        layoutForm.addWidget(self.user1Form.qGroupBoxUser)
        layoutForm.addStretch(0)
        layoutForm.minimumSize()

        self.layout.addLayout(layoutForm, 0, 0, 1, 1)
コード例 #2
0
ファイル: propertyeditor.py プロジェクト: mlilien/sloth
class LabelEditor(QScrollArea):
    def __init__(self, items, parent, insertionMode=False):
        QScrollArea.__init__(self, parent)
        self._editor = parent
        self._items = items
        self._insertion_mode = insertionMode

        # Find all classes
        self._label_classes = set([item['class'] for item in items if 'class' in item])
        n_classes = len(self._label_classes)
        LOG.debug("Creating editor for %d item classes: %s" % (n_classes, ", ".join(list(self._label_classes))))

        # Widget layout
        self._layout = QVBoxLayout()
        self._content = QWidget()
        self._content.setLayout(self._layout)

        attributes = set()
        for lc in self._label_classes:
            attributes |= set(self._editor.getLabelClassAttributes(lc))

        attributes = list(attributes)
        attributes.sort()
        for attr in attributes:
            handler = self._editor.getHandler(attr)
            if handler is not None:
                if len(items) > 1:
                    valid_items = [item for item in items
                                   if attr in self._editor.getLabelClassAttributes(item['class'])]
                    handler.setItems(valid_items, True)
                else:
                    handler.setItems(items)
                self._layout.addWidget(handler)

        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setWidgetResizable(True)
        self.setWidget(self._content)

    def sizeHint(self):
        minsz = self.minimumSize()
        sz = self._layout.minimumSize()
        left, top, right, bottom = self.getContentsMargins()
        return QSize(max(minsz.width(), sz.width() + left + right), max(minsz.height(), sz.height() + top + bottom))

    def labelClasses(self):
        return self._label_classes

    def currentProperties(self):
        if len(self._items) == 1:
            return self._items[0]
        else:
            return {}

    def insertionMode(self):
        return self._insertion_mode
コード例 #3
0
    def minimumSize(self):
        """Reimplemented from `QBoxLayout.minimimSize`."""
        if self.__minimumSize is None:
            msize = QVBoxLayout.minimumSize(self)
            # Extend the minimum size by including the minimum width of
            # hidden widgets (which QBoxLayout ignores), so the minimum
            # width does not depend on the tab open/close state.
            for i in range(self.count()):
                item = self.itemAt(i)
                if item.isEmpty() and item.widget() is not None:
                    msize.setWidth(
                        max(item.widget().minimumWidth(), msize.width()))
            self.__minimumSize = msize

        return self.__minimumSize
コード例 #4
0
class LabelEditor(QScrollArea):
    def __init__(self, items, parent, insertionMode=False):
        QScrollArea.__init__(self, parent)
        self._editor = parent
        self._items = items
        self._insertion_mode = insertionMode

        # Find all classes
        self._label_classes = set(
            [item['class'] for item in items if 'class' in item])
        n_classes = len(self._label_classes)
        LOG.debug("Creating editor for %d item classes: %s" %
                  (n_classes, ", ".join(list(self._label_classes))))

        # Widget layout
        self._layout = QVBoxLayout()
        self._content = QWidget()
        self._content.setLayout(self._layout)

        attributes = set()
        for lc in self._label_classes:
            attributes |= set(self._editor.getLabelClassAttributes(lc))

        attributes = list(attributes)
        attributes.sort()
        for attr in attributes:
            handler = self._editor.getHandler(attr)
            if handler is not None:
                if len(items) > 1:
                    valid_items = [
                        item for item in items if attr in
                        self._editor.getLabelClassAttributes(item['class'])
                    ]
                    handler.setItems(valid_items, True)
                else:
                    handler.setItems(items)
                self._layout.addWidget(handler)

        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setWidgetResizable(True)
        self.setWidget(self._content)

    def sizeHint(self):
        minsz = self.minimumSize()
        sz = self._layout.minimumSize()
        left, top, right, bottom = self.getContentsMargins()
        return QSize(max(minsz.width(),
                         sz.width() + left + right),
                     max(minsz.height(),
                         sz.height() + top + bottom))

    def labelClasses(self):
        return self._label_classes

    def currentProperties(self):
        if len(self._items) == 1:
            return self._items[0]
        else:
            return {}

    def insertionMode(self):
        return self._insertion_mode
コード例 #5
0
class ConsolePanel(QFrame):
    def __init__(self, master):
        super().__init__(master)

        self.cbTimestamp = QCheckBox("Timestamp", self)
        self.cbErrors = QCheckBox("Errors", self)
        self.cbInfo = QCheckBox("Info", self)
        self.cbOrders = QCheckBox("Orders", self)
        self.cbAnswers = QCheckBox("Answers", self)
        self.cbSensors = QCheckBox("Sensors", self)

        self.cbList = [self.cbTimestamp, self.cbErrors, self.cbInfo, self.cbOrders, self.cbAnswers, self.cbSensors]
        for cb in self.cbList:
            cb.setChecked(True)
            cb.stateChanged.connect(self.settings_changed)

        self.console = QTextEdit(self)
        self.console.setReadOnly(True)
        self.consoleVScrollBar = self.console.verticalScrollBar()
        self.font = "Consolas"
        self.fontSize = 9
        self.fontSize_small = 7
        self.timestampColor = QColor(119, 180, 177)
        self.textColor = QColor(197, 200, 198)
        self.errorColor = QColor(195, 48, 39)
        self.orderColor = QColor(1, 160, 228)
        self.answerColor = QColor(1, 162, 82)
        self.sensorColor = QColor(1, 160, 160)

        self.console.setStyleSheet("""
            background-color: rgb(29, 31, 33);
            color: rgb(197, 200, 198);
        """)

        self.consoleText = ""

        self.margin = 41 # Parameter to tune to make things work
        self.width_needed = None

        grid = QGridLayout()
        self.cbArea = QVBoxLayout()
        grid.addLayout(self.cbArea, 0, 0)
        grid.addWidget(self.console, 1, 0, 1, 2)
        grid.setRowStretch(1, 1)
        grid.setColumnStretch(1, 1)
        self.setLayout(grid)
        self.organizeWidgets(init=True)

    def resizeEvent(self, event):
        w = self.cbArea.minimumSize().width()
        availableWidth = event.size().width() - self.margin
        if availableWidth > 30:
            if availableWidth <= w or (self.width_needed is not None and availableWidth > w + self.width_needed):
                self.organizeWidgets(False, availableWidth - 30)

    def organizeWidgets(self, init, availableWidth=None):
        if not init:
            for i in reversed(range(self.cbArea.count())):
                item = self.cbArea.itemAt(i)
                if isinstance(item, QLayoutItem):
                    layout = item.layout()
                    for j in reversed(range(layout.count())):
                        widget = layout.itemAt(j).widget()
                        if widget is not None:
                            layout.removeWidget(widget)
                        else:
                            print("ERR")
                else:
                    print("Err")
                self.cbArea.removeItem(item)
                item.deleteLater()

        self.width_needed = None
        i = 0
        while i < len(self.cbList):
            line = QHBoxLayout()
            columnCount = 0
            while True:
                if availableWidth is not None and line.minimumSize().width() >= availableWidth:
                    if columnCount > 1:
                        i -= 1
                        line.removeWidget(self.cbList[i])
                    overlap = line.minimumSize().width() - availableWidth
                    if self.width_needed is None:
                        self.width_needed = overlap
                    else:
                        self.width_needed = min(self.width_needed, overlap)
                    break
                elif i >= len(self.cbList):
                    break
                else:
                    line.addWidget(self.cbList[i])
                    i +=1
                    columnCount += 1
            self.cbArea.addLayout(line)

    def formatTextToConsole(self, text):
        textLines = text.splitlines(keepends=True)
        lineNb = 0
        for line in textLines:
            lineNb += 1
            sLine = line.split('_', maxsplit=2)
            if len(sLine) != 3:
                # print("Incorrect line nb", lineNb, ":", line)
                continue
            try:
                int(sLine[0])
            except ValueError:
                print("Incorrect timestamp :", sLine[0])
                continue
            if sLine[1] == INFO_CHANNEL_NAME:
                if not self.cbInfo.isChecked():
                    continue
                color = self.textColor
            elif sLine[1] == ERROR_CHANNEL_NAME:
                if not self.cbErrors.isChecked():
                    continue
                color = self.errorColor
            elif sLine[1] == TRACE_CHANNEL_NAME:
                if not self.cbInfo.isChecked():
                    continue
                color = self.textColor
            elif sLine[1] == SPY_ORDER_CHANNEL_NAME:
                if not self.cbOrders.isChecked():
                    continue
                color = self.orderColor
            elif sLine[1] == ANSWER_DESCRIPTOR:
                if not self.cbAnswers.isChecked():
                    continue
                color = self.answerColor
            elif sLine[1] == SENSOR_CHANNEL_NAME:
                if not self.cbSensors.isChecked():
                    continue
                color = self.sensorColor
            else:
                print("Incorrect line type :", sLine[1])
                continue
            if self.cbTimestamp.isChecked():
                self.console.setTextColor(self.timestampColor)
                self.console.setCurrentFont(QFont(self.font, self.fontSize_small))
                self.console.insertPlainText(sLine[0] + " ")
            self.console.setTextColor(color)
            self.console.setCurrentFont(QFont(self.font, self.fontSize))
            self.console.insertPlainText(sLine[2])

    def setText(self, newText):
        self.consoleText = newText
        self.console.clear()
        self.formatTextToConsole(newText)
        self.consoleVScrollBar.setValue(self.consoleVScrollBar.maximum())

    def appendText(self, text):
        self.consoleText += text
        self.formatTextToConsole(text)
        self.consoleVScrollBar.setValue(self.consoleVScrollBar.maximum())

    def settings_changed(self):
        scrollValue = self.consoleVScrollBar.value()
        self.console.clear()
        self.formatTextToConsole(self.consoleText)
        self.consoleVScrollBar.setValue(scrollValue)
コード例 #6
0
    def __init__(self, parent=None, position=0, task_list=None):
        super(InfoDialog, self).__init__(parent)
        self.position = position
        self.task_list = task_list

        self.central_widget = QtWidgets.QWidget(self)
        self.resize(300, 400)
        self.setWindowTitle(self.tr('Properties'))

        whole_layout = QVBoxLayout(self.central_widget)

        gb_general = QGroupBox(self.central_widget)
        gb_general.setTitle(self.tr('General'))

        general_layout = QVBoxLayout(gb_general)

        general_grid = QGridLayout()
        general_grid.setColumnStretch(1, 1)

        label_file_name = QLabel(gb_general)
        label_file_name.setText(self.tr('File Name:'))

        self.label_file_name_value = QLabel(gb_general)
        self.label_file_name_value.setText("")

        label_size = QLabel(gb_general)
        label_size.setText(self.tr('Size:'))

        self.label_size_value = QLabel(gb_general)
        self.label_size_value.setText("")

        label_duration = QLabel(gb_general)
        label_duration.setText(self.tr('Duration:'))

        self.label_duration_value = QLabel(gb_general)
        self.label_duration_value.setText("")

        label_format_name = QLabel(gb_general)
        label_format_name.setText(self.tr('Format Name:'))

        self.label_format_name_value = QLabel(gb_general)
        self.label_format_name_value.setText("")

        label_format_long_name = QLabel(gb_general)
        label_format_long_name.setText(self.tr('Format Long Name:'))

        self.label_format_long_name_value = QLabel(gb_general)
        self.label_format_long_name_value.setText("")

        general_grid.addWidget(label_file_name, 0, 0, 1, 1)
        general_grid.addWidget(self.label_file_name_value, 0, 1, 1, 1)
        general_grid.addWidget(label_size, 1, 0, 1, 1)
        general_grid.addWidget(self.label_size_value, 1, 1, 1, 1)
        general_grid.addWidget(label_duration, 2, 0, 1, 1)
        general_grid.addWidget(self.label_duration_value, 2, 1, 1, 1)
        general_grid.addWidget(label_format_name, 3, 0, 1, 1)
        general_grid.addWidget(self.label_format_name_value, 3, 1, 1, 1)
        general_grid.addWidget(label_format_long_name, 4, 0, 1, 1)
        general_grid.addWidget(self.label_format_long_name_value, 4, 1, 1, 1)

        general_layout.addLayout(general_grid)

        gb_video = QGroupBox(self.central_widget)
        gb_video.setTitle(self.tr('Video'))
        video_layout = QVBoxLayout(gb_video)
        video_grid = QGridLayout()
        video_grid.setColumnStretch(1, 1)

        label_bit_rate = QLabel(gb_video)
        label_bit_rate.setText(self.tr('Bit Rate:'))

        self.label_bit_rate_value = QLabel(gb_video)
        self.label_bit_rate_value.setText("")

        label_width = QLabel(gb_video)
        label_width.setText(self.tr('Width:'))

        self.label_width_value = QLabel(gb_video)
        self.label_width_value.setText("")

        label_height = QLabel(gb_video)
        label_height.setText(self.tr('Height:'))

        self.label_height_value = QLabel(gb_video)
        self.label_height_value.setText("")

        label_codec_long_name = QLabel(gb_video)
        label_codec_long_name.setText(self.tr('Codec Long Name:'))

        self.label_codec_long_name_value = QLabel(gb_video)
        self.label_codec_long_name_value.setText("")

        label_codec_name = QLabel(gb_video)
        label_codec_name.setText(self.tr('Codec Name:'))

        self.label_codec_name_value = QLabel(gb_video)
        self.label_codec_name_value.setText("")

        video_grid.addWidget(label_bit_rate, 2, 0, 1, 1)
        video_grid.addWidget(self.label_bit_rate_value, 2, 1, 1, 1)
        video_grid.addWidget(label_width, 3, 0, 1, 1)
        video_grid.addWidget(self.label_width_value, 3, 1, 1, 1)
        video_grid.addWidget(label_height, 4, 0, 1, 1)
        video_grid.addWidget(self.label_height_value, 4, 1, 1, 1)
        video_grid.addWidget(label_codec_long_name, 1, 0, 1, 1)
        video_grid.addWidget(self.label_codec_long_name_value, 1, 1, 1, 1)
        video_grid.addWidget(label_codec_name, 0, 0, 1, 1)
        video_grid.addWidget(self.label_codec_name_value, 0, 1, 1, 1)

        video_layout.addLayout(video_grid)

        gb_audio = QGroupBox(self.central_widget)
        gb_audio.setTitle(self.tr('Audio'))

        audio_layout = QVBoxLayout(gb_audio)

        audio_grid = QGridLayout()
        audio_grid.setColumnStretch(1, 1)

        label_acodec_name = QLabel(gb_audio)
        label_acodec_name.setText(self.tr('Codec Name:'))

        self.label_acodec_name_value = QLabel(gb_audio)
        self.label_acodec_name_value.setText("")

        label_acodec_long_name = QLabel(gb_audio)
        label_acodec_long_name.setText(self.tr('Codec Long Name:'))

        self.label_acodec_long_name_value = QLabel(gb_audio)
        self.label_acodec_long_name_value.setText("")

        audio_grid.addWidget(label_acodec_name, 0, 0, 1, 1)
        audio_grid.addWidget(self.label_acodec_name_value, 0, 1, 1, 1)
        audio_grid.addWidget(label_acodec_long_name, 1, 0, 1, 1)
        audio_grid.addWidget(self.label_acodec_long_name_value, 1, 1, 1, 1)

        audio_layout.addLayout(audio_grid)

        whole_layout.addWidget(gb_general)
        whole_layout.addWidget(gb_video)
        whole_layout.addWidget(gb_audio)

        self.ok_button = QPushButton()
        self.ok_button.setText('OK')
        self.ok_button.clicked.connect(self.close)
        button_layout = QtWidgets.QHBoxLayout()
        button_layout.addSpacerItem(
            QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding,
                        QtWidgets.QSizePolicy.Minimum))
        button_layout.addWidget(self.ok_button)
        whole_layout.addLayout(button_layout)
        self._show_video_info(self.position)

        self.setMinimumSize(whole_layout.minimumSize())
コード例 #7
0
    def __init__(self, parent=None, name="Colormap Dialog"):
        QDialog.__init__(self, parent)
        self.setWindowTitle(name)
        self.title = name

        self.colormapList = [
            'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', 'YlOrBr',
            'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', 'GnBu', 'PuBu', 'YlGnBu',
            'PuBuGn', 'BuGn', 'YlGn'
        ]

        # histogramData is tupel(bins, counts)
        self.histogramData = None

        # default values
        self.dataMin = -10
        self.dataMax = 10
        self.minValue = 0
        self.maxValue = 1

        self.colormapIndex = 2
        self.colormapType = 0

        self.autoscale = False
        self.autoscale90 = False
        # main layout
        vlayout = QVBoxLayout(self)
        vlayout.setContentsMargins(10, 10, 10, 10)
        vlayout.setSpacing(0)

        # layout 1 : -combo to choose colormap
        #            -autoscale button
        #            -autoscale 90% button
        hbox1 = QWidget(self)
        hlayout1 = QHBoxLayout(hbox1)
        vlayout.addWidget(hbox1)
        hlayout1.setContentsMargins(0, 0, 0, 0)
        hlayout1.setSpacing(10)

        # combo
        self.combo = QComboBox(hbox1)
        for colormap in self.colormapList:
            self.combo.addItem(colormap)
        self.combo.activated[int].connect(self.colormapChange)
        hlayout1.addWidget(self.combo)

        # autoscale
        self.autoScaleButton = QPushButton("Autoscale", hbox1)
        self.autoScaleButton.setCheckable(True)
        self.autoScaleButton.setAutoDefault(False)
        self.autoScaleButton.toggled[bool].connect(self.autoscaleChange)
        hlayout1.addWidget(self.autoScaleButton)

        # autoscale 90%
        self.autoScale90Button = QPushButton("Autoscale 90%", hbox1)
        self.autoScale90Button.setCheckable(True)
        self.autoScale90Button.setAutoDefault(False)

        self.autoScale90Button.toggled[bool].connect(self.autoscale90Change)
        hlayout1.addWidget(self.autoScale90Button)

        # hlayout
        hbox0 = QWidget(self)
        self.__hbox0 = hbox0
        hlayout0 = QHBoxLayout(hbox0)
        hlayout0.setContentsMargins(0, 0, 0, 0)
        hlayout0.setSpacing(0)
        vlayout.addWidget(hbox0)
        #hlayout0.addStretch(10)

        self.buttonGroup = QButtonGroup()
        g1 = QCheckBox(hbox0)
        g1.setText("Linear")
        g2 = QCheckBox(hbox0)
        g2.setText("Logarithmic")
        g3 = QCheckBox(hbox0)
        g3.setText("Gamma")
        self.buttonGroup.addButton(g1, 0)
        self.buttonGroup.addButton(g2, 1)
        self.buttonGroup.addButton(g3, 2)
        self.buttonGroup.setExclusive(True)
        if self.colormapType == 1:
            self.buttonGroup.button(1).setChecked(True)
        elif self.colormapType == 2:
            self.buttonGroup.button(2).setChecked(True)
        else:
            self.buttonGroup.button(0).setChecked(True)
        hlayout0.addWidget(g1)
        hlayout0.addWidget(g2)
        hlayout0.addWidget(g3)
        vlayout.addWidget(hbox0)
        self.buttonGroup.buttonClicked[int].connect(self.buttonGroupChange)
        vlayout.addSpacing(20)

        hboxlimits = QWidget(self)
        hboxlimitslayout = QHBoxLayout(hboxlimits)
        hboxlimitslayout.setContentsMargins(0, 0, 0, 0)
        hboxlimitslayout.setSpacing(0)

        self.slider = None

        vlayout.addWidget(hboxlimits)

        vboxlimits = QWidget(hboxlimits)
        vboxlimitslayout = QVBoxLayout(vboxlimits)
        vboxlimitslayout.setContentsMargins(0, 0, 0, 0)
        vboxlimitslayout.setSpacing(0)
        hboxlimitslayout.addWidget(vboxlimits)

        # hlayout 2 : - min label
        #             - min texte
        hbox2 = QWidget(vboxlimits)
        self.__hbox2 = hbox2
        hlayout2 = QHBoxLayout(hbox2)
        hlayout2.setContentsMargins(0, 0, 0, 0)
        hlayout2.setSpacing(0)
        #vlayout.addWidget(hbox2)
        vboxlimitslayout.addWidget(hbox2)
        hlayout2.addStretch(10)

        self.minLabel = QLabel(hbox2)
        self.minLabel.setText("Minimum")
        hlayout2.addWidget(self.minLabel)

        hlayout2.addSpacing(5)
        hlayout2.addStretch(1)
        self.minText = MyQLineEdit(hbox2)
        self.minText.setFixedWidth(150)
        self.minText.setAlignment(QtCore.Qt.AlignRight)
        self.minText.returnPressed[()].connect(self.minTextChanged)
        hlayout2.addWidget(self.minText)

        # hlayout 3 : - min label
        #             - min text
        hbox3 = QWidget(vboxlimits)
        self.__hbox3 = hbox3
        hlayout3 = QHBoxLayout(hbox3)
        hlayout3.setContentsMargins(0, 0, 0, 0)
        hlayout3.setSpacing(0)
        #vlayout.addWidget(hbox3)
        vboxlimitslayout.addWidget(hbox3)

        hlayout3.addStretch(10)
        self.maxLabel = QLabel(hbox3)
        self.maxLabel.setText("Maximum")
        hlayout3.addWidget(self.maxLabel)

        hlayout3.addSpacing(5)
        hlayout3.addStretch(1)

        self.maxText = MyQLineEdit(hbox3)
        self.maxText.setFixedWidth(150)
        self.maxText.setAlignment(QtCore.Qt.AlignRight)

        self.maxText.returnPressed[()].connect(self.maxTextChanged)
        hlayout3.addWidget(self.maxText)

        # Graph widget for color curve...
        self.c = PlotWidget(self, backend=None)
        self.c.setGraphXLabel("Data Values")
        self.c.setInteractiveMode('select')

        self.marge = (abs(self.dataMax) + abs(self.dataMin)) / 6.0
        self.minmd = self.dataMin - self.marge
        self.maxpd = self.dataMax + self.marge

        self.c.setGraphXLimits(self.minmd, self.maxpd)
        self.c.setGraphYLimits(-11.5, 11.5)

        x = [self.minmd, self.dataMin, self.dataMax, self.maxpd]
        y = [-10, -10, 10, 10]
        self.c.addCurve(x,
                        y,
                        legend="ConstrainedCurve",
                        color='black',
                        symbol='o',
                        linestyle='-')
        self.markers = []
        self.__x = x
        self.__y = y
        labelList = ["", "Min", "Max", ""]
        for i in range(4):
            if i in [1, 2]:
                draggable = True
                color = "blue"
            else:
                draggable = False
                color = "black"
            #TODO symbol
            legend = "%d" % i
            self.c.addXMarker(x[i],
                              legend=legend,
                              text=labelList[i],
                              draggable=draggable,
                              color=color)
            self.markers.append((legend, ""))

        self.c.setMinimumSize(QSize(250, 200))
        vlayout.addWidget(self.c)

        self.c.sigPlotSignal.connect(self.chval)

        # colormap window can not be resized
        self.setFixedSize(vlayout.minimumSize())
        self.buttonBox = QDialogButtonBox()
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                          | QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        vlayout.addWidget(self.buttonBox)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)