예제 #1
0
 def add_widget(self, button, widget):
     """creates a QWidgetItem containing the widget,
     as child of the button-QWidgetItem
     """
     section = QTreeWidgetItem(button)
     section.setDisabled(True)
     section.setBackgroundColor(0, QColor(3, 169, 229))
     self.tree.setItemWidget(section, 0, widget)
     return section
예제 #2
0
    def create_root(self, parent, name, value):
        root = QTreeWidgetItem(parent)
        root.setText(0, name)
        root.setText(1, value)
        root.setTextColor(0, QColor('#ffffff'))
        root.setTextColor(1, QColor('#ffffff'))
        root.setBackgroundColor(0, QColor('#0066cc'))
        root.setBackgroundColor(1, QColor('#0066cc'))

        return root
예제 #3
0
 def add_button(self, title):
     """creates a QTreeWidgetItem containing a button 
     to expand or collapse its section
     """
     item = QTreeWidgetItem()
     item.setBackgroundColor(0, QColor(3, 169, 229))
     self.tree.addTopLevelItem(item)
     self.tree.setItemWidget(item, 0, SectionExpandButton(item, text = title, group = self.buttonGroup))
     
     return item
예제 #4
0
    def create_child(self, name, value):
        """Create child item of the tree"""
        root = QTreeWidgetItem()
        root.setText(0, name)
        root.setText(1, value)
        root.setTextColor(0, QColor('#0066cc'))
        root.setTextColor(1, QColor('#0066cc'))
        root.setBackgroundColor(0, QColor('#ccffff'))
        root.setBackgroundColor(1, QColor('#ccffff'))

        return root
예제 #5
0
    def _updateAll(self, newGroup=None):
        try:
            self.chSelector.itemChanged.disconnect(self.itemChanged)
            self.sSelector.itemChanged.disconnect(self.itemChanged)
        except:
            pass
        if newGroup == '':
            return
        
        chStruct = self.chartData[newGroup]
        sStruct = self.chartData[newGroup].getColStructure()
        
        self.chSelector.clear()
        for ws in chStruct:
            gparent = QTreeWidgetItem(self.chSelector)
            gparent.setText(0, ws)
            gparent.setBackgroundColor(0, Qt.white)
            gparent.setFlags(Qt.ItemIsEnabled)
            for key in chStruct[ws]:
                parent = QTreeWidgetItem(gparent)
                parent.setText(0, key)
                if chStruct[ws][key][0] == True:
                    dataNames = chStruct[ws][key][3]
                    sColor = QColor(chStruct[ws][key][4])
                    sColor.setAlpha(100)
                    parent.setBackgroundColor(0, sColor)
                else:
                    dataNames = ','.join(chStruct[ws][key][2])
                    sColor = QColor(chStruct[ws][key][3])
                    sColor.setAlpha(100)
                    parent.setBackgroundColor(0, sColor)
                    
                parent.setText(1, dataNames)
                if chStruct[ws][key][1] == True:
                    parent.setCheckState(0, Qt.Checked)
                else:
                    parent.setCheckState(0, Qt.Unchecked)
                parent.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
        
        self.sSelector.clear()
        self.gSelector.clear()
        for ws in sStruct:
            firstChannel = sStruct[ws][0]
            isOneSignal = self.chartData[newGroup][firstChannel][ws][0]
            if isOneSignal:
                gparent = QTreeWidgetItem(self.sSelector)
                gparent.setText(0, ws)
                gparent.setFlags(Qt.ItemIsEnabled | Qt.ItemIsDragEnabled
                                 | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable)
                if True:
##                if chStruct['CH1'][ws][5] == True:
                    gparent.setCheckState(0, Qt.Checked) 
                else:
                    gparent.setCheckState(0, Qt.Unchecked)
                    
                for key in sStruct[ws]:
                    parent = QTreeWidgetItem(gparent)
                    parent.setText(0, key)
                    if chStruct[key][ws][2] == True:
                        parent.setCheckState(0, Qt.Checked)
                    else:
                        parent.setCheckState(0, Qt.Unchecked)
                    parent.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                    sColor = QColor(chStruct[key][ws][4])
                    sColor.setAlpha(100)
                    sGradient = QLinearGradient(0, 0, 100, 10)
                    sGradient.setColorAt(0, sColor)
                    sGradient.setColorAt(1, Qt.white)
                    sBrush = QBrush(sGradient)
                    sBrush.setStyle(Qt.LinearGradientPattern)
                    sBrush.setColor(sColor)
                    gparent.setBackground(0, sBrush)
                    
            else:
                gparent = QTreeWidgetItem(self.gSelector)
                gparent.setText(0, ws)
                gparent.setFlags(Qt.ItemIsEnabled | Qt.ItemIsDropEnabled
                                 | Qt.ItemIsUserCheckable)
                if chStruct['CH1'][ws][5] == True:
                    gparent.setCheckState(0, Qt.Checked)
                else:
                    gparent.setCheckState(0, Qt.Unchecked)
                
                signalNames = chStruct[key][ws][2]
                sColor = QColor(chStruct[key][ws][3])
                sColor.setAlpha(100)
                gparent.setBackgroundColor(0, sColor)
                for signal in signalNames:
                    parent = QTreeWidgetItem(gparent)
                    parent.setText(0, signal)
                    parent.setFlags(Qt.ItemIsEnabled)

                    for key in sStruct[signal]:
                        sColor = QColor(chStruct[key][signal][4])
                        sColor.setAlpha(100)
                        parent.setBackgroundColor(0, sColor)
                        break                   
            
        self.chSelector.itemChanged.connect(self.itemChanged)
        self.sSelector.itemChanged.connect(self.itemChanged)
        self.curSelect = None
예제 #6
0
    def ui_setup(self):
        """Create setup user interface of serial port."""
        self.setHeaderHidden(True)
        self.setFixedSize(205, 205)
        self.setIndentation(0)
        self.setColumnCount(2)
        self.setColumnWidth(0, 100)
        self.setColumnWidth(1, 90)

        self._items['title'] = QTreeWidgetItem(self)
        self._items['title'].setText(0, 'Serial Port')
        self._items['title'].setTextColor(0, QColor(TXT_COLOR))
        self._items['title'].setFont(0, QFont('ubuntu', 11, QFont.Bold))
        self._items['title'].setBackgroundColor(0, QColor(TITLE_COLOR))
        self._items['title'].setBackgroundColor(1, QColor(TITLE_COLOR))

        for name in self._items_name:
            self._items[name] = QTreeWidgetItem(self)
            self._combo_boxes[name] = QComboBox(self)
            self._combo_boxes[name].setFixedSize(100, 24)
            self._combo_boxes[name].setStyleSheet(COMBO_BOX_STYLE)

        self._items['port'].setText(0, 'PortName')
        self._items['port'].setTextColor(0, QColor(TITLE_COLOR))
        self._items['port'].setBackgroundColor(0, QColor(ODD_COLOR))
        self._items['port'].setBackgroundColor(1, QColor(ODD_COLOR))
        for port in Serial.list_ports():
            if port.name:
                self._combo_boxes['port'].addItem(port.name, port.device)

        self._items['baud'].setText(0, 'BaudRate')
        self._items['baud'].setTextColor(0, QColor(TITLE_COLOR))
        self._items['baud'].setBackgroundColor(0, QColor(EVEN_COLOR))
        self._items['baud'].setBackgroundColor(1, QColor(EVEN_COLOR))
        self._combo_boxes['baud'].addItem('115200', 115200)
        self._combo_boxes['baud'].addItem('57600', 57600)
        self._combo_boxes['baud'].addItem('38400', 38400)
        self._combo_boxes['baud'].addItem('9600', 9600)

        self._items['data_bit'].setText(0, 'DataBit')
        self._items['data_bit'].setTextColor(0, QColor(TITLE_COLOR))
        self._items['data_bit'].setBackgroundColor(0, QColor(EVEN_COLOR))
        self._items['data_bit'].setBackgroundColor(1, QColor(EVEN_COLOR))
        self._combo_boxes['data_bit'].addItem('8', Serial.EIGHTBITS)
        self._combo_boxes['data_bit'].addItem('7', Serial.SEVENBITS)
        self._combo_boxes['data_bit'].addItem('6', Serial.SIXBITS)
        self._combo_boxes['data_bit'].addItem('5', Serial.FIVEBITS)

        self._items['parity'].setText(0, 'Parity')
        self._items['parity'].setTextColor(0, QColor(TITLE_COLOR))
        self._items['parity'].setBackgroundColor(0, QColor(ODD_COLOR))
        self._items['parity'].setBackgroundColor(1, QColor(ODD_COLOR))
        self._combo_boxes['parity'].addItem('None', Serial.PARITY_NONE)
        self._combo_boxes['parity'].addItem('Even', Serial.PARITY_EVEN)
        self._combo_boxes['parity'].addItem('Odd', Serial.PARITY_ODD)
        self._combo_boxes['parity'].addItem('Mark', Serial.PARITY_MARK)
        self._combo_boxes['parity'].addItem('Space', Serial.PARITY_SPACE)

        self._items['stop_bit'].setText(0, 'StopBit')
        self._items['stop_bit'].setTextColor(0, QColor(TITLE_COLOR))
        self._items['stop_bit'].setBackgroundColor(0, QColor(EVEN_COLOR))
        self._items['stop_bit'].setBackgroundColor(1, QColor(EVEN_COLOR))
        self._combo_boxes['stop_bit'].addItem('1', Serial.STOPBITS_ONE)
        self._combo_boxes['stop_bit'].addItem('1.5',
                                              Serial.STOPBITS_ONE_POINT_FIVE)
        self._combo_boxes['stop_bit'].addItem('2', Serial.STOPBITS_TWO)

        self._items['flow_ctrl'].setText(0, 'FlowCtrl')
        self._items['flow_ctrl'].setTextColor(0, QColor(TITLE_COLOR))
        self._items['flow_ctrl'].setBackgroundColor(0, QColor(ODD_COLOR))
        self._items['flow_ctrl'].setBackgroundColor(1, QColor(ODD_COLOR))
        self._combo_boxes['flow_ctrl'].addItem('None', None)
        self._combo_boxes['flow_ctrl'].addItem('xonxoff', 'xonxoff')
        self._combo_boxes['flow_ctrl'].addItem('rtscts', 'rtscts')
        self._combo_boxes['flow_ctrl'].addItem('dsrdtr', 'dsrdtr')

        self._refresh_button.setFixedSize(90, 25)
        self.setItemWidget(self._items['title'], 1, self._refresh_button)

        for name in self._items_name:
            self.setItemWidget(self._items[name], 1, self._combo_boxes[name])

        opt_item = QTreeWidgetItem(self)
        opt_item.setBackgroundColor(0, QColor(EVEN_COLOR))
        opt_item.setBackgroundColor(1, QColor(EVEN_COLOR))

        self._close_button.setEnabled(False)
        self._open_button.setEnabled(True)
        self.setItemWidget(opt_item, 1, self._close_button)
        self.setItemWidget(opt_item, 0, self._open_button)