Пример #1
0
	def paint(self, painter, option, index):
		painter.save()
		index0 = index.sibling( index.row(), 0 )
		utype = index0.data( Qt.UserRole )

		# # set background color
		if option.state & QStyle.State_Selected:
			painter.setPen  ( Qt.NoPen )
			painter.setBrush( GraphTreeItemDelegate._backgroundBrushSelected )
			painter.drawRect(option.rect)
		elif option.state & QStyle.State_MouseOver:
			painter.setPen  ( Qt.NoPen )
			painter.setBrush( GraphTreeItemDelegate._backgroundBrushHovered )
			painter.drawRect(option.rect)

		rect = option.rect
		icon = QIcon( index.data( Qt.DecorationRole) )
		rect.adjust( 5, 0, 0, 0 )
		if icon and not icon.isNull():
			icon.paint( painter, rect, Qt.AlignLeft )
			rect.adjust( 22, 0, 0, 0 )
		text = index.data(Qt.DisplayRole)
		if utype == 1: #GROUP
			painter.setPen( GraphTreeItemDelegate._textPenGroup )
		else:
			painter.setPen( GraphTreeItemDelegate._textPen )
		painter.drawText( rect, Qt.AlignLeft | Qt.AlignVCenter, text )
		painter.restore()
Пример #2
0
    def __init__(self, store):
        super(ItemSelector, self).__init__()

        self.setWindowTitle('Select Item Checkpoint')

        self.store = store

        items = self.store.get('/item')

        layout = QGridLayout()
        self.setLayout(layout)

        self.item_buttons = {}

        width = 5

        label = QLabel('Selected Item')
        label.setAlignment(Qt.AlignHCenter)
        label.setStyleSheet('font-weight: bold;')
        layout.addWidget(label, 0, 0, 1, width)

        for (i, item) in enumerate(sorted(items)):
            parts = items[item]['name'].split(' ') + ['({})'.format(items[item]['location'])]
            lines = ['']
            for part in parts:
                if len(lines[-1]) > 10:
                    lines.append('')

                lines[-1] += ' ' + part

            button = QPushButton('\n'.join([line.strip() for line in lines]))
            icon = QIcon(items[item].get('thumbnail', ''))
            if not icon.isNull():
                button.setIcon(icon)
                button.setIconSize(QSize(64, 64))
            button.setCheckable(True)

            button.clicked.connect(_call(self.select_item, item))

            self.item_buttons[item] = button
            layout.addWidget(button, i // width + 1, i % width)

        self.select_item(self.store.get('/robot/selected_item'))

        self.box_buttons = {}

        label = QLabel('Selected Box')
        label.setAlignment(Qt.AlignHCenter)
        label.setStyleSheet('font-weight: bold;')
        layout.addWidget(label, 0, width + 1)

        for (i, box) in enumerate(sorted(self.store.get('/order'))):
            button = QPushButton(box)
            button.setCheckable(True)
            button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
            button.clicked.connect(_call(self.select_box, box))

            self.box_buttons[box] = button
            layout.addWidget(button, i + 1, width + 1)

        self.select_box(self.store.get('/robot/selected_box'))

        self.bin_buttons = {}

        label = QLabel('Selected Bin')
        label.setAlignment(Qt.AlignHCenter)
        label.setStyleSheet('font-weight: bold;')
        layout.addWidget(label, 0, width + 2)

        for (i, bin) in enumerate(sorted(self.store.get('/shelf/bin'))):
            button = QPushButton(bin)
            button.setCheckable(True)
            button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
            button.clicked.connect(_call(self.select_bin, bin))

            self.bin_buttons[bin] = button
            layout.addWidget(button, i + 1, width + 2)

        self.select_bin(self.store.get('/robot/selected_bin'))