def on_mouse_release(self, x, y, button, modifiers): if button == pyglet.window.mouse.LEFT and self._in_drag: self._in_drag = False return pyglet.event.EVENT_HANDLED SingleContainer.on_mouse_release(self, x, y, button, modifiers) return pyglet.event.EVENT_UNHANDLED
def on_mouse_press(self, x, y, button, modifiers): if button == pyglet.window.mouse.LEFT and self.topbar.hit_test(x - self._gx, y - self._gy): self.collapsed = not self.collapsed return pyglet.event.EVENT_HANDLED SingleContainer.on_mouse_press(self, x, y, button, modifiers) return pyglet.event.EVENT_UNHANDLED
def __init__(self, title, **kwargs): '''Create a folding box Keyword arguments: name -- unique widget identifier content -- child container collapsed -- if true, container folded initially ''' SingleContainer.__init__(self, **kwargs) self.shapes['topbar'] = Rectangle() self.elements['title'] = BasicLabel(title, font_size=8, color=(0, 0, 0, 255), anchor_x='left', anchor_y='center') self.content = kwargs.get('content', None) self._last_h = 15 self._collapsed = False self._top_h = 0 self.collapsed = kwargs.get('collapsed', False)
def update_elements(self): if self._dirty and self.theme: background = self.theme['window']['image_background'] title_bar = self.theme['window']['image_title_bar'] font = self.elements['title'].document.get_font() height = font.ascent - font.descent h = title_bar.padding_bottom + height + title_bar.padding_top self.shapes['background'].update(self._gx, self._gy, self.w, self.h) self.shapes['title_bar'].update_in( self._gx - background.padding_left, self._gy + self.h, self.w + background.padding_left + background.padding_right, h) self.elements['title'].x = self._gx + self.w / 2 self.topbar = Rect( -background.padding_left, self.h, self.w + background.padding_left + background.padding_right, h) self.elements[ 'title'].y = self._gy + self.h + title_bar.padding_bottom - font.descent SingleContainer.update_elements(self)
def on_mouse_press(self, x, y, button, modifiers): if button == pyglet.window.mouse.LEFT and \ self.topbar.hit_test(x - self._gx, y - self._gy): self.collapsed = not self.collapsed return pyglet.event.EVENT_HANDLED SingleContainer.on_mouse_press(self, x, y, button, modifiers) return pyglet.event.EVENT_UNHANDLED
def update_theme(self, theme): SingleContainer.update_theme(self, theme) if theme: self.elements['frame'].patch = theme['dialogue']['image'] self.elements['title'].font_name = theme['font'] self.elements['title'].font_size = theme['font_size_small'] self.elements['title'].color = theme['font_color']
def on_mouse_drag(self, x, y, dx, dy, button, modifiers): if button == pyglet.window.mouse.LEFT and self._in_drag: self._x = x - self._offset_x self._y = y - self._offset_y self.find_root().update_layout() return pyglet.event.EVENT_HANDLED SingleContainer.on_mouse_drag(self, x, y, dx, dy, button, modifiers) return pyglet.event.EVENT_UNHANDLED
def on_mouse_press(self, x, y, button, modifiers): if button == pyglet.window.mouse.LEFT and \ self.topbar.hit_test(x - self.x, y - self.y): self._in_drag = True self._offset_x = x - self.x self._offset_y = y - self.y return pyglet.event.EVENT_HANDLED SingleContainer.on_mouse_press(self, x, y, button, modifiers) return pyglet.event.EVENT_UNHANDLED
def update_elements(self): if self.theme: patch = self.theme['folding_box'][('image_closed' if self._collapsed else 'image')] self.shapes['topbar'].update(self._gx + patch.padding_left, self._gy + self.h - patch.padding_top, self.w - patch.padding_left - patch.padding_right, 1) self.elements['title'].x = self._gx + patch.padding_left self.elements['title'].y = self._gy + self.h - patch.padding_top/2 + 1 self.topbar = Rect(0, self.h-patch.padding_top, self.w, patch.padding_top) SingleContainer.update_elements(self)
def on_mouse_press(self, x, y, button, modifiers): if button == pyglet.window.mouse.LEFT and \ self.topbar.hit_test(x - self._gx, y - self._gy): self._collapsed = not self._collapsed self._h, self._last_h = self._last_h, self._h self.elements['topbar'].patch = self.theme['folding_box'][('image_closed' if self._collapsed else 'image')] self.find_root().update_layout() return pyglet.event.EVENT_HANDLED SingleContainer.on_mouse_press(self, x, y, button, modifiers) return pyglet.event.EVENT_UNHANDLED
def update_theme(self, theme): SingleContainer.update_theme(self, theme) if theme: patch = self.theme['folding_box'][('image_closed' if self._collapsed else 'image')] self.elements['topbar'].patch = patch self.elements['title'].font_name = theme['font'] self.elements['title'].font_size = theme['font_size_small'] self.elements['title'].color = theme['font_color'] if self._collapsed: self._h = patch.padding_top else: self._last_h = patch.padding_top
def update_layout(self): SingleContainer.update_layout(self) if self.content: self._y = self._y + self._h - self.content.h self._w, self._h = self.content.w, self.content.h self.elements['frame'].update(0, 0, self.w, self.h) self.elements['title'].x = self.w/2 if self.resizeable: self.elements['resize'].update(self.w-15, 0, 15, 15) if self.theme: patch = self.theme['dialogue']['image'] self.topbar = Rect(-patch.padding_left, self.h, self.w + patch.padding_right, patch.padding_top) self.elements['title'].y = self.h + patch.padding_top/2
def update_elements(self): if self.theme: patch = self.theme["folding_box"][("image_closed" if self._collapsed else "image")] self.shapes["topbar"].update( self._gx + patch.padding_left, self._gy + self.h - patch.padding_top, self.w - patch.padding_left - patch.padding_right, 1, ) self.elements["title"].x = self._gx + patch.padding_left self.elements["title"].y = self._gy + self.h - patch.padding_top / 2 + 1 self.topbar = Rect(0, self.h - patch.padding_top, self.w, patch.padding_top) SingleContainer.update_elements(self)
def update_layout(self): SingleContainer.update_layout(self) if self.theme: patch = self.theme['folding_box'][('image_closed' if self._collapsed else 'image')] if self.content: self._w = self.content.w + patch.padding_left + patch.padding_right if not self._collapsed: self._h = self.content.h + patch.padding_bottom + patch.padding_top self.elements['topbar'].update(patch.padding_left, self.h - patch.padding_top, self.w - patch.padding_left - patch.padding_right, 1) self.elements['title'].x = patch.padding_left self.elements['title'].y = self.h - patch.padding_top/2 + 1 self.topbar = Rect(0, self.h-patch.padding_top, self.w, patch.padding_top)
def update_theme(self, theme): SingleContainer.update_theme(self, theme) if theme: patch = theme["folding_box"][("image_closed" if self._collapsed else "image")] self.shapes["topbar"].patch = patch self.elements["title"].font_name = theme["font"] self.elements["title"].font_size = theme["font_size_small"] self.elements["title"].color = theme["font_color"] if self._collapsed: self._h = patch.padding_top else: self._last_h = patch.padding_top self._top_h = patch.padding_top
def update_elements(self): if self.theme: patch = self.theme['folding_box'][('image_closed' if self._collapsed else 'image')] self.shapes['topbar'].update( self._gx + patch.padding_left, self._gy + self.h - patch.padding_top, self.w - patch.padding_left - patch.padding_right, 1) self.elements['title'].x = self._gx + patch.padding_left self.elements[ 'title'].y = self._gy + self.h - patch.padding_top / 2 + 1 self.topbar = Rect(0, self.h - patch.padding_top, self.w, patch.padding_top) SingleContainer.update_elements(self)
def update_theme(self, theme): SingleContainer.update_theme(self, theme) if theme: background_patch = theme['window']['image_background'] title_patch = theme['window']['image_title_bar'] self.shapes['background'].patch = background_patch self.shapes['title_bar'].patch = title_patch self.elements['title'].font_name = theme['font'] self.elements['title'].font_size = theme['font_size_small'] self.elements['title'].color = theme['font_color'] font = self.elements['title'].document.get_font() height = font.ascent - font.descent self._pref_size = Size(title_patch.padding_x + self.elements['title'].content_width, background_patch.padding_y + title_patch.padding_y + height)
def update_theme(self, theme): SingleContainer.update_theme(self, theme) if theme: patch = theme['folding_box'][('image_closed' if self._collapsed else 'image')] self.shapes['topbar'].patch = patch self.elements['title'].font_name = theme['font'] self.elements['title'].font_size = theme['font_size_small'] self.elements['title'].color = theme['font_color'] if self._collapsed: self._h = patch.padding_top else: self._last_h = patch.padding_top self._top_h = patch.padding_top
def on_mouse_press(self, x, y, button, modifiers): if button == pyglet.window.mouse.LEFT and \ self.topbar.hit_test(x - self.x, y - self.y): self._in_drag = True self._offset_x = x - self.x self._offset_y = y - self.y return pyglet.event.EVENT_HANDLED if self.resizeable and button == pyglet.window.mouse.LEFT and \ self.elements['resize'].hit_test(x - self.x, y - self.y): self._in_resize = True self._orig_y = self.y self._orig_h = self.h self._offset_x = x - self.x - self.w self._offset_y = y - self.y return pyglet.event.EVENT_HANDLED SingleContainer.on_mouse_press(self, x, y, button, modifiers) return pyglet.event.EVENT_UNHANDLED
def __init__(self, x, y, w, h, title, **kwargs): '''Create a folding box Keyword arguments: name -- unique widget identifier content -- child container collapsed -- if true, container folded initially ''' SingleContainer.__init__(self, x, y, w, h+15, **kwargs) self.elements['topbar'] = Rectangle() self.elements['title'] = pyglet.text.Label(title, font_size=8, color=(0,0,0,255), x=w/2, y=h+7, anchor_x='left', anchor_y='center') self._last_h = 15 self._collapsed = kwargs.get('collapsed', False) if self._collapsed: self._h, self._last_h = self._last_h, self._h self.content = kwargs.get('content', Container(0, 0, w, h))
def update_elements(self): if self._dirty and self.theme: background = self.theme['window']['image_background'] title_bar = self.theme['window']['image_title_bar'] font = self.elements['title'].document.get_font() height = font.ascent - font.descent h = title_bar.padding_bottom + height + title_bar.padding_top self.shapes['background'].update(self._gx, self._gy, self.w, self.h) self.shapes['title_bar'].update_in(self._gx - background.padding_left, self._gy + self.h, self.w + background.padding_left + background.padding_right, h) self.elements['title'].x = self._gx + self.w/2 self.topbar = Rect(-background.padding_left, self.h, self.w + background.padding_left + background.padding_right, h) self.elements['title'].y = self._gy + self.h + title_bar.padding_bottom - font.descent SingleContainer.update_elements(self)
def __init__(self, title, **kwargs): '''Create a dialogue Keyword arguments: name -- unique widget identifier content -- child container ''' SingleContainer.__init__(self, **kwargs) self.resizeable = kwargs.get('resizeable', False) self.shapes['background'] = Rectangle() self.shapes['title_bar'] = Rectangle() self.elements['title'] = BasicLabel(title, anchor_x='center') self.topbar = Rect(0, 0, 0, 15) self._in_drag = False self.content = kwargs.get('content', None)
def update_theme(self, theme): SingleContainer.update_theme(self, theme) if theme: background_patch = theme['window']['image_background'] title_patch = theme['window']['image_title_bar'] self.shapes['background'].patch = background_patch self.shapes['title_bar'].patch = title_patch self.elements['title'].font_name = theme['font'] self.elements['title'].font_size = theme['font_size_small'] self.elements['title'].color = theme['font_color'] font = self.elements['title'].document.get_font() height = font.ascent - font.descent self._pref_size = Size( title_patch.padding_x + self.elements['title'].content_width, background_patch.padding_y + title_patch.padding_y + height)
def __init__(self, title, **kwargs): '''Create a folding box Keyword arguments: name -- unique widget identifier content -- child container collapsed -- if true, container folded initially ''' SingleContainer.__init__(self, **kwargs) self.shapes['topbar'] = Rectangle() self.elements['title'] = BasicLabel(title, font_size=8, color=(0,0,0,255), anchor_x='left', anchor_y='center') self.content = kwargs.get('content', None) self._last_h = 15 self._collapsed = False self._top_h = 0 self.collapsed = kwargs.get('collapsed', False)
def __init__(self, x, y, w, h, title, **kwargs): '''Create a dialogue Keyword arguments: name -- unique widget identifier content -- child container resizeable -- if true, the dialogue is resizable ''' SingleContainer.__init__(self, x, y, w, h, **kwargs) self.resizeable = kwargs.get('resizeable', False) self.elements['frame'] = Rectangle() self.elements['title'] = pyglet.text.Label(title, font_size=8, bold=True, color=(0,0,0,255), x=w/2, y=h+7, anchor_x='center', anchor_y='center') if self.resizeable: self.elements['resize'] = Rectangle(w-15, 0, 15, 15, (0.75, 0.75, 0.75, 0.5)) self.topbar = Rect(0, h, w, 15) self._in_drag = False self._in_resize = False self.content = kwargs.get('content', Container(0, 0, w, h))
def __init__(self, title, **kwargs): """Create a folding box Keyword arguments: name -- unique widget identifier content -- child container collapsed -- if true, container folded initially """ SingleContainer.__init__(self, **kwargs) self.shapes["topbar"] = Rectangle() self.elements["title"] = BasicLabel( title, font_size=8, color=(0, 0, 0, 255), anchor_x="left", anchor_y="center" ) self.content = kwargs.get("content", None) self._last_h = 15 self._collapsed = False self._top_h = 0 self.collapsed = kwargs.get("collapsed", False)
def on_mouse_drag(self, x, y, dx, dy, button, modifiers): if button == pyglet.window.mouse.LEFT and self._in_drag: self.x = x - self._offset_x self.y = y - self._offset_y return pyglet.event.EVENT_HANDLED if button == pyglet.window.mouse.LEFT and self._in_resize: self._w = x - self.x - self._offset_x if self.w < 100: self._w = 100 self._h = self._orig_h - (y - self._orig_y - self._offset_y) self.y = self._orig_y + (y - self._orig_y - self._offset_y) if self.h < 50: self.y -= 50 - self.h self._h = 50 self.content._w, self.content._h = self.w, self.h self.update_layout() return pyglet.event.EVENT_HANDLED SingleContainer.on_mouse_drag(self, x, y, dx, dy, button, modifiers) return pyglet.event.EVENT_UNHANDLED
def reset_size(self, size): self._y += self._h - size.h SingleContainer.reset_size(self, size)