Example #1
0
    def paint_foreground_cb(self, cr, wd, ht):
        """Fg marker painting, for `ColorAdjusterWidget` impls.
        """
        col = HSVColor(color=self.get_managed_color())
        col.s = 1.0
        radius = self.get_radius(wd, ht, self.BORDER_WIDTH)
        cx = int(wd // 2)
        cy = int(ht // 2)
        cr.arc(cx, cy, radius+0.5, 0, 2*math.pi)
        cr.clip()
        x, y = self.get_pos_for_color(col)
        col.s = 0.70
        ex, ey = self.get_pos_for_color(col)

        cr.set_line_width(5)
        cr.move_to(x, y)
        cr.line_to(ex, ey)
        cr.set_source_rgb(0, 0, 0)
        cr.stroke_preserve()

        cr.set_source_rgb(1, 1, 1)
        cr.set_line_width(3.5)
        cr.stroke_preserve()

        cr.set_source_rgb(*col.get_rgb())
        cr.set_line_width(0.25)
        cr.stroke()
Example #2
0
    def paint_foreground_cb(self, cr, wd, ht):
        """Fg marker painting, for `ColorAdjusterWidget` impls.
        """
        col = HSVColor(color=self.get_managed_color())
        col.s = 1.0
        radius = self.get_radius(wd, ht, self.BORDER_WIDTH)
        cx = int(wd // 2)
        cy = int(ht // 2)
        cr.arc(cx, cy, radius + 0.5, 0, 2 * math.pi)
        cr.clip()
        x, y = self.get_pos_for_color(col)
        col.s = 0.70
        ex, ey = self.get_pos_for_color(col)

        cr.set_line_width(5)
        cr.move_to(x, y)
        cr.line_to(ex, ey)
        cr.set_source_rgb(0, 0, 0)
        cr.stroke_preserve()

        cr.set_source_rgb(1, 1, 1)
        cr.set_line_width(3.5)
        cr.stroke_preserve()

        cr.set_source_rgb(*col.get_rgb())
        cr.set_line_width(0.25)
        cr.stroke()
Example #3
0
 def __scroll_cb(self, widget, event):
     d = self.SCROLL_DELTA
     if event.direction in (gdk.SCROLL_DOWN, gdk.SCROLL_LEFT):
         d *= -1
     col = HSVColor(color=self.get_managed_color())
     v = clamp(col.v + d, 0.0, 1.0)
     if col.v != v:
         col.v = v
         self.set_managed_color(col)
     return True
Example #4
0
 def __scroll_cb(self, widget, event):
     d = self.SCROLL_DELTA
     if event.direction in (gdk.SCROLL_DOWN, gdk.SCROLL_LEFT):
         d *= -1
     col = HSVColor(color=self.get_managed_color())
     v = clamp(col.v+d, 0.0, 1.0)
     if col.v != v:
         col.v = v
         self.set_managed_color(col)
     return True
class HSVColorRange(ThreeValueColorRange):
    type = "HSV"
    base_color = HSVColor(0, 1, 1)
    references = {
        "hue": (0, HSVHueSlider),
        "saturation": (1, HSVSaturationSlider),
        "value": (2, HSVValueSlider),
    }

    def in_range(self, color: color.UIColor) -> (bool, float, float):
        return super().in_range(color.get_hsv())

    @property
    def h(self):
        return self._get_val_mean(0)

    @property
    def s(self):
        return self._get_val_mean(1)

    @property
    def v(self):
        return self._get_val_mean(2)

    def center_color(self) -> color.UIColor:
        return color.HSVColor(self.h, self.s, self.v)
Example #6
0
 def get_new_color(self, pick_color, brush_color):
     # Normal pick mode, but preserve hue for achromatic colors.
     pick_h, pick_s, pick_v = pick_color.get_hsv()
     if pick_s == 0 or pick_v == 0:
         return HSVColor(brush_color.h, pick_s, pick_v)
     else:
         return pick_color
Example #7
0
    def render_background_cb(self, cr, wd, ht, icon_border=None):
        col = HSVColor(color=self.get_managed_color())
        b = icon_border
        if b is None:
            b = self.BORDER_WIDTH
        eff_wd = int(wd - 2 * b)
        eff_ht = int(ht - 2 * b)
        f1, f2 = self.__get_faces()

        step = max(1, int(eff_wd // 128))

        rect_x, rect_y = int(b) + 0.5, int(b) + 0.5
        rect_w, rect_h = int(eff_wd) - 1, int(eff_ht) - 1

        # Paint the central area offscreen
        cr.push_group()
        for x in xrange(0, eff_wd, step):
            amt = x / eff_wd
            setattr(col, f1, amt)
            setattr(col, f2, 1.0)
            lg = cairo.LinearGradient(b + x, b, b + x, b + eff_ht)
            lg.add_color_stop_rgb(*([0.0] + list(col.get_rgb())))
            setattr(col, f2, 0.0)
            lg.add_color_stop_rgb(*([1.0] + list(col.get_rgb())))
            cr.rectangle(b + x, b, step, eff_ht)
            cr.set_source(lg)
            cr.fill()
        slice_patt = cr.pop_group()

        # Tango-like outline
        cr.set_line_join(cairo.LINE_JOIN_ROUND)
        cr.rectangle(rect_x, rect_y, rect_w, rect_h)
        cr.set_line_width(self.OUTLINE_WIDTH)
        cr.set_source_rgba(*self.OUTLINE_RGBA)
        cr.stroke()

        # The main area
        cr.set_source(slice_patt)
        cr.paint()

        # Tango-like highlight over the top
        cr.rectangle(rect_x, rect_y, rect_w, rect_h)
        cr.set_line_width(self.EDGE_HIGHLIGHT_WIDTH)
        cr.set_source_rgba(*self.EDGE_HIGHLIGHT_RGBA)
        cr.stroke()
Example #8
0
    def render_background_cb(self, cr, wd, ht, icon_border=None):
        col = HSVColor(color=self.get_managed_color())
        b = icon_border
        if b is None:
            b = self.BORDER_WIDTH
        eff_wd = int(wd - 2*b)
        eff_ht = int(ht - 2*b)
        f1, f2 = self.__get_faces()

        step = max(1, int(eff_wd // 128))

        rect_x, rect_y = int(b)+0.5, int(b)+0.5
        rect_w, rect_h = int(eff_wd)-1, int(eff_ht)-1

        # Paint the central area offscreen
        cr.push_group()
        for x in xrange(0, eff_wd, step):
            amt = x / eff_wd
            setattr(col, f1, amt)
            setattr(col, f2, 1.0)
            lg = cairo.LinearGradient(b+x, b, b+x, b+eff_ht)
            lg.add_color_stop_rgb(*([0.0] + list(col.get_rgb())))
            setattr(col, f2, 0.0)
            lg.add_color_stop_rgb(*([1.0] + list(col.get_rgb())))
            cr.rectangle(b+x, b, step, eff_ht)
            cr.set_source(lg)
            cr.fill()
        slice_patt = cr.pop_group()

        # Tango-like outline
        cr.set_line_join(cairo.LINE_JOIN_ROUND)
        cr.rectangle(rect_x, rect_y, rect_w, rect_h)
        cr.set_line_width(self.OUTLINE_WIDTH)
        cr.set_source_rgba(*self.OUTLINE_RGBA)
        cr.stroke()

        # The main area
        cr.set_source(slice_patt)
        cr.paint()

        # Tango-like highlight over the top
        cr.rectangle(rect_x, rect_y, rect_w, rect_h)
        cr.set_line_width(self.EDGE_HIGHLIGHT_WIDTH)
        cr.set_source_rgba(*self.EDGE_HIGHLIGHT_RGBA)
        cr.stroke()
Example #9
0
 def _update_footer_color_widgets(self, settings):
     """Updates the footer bar color info when the brush color changes."""
     if not settings.intersection(('color_h', 'color_s', 'color_v')):
         return
     bm_btn_name = "footer_bookmark_current_color_button"
     bm_btn = self.app.builder.get_object(bm_btn_name)
     brush_color = HSVColor(*self.app.brush.get_color_hsv())
     palette = self.app.brush_color_manager.palette
     bm_btn.set_sensitive(brush_color not in palette)
Example #10
0
 def get_position_for_color(self, col):
     col = HSVColor(color=col)
     f1, f2 = self.__get_faces()
     f1_amt = getattr(col, f1)
     f2_amt = getattr(col, f2)
     f2_amt = 1.0 - f2_amt
     alloc = self.get_allocation()
     b = self.BORDER_WIDTH
     wd = alloc.width
     ht = alloc.height
     eff_wd = wd - 2 * b
     eff_ht = ht - 2 * b
     x = b + f1_amt * eff_wd
     y = b + f2_amt * eff_ht
     return x, y
Example #11
0
 def get_color_at_position(self, x, y):
     alloc = self.get_allocation()
     b = self.BORDER_WIDTH
     wd = alloc.width
     ht = alloc.height
     eff_wd = wd - 2 * b
     eff_ht = ht - 2 * b
     f1_amt = clamp((x - b) / eff_wd, 0, 1)
     f2_amt = clamp((y - b) / eff_ht, 0, 1)
     col = HSVColor(color=self.get_managed_color())
     f1, f2 = self.__get_faces()
     f2_amt = 1.0 - f2_amt
     setattr(col, f1, f1_amt)
     setattr(col, f2, f2_amt)
     return col
Example #12
0
        return frame

    def set_color_manager(self, manager):
        CombinedAdjusterPage.set_color_manager(self, manager)
        self.__v_adj.set_color_manager(manager)
        self.__hs_adj.set_color_manager(manager)


if __name__ == '__main__':
    import os
    import sys
    from adjbases import ColorManager
    mgr = ColorManager(prefs={}, datapath='.')
    if len(sys.argv) > 1:
        # Generate icons
        mgr.set_color(HSVColor(0.0, 0.0, 0.8))
        wheel = HSVHueSaturationWheel()
        wheel.set_color_manager(mgr)
        icon_name = HSVAdjusterPage.get_page_icon_name()
        for dir_name in sys.argv[1:]:
            wheel.save_icon_tree(dir_name, icon_name)
    else:
        # Interactive test
        mgr.set_color(HSVColor(0.333, 0.6, 0.5))
        page = HSVAdjusterPage()
        page.set_color_manager(mgr)
        window = gtk.Window()
        window.add(page.get_page_widget())
        window.set_title(os.path.basename(sys.argv[0]))
        window.set_border_width(6)
        window.connect("destroy", lambda *a: gtk.main_quit())
Example #13
0
 def get_color_for_bar_amount(self, amt):
     col = HSVColor(color=self.get_managed_color())
     f0 = self.__cube._faces[0]
     setattr(col, f0, amt)
     return col
Example #14
0
 def get_color_for_bar_amount(self, amt):
     col = HSVColor(color=self.get_managed_color())
     col.v = amt
     return col
Example #15
0
 def get_normalized_polar_pos_for_color(self, col):
     col = HSVColor(color=col)
     return col.s, col.h
Example #16
0
        frame = Gtk.AspectFrame(obey_child=True)
        frame.set_shadow_type(Gtk.ShadowType.NONE)
        frame.add(self.__table)
        return frame

    def set_color_manager(self, manager):
        ColorAdjuster.set_color_manager(self, manager)
        self.__y_adj.set_property("color-manager", manager)
        self.__hc_adj.set_property("color-manager", manager)


if __name__ == '__main__':
    import os
    import sys
    mgr = ColorManager(prefs={}, datapath='.')
    mgr.set_color(HSVColor(0.0, 0.0, 0.55))
    if len(sys.argv) > 1:
        # Generate icons
        wheel = HCYHueChromaWheel()
        wheel.set_color_manager(mgr)
        icon_name = HCYAdjusterPage.get_page_icon_name()
        for dir_name in sys.argv[1:]:
            wheel.save_icon_tree(dir_name, icon_name)
    else:
        # Interactive test
        page = HCYAdjusterPage()
        page.set_color_manager(mgr)
        window = Gtk.Window()
        window.add(page.get_page_widget())
        window.set_title(os.path.basename(sys.argv[0]))
        window.set_border_width(6)
Example #17
0
 def get_bar_amount_for_color(self, col):
     col = HSVColor(color=col)
     return max(0.0, col.v)
Example #18
0
 def color_at_normalized_polar_pos(self, r, theta):
     col = HSVColor(color=self.get_managed_color())
     col.h = theta
     return col
Example #19
0
 def get_color_for_bar_amount(self, amt):
     col = HSVColor(color=self.get_managed_color())
     col.v = amt
     return col
Example #20
0
 def _hsv_changed_cb(self, hsv):
     if hsv.is_adjusting():
         return
     h, s, v = hsv.get_color()
     color = HSVColor(h, s, v)
     self.set_managed_color(color)
Example #21
0
 def color_at_normalized_polar_pos(self, r, theta):
     col = HSVColor(color=self.get_managed_color())
     col.h = theta
     col.s = r
     return col
Example #22
0
 def get_background_validity(self):
     col = HSVColor(color=self.get_managed_color())
     f0 = self.__cube._faces[0]
     return f0, getattr(col, f0)