Example #1
0
    def __init__(self, app, color=(1.,0.,0)):
        gtk.VBox.__init__(self)
        self.color = color
        self.hsv = rgb_to_hsv(*color)
        self.atomic = False

        hbox = gtk.HBox()
        self.hsel = hsel = HSelector(app, color)
        hsel.on_select = self.user_selected_color
        self.hspin = hspin = make_spin(0,359, self.hue_change)
        hbox.pack_start(hsel, expand=True)
        hbox.pack_start(hspin, expand=False)

        sbox = gtk.HBox()
        self.ssel = ssel = SSelector(app, color)
        ssel.on_select = self.user_selected_color
        self.sspin = sspin = make_spin(0,100, self.sat_change)
        sbox.pack_start(ssel, expand=True)
        sbox.pack_start(sspin, expand=False)

        vbox = gtk.HBox()
        self.vsel = vsel = VSelector(app, color)
        vsel.on_select = self.user_selected_color
        self.vspin = vspin = make_spin(0,100, self.val_change)
        vbox.pack_start(vsel, expand=True)
        vbox.pack_start(vspin, expand=False)

        self.pack_start(hbox, expand=False)
        self.pack_start(sbox, expand=False)
        self.pack_start(vbox, expand=False)

        self.set_tooltip_text(_("Change Hue, Saturation and Value"))
Example #2
0
    def __init__(self, app, color=(1.,0.,0)):
        gtk.VBox.__init__(self)
        self.color = color
        self.hsv = rgb_to_hsv(*color)
        self.atomic = False

        rbox = gtk.HBox()
        self.rsel = rsel = RSelector(app, color)
        rsel.on_select = self.user_selected_color
        self.rspin = rspin = make_spin(0,255, self.r_change)
        rbox.pack_start(rsel, expand=True)
        rbox.pack_start(rspin, expand=False)

        gbox = gtk.HBox()
        self.gsel = gsel = GSelector(app, color)
        gsel.on_select = self.user_selected_color
        self.gspin = gspin = make_spin(0,255, self.g_change)
        gbox.pack_start(gsel, expand=True)
        gbox.pack_start(gspin, expand=False)

        bbox = gtk.HBox()
        self.bsel = bsel = BSelector(app, color)
        bsel.on_select = self.user_selected_color
        self.bspin = bspin = make_spin(0,255, self.b_change)
        bbox.pack_start(bsel, expand=True)
        bbox.pack_start(bspin, expand=False)

        self.pack_start(rbox, expand=False)
        self.pack_start(gbox, expand=False)
        self.pack_start(bbox, expand=False)

        self.set_tooltip_text(_("Change Red, Green and Blue components"))
Example #3
0
 def get_color_hsv(self):
     h = self.get_base_value('color_h')
     s = self.get_base_value('color_s')
     v = self.get_base_value('color_v')
     rgb = helpers.hsv_to_rgb(h, s, v)
     rgb = rgb[0]**(1 / 2.4), rgb[1]**(1 / 2.4), rgb[2]**(1 / 2.4)
     hsv = helpers.rgb_to_hsv(*rgb)
     h, s, v = hsv
     assert not math.isnan(h)
     return (h, s, v)
    def brush_selected_cb(self, bm, managed_brush, brushinfo):
        """Responds to the user changing their brush.

        This observer callback is responsible for allocating the current brush
        settings to the current brush singleton in `self.app`. The Brush
        Selector, the Pick Context action, and the Brushkeys and
        Device-specific brush associations all cause this to be invoked.
        """
        self._in_brush_selected_cb = True
        b = self.app.brush
        prev_lock_alpha = b.is_alpha_locked()

        # Changing the effective brush
        b.begin_atomic()
        color = b.get_color_hsv()

        mix_old = b.get_base_value('restore_color')
        b.load_from_brushinfo(brushinfo)
        self.unmodified_brushinfo = b.clone()

        # Preserve color
        mix = b.get_base_value('restore_color')
        if mix:
            c1 = hsv_to_rgb(*color)
            c2 = hsv_to_rgb(*b.get_color_hsv())
            c3 = [(1.0 - mix) * v1 + mix * v2 for v1, v2 in zip(c1, c2)]
            color = rgb_to_hsv(*c3)
        elif mix_old and self._last_selected_color:
            # switching from a brush with fixed color back to a normal one
            color = self._last_selected_color
        b.set_color_hsv(color)

        b.set_string_property("parent_brush_name", managed_brush.name)

        if b.is_eraser():
            # User picked a dedicated eraser brush
            # Unset any lock_alpha state (necessary?)
            self.set_override_setting("lock_alpha", False)
        else:
            # Preserve the old lock_alpha state
            self.set_override_setting("lock_alpha", prev_lock_alpha)

        b.end_atomic()

        # Updates the blend mode buttons to match the new settings.
        # First decide which blend mode is active and which aren't.
        active_blend_mode = self.bm.normal_mode
        for mode in self.bm.modes:
            setting_name = mode.setting_name
            if setting_name is not None:
                if b.has_large_base_value(setting_name):
                    active_blend_mode = mode
        active_blend_mode.active = True

        self._in_brush_selected_cb = False
Example #5
0
 def get_color_hsv(self):
     tf = self.EOTF
     h = self.get_base_value('color_h')
     s = self.get_base_value('color_s')
     v = self.get_base_value('color_v')
     rgb = helpers.hsv_to_rgb(h, s, v)
     rgb = rgb[0]**(1 / tf), rgb[1]**(1 / tf), rgb[2]**(1 / tf)
     hsv = helpers.rgb_to_hsv(*rgb)
     h, s, v = hsv
     assert not math.isnan(h)
     return (h, s, v)
Example #6
0
 def set_color_hsv(self, hsv):
     if not hsv:
         return
     self.begin_atomic()
     try:
         rgb = helpers.hsv_to_rgb(*hsv)
         rgb = rgb[0]**2.4, rgb[1]**2.4, rgb[2]**2.4
         hsv = helpers.rgb_to_hsv(*rgb)
         h, s, v = hsv
         self.set_base_value('color_h', h)
         self.set_base_value('color_s', s)
         self.set_base_value('color_v', v)
     finally:
         self.end_atomic()
Example #7
0
 def set_color_hsv(self, hsv):
     tf = self.EOTF
     if not hsv:
         return
     self.begin_atomic()
     try:
         rgb = helpers.hsv_to_rgb(*hsv)
         rgb = rgb[0]**tf, rgb[1]**tf, rgb[2]**tf
         hsv = helpers.rgb_to_hsv(*rgb)
         h, s, v = hsv
         self.set_base_value('color_h', h)
         self.set_base_value('color_s', s)
         self.set_base_value('color_v', v)
     finally:
         self.end_atomic()
Example #8
0
def _oldfmt_parse_value(rawvalue, cname, version):
    """Parses a raw setting value.

    This code handles a format that changed over time, so the
    parse is for a given setting name and brushfile version.

    """
    if cname in STRING_VALUE_SETTINGS:
        string = brushinfo_unquote(rawvalue)
        return [(cname, string)]
    elif version <= 1 and cname == 'color':
        rgb = [int(c) / 255.0 for c in rawvalue.split(" ")]
        h, s, v = helpers.rgb_to_hsv(*rgb)
        return [
            ('color_h', [h, {}]),
            ('color_s', [s, {}]),
            ('color_v', [v, {}]),
        ]
    elif version <= 1 and cname == 'change_radius':
        if rawvalue == '0.0':
            return []
        raise Obsolete('change_radius is not supported any more')
    elif version <= 2 and cname == 'adapt_color_from_image':
        if rawvalue == '0.0':
            return []
        raise Obsolete(
            'adapt_color_from_image is obsolete, ignored;'
            ' use smudge and smudge_length instead'
        )
    elif version <= 1 and cname == 'painting_time':
        return []

    if version <= 1 and cname == 'speed':
        cname = 'speed1'
    parts = rawvalue.split('|')
    basevalue = float(parts[0])
    input_points = {}
    for part in parts[1:]:
        inputname, rawpoints = part.strip().split(' ', 1)
        if version <= 1:
            points = _oldfmt_parse_points_v1(rawpoints)
        else:
            points = _oldfmt_parse_points_v2(rawpoints)
        assert len(points) >= 2
        input_points[inputname] = points
    return [(cname, [float(basevalue), input_points])]
Example #9
0
 def select_color_at(self, x,y):
     color, is_hsv = self.get_color_at(x,y)
     if color is None:
         return
     if is_hsv:
         self.hsv = color
         self.color = hsv_to_rgb(*color)
     else:
         self.color = color
         self.hsv = rgb_to_hsv(*color)
     if self.device_pressed:
         selected_color = self.color
         # Potential device change, therefore brush & colour change...
         self.app.doc.tdw.device_used(self.device_pressed)
         self.color = selected_color #... but *this* is what the user wants
     self.redraw_on_select()
     self.on_select(self.hsv)
Example #10
0
    def __init__(self,app,color=(1,0,0)):
        GColorSelector.__init__(self,app)
        self.color = color
        self.hsv = rgb_to_hsv(*color)

        self.samples = []      # [(h,s,v)] -- list of `harmonic' colors
        self.last_line = None  # 
        app.ch.color_pushed_observers.append(self.color_pushed_cb)

        self.has_hover_areas = True
        self.hover_area = AREA_OUTSIDE
        self.previous_hover_area = None
        self.previous_hover_xy = None

        self.picker_icons = []
        self.connect("map-event", self.init_picker_icons)
        self.connect("style-set", self.init_picker_icons)

        self.picker_state = gtk.STATE_NORMAL
        self.button_press = None
Example #11
0
 def set_color_rgb(self, rgb):
     self.set_color_hsv(helpers.rgb_to_hsv(*rgb))
Example #12
0
    def brush_selected_cb(self, bm, managed_brush, brushinfo):
        """Responds to the user changing their brush.

        This observer callback is responsible for allocating the current brush
        settings to the current brush singleton in `self.app`. The Brush
        Selector, the Pick Context action, and the Brushkeys and
        Device-specific brush associations all cause this to be invoked.
        """
        self._in_brush_selected_cb = True
        b = self.app.brush
        prev_lock_alpha = b.is_alpha_locked()

        # Changing the effective brush
        # Preserve colour
        b.begin_atomic()
        color = b.get_color_hsv()

        mix_old = b.get_base_value('restore_color')
        b.load_from_brushinfo(brushinfo)
        self.unmodified_brushinfo = b.clone()

        mix = b.get_base_value('restore_color')
        if mix:
            c1 = hsv_to_rgb(*color)
            c2 = hsv_to_rgb(*b.get_color_hsv())
            c3 = [(1.0-mix)*v1 + mix*v2 for v1, v2 in zip(c1, c2)]
            color = rgb_to_hsv(*c3)
        elif mix_old:
            # switching from a brush with fixed color back to a normal one
            color = self._last_selected_color

        b.set_color_hsv(color)
        b.set_string_property("parent_brush_name", managed_brush.name)
        if b.is_eraser():
            # User picked a dedicated eraser brush
            # Unset any lock_alpha state (necessary?)
            self.set_override_setting("lock_alpha", False)
        else:
            # Preserve the old lock_alpha state
            self.set_override_setting("lock_alpha", prev_lock_alpha)
        b.end_atomic()

        # Updates the blend mode buttons to match the new settings.
        # First decide which blend mode is active and which aren't.
        active_blend_mode = self.normal_mode
        blend_modes = []
        for mode_action in self.action_group.list_actions():
            setting_name = mode_action.setting_name
            if setting_name is not None:
                if b.has_large_base_value(setting_name):
                    active_blend_mode = mode_action
            blend_modes.append(mode_action)
        blend_modes.remove(active_blend_mode)

        # Twiddle the UI to match without emitting "activate" signals.
        active_blend_mode.block_activate()
        active_blend_mode.set_active(True)
        active_blend_mode.unblock_activate()
        for other in blend_modes:
            other.block_activate()
            other.set_active(False)
            other.unblock_activate()

        self._in_brush_selected_cb = False
Example #13
0
 def color_pushed_cb(self, pushed_color):
     rgb = self.app.ch.last_color
     hsv = helpers.rgb_to_hsv(*rgb)
     self.current_col.set_color_hsv(*hsv)
Example #14
0
 def __init__(self, app, color=(1,0,0), height=16):
     GColorSelector.__init__(self,app)
     self.color = color
     self.hsv = rgb_to_hsv(*color)
     self.set_size_request(height*2,height)
Example #15
0
 def b_change(self, spin):
     if self.atomic:
         return
     r,g,b = self.color
     self.set_color(rgb_to_hsv(r,g, spin.get_value()/255.))