Example #1
0
class SectionListWidget(urwid.ListBox, BaseWidgetClass):
    def __init__(self, content, factory=factories.section_list_factory, index=1):
        logging.debug("[SectionListWidget] init with content: %s" % list(content))
        BaseWidgetClass.__init__(self)
        self.structured_data = SectionList(content)
        self.factory = factory
        self.content = self.factory(self.structured_data)
        urwid.ListBox.__init__(self, self.content)
        self.set_focus(index)

    def go_up(self):
        index = self.get_current_position()
        if index is None:
            return
        index -= 1
        if index < 1:
            index = 1
        self.set_focus(index)
        if not self.get_current_widget().walkable and index != 1:
            self.go_up()

    def go_down(self):
        index = self.get_current_position()
        if index is None:
            return
        index += 1
        if index >= len(self.content):
            index = len(self.content) - 1
        self.set_focus(index)
        if not self.get_current_widget().walkable and index != len(self.content) - 1:
            self.go_down()

    def append_section(self, section):
        self.structured_data.append(Section((section, [])))
        self.update()

    def update(self):
        self.content = self.factory(self.structured_data)
        self.body.contents = self.content[:]

    def append_item(self, item):
        current_widget = self.get_current_widget()
        if current_widget is None:
            return
        if hasattr(current_widget, "ref_to_object"):
            father = current_widget.ref_to_object.father
        else:
            father = self.content[self.get_current_position() - 1].ref_to_object
        father.childs.append(SectionChild(item, father))
        self.update()

    def get_current_position(self):
        return self.get_focus()[1]

    def get_current_widget(self):
        return self.get_focus()[0]
Example #2
0
 def __init__(self,
              content,
              factory=factories.section_list_factory,
              index=1):
     logging.debug("[SectionListWidget] init with content: %s" %
                   list(content))
     BaseWidgetClass.__init__(self)
     self.structured_data = SectionList(content)
     self.factory = factory
     self.content = self.factory(self.structured_data)
     urwid.ListBox.__init__(self, self.content)
     self.set_focus(index)
Example #3
0
 def __init__(self, content, factory=factories.section_list_factory, index=1):
     logging.debug("[SectionListWidget] init with content: %s" % list(content))
     BaseWidgetClass.__init__(self)
     self.structured_data = SectionList(content)
     self.factory = factory
     self.content = self.factory(self.structured_data)
     urwid.ListBox.__init__(self, self.content)
     self.set_focus(index)
Example #4
0
class SectionListWidget(urwid.ListBox, BaseWidgetClass):
    def __init__(self,
                 content,
                 factory=factories.section_list_factory,
                 index=1):
        logging.debug("[SectionListWidget] init with content: %s" %
                      list(content))
        BaseWidgetClass.__init__(self)
        self.structured_data = SectionList(content)
        self.factory = factory
        self.content = self.factory(self.structured_data)
        urwid.ListBox.__init__(self, self.content)
        self.set_focus(index)

    def go_up(self):
        index = self.get_current_position()
        if index is None:
            return
        index -= 1
        if index < 1:
            index = 1
        self.set_focus(index)
        if not self.get_current_widget().walkable and index != 1:
            self.go_up()

    def go_down(self):
        index = self.get_current_position()
        if index is None:
            return
        index += 1
        if index >= len(self.content):
            index = len(self.content) - 1
        self.set_focus(index)
        if not self.get_current_widget().walkable and index != len(
                self.content) - 1:
            self.go_down()

    def append_section(self, section):
        self.structured_data.append(Section((section, [])))
        self.update()

    def update(self):
        self.content = self.factory(self.structured_data)
        self.body.contents = self.content[:]

    def append_item(self, item):
        current_widget = self.get_current_widget()
        if current_widget is None:
            return
        if hasattr(current_widget, "ref_to_object"):
            father = current_widget.ref_to_object.father
        else:
            father = self.content[self.get_current_position() -
                                  1].ref_to_object
        father.childs.append(SectionChild(item, father))
        self.update()

    def get_current_position(self):
        return self.get_focus()[1]

    def get_current_widget(self):
        return self.get_focus()[0]