def size(self, dialog): """ Recalculate the size of the Scrollable. @param dialog Dialog which contains us """ if dialog is None: return Widget.size(self, dialog) if self.is_fixed_size: self.width, self.height = self.max_width, self.max_height self.hscrollbar_height = dialog.theme["hscrollbar"]["left"]["image"].height self.vscrollbar_width = dialog.theme["vscrollbar"]["up"]["image"].width if self.root_group is None: # do we need to re-clone dialog groups? self.theme = dialog.theme self.batch = dialog.batch self.root_group = ScrollableGroup(0, 0, self.width, self.height, parent=dialog.fg_group) self.panel_group = pyglet.graphics.OrderedGroup(0, self.root_group) self.bg_group = pyglet.graphics.OrderedGroup(1, self.root_group) self.fg_group = pyglet.graphics.OrderedGroup(2, self.root_group) self.highlight_group = pyglet.graphics.OrderedGroup(3, self.root_group) Wrapper.delete(self) # force children to abandon old groups Wrapper.size(self, self) # all children are to use our groups if self.always_show_scrollbars or (self.max_width and self.width > self.max_width): if self.hscrollbar is None: self.hscrollbar = HScrollbar(self.max_width) else: if self.hscrollbar is not None: self.hscrollbar.delete() self.hscrollbar = None if self.always_show_scrollbars or (self.max_height and self.height > self.max_height): if self.vscrollbar is None: self.vscrollbar = VScrollbar(self.max_height) else: if self.vscrollbar is not None: self.vscrollbar.delete() self.vscrollbar = None self.width = min(self.max_width or self.width, self.width) self.content_width = self.width self.height = min(self.max_height or self.height, self.height) self.content_height = self.height if self.hscrollbar is not None: self.hscrollbar.size(dialog) self.hscrollbar.set(self.max_width, max(self.content.width, self.max_width)) self.height += self.hscrollbar.height if self.vscrollbar is not None: self.vscrollbar.size(dialog) self.vscrollbar.set(self.max_height, max(self.content.height, self.max_height)) self.width += self.vscrollbar.width
def delete(self): """ Delete all graphical elements associated with the Scrollable """ Wrapper.delete(self) if self.hscrollbar is not None: self.hscrollbar.delete() self.hscrollbar = None if self.vscrollbar is not None: self.vscrollbar.delete() self.vscrollbar = None self.root_group = None self.panel_group = None self.bg_group = None self.fg_group = None self.highlight_group = None
def size(self, dialog): """ Recalculate the size of the Scrollable. @param dialog Dialog which contains us """ if dialog is None: return Widget.size(self, dialog) if self.is_fixed_size: self.width, self.height = self.max_width, self.max_height self.hscrollbar_height = \ dialog.theme['hscrollbar']['left']['image'].height self.vscrollbar_width = \ dialog.theme['vscrollbar']['up']['image'].width if self.root_group is None: # do we need to re-clone dialog groups? self.theme = dialog.theme self.batch = dialog.batch self.root_group = ScrollableGroup(0, 0, self.width, self.height, parent=dialog.fg_group) self.panel_group = pyglet.graphics.OrderedGroup(0, self.root_group) self.bg_group = pyglet.graphics.OrderedGroup(1, self.root_group) self.fg_group = pyglet.graphics.OrderedGroup(2, self.root_group) self.highlight_group = pyglet.graphics.OrderedGroup( 3, self.root_group) Wrapper.delete(self) # force children to abandon old groups Wrapper.size(self, self) # all children are to use our groups if self.always_show_scrollbars or \ (self.max_width and self.width > self.max_width): if self.hscrollbar is None: self.hscrollbar = HScrollbar(self.max_width) else: if self.hscrollbar is not None: self.hscrollbar.delete() self.hscrollbar = None if self.always_show_scrollbars or \ (self.max_height and self.height > self.max_height): if self.vscrollbar is None: self.vscrollbar = VScrollbar(self.max_height) else: if self.vscrollbar is not None: self.vscrollbar.delete() self.vscrollbar = None self.width = min(self.max_width or self.width, self.width) self.content_width = self.width self.height = min(self.max_height or self.height, self.height) self.content_height = self.height if self.hscrollbar is not None: self.hscrollbar.size(dialog) self.hscrollbar.set(self.max_width, max(self.content.width, self.max_width)) self.height += self.hscrollbar.height if self.vscrollbar is not None: self.vscrollbar.size(dialog) self.vscrollbar.set(self.max_height, max(self.content.height, self.max_height)) self.width += self.vscrollbar.width