Пример #1
0
    def is_online_callback(self):

        outputBytes = self.process.readAll().data()

        outputUnicode = outputBytes.decode('utf-8')

        try:
            outputObject = json.loads(outputUnicode)

        except ValueError as errorMessage:
            print(errorMessage)
            return

        brush = QBrush(Qt.SolidPattern)
        if outputObject.get('error'):
            color = QColor(255, 0, 0)  #red
            onlineStatus = 'Off'
        else:
            color = QColor(0, 255, 0)  #green
            onlineStatus = 'On'
        brush.setColor(color)

        itemWidget = self.table_widget_item

        itemWidget.setBackground(brush)
        itemWidget.setText(onlineStatus)
Пример #2
0
    def is_online_callback(self):

        outputBytes = self.process.readAll().data()

        outputUnicode = outputBytes.decode("utf-8")

        try:
            outputObject = json.loads(outputUnicode)

        except ValueError as errorMessage:
            print(errorMessage)
            return

        brush = QBrush(Qt.SolidPattern)
        if outputObject.get("error"):
            color = QColor(255, 0, 0)  # red
            onlineStatus = "Off"
        else:
            color = QColor(0, 255, 0)  # green
            onlineStatus = "On"
        brush.setColor(color)

        itemWidget = self.table_widget_item

        itemWidget.setBackground(brush)
        itemWidget.setText(onlineStatus)
 def recolor_cells(self, min_val, max_val):
     cmap = ColorMapper(max_val, min_val)
     the_items = self.get_all_table_items()
     for the_item in the_items:
         the_qtype = the_item.type()
         if the_qtype > QSTRING:
             data_item = (self.inv_qtype(the_qtype)(the_item.text()))
             the_color = cmap.rgb_color_from_val(data_item)
             newBrush = QBrush()
             newBrush.setColor(QColor(the_color[0], the_color[1], the_color[2]))
             newBrush.setStyle(QtCore.Qt.SolidPattern)
             the_item.setBackground(newBrush)
    def __init__(self, data_list, header_rows=0, roundit=None, cmap=None, click_handler=None, resize_columns=True, stretch_last=False, header_text=None, row_height=0, sort_column=0, sort_order=QtCore.Qt.AscendingOrder):
        self._data_list = data_list
        self._nrows = len(self._data_list)
        self._ncols = len(self._data_list[0])
        QTableWidget.__init__(self, self._nrows, self._ncols)
        self.setWordWrap(True) # I think it is already true by default
        if header_rows > 0:
            self.setHorizontalHeaderLabels(self._data_list[0])
            self._data_list = self._data_list[1:]
            self._nrows -= 1

        for r in range(self._nrows):
            for c in range(self._ncols):
                data_item = self._data_list[r][c]
                qtype = self.get_qtype(data_item)
                if (roundit != None) and (qtype == QFLOAT):  # @UndefinedVariable
                    data_item = round(data_item, roundit)
                if (r < header_rows - 1):
                    data_item = "_" + str(data_item) # do this so the header rows are sorted to the top
                # newItem = QTableWidgetItem(str(data_item))
                newItem = QTableWidgetItem(type=qtype)
                if type(data_item) == str:
                    newItem.setText(data_item)
                else:
                    newItem.setData(QtCore.Qt.DisplayRole, data_item)
                if r < header_rows - 1:
                    newItem.setFont(QFont("Helvetica", 12, QFont.Bold))
                else:
                    newItem.setFont(QFont("Helvetica", 12))
                    if (cmap != None) and (type(data_item) == float) and (r >= header_rows):
                        the_color = cmap.rgb_color_from_val(data_item)
                        newBrush = QBrush()
                        newBrush.setColor(QColor(the_color[0], the_color[1], the_color[2]))
                        newBrush.setStyle(QtCore.Qt.SolidPattern)
                        newItem.setBackground(newBrush)
                self.setItem(r, c, newItem)
        if resize_columns:
            self.resizeColumnsToContents()
        self.resizeRowsToContents()
        self.sortItems(0, order=QtCore.Qt.AscendingOrder)
        self.setSortingEnabled(True)
        if row_height != 0:
            vh = self.verticalHeader()
            vh.setDefaultSectionSize(row_height)
        if click_handler != None:
            self._click_handler = click_handler
            self.itemClicked.connect(self.item_click_action)
        if stretch_last:
            hh = self.horizontalHeader()
            hh.setStretchLastSection(True)
        self.roundit = roundit
        self.header_rows = header_rows
 def recolorold(self):
     cmap = ColorMapper(self.max_val.value, self.min_val.value)
     for r in range(self._nrows):
         for c in range(self._ncols):
             data_item = self._data_list[r][c]
             qtype = self.get_qtype(data_item)
             if (self.roundit != None) and (qtype == QFLOAT):  # @UndefinedVariable
                 data_item = round(data_item, self.roundit)
             # newItem = QTableWidgetItem(str(data_item))
             if (qtype > QSTRING) and (r >= self.header_rows - 1):
                 the_color = cmap.rgb_color_from_val(data_item)
                 newBrush = QBrush()
                 newBrush.setColor(QColor(the_color[0], the_color[1], the_color[2]))
                 newBrush.setStyle(QtCore.Qt.SolidPattern)
                 self.tableWidget.item(r, c).setBackground(newBrush)
Пример #6
0
    def is_online(self, tableWidgetItem):

        Stream.clear_streams()

        process = QProcess()

        self.process = process
        self.table_widget_item = tableWidgetItem

        arguments = ["--json"] + self.arguments

        process.setProcessChannelMode(QProcess.MergedChannels)
        process.start("livestreamer", arguments)
        process.readyReadStandardOutput.connect(self.is_online_callback)

        brush = QBrush(Qt.SolidPattern)
        color = QColor(255, 255, 255)  # white
        brush.setColor(color)
        tableWidgetItem.setBackground(brush)
        tableWidgetItem.setText("Checking..")

        Stream.ALL_STREAMS.append(self)
Пример #7
0
    def is_online(self, tableWidgetItem):

        Stream.clear_streams()

        process = QProcess()

        self.process = process
        self.table_widget_item = tableWidgetItem

        arguments = ['--json'] + self.arguments

        process.setProcessChannelMode(QProcess.MergedChannels)
        process.start('livestreamer', arguments)
        process.readyReadStandardOutput.connect(self.is_online_callback)

        brush = QBrush(Qt.SolidPattern)
        color = QColor(255, 255, 255)  #white
        brush.setColor(color)
        tableWidgetItem.setBackground(brush)
        tableWidgetItem.setText('Checking..')

        Stream.ALL_STREAMS.append(self)
Пример #8
0
class SelectBox(QRubberBand):
    """
    Subclass of `QRubberBand`_

    TOWRITE

    """
    def __init__(self, s, parent=None):
        """
        Default class constructor.

        :param `s`: TOWRITE
        :type `s`: QRubberBand.Shape
        :param `parent`: Pointer to a parent widget instance.
        :type `parent`: `QWidget`_
        """
        super(SelectBox, self).__init__(parent)

        # private
        self._leftBrushColor = QColor()
        self._rightBrushColor = QColor()
        self._leftPenColor = QColor()
        self._rightPenColor = QColor()
        self._alpha = 255  # quint8  #: TODO: what is the initial int?

        self._dirBrush = QBrush()
        self._leftBrush = QBrush()
        self._rightBrush = QBrush()

        self._dirPen = QPen()
        self._leftPen = QPen()
        self._rightPen = QPen()

        self._boxDir = False  #: TODO: is this initial bool value right?

        # Default values
        self.setColors(QColor(Qt.darkGreen), QColor(Qt.green),
                       QColor(Qt.darkBlue), QColor(Qt.blue), 32)

    def setDirection(self, dir):
        """
        TOWRITE

        :param `dir`: TOWRITE
        :type `dir`: int
        """
        if not dir:
            self._dirPen = self._leftPen
            self._dirBrush = self._leftBrush
        else:
            self._dirPen = self._rightPen
            self._dirBrush = self._rightBrush
        self._boxDir = dir

    def setColors(self, colorL, fillL, colorR, fillR, newAlpha):
        """
        TOWRITE

        :param `colorL`: TOWRITE
        :type `colorL`: `QColor`_
        :param `fillL`: TOWRITE
        :type `fillL`: `QColor`_
        :param `colorR`: TOWRITE
        :type `colorR`: `QColor`_
        :param `fillR`: TOWRITE
        :type `fillR`: `QColor`_
        :param `newAlpha`: TOWRITE
        :type `newAlpha`: int
        """
        qDebug("SelectBox setColors()")
        self._alpha = newAlpha

        self._leftPenColor = colorL  # TODO: allow customization
        self._leftBrushColor = QColor(fillL.red(), fillL.green(), fillL.blue(),
                                      alpha)
        self._rightPenColor = colorR  # TODO: allow customization
        self._rightBrushColor = QColor(fillR.red(), fillR.green(),
                                       fillR.blue(), alpha)

        self._leftPen.setColor(self._leftPenColor)
        self._leftPen.setStyle(Qt.DashLine)
        self._leftBrush.setStyle(Qt.SolidPattern)
        self._leftBrush.setColor(self._leftBrushColor)

        self._rightPen.setColor(self._rightPenColor)
        self._rightPen.setStyle(Qt.SolidLine)
        self._rightBrush.setStyle(Qt.SolidPattern)
        self._rightBrush.setColor(self._rightBrushColor)

        if not self._boxDir:
            self._dirPen = self._leftPen
            self._dirBrush = self._leftBrush
        else:
            self._dirPen = self._rightPen
            self._dirBrush = self._rightBrush

        self.forceRepaint()

    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`SelectBox`.

        :param `event`: A `QPaintEvent`_ to be processed.
        """
        painter = QPainter(self)
        painter.setPen(self._dirPen)
        width, height = self.width(), self.height()
        painter.fillRect(0, 0, width - 1, height - 1, self._dirBrush)
        painter.drawRect(0, 0, width - 1, height - 1)

    def forceRepaint(self):
        """
        Force repaint the rubberband.

        .. NOTE:: HACK: Take that QRubberBand!
        """
        # HACK: Take that QRubberBand!
        hack = self.size()  # QSize
        self.resize(hack + QSize(1, 1))
        self.resize(hack)
Пример #9
0
class SelectBox(QRubberBand):
    """
    Subclass of `QRubberBand`_

    TOWRITE

    """
    def __init__(self, s, parent=None):
        """
        Default class constructor.

        :param `s`: TOWRITE
        :type `s`: QRubberBand.Shape
        :param `parent`: Pointer to a parent widget instance.
        :type `parent`: `QWidget`_
        """
        super(SelectBox, self).__init__(s, parent)

        # private
        self._leftBrushColor = QColor()
        self._rightBrushColor = QColor()
        self._leftPenColor = QColor()
        self._rightPenColor = QColor()
        self._alpha = 255  # quint8  #: TODO: what is the initial int?

        self._dirBrush = QBrush()
        self._leftBrush = QBrush()
        self._rightBrush = QBrush()

        self._dirPen = QPen()
        self._leftPen = QPen()
        self._rightPen = QPen()

        self._boxDir = False  #: TODO: is this initial bool value right?

        # Default values
        self.setColors(QColor(Qt.darkGreen), QColor(Qt.green), QColor(Qt.darkBlue), QColor(Qt.blue), 32)

    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`SelectBox`.

        :param `event`: A `QPaintEvent`_ to be processed.
        """
        painter = QPainter(self)
        painter.setPen(self._dirPen)
        width, height = self.width(), self.height()
        painter.fillRect(0, 0, width - 1, height - 1, self._dirBrush)
        painter.drawRect(0, 0, width - 1, height - 1)

    def forceRepaint(self):
        """
        Force repaint the rubberband.

        .. NOTE:: HACK: Take that QRubberBand!
        """
        # HACK: Take that QRubberBand!
        hack = self.size()  # QSize
        self.resize(hack + QSize(1, 1))
        self.resize(hack)

    # Slots ------------------------------------------------------------------

    @Slot(int)
    def setDirection(self, dir):
        """
        TOWRITE

        :param `dir`: TOWRITE
        :type `dir`: int
        """
        if not dir:
            self._dirPen = self._leftPen
            self._dirBrush = self._leftBrush
        else:
            self._dirPen = self._rightPen
            self._dirBrush = self._rightBrush
        self._boxDir = dir

    @Slot(QColor, QColor, QColor, QColor, int)
    def setColors(self, colorL, fillL, colorR, fillR, newAlpha):
        """
        TOWRITE

        :param `colorL`: TOWRITE
        :type `colorL`: `QColor`_
        :param `fillL`: TOWRITE
        :type `fillL`: `QColor`_
        :param `colorR`: TOWRITE
        :type `colorR`: `QColor`_
        :param `fillR`: TOWRITE
        :type `fillR`: `QColor`_
        :param `newAlpha`: TOWRITE
        :type `newAlpha`: int
        """
        qDebug("SelectBox setColors()")
        self._alpha = newAlpha

        self._leftPenColor = colorL  # TODO: allow customization
        self._leftBrushColor = QColor(fillL.red(), fillL.green(), fillL.blue(), self._alpha)
        self._rightPenColor = colorR  # TODO: allow customization
        self._rightBrushColor = QColor(fillR.red(), fillR.green(), fillR.blue(), self._alpha)

        self._leftPen.setColor(self._leftPenColor)
        self._leftPen.setStyle(Qt.DashLine)
        self._leftBrush.setStyle(Qt.SolidPattern)
        self._leftBrush.setColor(self._leftBrushColor)

        self._rightPen.setColor(self._rightPenColor)
        self._rightPen.setStyle(Qt.SolidLine)
        self._rightBrush.setStyle(Qt.SolidPattern)
        self._rightBrush.setColor(self._rightBrushColor)

        if not self._boxDir:
            self._dirPen = self._leftPen
            self._dirBrush = self._leftBrush
        else:
            self._dirPen = self._rightPen
            self._dirBrush = self._rightBrush

        self.forceRepaint()