def determine_size(self): self._content.determine_size() size = self._content._pref_size if self.collapsed: self._pref_size = Size(size[0], self._top_h) else: self._pref_size = Size(size[0], size[1] + self._top_h)
def determine_size(self): w, h = 0, self.padding[self._axis] for c in self.children: c.determine_size() min = c._pref_size if min[1 - self._axis] > w: w = min[1 - self._axis] h += min[self._axis] + self.padding[self._axis] if self._axis == 1: self._pref_size = Size(w + self.padding[1 - self._axis] * 2, h) else: self._pref_size = Size(h, w + self.padding[1 - self._axis] * 2)
def __init__(self, **kwargs): '''Initialise a Widget Keyword arguments: name -- unique widget identifier ''' self._x, self._y = kwargs.get('x', 0), kwargs.get('y', 0) self._w, self._h = kwargs.get('w', 0), kwargs.get('h', 0) self._gx, self._gy = self._x, self._y self._pref_size = Size() self._name = kwargs.get('name') self.parent = None self._theme = None self._batch = None self._group = None self._dirty = False self._visible = True self.halign = kwargs.get('halign', 'center') self.valign = kwargs.get('valign', 'center') self.shapes = {} self.elements = {} self.expandable = [kwargs.get('hexpand', self._w==0), kwargs.get('vexpand', self._h==0)]
def determine_size(self): maxw = self.w - self.padding[0]*2 w, h, maxh = self.padding[0], self.padding[1], 0 self.lines = [] line = [] for c in self.children: c.determine_size() min = c._pref_size if w + min.w < maxw: line.append(c) else: self.lines.append((maxh, w, line)) line = [c] h += maxh + self.padding[1] w, maxh = self.padding[0], 0 if min.h > maxh: maxh = min.h w += min.w + self.padding[0] if len(line) > 0: self.lines.append((maxh, w, line)) h += maxh + self.padding[1] self._pref_size = Size(self.w, max(h, self.padding[1]*2))
def update_theme(self, theme): Widget.update_theme(self, theme) if theme: patch = theme['slider']['image_slider'] patch_knob = theme['slider']['image_knob'] self._pref_size = Size(self.w, patch.padding_bottom + patch.padding_top) self.shapes['track'].patch = patch self.shapes['knob'].patch = patch_knob
def reset_size(self, size): Widget.reset_size(self, size) minh = self._pref_size[self._axis] freeh = size[self._axis] - minh flexible = [c for c in self.children if c.expandable[self._axis]] l = len(flexible) if l > 0: extrah = freeh / len(flexible) th = self.padding[self._axis] step = (1, -1)[self._axis] for c in self.children[::step]: if self._axis == 1: c._x, c._y = self.padding[1 - self._axis], th else: c._y, c._x = self.padding[1 - self._axis], th min = c._pref_size if c.expandable[1 - self._axis]: nw = size[1 - self._axis] - self.padding[1 - self._axis] * 2 else: nw = min[1 - self._axis] if c.expandable[self._axis]: nh = min[self._axis] + extrah else: nh = min[self._axis] if self._axis == 1: c.reset_size(Size(nw, nh)) else: c.reset_size(Size(nh, nw)) th += nh + self.padding[self._axis]
def update_theme(self, theme): Widget.update_theme(self, theme) if theme: self.content.font_name = self.theme['font'] self.content.font_size = self.theme['font_size'] self.content.color = theme['font_color'] font = self.content.document.get_font() height = font.ascent - font.descent self._w, self._h = self.content.content_width, height self._pref_size = Size(self.content.content_width, height)
def update_theme(self, theme): Widget.update_theme(self, theme) if theme: patch = theme['checkbox'][('image_checked' if self.value else 'image_unchecked')] label = self.elements['label'] label.font_name = theme['font'] label.font_size = theme['font_size'] label.color = theme['font_color'] font = label.document.get_font() height = font.ascent - font.descent self._pref_size = Size(patch.padding_left + label.content_width + patch.padding_right, patch.padding_bottom + height + patch.padding_top) self.shapes['box'].patch = patch
def update_theme(self, theme): Widget.update_theme(self, theme) if theme: patch = theme['textbox']['image'] self.shapes['frame'].patch = patch self.label.document.set_style(0, len(self.label.document.text), { 'font_size': theme['font_size'], 'color': theme['font_color'] }) font = self.label.document.get_font() height = font.ascent - font.descent self._pref_size = Size(self.w, patch.padding_y + height) self.label.layout.width = self.w - patch.padding_x self.label.layout.height = height
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): Widget.update_theme(self, theme) if theme: patch = theme['button'][('image_down' if self._down else 'image_up')] label = self.elements['label'] label.font_name = self.theme['font'] label.font_size = self.theme['font_size'] label.color = theme['font_color'] font = label.document.get_font() height = font.ascent - font.descent self._pref_size = Size( patch.padding_left + label.content_width + patch.padding_right, patch.padding_bottom + height + patch.padding_top) label.x = patch.padding_left + label.content_width / 2 label.y = patch.padding_bottom + height / 2 - font.descent self.shapes['frame'].patch = patch
def reset_size(self, size): Widget.reset_size(self, size) if not self.collapsed: self._content.reset_size(Size(size.w, size.h - self._top_h))