def __init__(self, inner_padding=5, scrollable=False, style=FS_raised, **kwargs): """ Creates a new frame with the given options and style. If scrollable is True, the contents of the frame will scroll if they don't fit into the frame height. inner_padding only has effect if scrollable is True. You can call fit_to_children() to make the frame fit automatically to it's contents.""" LUIObject.__init__(self) # Each *style* has a different border size (size of the shadow). The # border size shouldn't get calculated to the actual framesize, so we # are determining it first and then substracting it. # TODO: We could do this automatically, determined by the sprite size # probably? self._border_size = 0 self.padding = 10 self.solid = True prefix = "" if style == LUIFrame.FS_raised: temp = LUISprite(self, "Frame_Left", "skin") self._border_size = temp.width self.remove_child(temp) prefix = "Frame_" elif style == LUIFrame.FS_sunken: self._border_size = 0 prefix = "SunkenFrame_" else: raise Exception("Unkown LUIFrame style: " + style) self._scrollable = scrollable self._layout = LUICornerLayout(parent=self, image_prefix=prefix) self._layout.margin = -(self.padding.top + self._border_size) if self._scrollable: self._content = LUIObject(self) self._content.size = (self.width, self.height) self._content.pos = (self._border_size, self._border_size) self._scroll_content = LUIScrollableRegion( self._content, width=self.width - 2 * self.padding.left, height=self.height - 2 * self.padding.left, padding=inner_padding) self.content_node = self._scroll_content.content_node LUIInitialState.init(self, kwargs)
def __init__(self, parent, width=200): LUIObject.__init__(self, x=0, y=0, w=width, h=1, solid=True) self.layout = LUICornerLayout(parent=self, image_prefix="Selectdrop_", width=width + 10, height=100) self.layout.margin_left = -3 self.opener = LUISprite(self, "SelectboxOpen_Right", "skin") self.opener.right = -4 self.opener.top = -25 self.opener.z_offset = 3 self.container = LUIObject(self.layout, 0, 0, 0, 0) self.container.width = self.width self.container.clip_bounds = (0,0,0,0) self.container.left = 5 self.selectbox = parent self.parent = self.selectbox
def __init__(self, innerPadding=5, scrollable=False, style=Raised, **kwargs): """ Creates a new frame with the given options and style. If scrollable is True, the contents of the frame will scroll if they don't fit into the frame height. innerPadding only has effect if scrollable is True. You can call fit_to_children() to make the frame fit automatically to it's contents.""" LUIObject.__init__(self) # Each *style* has a different border size (size of the shadow). The # border size shouldn't get calculated to the actual framesize, so we # are determining it first and then substracting it. # TODO: We could do this automatically, determined by the sprite size # probably? self.borderSize = 0 self.padding = 10 self.solid = True prefix = "" if style == LUIFrame.Raised: self.borderSize = 33 prefix = "Frame_" elif style == LUIFrame.Sunken: self.borderSize = 5 prefix = "SunkenFrame_" else: print "Unkown UIFrame style:", style self.layout = LUICornerLayout(parent=self, image_prefix=prefix) LUIInitialState.init(self, kwargs) self.effectivePadding = self.padding_top + self.borderSize self.scrollable = scrollable self.layout.margin = -self.effectivePadding # TODO: Scrollable # if self.scrollable: self.content = LUIObject(self)
def __init__(self, parent, width=200): LUIObject.__init__(self, x=0, y=0, w=width, h=1, solid=True) self._layout = LUICornerLayout(parent=self, image_prefix="Selectdrop_", width=width + 10, height=100) self._layout.margin.left = -3 self._opener = LUISprite(self, "SelectboxOpen_Right", "skin") self._opener.right = -4 self._opener.top = -25 self._opener.z_offset = 3 self._container = LUIObject(self._layout, 0, 0, 0, 0) self._container.width = self.width self._container.clip_bounds = (0, 0, 0, 0) self._container.left = 5 self._container.solid = True self._container.bind("mousedown", lambda *args: self.request_focus()) self._selectbox = parent self._option_focus = False self.parent = self._selectbox
class LUIFrame(LUIObject): Sunken = 1 Raised = 2 """ A container which can store multiple ui-elements """ def __init__(self, innerPadding=5, scrollable=False, style=Raised, **kwargs): """ Creates a new frame with the given options and style. If scrollable is True, the contents of the frame will scroll if they don't fit into the frame height. innerPadding only has effect if scrollable is True. You can call fit_to_children() to make the frame fit automatically to it's contents.""" LUIObject.__init__(self) # Each *style* has a different border size (size of the shadow). The # border size shouldn't get calculated to the actual framesize, so we # are determining it first and then substracting it. # TODO: We could do this automatically, determined by the sprite size # probably? self.borderSize = 0 self.padding = 10 self.solid = True prefix = "" if style == LUIFrame.Raised: self.borderSize = 33 prefix = "Frame_" elif style == LUIFrame.Sunken: self.borderSize = 5 prefix = "SunkenFrame_" else: print "Unkown UIFrame style:", style self.layout = LUICornerLayout(parent=self, image_prefix=prefix) LUIInitialState.init(self, kwargs) self.effectivePadding = self.padding_top + self.borderSize self.scrollable = scrollable self.layout.margin = -self.effectivePadding # TODO: Scrollable # if self.scrollable: self.content = LUIObject(self) # self.content.size = (width, height) # self.content.pos = (self.borderSize, self.borderSize) # self.scrollContent = UIScrollableRegion(self.content, width=width-2*padding, height=height-2*padding, padding=innerPadding) # self.contentNode = self.scrollContent.get_content_node() def on_resized(self, event): """ Internal callback when the Frame got resized """ self.layout.size = self.size + 2* self.borderSize self.layout.update_layout() def fit_to_children(self): """ Resizes the frame so it exactly fits its contents """ self.layout.size = 0, 0 LUIObject.fit_to_children(self) def fit_height_to_children(self): """ Resizes the frame vertically to fit its contents """ self.layout.size = 0, 0 LUIObject.fit_height_to_children(self) def fit_width_to_children(self): """ Resizes the frame horizontally to fit its contents """ self.layout.size = 0, 0 LUIObject.fit_width_to_children(self)
class UISelectdrop(LUIObject): def __init__(self, parent, width=200): LUIObject.__init__(self, x=0, y=0, w=width, h=1, solid=True) self.layout = LUICornerLayout(parent=self, image_prefix="Selectdrop_", width=width + 10, height=100) self.layout.margin_left = -3 self.opener = LUISprite(self, "SelectboxOpen_Right", "skin") self.opener.right = -4 self.opener.top = -25 self.opener.z_offset = 3 self.container = LUIObject(self.layout, 0, 0, 0, 0) self.container.width = self.width self.container.clip_bounds = (0,0,0,0) self.container.left = 5 self.selectbox = parent self.parent = self.selectbox def _on_opt_over(self, event): event.sender.color = (0,0,0,0.1) def _on_opt_out(self, event): event.sender.color = (0,0,0,0) def _on_opt_click(self, optid, event): self.selectbox._on_option_selected(optid) def _render_options(self, options): visible = min(4, len(options)) offsetTop = 6 self.layout.height = visible * 30 + offsetTop + 11 self.container.height = visible * 30 + offsetTop + 1 self.layout.update_layout() self.container.remove_all_children() currentY = offsetTop for optId, optVal in options: optContainer = LUIObject(self.container, x=0, y=currentY, w=self.container.width - 30, h=30) optBg = LUISprite(optContainer, "blank", "skin") optBg.width = self.container.width optBg.height = optContainer.height optBg.color = (0,0,0,0) optBg.bind("mouseover", self._on_opt_over) optBg.bind("mouseout", self._on_opt_out) optBg.bind("click", partial(self._on_opt_click, optId)) optBg.solid = True optLabel = LUILabel(parent=optContainer, text=unicode(optVal), shadow=True) optLabel.top = 5 optLabel.left = 8 if optId == self.selectbox.get_selected_option(): optLabel.color = (0.6, 0.9, 0.4, 1.0) divider = LUISprite(optContainer, "SelectdropDivider", "skin") divider.top = 30 - divider.height / 2 divider.width = self.container.width currentY += 30