menu: optimize container populate
- don't populate all items at once - populate items when container is pushed to stack - precreate List back item, don't create it during populate. - don't update items during populate Signed-off-by: Janar Sööt <janar.soot@gmail.com>
This commit is contained in:
parent
2a27093f69
commit
ccfcc3789b
|
@ -328,7 +328,6 @@ class MenuContainer(MenuElement):
|
||||||
item.add_parents(self._parents)
|
item.add_parents(self._parents)
|
||||||
item.add_parents(self)
|
item.add_parents(self)
|
||||||
item.assert_recursive_relation()
|
item.assert_recursive_relation()
|
||||||
item.populate()
|
|
||||||
if index is None:
|
if index is None:
|
||||||
self._allitems.append((item, name))
|
self._allitems.append((item, name))
|
||||||
else:
|
else:
|
||||||
|
@ -346,7 +345,6 @@ class MenuContainer(MenuElement):
|
||||||
self._populate()
|
self._populate()
|
||||||
# send populate event
|
# send populate event
|
||||||
self.send_event('populate', self)
|
self.send_event('populate', self)
|
||||||
self.update_items()
|
|
||||||
|
|
||||||
def update_items(self):
|
def update_items(self):
|
||||||
_a = [(item, name) for item, name in self._allitems
|
_a = [(item, name) for item, name in self._allitems
|
||||||
|
@ -553,7 +551,12 @@ class MenuInput(MenuCommand):
|
||||||
class MenuList(MenuContainer):
|
class MenuList(MenuContainer):
|
||||||
def __init__(self, manager, config):
|
def __init__(self, manager, config):
|
||||||
super(MenuList, self).__init__(manager, config)
|
super(MenuList, self).__init__(manager, config)
|
||||||
self._show_title = True
|
# create back item
|
||||||
|
self._itemBack = self.manager.menuitem_from({
|
||||||
|
'type': 'command',
|
||||||
|
'name': '..',
|
||||||
|
'gcode': '{menu.back()}'
|
||||||
|
})
|
||||||
|
|
||||||
def _names_aslist(self):
|
def _names_aslist(self):
|
||||||
return self.manager.lookup_children(self.get_ns())
|
return self.manager.lookup_children(self.get_ns())
|
||||||
|
@ -561,15 +564,7 @@ class MenuList(MenuContainer):
|
||||||
def _populate(self):
|
def _populate(self):
|
||||||
super(MenuList, self)._populate()
|
super(MenuList, self)._populate()
|
||||||
# add back as first item
|
# add back as first item
|
||||||
name = '..'
|
self.insert_item(self._itemBack, 0)
|
||||||
if self._show_title:
|
|
||||||
name += ' %s' % str(self._name())
|
|
||||||
item = self.manager.menuitem_from({
|
|
||||||
'type': 'command',
|
|
||||||
'name': self.manager.asliteral(name),
|
|
||||||
'gcode': '{menu.back()}'
|
|
||||||
})
|
|
||||||
self.insert_item(item, 0)
|
|
||||||
|
|
||||||
def render_container(self, eventtime):
|
def render_container(self, eventtime):
|
||||||
rows = []
|
rows = []
|
||||||
|
@ -702,7 +697,6 @@ class MenuManager:
|
||||||
self.update_context(eventtime)
|
self.update_context(eventtime)
|
||||||
if isinstance(self.root, MenuContainer):
|
if isinstance(self.root, MenuContainer):
|
||||||
self.root.init_selection()
|
self.root.init_selection()
|
||||||
self.root.populate()
|
|
||||||
self.stack_push(self.root)
|
self.stack_push(self.root)
|
||||||
self.running = True
|
self.running = True
|
||||||
return
|
return
|
||||||
|
@ -748,6 +742,7 @@ class MenuManager:
|
||||||
def stack_push(self, container):
|
def stack_push(self, container):
|
||||||
if not isinstance(container, MenuContainer):
|
if not isinstance(container, MenuContainer):
|
||||||
raise error("Wrong type, expected MenuContainer")
|
raise error("Wrong type, expected MenuContainer")
|
||||||
|
container.populate()
|
||||||
top = self.stack_peek()
|
top = self.stack_peek()
|
||||||
if top is not None:
|
if top is not None:
|
||||||
if isinstance(top, MenuList):
|
if isinstance(top, MenuList):
|
||||||
|
|
Loading…
Reference in New Issue