本文整理汇总了Python中albow.Menu.set_scroll_items方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.set_scroll_items方法的具体用法?Python Menu.set_scroll_items怎么用?Python Menu.set_scroll_items使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类albow.Menu
的用法示例。
在下文中一共展示了Menu.set_scroll_items方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SlotEditor
# 需要导入模块: from albow import Menu [as 别名]
# 或者: from albow.Menu import set_scroll_items [as 别名]
class SlotEditor(Panel):
def __init__(self, inventory, data):
Panel.__init__(self)
self.inventory = inventory
slot, id, count, damage = data
self.former_id_text = id
self.slot = slot
self.id = TextFieldWrapped(text=id, doNotTranslate=True, width=300)
#&# Prototype for blocks/items names
self.menu = None
m = Menu("", [""])
h = m.font.get_linesize()
self.menu = Menu("", [""], scrolling=True, scroll_items=(self.root.local_to_global(self.root.bottomleft)[1] - self.root.local_to_global(self.bottomleft)[1] - (m.margin * 2)) / h)
del m
self.id.change_action = self.text_entered
self.id.escape_action = self.close_menu
self.menu.key_down = self.id.key_down
#&#
self.count = IntField(text="%s"%count, min=-64, max=64)
self.damage = IntField(text="%s"%damage, min=-32768, max=32767)
header = Label(_("Inventory Slot #%s")%slot, doNotTranslate=True)
row = Row([Label("id"), self.id,
Label("Count"), self.count,
Label("Damage"), self.damage,
])
buttons = Row([Button("Save", action=self.dismiss), Button("Cancel", action=self.cancel)])
col = Column([header, row, buttons], spacing=2)
self.add(col)
self.shrink_wrap()
def cancel(self, *args, **kwargs):
kwargs['save'] = False
self.dismiss(*args, **kwargs)
def dismiss(self, *args, **kwargs):
if kwargs.pop('save', True):
data = [self.slot, self.id.text, self.count.text, self.damage.text]
self.inventory.change_value(data)
Panel.dismiss(self, *args, **kwargs)
#&# Prototype for blocks/items names
def text_entered(self):
text = self.id.get_text()
if self.former_id_text == text:
return
results = []
for k in map_items.keys():
k = mclangres.translate(k)
if text.lower() in k.lower():
results.append(k)
results.sort()
self.menu.set_items([[a] for a in results])
self.menu.scrolling = True
self.menu.set_scroll_items((self.root.local_to_global(self.parent.bottomleft)[1] - self.root.local_to_global(self.bottomleft)[1] - (self.menu.margin * 2)) / self.menu.font.get_linesize())
sel = self.menu.present(self.id, (0, self.id.bottom - self.margin))
if sel >= 0:
self.former_id_text = self.menu.items[sel][0]
self.id.change_text(self.menu.items[sel][0])
self.former_id_text = self.menu.items[sel][0]
def close_menu(self):
if self.menu:
self.menu.dismiss(-1)