class FoldingSection(Control, VerticalLayout): def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER): Control.__init__(self) if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False self.is_open = is_open self.folding_content = content self.book = Graphic(self._get_image_path()) self.header = HorizontalLayout([ Graphic(path=["section", "left"], is_expandable=left_expand), Frame(HorizontalLayout([ self.book, Label(title, path=["section"]), ]), path=["section", "center"], use_bg_group=True), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0) layout = [self.header] if self.is_open: layout.append(content) VerticalLayout.__init__(self, content=layout, align=align) def _get_controls(self): return VerticalLayout._get_controls(self) + \ [(self, self.header.x, self.header.x + self.header.width, self.header.y + self.header.height, self.header.y)] def _get_image_path(self): if self.is_open: return ["section", "opened"] else: return ["section", "closed"] def hit_test(self, x, y): return self.header.hit_test(x, y) def on_mouse_press(self, x, y, button, modifiers): self.is_open = not self.is_open self.book.delete() self.book.path = self._get_image_path() if self.is_open: self.add(self.folding_content) else: self.remove(self.folding_content) self.folding_content.delete() def teardown(self): self.folding_content.teardown() self.folding_content = None VerticalLayout.teardown(self)
def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER): Control.__init__(self) if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False self.is_open = is_open self.folding_content = content self.book = Graphic(self._get_image_path()) self.header = HorizontalLayout([ Graphic(path=["section", "left"], is_expandable=left_expand), Frame(HorizontalLayout([ self.book, Label(title, path=["section"]), ]), path=["section", "center"], use_bg_group=True), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0) layout = [self.header] if self.is_open: layout.append(content) VerticalLayout.__init__(self, content=layout, align=align)
def __init__(self, title, content): VerticalLayout.__init__( self, content=[ HorizontalLayout([ Graphic(path=["titlebar", "left"], is_expandable=True), Frame(Label(title, path=["titlebar"]), path=["titlebar", "center"]), Graphic(path=["titlebar", "right"], is_expandable=True), ], align=VALIGN_BOTTOM, padding=0), Frame(content, path=["titlebar", "frame"], is_expandable=True), ], padding=0)
def __init__(self, title, align=HALIGN_CENTER): if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False HorizontalLayout.__init__(self, content=[ Graphic(path=["section", "left"], is_expandable=left_expand), Frame(Label(title, path=["section"]), path=['section', 'center'], use_bg_group=True), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0)