예제 #1
0
 def _paint_palette_layout(self, cr):
     if self._palette is None:
         return
     state = self.get_state()
     style = self.get_style()
     dx, dy = self.get_painting_offset()
     bg_col = RGBColor.new_from_gdk_color(style.bg[state])
     self._palette.render(cr, rows=self._rows, columns=self._columns,
                          swatch_size=self._swatch_size,
                          bg_color=bg_col,
                          offset_x=dx, offset_y=dy,
                          rtl=False)
예제 #2
0
    def _draw_cb(self, widget, cr):
        if self._palette is None:
            return
        alloc = widget.get_allocation()
        w, h = alloc.width, alloc.height
        s_max = 16  # min(w, h)
        s_min = 4
        ncolumns = self._palette.get_columns()
        ncolors = len(self._palette)
        if ncolors == 0:
            return
        if not ncolumns == 0:
            s = w / ncolumns
            s = clamp(s, s_min, s_max)
            s = int(s)
            if s*ncolumns > w:
                ncolumns = 0
        if ncolumns == 0:
            s = math.sqrt(float(w*h) / ncolors)
            s = clamp(s, s_min, s_max)
            s = int(s)
            ncolumns = max(1, int(w / s))
        nrows = int(ncolors // ncolumns)
        if ncolors % ncolumns != 0:
            nrows += 1
        nrows = max(1, nrows)
        dx, dy = 0, 0
        if nrows*s < h:
            dy = int(h - nrows*s) / 2
        if ncolumns*s < w:
            dx = int(w - ncolumns*s) / 2

        state = self.get_state()
        style = self.get_style()
        bg_color = RGBColor.new_from_gdk_color(style.bg[state])

        self._palette.render(cr, rows=nrows, columns=ncolumns,
                             swatch_size=s, bg_color=bg_color,
                             offset_x=dx, offset_y=dy,
                             rtl=False)