Пример #1
0
    def DrawSlots(self, parent):
        images = Widget(parent)
        images.setLayout(GroupLayout())

        vscroll = VScrollPanel(images)
        vscroll.setFixedHeight(300)
        vscroll.setFixedWidth(240)
        vscroll.setLayout(GroupLayout())

        self.DrawAllSlots(vscroll)
Пример #2
0
class ListPanel(Widget):
    def __init__(self, parent, items):
        super().__init__(parent)
        self.item_width = 400
        self.setFixedSize(np.array([self.item_width + 20, 260]))
        self.setLayout(BoxLayout(Orientation.Vertical, Alignment.Middle, 0, 0))
        self.cb = None
        self.selected = None
        self.vscroll = None
        self.setItems(items, np.arange(len(items)))

    def setItems(self, items, item_ids):
        if self.vscroll is not None:
            self.removeChild(self.vscroll)
        self.vscroll = VScrollPanel(self)
        self.vscroll.setFixedHeight(200)
        self.vscroll.setFixedWidth(self.item_width)
        self.itemwidget = Widget(self.vscroll)
        self.itemwidget.setLayout(
            BoxLayout(Orientation.Vertical, Alignment.Middle, 0, 0))

        def label_click_handler(button):
            self.selected = int(button.id())
            if self.cb is not None:
                self.cb(self.selected)

        self.list_items = []
        for i, item in enumerate(items):
            list_item = Button(self.itemwidget, item)
            list_item.setFixedWidth(self.item_width)
            list_item.setCallback(
                lambda button=list_item: label_click_handler(button))
            list_item.setId(str(item_ids[i]))
            list_item.setTooltip(item)
            list_item.setFontSize(14)
            list_item.setFlags(Button.Flags.RadioButton)
            self.list_items.append(list_item)
        self.selected = None
        self.setSelectedIndex(0)

    def setCallback(self, cb):
        self.cb = cb

    def setSelectedIndex(self, index):
        self.selected = index