Beispiel #1
0
 def show_menu(self, pos):
     if self.menu and self.selected_item_index:
         m = Menu("Menu", self.menu)
         i = m.present(self, pos)
         if i > -1:
             meth = getattr(self, self.menu[i][1], None)
             if meth:
                 meth()
Beispiel #2
0
class MenuButton(Button):
    def __init__(self, title, choices, **kw):
        Button.__init__(self, title, **kw)
        self.choices = choices
        self.menu = Menu(title, ((c,c) for c in choices))
        
    def action(self):
        index = self.menu.present(self, (0,0))
        if index == -1: return
        self.menu_picked(index)
        
    def menu_picked(self, index):
        pass
Beispiel #3
0
class MenuButton(Button):
    def __init__(self, title, choices, **kw):
        Button.__init__(self, title, **kw)
        self.choices = choices
        self.menu = Menu(title, ((c, c) for c in choices))

    def action(self):
        index = self.menu.present(self, (0, 0))
        if index == -1:
            return
        self.menu_picked(index)

    def menu_picked(self, index):
        pass
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)