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)
window.setFixedSize((width, height)) # attach a vertical scroll panel vscroll = VScrollPanel(window) vscroll.setFixedSize((width, height)) # vscroll should only have *ONE* child. this is what `wrapper` is for wrapper = Widget(vscroll) wrapper.setFixedSize((width, height)) wrapper.setLayout(GridLayout()) # defaults: 2 columns # NOTE: don't __dict__ crawl in real code! # this is just because it's more convenient to do this for enumerating all # of the icons -- see cpp example for alternative... for key in entypo.__dict__.keys(): if key.startswith("ICON_"): b = Button(wrapper, "entypo.{0}".format(key), entypo.__dict__[key]) b.setIconPosition(Button.IconPosition.Left) b.setFixedWidth(half_width) screen.performLayout() screen.drawAll() screen.setVisible(True) nanogui.mainloop() del screen gc.collect() nanogui.shutdown()