コード例 #1
0
 def render_as_icon(self, cr, size):
     """Renders as an icon into a Cairo context.
     """
     # Strategy: construct tmp R,G,B sliders with a color that shows off
     # their primary a bit. Render carefully (might need special handling for
     # the 16px size).
     from adjbases import ColorManager
     mgr = ColorManager(prefs={}, datapath=".")
     mgr.set_color(RGBColor(0.3, 0.3, 0.4))
     adjs = [RGBRedSlider(), RGBGreenSlider(), RGBBlueSlider()]
     for adj in adjs:
         adj.set_color_manager(mgr)
     if size <= 16:
         cr.save()
         for adj in adjs:
             adj.BORDER_WIDTH = 1
             adj.render_background_cb(cr, wd=16, ht=5)
             cr.translate(0, 5)
         cr.restore()
     else:
         cr.save()
         bar_ht = int(size // 3)
         offset = int((size - bar_ht * 3) // 2)
         cr.translate(0, offset)
         for adj in adjs:
             adj.BORDER_WIDTH = max(2, int(size // 16))
             adj.render_background_cb(cr, wd=size, ht=bar_ht)
             cr.translate(0, bar_ht)
         cr.restore()
     for adj in adjs:
         adj.set_color_manager(None)
コード例 #2
0
ファイル: hsvsquare.py プロジェクト: yishaicorran/mypaint
 def render_as_icon(self, cr, size):
     """Renders as an icon into a Cairo context.
     """
     # Strategy: construct tmp R,G,B sliders with a color that shows off
     # their primary a bit. Render carefully (might need special handling for
     # the 16px size).
     from adjbases import ColorManager
     mgr = ColorManager(prefs={}, datapath=".")
     mgr.set_color(RGBColor(0.3, 0.3, 0.4))
     ring_adj = _HSVSquareOuterRing(self)
     ring_adj.set_color_manager(mgr)
     square_adj = _HSVSquareInnerSquare(self)
     square_adj.set_color_manager(mgr)
     if size <= 16:
         cr.save()
         ring_adj.render_background_cb(cr, wd=16, ht=16)
         cr.translate(-6, -6)
         square_adj.render_background_cb(cr, wd=12, ht=12)
         cr.restore()
     else:
         cr.save()
         square_offset = int(size / 5.0 * 1.6)
         square_dim = int(size * 0.64)
         ring_adj.render_background_cb(cr, wd=size, ht=size)
         #do minor rounding adjustments for hsvsquare icons at this size
         if size == 24:
             cr.translate(-1, -1)
             square_dim += 1
         cr.translate(-square_offset, -square_offset)
         square_adj.render_background_cb(cr, wd=square_dim, ht=square_dim)
         cr.restore()
     ring_adj.set_color_manager(None)
     square_adj.set_color_manager(None)
コード例 #3
0
ファイル: hsvsquare.py プロジェクト: TuringMachinegun/mypaint
 def render_as_icon(self, cr, size):
     """Renders as an icon into a Cairo context.
     """
     # Strategy: construct tmp R,G,B sliders with a color that shows off
     # their primary a bit. Render carefully (might need special handling for
     # the 16px size).
     from adjbases import ColorManager
     mgr = ColorManager(prefs={}, datapath=".")
     mgr.set_color(RGBColor(0.3, 0.3, 0.4))
     ring_adj = _HSVSquareOuterRing(self)
     ring_adj.set_color_manager(mgr)
     square_adj = _HSVSquareInnerSquare(self)
     square_adj.set_color_manager(mgr)
     if size <= 16:
         cr.save()
         ring_adj.render_background_cb(cr, wd=16, ht=16)
         cr.translate(-6, -6)
         square_adj.render_background_cb(cr, wd=12, ht=12)
         cr.restore()
     else:
         cr.save()
         square_offset = int(size/5.0 * 1.6)
         square_dim = int(size * 0.64)
         ring_adj.render_background_cb(cr, wd=size, ht=size)
         #do minor rounding adjustments for hsvsquare icons at this size
         if size == 24:
             cr.translate(-1, -1)
             square_dim+=1
         cr.translate(-square_offset, -square_offset)
         square_adj.render_background_cb(cr, wd=square_dim, ht=square_dim)
         cr.restore()
     ring_adj.set_color_manager(None)
     square_adj.set_color_manager(None)
コード例 #4
0
ファイル: sliders.py プロジェクト: jesterKing/mypaint-xsheet
 def render_as_icon(self, cr, size):
     """Renders as an icon into a Cairo context.
     """
     # Strategy: construct tmp R,G,B sliders with a colour that shows off
     # their primary a bit. Render carefully (might need special handling for
     # the 16px size).
     from adjbases import ColorManager
     mgr = ColorManager()
     mgr.set_color(RGBColor(0.3, 0.3, 0.4))
     adjs = [RGBRedSlider(), RGBGreenSlider(), RGBBlueSlider()]
     for adj in adjs:
         adj.set_color_manager(mgr)
     if size <= 16:
         cr.save()
         for adj in adjs:
             adj.border = 1
             adj.render_background_cb(cr, wd=16, ht=5)
             cr.translate(0, 5)
         cr.restore()
     else:
         cr.save()
         bar_ht = int(size/3)
         offset = int((size - bar_ht*3) / 2)
         cr.translate(0, offset)
         for adj in adjs:
             adj.border = max(2, int(size/16))
             adj.render_background_cb(cr, wd=size, ht=bar_ht)
             cr.translate(0, bar_ht)
         cr.restore()
     for adj in adjs:
         adj.set_color_manager(None)
コード例 #5
0
 def __init__(self, parent, target):
     super(HCYMaskTemplateDialog, self).__init__(
         title=C_(
             u"HCY Gamut Mask new-from-template dialog: window title",
             "New Gamut Mask from Template",
         ),
         transient_for=parent,
         modal=True,
         destroy_with_parent=True,
         window_position=Gtk.WindowPosition.MOUSE,
         buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT),
     )
     target_mgr = target.get_color_manager()
     prefs_ro = deepcopy(target_mgr.get_prefs())
     datapath = target_mgr.get_data_path()
     mgr = ColorManager(prefs=prefs_ro, datapath=datapath)
     mgr.set_wheel_type(target_mgr.get_wheel_type())
     self.target = target
     for name, desc, mask_shapes_float in self.__templates:
         mask = []
         for mask_shape_float in mask_shapes_float:
             shape = []
             for h, c, y in mask_shape_float:
                 h = mgr.undistort_hue(h)
                 shape.append(HCYColor(h, c, y))
             mask.append(shape)
         label = Gtk.Label()
         label.set_markup("<b>%s</b>\n\n%s" % (name, desc))
         label.set_size_request(375, -1)
         label.set_line_wrap(True)
         label.set_alignment(0, 0.5)
         preview = HCYMaskPreview()
         preview.set_color_manager(mgr)
         preview.set_mask(mask)
         preview_frame = Gtk.AspectFrame(obey_child=True)
         preview_frame.add(preview)
         preview_frame.set_shadow_type(Gtk.ShadowType.NONE)
         hbox = Gtk.HBox()
         hbox.set_spacing(6)
         hbox.pack_start(preview_frame, False, False, 0)
         hbox.pack_start(label, True, True, 0)
         button = Gtk.Button()
         button.add(hbox)
         button.set_relief(Gtk.ReliefStyle.NONE)
         button.connect("clicked", self.__button_clicked_cb, mask)
         self.vbox.pack_start(button, True, True, 0)
     self.connect("response", self.__response_cb)
     self.connect("show", self.__show_cb)
     for w in self.vbox:
         w.show_all()
     ref_color = target.get_managed_color()
     mgr.set_color(ref_color)
コード例 #6
0
 def __init__(self, parent, target):
     gtk.Dialog.__init__(
         self,
         C_(
             u"HCY Gamut Mask new-from-template dialog: window title",
             "New Gamut Mask from Template",
         ),
         parent,
         gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
         (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT),
     )
     self.set_position(gtk.WIN_POS_MOUSE)
     target_mgr = target.get_color_manager()
     prefs_ro = deepcopy(target_mgr.get_prefs())
     datapath = target_mgr.get_data_path()
     mgr = ColorManager(prefs=prefs_ro, datapath=datapath)
     mgr.set_wheel_type(target_mgr.get_wheel_type())
     self.target = target
     for name, desc, mask_shapes_float in self.__templates:
         mask = []
         for mask_shape_float in mask_shapes_float:
             shape = []
             for h, c, y in mask_shape_float:
                 h = mgr.undistort_hue(h)
                 shape.append(HCYColor(h, c, y))
             mask.append(shape)
         label = gtk.Label()
         label.set_markup("<b>%s</b>\n\n%s" % (name, desc))
         label.set_size_request(375, -1)
         label.set_line_wrap(True)
         label.set_alignment(0, 0.5)
         preview = HCYMaskPreview()
         preview.set_color_manager(mgr)
         preview.set_mask(mask)
         preview_frame = gtk.AspectFrame(obey_child=True)
         preview_frame.add(preview)
         preview_frame.set_shadow_type(gtk.SHADOW_NONE)
         hbox = gtk.HBox()
         hbox.set_spacing(6)
         hbox.pack_start(preview_frame, False, False)
         hbox.pack_start(label, True, True)
         button = gtk.Button()
         button.add(hbox)
         button.set_relief(gtk.RELIEF_NONE)
         button.connect("clicked", self.__button_clicked_cb, mask)
         self.vbox.pack_start(button, True, True)
     self.connect("response", self.__response_cb)
     self.connect("show", self.__show_cb)
     for w in self.vbox:
         w.show_all()
     ref_color = target.get_managed_color()
     mgr.set_color(ref_color)
コード例 #7
0
ファイル: hcywheel.py プロジェクト: j-fu/mypaint
 def __load_clicked(self, button):
     preview = HCYMaskPreview()
     preview.set_size_request(128, 128)
     target_mgr = self.target.get_color_manager()
     prefs_ro = deepcopy(target_mgr.get_prefs())
     datapath = target_mgr.get_data_path()
     mgr = ColorManager(prefs=prefs_ro, datapath=datapath)
     preview.set_color_manager(mgr)
     preview.set_managed_color(self.editor.get_managed_color())
     dialog_title = _("Load mask from a Gimp palette")
     pal = palette_load_via_dialog(title=dialog_title,
                                   parent=self,
                                   preview=preview)
     if pal is None:
         return
     self.editor.set_mask_from_palette(pal)
コード例 #8
0
ファイル: hcywheel.py プロジェクト: benpope82/mypaint
 def __init__(self, parent, target):
     super(HCYMaskTemplateDialog, self).__init__(
         title=C_(
             u"HCY Gamut Mask new-from-template dialog: window title",
             "New Gamut Mask from Template",
         ),
         transient_for=parent,
         modal=True,
         destroy_with_parent=True,
         window_position=Gtk.WindowPosition.MOUSE,
         buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT),
     )
     target_mgr = target.get_color_manager()
     prefs_ro = deepcopy(target_mgr.get_prefs())
     datapath = target_mgr.get_data_path()
     mgr = ColorManager(prefs=prefs_ro, datapath=datapath)
     mgr.set_wheel_type(target_mgr.get_wheel_type())
     self.target = target
     for name, desc, mask_shapes_float in self.__templates:
         mask = []
         for mask_shape_float in mask_shapes_float:
             shape = []
             for h, c, y in mask_shape_float:
                 h = mgr.undistort_hue(h)
                 shape.append(HCYColor(h, c, y))
             mask.append(shape)
         label = Gtk.Label()
         label.set_markup("<b>%s</b>\n\n%s" % (name, desc))
         label.set_size_request(375, -1)
         label.set_line_wrap(True)
         label.set_alignment(0, 0.5)
         preview = HCYMaskPreview()
         preview.set_color_manager(mgr)
         preview.set_mask(mask)
         preview_frame = Gtk.AspectFrame(obey_child=True)
         preview_frame.add(preview)
         preview_frame.set_shadow_type(Gtk.ShadowType.NONE)
         hbox = Gtk.HBox()
         hbox.set_spacing(6)
         hbox.pack_start(preview_frame, False, False, 0)
         hbox.pack_start(label, True, True, 0)
         button = Gtk.Button()
         button.add(hbox)
         button.set_relief(Gtk.ReliefStyle.NONE)
         button.connect("clicked", self.__button_clicked_cb, mask)
         self.vbox.pack_start(button, True, True, 0)
     self.connect("response", self.__response_cb)
     self.connect("show", self.__show_cb)
     for w in self.vbox:
         w.show_all()
     ref_color = target.get_managed_color()
     mgr.set_color(ref_color)
コード例 #9
0
ファイル: hcywheel.py プロジェクト: j-fu/mypaint
 def __save_clicked(self, button):
     pal = Palette()
     mask = self.editor.get_mask()
     for i, shape in enumerate(mask):
         for j, col in enumerate(shape):
             col_name = "mask#%d primary#%d" % (i, j)  # NOT localised
             pal.append(col, col_name)
     preview = HCYMaskPreview()
     preview.set_size_request(128, 128)
     target_mgr = self.target.get_color_manager()
     prefs_ro = deepcopy(target_mgr.get_prefs())
     datapath = target_mgr.get_data_path()
     mgr = ColorManager(prefs=prefs_ro, datapath=datapath)
     preview.set_color_manager(mgr)
     preview.set_managed_color(self.editor.get_managed_color())
     palette_save_via_dialog(pal,
                             title=_("Save mask as a Gimp palette"),
                             parent=self,
                             preview=preview)
コード例 #10
0
        if self._updating:
            return
        self._updating = True
        color = self.get_managed_color()
        self._hsv_widget.set_color(*color.get_hsv())
        self._updating = False

    def set_current_color(self, color):
        self._hsv_widget.set_color(*color.get_hsv())

    def _hsv_changed_cb(self, hsv):
        h, s, v = hsv.get_color()
        for cb in self.hsv_changed_observers:
            cb(h, s, v)
        if not hsv.is_adjusting():
            color = HSVColor(h, s, v)
            self.set_managed_color(color)


if __name__ == '__main__':
    from adjbases import ColorManager
    mgr = ColorManager(prefs={}, datapath='.')
    win = gtk.Window()
    win.set_title("hsvtriangle test")
    win.connect("destroy", gtk.main_quit)
    hsv = HSVTriangle()
    hsv.set_color_manager(mgr)
    win.add(hsv)
    win.show_all()
    gtk.main()
コード例 #11
0
ファイル: hcywheel.py プロジェクト: kleopatra999/mypaint
        frame = gtk.AspectFrame(obey_child=True)
        frame.set_shadow_type(gtk.SHADOW_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
    from adjbases import ColorManager
    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]))
コード例 #12
0
ファイル: paletteview.py プロジェクト: loentar/mypaint
    def __init__(self, parent, target_color_manager):
        flags = Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT
        Gtk.Dialog.__init__(self, _("Palette Editor"), parent, flags,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
                             Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        self.set_position(Gtk.WindowPosition.MOUSE)

        assert isinstance(target_color_manager, ColorManager)
        #: ColorManager containing the palette to be edited.
        self._target_color_manager = target_color_manager

        view = PaletteView()
        view.set_size_request(400, 300)
        view.grid.show_matched_color = True
        view.grid.can_select_empty = True
        self._view = view

        #: The working ColorManager, holding a working copy of the palette
        #: to be edited.
        self._mgr = ColorManager(prefs={},
                                 datapath=target_color_manager.get_data_path())
        self._mgr.set_color(RGBColor(1, 1, 1))
        view.set_color_manager(self._mgr)

        # Action buttons, positiopned down the right hand side
        action_bbox = Gtk.VButtonBox()
        load_btn = self._load_button = Gtk.Button(stock=Gtk.STOCK_OPEN)
        save_btn = self._save_button = Gtk.Button(stock=Gtk.STOCK_SAVE)
        add_btn = self._add_button = Gtk.Button(stock=Gtk.STOCK_ADD)
        remove_btn = self._remove_button = Gtk.Button(stock=Gtk.STOCK_REMOVE)
        clear_btn = self._clear_button = Gtk.Button(stock=Gtk.STOCK_CLEAR)
        action_bbox.pack_start(load_btn)
        action_bbox.pack_start(save_btn)
        action_bbox.pack_start(add_btn)
        action_bbox.pack_start(remove_btn)
        action_bbox.pack_start(clear_btn)
        action_bbox.set_layout(Gtk.ButtonBoxStyle.START)
        load_btn.connect("clicked", self._load_btn_clicked)
        save_btn.connect("clicked", self._save_btn_clicked)
        remove_btn.connect("clicked", self._remove_btn_clicked)
        add_btn.connect("clicked", self._add_btn_clicked)
        clear_btn.connect("clicked", self._clear_btn_clicked)
        load_btn.set_tooltip_text(_("Load from a GIMP palette file"))
        save_btn.set_tooltip_text(_("Save to a GIMP palette file"))
        add_btn.set_tooltip_text(_("Add a new empty swatch"))
        remove_btn.set_tooltip_text(_("Remove the current swatch"))
        clear_btn.set_tooltip_text(_("Remove all swatches"))

        # Button initial state and subsequent updates
        remove_btn.set_sensitive(False)
        self._mgr.palette.match_changed += self._palette_match_changed_cb
        self._mgr.palette.info_changed += self._palette_changed_cb
        self._mgr.palette.sequence_changed += self._palette_changed_cb
        self._mgr.palette.color_changed += self._palette_changed_cb

        # Palette name and number of entries
        palette_details_hbox = Gtk.HBox()
        palette_name_label = Gtk.Label(_("Name:"))
        palette_name_label.set_tooltip_text(_("Name or description for"
                                              " this palette"))
        palette_name_entry = Gtk.Entry()
        palette_name_entry.connect("changed", self._palette_name_changed_cb)
        self._palette_name_entry = palette_name_entry
        self._columns_adj = Gtk.Adjustment(
            value=0, lower=0, upper=99,
            step_incr=1, page_incr=1, page_size=0
        )
        self._columns_adj.connect("value-changed", self._columns_changed_cb)
        columns_label = Gtk.Label(_("Columns:"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_spinbutton = Gtk.SpinButton(
            adjustment=self._columns_adj,
            climb_rate=1.5,
            digits=0
        )
        palette_details_hbox.set_spacing(0)
        palette_details_hbox.set_border_width(0)
        palette_details_hbox.pack_start(palette_name_label, False, False, 0)
        palette_details_hbox.pack_start(palette_name_entry, True, True, 6)
        palette_details_hbox.pack_start(columns_label, False, False, 6)
        palette_details_hbox.pack_start(columns_spinbutton, False, False, 0)

        color_name_hbox = Gtk.HBox()
        color_name_label = Gtk.Label(_("Color name:"))
        color_name_label.set_tooltip_text(_("Current color's name"))
        color_name_entry = Gtk.Entry()
        color_name_entry.connect("changed", self._color_name_changed_cb)
        color_name_entry.set_sensitive(False)
        self._color_name_entry = color_name_entry
        color_name_hbox.set_spacing(6)
        color_name_hbox.pack_start(color_name_label, False, False, 0)
        color_name_hbox.pack_start(color_name_entry, True, True, 0)

        palette_vbox = Gtk.VBox()
        palette_vbox.set_spacing(12)
        palette_vbox.pack_start(palette_details_hbox, False, False)
        palette_vbox.pack_start(view, True, True)
        palette_vbox.pack_start(color_name_hbox, False, False)

        # Dialog contents
        # Main edit area to the left, buttons to the right
        hbox = Gtk.HBox()
        hbox.set_spacing(12)
        hbox.pack_start(palette_vbox, True, True)
        hbox.pack_start(action_bbox, False, False)
        hbox.set_border_width(12)
        self.vbox.pack_start(hbox, True, True)

        # Dialog vbox contents must be shown separately
        for w in self.vbox:
            w.show_all()

        self.connect("response", self._response_cb)
        self.connect("show", self._show_cb)
コード例 #13
0
ファイル: paletteview.py プロジェクト: loentar/mypaint
class PaletteEditorDialog (Gtk.Dialog):
    """Dialog for editing, loading and saving the current palette.
    """

    def __init__(self, parent, target_color_manager):
        flags = Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT
        Gtk.Dialog.__init__(self, _("Palette Editor"), parent, flags,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
                             Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        self.set_position(Gtk.WindowPosition.MOUSE)

        assert isinstance(target_color_manager, ColorManager)
        #: ColorManager containing the palette to be edited.
        self._target_color_manager = target_color_manager

        view = PaletteView()
        view.set_size_request(400, 300)
        view.grid.show_matched_color = True
        view.grid.can_select_empty = True
        self._view = view

        #: The working ColorManager, holding a working copy of the palette
        #: to be edited.
        self._mgr = ColorManager(prefs={},
                                 datapath=target_color_manager.get_data_path())
        self._mgr.set_color(RGBColor(1, 1, 1))
        view.set_color_manager(self._mgr)

        # Action buttons, positiopned down the right hand side
        action_bbox = Gtk.VButtonBox()
        load_btn = self._load_button = Gtk.Button(stock=Gtk.STOCK_OPEN)
        save_btn = self._save_button = Gtk.Button(stock=Gtk.STOCK_SAVE)
        add_btn = self._add_button = Gtk.Button(stock=Gtk.STOCK_ADD)
        remove_btn = self._remove_button = Gtk.Button(stock=Gtk.STOCK_REMOVE)
        clear_btn = self._clear_button = Gtk.Button(stock=Gtk.STOCK_CLEAR)
        action_bbox.pack_start(load_btn)
        action_bbox.pack_start(save_btn)
        action_bbox.pack_start(add_btn)
        action_bbox.pack_start(remove_btn)
        action_bbox.pack_start(clear_btn)
        action_bbox.set_layout(Gtk.ButtonBoxStyle.START)
        load_btn.connect("clicked", self._load_btn_clicked)
        save_btn.connect("clicked", self._save_btn_clicked)
        remove_btn.connect("clicked", self._remove_btn_clicked)
        add_btn.connect("clicked", self._add_btn_clicked)
        clear_btn.connect("clicked", self._clear_btn_clicked)
        load_btn.set_tooltip_text(_("Load from a GIMP palette file"))
        save_btn.set_tooltip_text(_("Save to a GIMP palette file"))
        add_btn.set_tooltip_text(_("Add a new empty swatch"))
        remove_btn.set_tooltip_text(_("Remove the current swatch"))
        clear_btn.set_tooltip_text(_("Remove all swatches"))

        # Button initial state and subsequent updates
        remove_btn.set_sensitive(False)
        self._mgr.palette.match_changed += self._palette_match_changed_cb
        self._mgr.palette.info_changed += self._palette_changed_cb
        self._mgr.palette.sequence_changed += self._palette_changed_cb
        self._mgr.palette.color_changed += self._palette_changed_cb

        # Palette name and number of entries
        palette_details_hbox = Gtk.HBox()
        palette_name_label = Gtk.Label(_("Name:"))
        palette_name_label.set_tooltip_text(_("Name or description for"
                                              " this palette"))
        palette_name_entry = Gtk.Entry()
        palette_name_entry.connect("changed", self._palette_name_changed_cb)
        self._palette_name_entry = palette_name_entry
        self._columns_adj = Gtk.Adjustment(
            value=0, lower=0, upper=99,
            step_incr=1, page_incr=1, page_size=0
        )
        self._columns_adj.connect("value-changed", self._columns_changed_cb)
        columns_label = Gtk.Label(_("Columns:"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_spinbutton = Gtk.SpinButton(
            adjustment=self._columns_adj,
            climb_rate=1.5,
            digits=0
        )
        palette_details_hbox.set_spacing(0)
        palette_details_hbox.set_border_width(0)
        palette_details_hbox.pack_start(palette_name_label, False, False, 0)
        palette_details_hbox.pack_start(palette_name_entry, True, True, 6)
        palette_details_hbox.pack_start(columns_label, False, False, 6)
        palette_details_hbox.pack_start(columns_spinbutton, False, False, 0)

        color_name_hbox = Gtk.HBox()
        color_name_label = Gtk.Label(_("Color name:"))
        color_name_label.set_tooltip_text(_("Current color's name"))
        color_name_entry = Gtk.Entry()
        color_name_entry.connect("changed", self._color_name_changed_cb)
        color_name_entry.set_sensitive(False)
        self._color_name_entry = color_name_entry
        color_name_hbox.set_spacing(6)
        color_name_hbox.pack_start(color_name_label, False, False, 0)
        color_name_hbox.pack_start(color_name_entry, True, True, 0)

        palette_vbox = Gtk.VBox()
        palette_vbox.set_spacing(12)
        palette_vbox.pack_start(palette_details_hbox, False, False)
        palette_vbox.pack_start(view, True, True)
        palette_vbox.pack_start(color_name_hbox, False, False)

        # Dialog contents
        # Main edit area to the left, buttons to the right
        hbox = Gtk.HBox()
        hbox.set_spacing(12)
        hbox.pack_start(palette_vbox, True, True)
        hbox.pack_start(action_bbox, False, False)
        hbox.set_border_width(12)
        self.vbox.pack_start(hbox, True, True)

        # Dialog vbox contents must be shown separately
        for w in self.vbox:
            w.show_all()

        self.connect("response", self._response_cb)
        self.connect("show", self._show_cb)

    def _show_cb(self, widget, *a):
        # Each time the dialog is shown, update with the target
        # palette, for editing.
        self.vbox.show_all()
        palette = self._target_color_manager.palette
        name = palette.get_name()
        if name is None:
            name = ""
        self._palette_name_entry.set_text(name)
        self._columns_adj.set_value(palette.get_columns())
        self._mgr.palette.update(palette)

    def _palette_name_changed_cb(self, editable):
        name = editable.get_chars(0, -1)
        if name == "":
            name = None
        pal = self._mgr.palette
        pal.name = unicode(name)

    def _columns_changed_cb(self, adj):
        ncolumns = int(adj.get_value())
        pal = self._mgr.palette
        pal.set_columns(ncolumns)

    def _color_name_changed_cb(self, editable):
        name = editable.get_chars(0, -1)
        palette = self._mgr.palette
        i = palette.match_position
        if i is None:
            return
        old_name = palette.get_color_name(i)
        if name == "":
            name = None
        if name != old_name:
            palette.set_color_name(i, name)

    def _response_cb(self, widget, response_id):
        if response_id == Gtk.ResponseType.ACCEPT:
            palette = self._mgr.palette
            target_palette = self._target_color_manager.palette
            target_palette.update(palette)
        self.hide()
        return True

    def _palette_match_changed_cb(self, palette):
        col_name_entry = self._color_name_entry
        i = palette.match_position
        if i is not None:
            col = palette[i]
            if col is not None:
                name = palette.get_color_name(i)
                if name is None:
                    name = ""
                col_name_entry.set_sensitive(True)
                col_name_entry.set_text(name)
            else:
                col_name_entry.set_sensitive(False)
                col_name_entry.set_text(_("Empty palette slot"))
        else:
            col_name_entry.set_sensitive(False)
            col_name_entry.set_text("")
        self._update_buttons()

    def _update_buttons(self):
        palette = self._mgr.palette
        emptyish = len(palette) == 0
        if len(palette) == 1:
            if palette[0] is None:
                emptyish = True
        can_save = not emptyish
        can_clear = not emptyish
        can_remove = True
        if emptyish or self._mgr.palette.match_position is None:
            can_remove = False
        self._save_button.set_sensitive(can_save)
        self._remove_button.set_sensitive(can_remove)
        self._clear_button.set_sensitive(can_clear)

    def _palette_changed_cb(self, palette, *args, **kwargs):
        new_name = palette.get_name()
        if new_name is None:
            new_name = ""
        old_name = self._palette_name_entry.get_chars(0, -1)
        if old_name != new_name:
            self._palette_name_entry.set_text(new_name)
        self._columns_adj.set_value(palette.get_columns())
        self._update_buttons()

    def _add_btn_clicked(self, button):
        palette = self._mgr.palette
        i = palette.match_position
        if i is None:
            i = len(palette)
            palette.append(None)
            palette.match_position = i
        else:
            palette.insert(i, None)

    def _remove_btn_clicked(self, button):
        palette = self._mgr.palette
        i = palette.match_position
        if i >= 0 and i < len(palette):
            palette.pop(i)
            if len(palette) == 0:
                palette.append(None)

    def _load_btn_clicked(self, button):
        preview = _PalettePreview()
        manager = self._target_color_manager
        datapath = manager.get_data_path()
        palettes_dir = os.path.join(datapath, DATAPATH_PALETTES_SUBDIR)
        palette = palette_load_via_dialog(title=_("Load palette"),
                                          parent=self,
                                          preview=preview,
                                          shortcuts=[palettes_dir])
        if palette is not None:
            self._mgr.palette.update(palette)

    def _save_btn_clicked(self, button):
        preview = _PalettePreview()
        palette_save_via_dialog(self._mgr.palette, title=_("Save palette"),
                                parent=self, preview=preview)

    def _clear_btn_clicked(self, button):
        pal = self._mgr.palette
        pal.clear()
コード例 #14
0
ファイル: paletteview.py プロジェクト: j-fu/mypaint
    def __init__(self, parent, target_color_manager):
        flags = Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT
        Gtk.Dialog.__init__(self, _("Palette Editor"), parent, flags,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
                             Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        self.set_position(Gtk.WindowPosition.MOUSE)

        assert isinstance(target_color_manager, ColorManager)
        #: ColorManager containing the palette to be edited.
        self._target_color_manager = target_color_manager

        view = PaletteView()
        view.set_size_request(400, 300)
        view.grid.show_matched_color = True
        view.grid.can_select_empty = True
        self._view = view

        #: The working ColorManager, holding a working copy of the palette
        #: to be edited.
        self._mgr = ColorManager(prefs={},
                                 datapath=target_color_manager.get_data_path())
        self._mgr.set_color(RGBColor(1, 1, 1))
        view.set_color_manager(self._mgr)

        # Action buttons, positiopned down the right hand side
        action_bbox = Gtk.VButtonBox()
        load_btn = self._load_button = Gtk.Button(stock=Gtk.STOCK_OPEN)
        save_btn = self._save_button = Gtk.Button(stock=Gtk.STOCK_SAVE)
        add_btn = self._add_button = Gtk.Button(stock=Gtk.STOCK_ADD)
        remove_btn = self._remove_button = Gtk.Button(stock=Gtk.STOCK_REMOVE)
        clear_btn = self._clear_button = Gtk.Button(stock=Gtk.STOCK_CLEAR)
        action_bbox.pack_start(load_btn)
        action_bbox.pack_start(save_btn)
        action_bbox.pack_start(add_btn)
        action_bbox.pack_start(remove_btn)
        action_bbox.pack_start(clear_btn)
        action_bbox.set_layout(Gtk.ButtonBoxStyle.START)
        load_btn.connect("clicked", self._load_btn_clicked)
        save_btn.connect("clicked", self._save_btn_clicked)
        remove_btn.connect("clicked", self._remove_btn_clicked)
        add_btn.connect("clicked", self._add_btn_clicked)
        clear_btn.connect("clicked", self._clear_btn_clicked)
        load_btn.set_tooltip_text(_("Load from a GIMP palette file"))
        save_btn.set_tooltip_text(_("Save to a GIMP palette file"))
        add_btn.set_tooltip_text(_("Add a new empty swatch"))
        remove_btn.set_tooltip_text(_("Remove the current swatch"))
        clear_btn.set_tooltip_text(_("Remove all swatches"))

        # Button initial state and subsequent updates
        remove_btn.set_sensitive(False)
        self._mgr.palette.match_changed += self._palette_match_changed_cb
        self._mgr.palette.info_changed += self._palette_changed_cb
        self._mgr.palette.sequence_changed += self._palette_changed_cb
        self._mgr.palette.color_changed += self._palette_changed_cb

        # Palette name and number of entries
        palette_details_hbox = Gtk.HBox()
        palette_name_label = Gtk.Label(_("Name:"))
        palette_name_label.set_tooltip_text(_("Name or description for"
                                              " this palette"))
        palette_name_entry = Gtk.Entry()
        palette_name_entry.connect("changed", self._palette_name_changed_cb)
        self._palette_name_entry = palette_name_entry
        self._columns_adj = Gtk.Adjustment(
            value=0, lower=0, upper=99,
            step_incr=1, page_incr=1, page_size=0
        )
        self._columns_adj.connect("value-changed", self._columns_changed_cb)
        columns_label = Gtk.Label(_("Columns:"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_spinbutton = Gtk.SpinButton(
            adjustment=self._columns_adj,
            climb_rate=1.5,
            digits=0
        )
        palette_details_hbox.set_spacing(0)
        palette_details_hbox.set_border_width(0)
        palette_details_hbox.pack_start(palette_name_label, False, False, 0)
        palette_details_hbox.pack_start(palette_name_entry, True, True, 6)
        palette_details_hbox.pack_start(columns_label, False, False, 6)
        palette_details_hbox.pack_start(columns_spinbutton, False, False, 0)

        color_name_hbox = Gtk.HBox()
        color_name_label = Gtk.Label(_("Color name:"))
        color_name_label.set_tooltip_text(_("Current color's name"))
        color_name_entry = Gtk.Entry()
        color_name_entry.connect("changed", self._color_name_changed_cb)
        color_name_entry.set_sensitive(False)
        self._color_name_entry = color_name_entry
        color_name_hbox.set_spacing(6)
        color_name_hbox.pack_start(color_name_label, False, False, 0)
        color_name_hbox.pack_start(color_name_entry, True, True, 0)

        palette_vbox = Gtk.VBox()
        palette_vbox.set_spacing(12)
        palette_vbox.pack_start(palette_details_hbox, False, False)
        palette_vbox.pack_start(view, True, True)
        palette_vbox.pack_start(color_name_hbox, False, False)

        # Dialog contents
        # Main edit area to the left, buttons to the right
        hbox = Gtk.HBox()
        hbox.set_spacing(12)
        hbox.pack_start(palette_vbox, True, True)
        hbox.pack_start(action_bbox, False, False)
        hbox.set_border_width(12)
        self.vbox.pack_start(hbox, True, True)

        # Dialog vbox contents must be shown separately
        for w in self.vbox:
            w.show_all()

        self.connect("response", self._response_cb)
        self.connect("show", self._show_cb)
コード例 #15
0
    def __init__(self, parent, target):
        gtk.Dialog.__init__(self, _("Palette Editor"), parent,
                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                             gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        self.set_position(gtk.WIN_POS_MOUSE)
        self.__target = target
        view = PaletteView()
        view.set_size_request(400, 300)
        view.grid.show_current_index = True
        view.grid.manage_current_index = True
        view.grid.can_select_empty = True
        self.__view = view

        self.__mgr = ColorManager()
        self.__mgr.set_color(RGBColor(1,1,1))
        view.set_color_manager(self.__mgr)

        # Action buttons, positiopned down the right hand side
        action_bbox = gtk.VButtonBox()
        load_btn = self.__load_button = gtk.Button(stock=gtk.STOCK_OPEN)
        save_btn = self.__save_button = gtk.Button(stock=gtk.STOCK_SAVE)
        add_btn = self.__add_button = gtk.Button(stock=gtk.STOCK_ADD)
        remove_btn = self.__remove_button = gtk.Button(stock=gtk.STOCK_REMOVE)
        clear_btn = self.__clear_button = gtk.Button(stock=gtk.STOCK_CLEAR)
        action_bbox.pack_start(load_btn)
        action_bbox.pack_start(save_btn)
        action_bbox.pack_start(add_btn)
        action_bbox.pack_start(remove_btn)
        action_bbox.pack_start(clear_btn)
        action_bbox.set_layout(gtk.BUTTONBOX_START)
        load_btn.connect("clicked", self.__load_btn_clicked)
        save_btn.connect("clicked", self.__save_btn_clicked)
        remove_btn.connect("clicked", self.__remove_btn_clicked)
        add_btn.connect("clicked", self.__add_btn_clicked)
        clear_btn.connect("clicked", self.__clear_btn_clicked)
        load_btn.set_tooltip_text(_("Load from a GIMP palette file"))
        save_btn.set_tooltip_text(_("Save to a GIMP palette file"))
        add_btn.set_tooltip_text(_("Add a new empty swatch"))
        remove_btn.set_tooltip_text(_("Remove the current swatch"))
        clear_btn.set_tooltip_text(_("Remove all swatches"))

        # Button initial state and subsequent updates
        remove_btn.set_sensitive(False)
        view.grid.current_index_observers.append(
          self.__current_index_changed_cb)
        view.grid.palette_observers.append(self.__palette_changed_cb)

        # Palette name and number of entries
        palette_details_hbox = gtk.HBox()
        palette_name_label = gtk.Label(_("Name:"))
        palette_name_label.set_tooltip_text(
          _("Name or description for this palette"))
        palette_name_entry = gtk.Entry()
        palette_name_entry.connect("changed", self.__palette_name_changed_cb)
        self.__palette_name_entry = palette_name_entry
        self.__columns_adj = gtk.Adjustment(
          value=0, lower=0, upper=99,
          step_incr=1, page_incr=1, page_size=0 )
        self.__columns_adj.connect("value-changed", self.__columns_changed_cb)
        columns_label = gtk.Label(_("Columns:"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_spinbutton = gtk.SpinButton(
          adjustment=self.__columns_adj,
          climb_rate=1.5,
          digits=0 )
        palette_details_hbox.set_spacing(0)
        palette_details_hbox.set_border_width(0)
        palette_details_hbox.pack_start(palette_name_label, False, False, 0)
        palette_details_hbox.pack_start(palette_name_entry, True, True, 6)
        palette_details_hbox.pack_start(columns_label, False, False, 6)
        palette_details_hbox.pack_start(columns_spinbutton, False, False, 0)

        color_name_hbox = gtk.HBox()
        color_name_label = gtk.Label(_("Color name:"))
        color_name_label.set_tooltip_text(_("Current colour's name"))
        color_name_entry = gtk.Entry()
        color_name_entry.connect("changed", self.__color_name_changed_cb)
        color_name_entry.set_sensitive(False)
        self.__color_name_entry = color_name_entry
        color_name_hbox.set_spacing(6)
        color_name_hbox.pack_start(color_name_label, False, False, 0)
        color_name_hbox.pack_start(color_name_entry, True, True, 0)

        palette_vbox = gtk.VBox()
        palette_vbox.set_spacing(12)
        palette_vbox.pack_start(palette_details_hbox, False, False)
        palette_vbox.pack_start(view, True, True)
        palette_vbox.pack_start(color_name_hbox, False, False)

        # Dialog contents
        # Main edit area to the left, buttons to the right
        hbox = gtk.HBox()
        hbox.set_spacing(12)
        hbox.pack_start(palette_vbox, True, True)
        hbox.pack_start(action_bbox, False, False)
        hbox.set_border_width(12)
        self.vbox.pack_start(hbox, True, True)

        # Dialog vbox contents must be shown separately
        for w in self.vbox:
            w.show_all()

        self.connect("response", self.__response_cb)
        self.connect("show", self.__show_cb)
コード例 #16
0
    def __init__(self, parent, target):
        super(HCYMaskPropertiesDialog, self).__init__(
            title=C_(
                "HCY Gamut Mask Editor dialog: window title",
                u"Gamut Mask Editor",
            ),
            transient_for=parent,
            modal=True,
            destroy_with_parent=True,
            window_position=Gtk.WindowPosition.CENTER_ON_PARENT,
            buttons=(
                Gtk.STOCK_CANCEL,
                Gtk.ResponseType.REJECT,
                Gtk.STOCK_OK,
                Gtk.ResponseType.ACCEPT,
            ),
        )
        self.target = target
        ed = HCYMaskEditorWheel()
        target_mgr = target.get_color_manager()
        prefs_ro = deepcopy(target_mgr.get_prefs())
        datapath = target_mgr.get_data_path()
        ed_mgr = ColorManager(prefs=prefs_ro, datapath=datapath)
        ed.set_color_manager(ed_mgr)
        self.editor = ed
        ed.set_size_request(300, 300)
        ed.mask_toggle.set_active(True)
        self.mask_toggle_ctrl = Gtk.CheckButton(
            C_(
                "HCY Gamut Mask Editor dialog: mask-is-active checkbox",
                u"Active",
            ),
            use_underline=False,
        )
        self.mask_toggle_ctrl.set_tooltip_text(ed.mask_toggle.get_tooltip())
        ed.mask_observers.append(self.__mask_changed_cb)

        hbox = Gtk.HBox()
        hbox.set_spacing(3)

        # Sidebar buttonbox
        # On the right and packed to the top. This places its secondary
        # control, a mask toggle button, next to the "OK" button so it's less
        # likely to be missed.
        bbox = Gtk.VButtonBox()
        new_btn = self.__new_button = Gtk.Button(stock=Gtk.STOCK_NEW)
        load_btn = self.__load_button = Gtk.Button(stock=Gtk.STOCK_OPEN)
        save_btn = self.__save_button = Gtk.Button(stock=Gtk.STOCK_SAVE)
        clear_btn = self.__clear_button = Gtk.Button(stock=Gtk.STOCK_CLEAR)

        help_btn = self.__help_button = Gtk.LinkButton.new_with_label(
            uri=MASK_EDITOR_HELP_URI,
            label=C_(
                "HCY Mask Editor: action button labels",
                u"Help…",
            ),
        )

        new_btn.set_tooltip_text(
            C_("HCY Mask Editor: action button tooltips",
               u"Create mask from template."), )
        load_btn.set_tooltip_text(
            C_("HCY Mask Editor: action button tooltips",
               u"Load mask from a GIMP palette file."), )
        save_btn.set_tooltip_text(
            C_("HCY Mask Editor: action button tooltips",
               u"Save mask to a GIMP palette file."), )
        clear_btn.set_tooltip_text(
            C_("HCY Mask Editor: action button tooltips",
               u"Erase the mask."), )
        help_btn.set_tooltip_text(
            C_("HCY Mask Editor: action button tooltips",
               u"Open the online help for this dialog in a web browser."), )

        new_btn.connect("clicked", self.__new_clicked)
        save_btn.connect("clicked", self.__save_clicked)
        load_btn.connect("clicked", self.__load_clicked)
        clear_btn.connect("clicked", self.__clear_clicked)

        bbox.pack_start(new_btn, True, True, 0)
        bbox.pack_start(load_btn, True, True, 0)
        bbox.pack_start(save_btn, True, True, 0)
        bbox.pack_start(clear_btn, True, True, 0)

        action_area = self.get_action_area()
        if isinstance(action_area, Gtk.ButtonBox):
            action_area.pack_start(help_btn, True, True, 0)
            action_area.set_child_secondary(help_btn, True)
            action_area.set_child_non_homogeneous(help_btn, True)
            bbox.pack_start(self.mask_toggle_ctrl, True, True, 0)
            bbox.set_child_secondary(self.mask_toggle_ctrl, True)
        else:
            bbox.pack_start(self.mask_toggle_ctrl, True, True, 0)
            bbox.pack_start(help_btn, True, True, 0)
            bbox.set_child_secondary(help_btn, True)

        bbox.set_layout(Gtk.ButtonBoxStyle.START)

        hbox.pack_start(ed, True, True, 0)
        hbox.pack_start(bbox, False, False, 0)
        hbox.set_border_width(9)

        self.vbox.pack_start(hbox, True, True, 0)

        self.connect("response", self.__response_cb)
        self.connect("show", self.__show_cb)
        for w in self.vbox:
            w.show_all()
コード例 #17
0
ファイル: hsvwheel.py プロジェクト: gwojcik/mypaint
        frame = gtk.AspectFrame(obey_child=True)
        frame.set_shadow_type(gtk.SHADOW_NONE)
        frame.add(self.__table)
        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())
コード例 #18
0
        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

    def paint_foreground_cb(self, cr, wd, ht):
        x, y = self.get_position_for_color(self.get_managed_color())
        draw_marker_circle(cr, x, y)


if __name__ == '__main__':
    import os
    import sys
    from adjbases import ColorManager
    mgr = ColorManager(prefs={}, datapath='.')
    cube = HSVCubePage()
    cube.set_color_manager(mgr)
    mgr.set_color(RGBColor(0.3, 0.6, 0.7))
    if len(sys.argv) > 1:
        slice = HSVCubeSlice(cube)
        slice.set_color_manager(mgr)
        icon_name = cube.get_page_icon_name()
        for dir_name in sys.argv[1:]:
            slice.save_icon_tree(dir_name, icon_name)
    else:
        # Interactive test
        window = Gtk.Window()
        window.add(cube.get_page_widget())
        window.set_title(os.path.basename(sys.argv[0]))
        window.connect("destroy", lambda *a: Gtk.main_quit())
コード例 #19
0
class PaletteEditorDialog (gtk.Dialog):
    """Dialog for editing, loading and saving the current palette.
    """

    __target = None  #: The target PaletteView, where changes are sent

    def __init__(self, parent, target):
        gtk.Dialog.__init__(self, _("Palette Editor"), parent,
                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                             gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        self.set_position(gtk.WIN_POS_MOUSE)
        self.__target = target
        view = PaletteView()
        view.set_size_request(400, 300)
        view.grid.show_current_index = True
        view.grid.manage_current_index = True
        view.grid.can_select_empty = True
        self.__view = view

        self.__mgr = ColorManager()
        self.__mgr.set_color(RGBColor(1,1,1))
        view.set_color_manager(self.__mgr)

        # Action buttons, positiopned down the right hand side
        action_bbox = gtk.VButtonBox()
        load_btn = self.__load_button = gtk.Button(stock=gtk.STOCK_OPEN)
        save_btn = self.__save_button = gtk.Button(stock=gtk.STOCK_SAVE)
        add_btn = self.__add_button = gtk.Button(stock=gtk.STOCK_ADD)
        remove_btn = self.__remove_button = gtk.Button(stock=gtk.STOCK_REMOVE)
        clear_btn = self.__clear_button = gtk.Button(stock=gtk.STOCK_CLEAR)
        action_bbox.pack_start(load_btn)
        action_bbox.pack_start(save_btn)
        action_bbox.pack_start(add_btn)
        action_bbox.pack_start(remove_btn)
        action_bbox.pack_start(clear_btn)
        action_bbox.set_layout(gtk.BUTTONBOX_START)
        load_btn.connect("clicked", self.__load_btn_clicked)
        save_btn.connect("clicked", self.__save_btn_clicked)
        remove_btn.connect("clicked", self.__remove_btn_clicked)
        add_btn.connect("clicked", self.__add_btn_clicked)
        clear_btn.connect("clicked", self.__clear_btn_clicked)
        load_btn.set_tooltip_text(_("Load from a GIMP palette file"))
        save_btn.set_tooltip_text(_("Save to a GIMP palette file"))
        add_btn.set_tooltip_text(_("Add a new empty swatch"))
        remove_btn.set_tooltip_text(_("Remove the current swatch"))
        clear_btn.set_tooltip_text(_("Remove all swatches"))

        # Button initial state and subsequent updates
        remove_btn.set_sensitive(False)
        view.grid.current_index_observers.append(
          self.__current_index_changed_cb)
        view.grid.palette_observers.append(self.__palette_changed_cb)

        # Palette name and number of entries
        palette_details_hbox = gtk.HBox()
        palette_name_label = gtk.Label(_("Name:"))
        palette_name_label.set_tooltip_text(
          _("Name or description for this palette"))
        palette_name_entry = gtk.Entry()
        palette_name_entry.connect("changed", self.__palette_name_changed_cb)
        self.__palette_name_entry = palette_name_entry
        self.__columns_adj = gtk.Adjustment(
          value=0, lower=0, upper=99,
          step_incr=1, page_incr=1, page_size=0 )
        self.__columns_adj.connect("value-changed", self.__columns_changed_cb)
        columns_label = gtk.Label(_("Columns:"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_spinbutton = gtk.SpinButton(
          adjustment=self.__columns_adj,
          climb_rate=1.5,
          digits=0 )
        palette_details_hbox.set_spacing(0)
        palette_details_hbox.set_border_width(0)
        palette_details_hbox.pack_start(palette_name_label, False, False, 0)
        palette_details_hbox.pack_start(palette_name_entry, True, True, 6)
        palette_details_hbox.pack_start(columns_label, False, False, 6)
        palette_details_hbox.pack_start(columns_spinbutton, False, False, 0)

        color_name_hbox = gtk.HBox()
        color_name_label = gtk.Label(_("Color name:"))
        color_name_label.set_tooltip_text(_("Current colour's name"))
        color_name_entry = gtk.Entry()
        color_name_entry.connect("changed", self.__color_name_changed_cb)
        color_name_entry.set_sensitive(False)
        self.__color_name_entry = color_name_entry
        color_name_hbox.set_spacing(6)
        color_name_hbox.pack_start(color_name_label, False, False, 0)
        color_name_hbox.pack_start(color_name_entry, True, True, 0)

        palette_vbox = gtk.VBox()
        palette_vbox.set_spacing(12)
        palette_vbox.pack_start(palette_details_hbox, False, False)
        palette_vbox.pack_start(view, True, True)
        palette_vbox.pack_start(color_name_hbox, False, False)

        # Dialog contents
        # Main edit area to the left, buttons to the right
        hbox = gtk.HBox()
        hbox.set_spacing(12)
        hbox.pack_start(palette_vbox, True, True)
        hbox.pack_start(action_bbox, False, False)
        hbox.set_border_width(12)
        self.vbox.pack_start(hbox, True, True)

        # Dialog vbox contents must be shown separately
        for w in self.vbox:
            w.show_all()

        self.connect("response", self.__response_cb)
        self.connect("show", self.__show_cb)


    def __show_cb(self, widget, *a):
        # Each time the dialog is shown, clone the target's palette for
        # editing.
        self.vbox.show_all()
        palette = deepcopy(self.__target.get_palette())
        name = palette.get_name()
        if name is None:
            name = ""
        self.__palette_name_entry.set_text(name)
        self.__columns_adj.set_value(palette.get_columns())
        self.__view.set_palette(palette)


    def __palette_name_changed_cb(self, editable):
        name = editable.get_chars(0, -1)
        if name == "":
            name = None
        pal = self.__view.get_palette()
        pal.set_name(name)
        self.__view.set_palette(pal)


    def __columns_changed_cb(self, adj):
        ncolumns = int(adj.get_value())
        pal = self.__view.get_palette()
        pal.set_columns(ncolumns)
        self.__view.set_palette(pal)


    def __color_name_changed_cb(self, editable):
        name = editable.get_chars(0, -1)
        grid = self.__view.grid
        palette = grid._palette
        i = grid._current_index
        if i is None:
            return
        old_name = palette.get_color_name(i)
        if name == "":
            name = None
        if name != old_name:
            palette.set_color_name(i, name)


    def __response_cb(self, widget, response_id):
        if response_id == gtk.RESPONSE_ACCEPT:
            palette = self.__view.get_palette()
            self.__target.set_palette(palette)
        self.hide()
        return True


    def __current_index_changed_cb(self, i):
        col_name_entry = self.__color_name_entry
        remove_btn = self.__remove_button
        palette = self.__view.get_palette()
        if i is not None:
            col = palette.get_color(i)
            if col is not None:
                name = palette.get_color_name(i)
                if name is None:
                    name = ""
                col_name_entry.set_sensitive(True)
                col_name_entry.set_text(name)
            else:
                col_name_entry.set_sensitive(False)
                col_name_entry.set_text(_("Empty palette slot"))
        else:
            col_name_entry.set_sensitive(False)
            col_name_entry.set_text("")
        self.__update_buttons()


    def __update_buttons(self):
        palette = self.__view.grid._palette
        emptyish = len(palette) == 0
        if len(palette) == 1:
            if palette[0] is None:
                emptyish = True
        can_save = not emptyish
        can_clear = not emptyish
        can_remove = True
        if emptyish or self.__view.grid._current_index is None:
            can_remove = False
        self.__save_button.set_sensitive(can_save)
        self.__remove_button.set_sensitive(can_remove)
        self.__clear_button.set_sensitive(can_clear)


    def __palette_changed_cb(self, palette):
        new_name = palette.get_name()
        if new_name is None:
            new_name = ""
        old_name = self.__palette_name_entry.get_chars(0, -1)
        if old_name != new_name:
            self.__palette_name_entry.set_text(new_name)
        self.__columns_adj.set_value(palette.get_columns())
        self.__update_buttons()


    def __add_btn_clicked(self, button):
        grid = self.__view.grid
        palette = self.__view.get_palette()
        i = grid._current_index
        if i is None:
            i = len(palette)
            palette.append(None)
        else:
            palette.insert(i, None)
            i += 1
        self.__view.set_palette(palette)
        grid.set_current_index(i)


    def __remove_btn_clicked(self, button):
        grid = self.__view.grid
        palette = self.__view.get_palette()
        i = grid._current_index
        if i >= 0 and i < len(palette):
            palette.pop(i)
            if len(palette) == 0:
                palette.append(None)
            self.__view.set_palette(palette)
            if i > 0:
                i -= 1
            grid.set_current_index(i)


    def __load_btn_clicked(self, button):
        preview = _PalettePreview()
        manager = self.__target.get_color_manager()
        datapath = manager.get_data_path()
        palettes_dir = os.path.join(datapath, DATAPATH_PALETTES_SUBDIR)
        palette = Palette.load_via_dialog(title=_("Load palette"),
                                          parent=self,
                                          preview=preview,
                                          shortcuts=[palettes_dir])
        if palette is not None:
            self.__view.set_palette(palette)


    def __save_btn_clicked(self, button):
        preview = _PalettePreview()
        pal = self.__view.get_palette()
        pal.save_via_dialog(title=_("Save palette"), parent=self,
                            preview=preview)


    def __clear_btn_clicked(self, button):
        pal = Palette()
        pal.append(None)
        self.__view.set_palette(pal)
コード例 #20
0
ファイル: hcywheel.py プロジェクト: j-fu/mypaint
    def __init__(self, parent, target):
        gtk.Dialog.__init__(
            self, _("Gamut mask editor"), parent,
            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
            (gtk.STOCK_HELP, gtk.RESPONSE_HELP, gtk.STOCK_CANCEL,
             gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        self.set_position(gtk.WIN_POS_MOUSE)
        self.target = target
        ed = HCYMaskEditorWheel()
        target_mgr = target.get_color_manager()
        prefs_ro = deepcopy(target_mgr.get_prefs())
        datapath = target_mgr.get_data_path()
        ed_mgr = ColorManager(prefs=prefs_ro, datapath=datapath)
        ed.set_color_manager(ed_mgr)
        self.editor = ed
        ed.set_size_request(300, 300)
        ed.mask_toggle.set_active(True)
        self.mask_toggle_ctrl = gtk.CheckButton(_("Active"),
                                                use_underline=False)
        self.mask_toggle_ctrl.set_tooltip_text(ed.mask_toggle.get_tooltip())
        ed.mask_observers.append(self.__mask_changed_cb)

        hbox = gtk.HBox()
        hbox.set_spacing(3)

        # Sidebar buttonbox
        # On the right and packed to the top. This places its secondary
        # control, a mask toggle button, next to the "OK" button so it's less
        # likely to be missed.
        bbox = gtk.VButtonBox()
        new_btn = self.__new_button = gtk.Button(stock=gtk.STOCK_NEW)
        load_btn = self.__load_button = gtk.Button(stock=gtk.STOCK_OPEN)
        save_btn = self.__save_button = gtk.Button(stock=gtk.STOCK_SAVE)
        clear_btn = self.__clear_button = gtk.Button(stock=gtk.STOCK_CLEAR)

        new_btn.set_tooltip_text(_("Create mask from template"))
        load_btn.set_tooltip_text(_("Load mask from a GIMP palette file"))
        save_btn.set_tooltip_text(_("Save mask to a GIMP palette file"))
        clear_btn.set_tooltip_text(_("Erase the mask"))

        new_btn.connect("clicked", self.__new_clicked)
        save_btn.connect("clicked", self.__save_clicked)
        load_btn.connect("clicked", self.__load_clicked)
        clear_btn.connect("clicked", self.__clear_clicked)

        bbox.pack_start(new_btn)
        bbox.pack_start(load_btn)
        bbox.pack_start(save_btn)
        bbox.pack_start(clear_btn)
        bbox.pack_start(self.mask_toggle_ctrl)
        bbox.set_child_secondary(self.mask_toggle_ctrl, True)
        bbox.set_layout(gtk.BUTTONBOX_START)

        hbox.pack_start(ed, True, True)
        hbox.pack_start(bbox, False, False)
        hbox.set_border_width(9)

        self.vbox.pack_start(hbox, True, True)

        self.connect("response", self.__response_cb)
        self.connect("show", self.__show_cb)
        for w in self.vbox:
            w.show_all()
コード例 #21
0
ファイル: hsvcube.py プロジェクト: Jehan/mypaint
        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

    def paint_foreground_cb(self, cr, wd, ht):
        x, y = self.get_position_for_color(self.get_managed_color())
        draw_marker_circle(cr, x, y)


if __name__ == '__main__':
    import os
    import sys
    from adjbases import ColorManager
    mgr = ColorManager(prefs={}, datapath='.')
    cube = HSVCubePage()
    cube.set_color_manager(mgr)
    mgr.set_color(RGBColor(0.3, 0.6, 0.7))
    if len(sys.argv) > 1:
        slice = HSVCubeSlice(cube)
        slice.set_color_manager(mgr)
        icon_name = cube.get_page_icon_name()
        for dir_name in sys.argv[1:]:
            slice.save_icon_tree(dir_name, icon_name)
    else:
        # Interactive test
        window = gtk.Window()
        window.add(cube.get_page_widget())
        window.set_title(os.path.basename(sys.argv[0]))
        window.connect("destroy", lambda *a: gtk.main_quit())
コード例 #22
0
ファイル: hsvwheel.py プロジェクト: thorsummoner/mypaint
        frame = gtk.AspectFrame(obey_child=True)
        frame.set_shadow_type(gtk.SHADOW_NONE)
        frame.add(self.__table)
        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())
コード例 #23
0
ファイル: paletteview.py プロジェクト: j-fu/mypaint
class PaletteEditorDialog (Gtk.Dialog):
    """Dialog for editing, loading and saving the current palette.
    """

    def __init__(self, parent, target_color_manager):
        flags = Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT
        Gtk.Dialog.__init__(self, _("Palette Editor"), parent, flags,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,
                             Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
        self.set_position(Gtk.WindowPosition.MOUSE)

        assert isinstance(target_color_manager, ColorManager)
        #: ColorManager containing the palette to be edited.
        self._target_color_manager = target_color_manager

        view = PaletteView()
        view.set_size_request(400, 300)
        view.grid.show_matched_color = True
        view.grid.can_select_empty = True
        self._view = view

        #: The working ColorManager, holding a working copy of the palette
        #: to be edited.
        self._mgr = ColorManager(prefs={},
                                 datapath=target_color_manager.get_data_path())
        self._mgr.set_color(RGBColor(1, 1, 1))
        view.set_color_manager(self._mgr)

        # Action buttons, positiopned down the right hand side
        action_bbox = Gtk.VButtonBox()
        load_btn = self._load_button = Gtk.Button(stock=Gtk.STOCK_OPEN)
        save_btn = self._save_button = Gtk.Button(stock=Gtk.STOCK_SAVE)
        add_btn = self._add_button = Gtk.Button(stock=Gtk.STOCK_ADD)
        remove_btn = self._remove_button = Gtk.Button(stock=Gtk.STOCK_REMOVE)
        clear_btn = self._clear_button = Gtk.Button(stock=Gtk.STOCK_CLEAR)
        action_bbox.pack_start(load_btn)
        action_bbox.pack_start(save_btn)
        action_bbox.pack_start(add_btn)
        action_bbox.pack_start(remove_btn)
        action_bbox.pack_start(clear_btn)
        action_bbox.set_layout(Gtk.ButtonBoxStyle.START)
        load_btn.connect("clicked", self._load_btn_clicked)
        save_btn.connect("clicked", self._save_btn_clicked)
        remove_btn.connect("clicked", self._remove_btn_clicked)
        add_btn.connect("clicked", self._add_btn_clicked)
        clear_btn.connect("clicked", self._clear_btn_clicked)
        load_btn.set_tooltip_text(_("Load from a GIMP palette file"))
        save_btn.set_tooltip_text(_("Save to a GIMP palette file"))
        add_btn.set_tooltip_text(_("Add a new empty swatch"))
        remove_btn.set_tooltip_text(_("Remove the current swatch"))
        clear_btn.set_tooltip_text(_("Remove all swatches"))

        # Button initial state and subsequent updates
        remove_btn.set_sensitive(False)
        self._mgr.palette.match_changed += self._palette_match_changed_cb
        self._mgr.palette.info_changed += self._palette_changed_cb
        self._mgr.palette.sequence_changed += self._palette_changed_cb
        self._mgr.palette.color_changed += self._palette_changed_cb

        # Palette name and number of entries
        palette_details_hbox = Gtk.HBox()
        palette_name_label = Gtk.Label(_("Name:"))
        palette_name_label.set_tooltip_text(_("Name or description for"
                                              " this palette"))
        palette_name_entry = Gtk.Entry()
        palette_name_entry.connect("changed", self._palette_name_changed_cb)
        self._palette_name_entry = palette_name_entry
        self._columns_adj = Gtk.Adjustment(
            value=0, lower=0, upper=99,
            step_incr=1, page_incr=1, page_size=0
        )
        self._columns_adj.connect("value-changed", self._columns_changed_cb)
        columns_label = Gtk.Label(_("Columns:"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_label.set_tooltip_text(_("Number of columns"))
        columns_spinbutton = Gtk.SpinButton(
            adjustment=self._columns_adj,
            climb_rate=1.5,
            digits=0
        )
        palette_details_hbox.set_spacing(0)
        palette_details_hbox.set_border_width(0)
        palette_details_hbox.pack_start(palette_name_label, False, False, 0)
        palette_details_hbox.pack_start(palette_name_entry, True, True, 6)
        palette_details_hbox.pack_start(columns_label, False, False, 6)
        palette_details_hbox.pack_start(columns_spinbutton, False, False, 0)

        color_name_hbox = Gtk.HBox()
        color_name_label = Gtk.Label(_("Color name:"))
        color_name_label.set_tooltip_text(_("Current color's name"))
        color_name_entry = Gtk.Entry()
        color_name_entry.connect("changed", self._color_name_changed_cb)
        color_name_entry.set_sensitive(False)
        self._color_name_entry = color_name_entry
        color_name_hbox.set_spacing(6)
        color_name_hbox.pack_start(color_name_label, False, False, 0)
        color_name_hbox.pack_start(color_name_entry, True, True, 0)

        palette_vbox = Gtk.VBox()
        palette_vbox.set_spacing(12)
        palette_vbox.pack_start(palette_details_hbox, False, False)
        palette_vbox.pack_start(view, True, True)
        palette_vbox.pack_start(color_name_hbox, False, False)

        # Dialog contents
        # Main edit area to the left, buttons to the right
        hbox = Gtk.HBox()
        hbox.set_spacing(12)
        hbox.pack_start(palette_vbox, True, True)
        hbox.pack_start(action_bbox, False, False)
        hbox.set_border_width(12)
        self.vbox.pack_start(hbox, True, True)

        # Dialog vbox contents must be shown separately
        for w in self.vbox:
            w.show_all()

        self.connect("response", self._response_cb)
        self.connect("show", self._show_cb)

    def _show_cb(self, widget, *a):
        # Each time the dialog is shown, update with the target
        # palette, for editing.
        self.vbox.show_all()
        palette = self._target_color_manager.palette
        name = palette.get_name()
        if name is None:
            name = ""
        self._palette_name_entry.set_text(name)
        self._columns_adj.set_value(palette.get_columns())
        self._mgr.palette.update(palette)

    def _palette_name_changed_cb(self, editable):
        name = editable.get_chars(0, -1)
        if name == "":
            name = None
        pal = self._mgr.palette
        pal.name = unicode(name)

    def _columns_changed_cb(self, adj):
        ncolumns = int(adj.get_value())
        pal = self._mgr.palette
        pal.set_columns(ncolumns)

    def _color_name_changed_cb(self, editable):
        name = editable.get_chars(0, -1)
        palette = self._mgr.palette
        i = palette.match_position
        if i is None:
            return
        old_name = palette.get_color_name(i)
        if name == "":
            name = None
        if name != old_name:
            palette.set_color_name(i, name)

    def _response_cb(self, widget, response_id):
        if response_id == Gtk.ResponseType.ACCEPT:
            palette = self._mgr.palette
            target_palette = self._target_color_manager.palette
            target_palette.update(palette)
        self.hide()
        return True

    def _palette_match_changed_cb(self, palette):
        col_name_entry = self._color_name_entry
        i = palette.match_position
        if i is not None:
            col = palette[i]
            if col is not None:
                name = palette.get_color_name(i)
                if name is None:
                    name = ""
                col_name_entry.set_sensitive(True)
                col_name_entry.set_text(name)
            else:
                col_name_entry.set_sensitive(False)
                col_name_entry.set_text(_("Empty palette slot"))
        else:
            col_name_entry.set_sensitive(False)
            col_name_entry.set_text("")
        self._update_buttons()

    def _update_buttons(self):
        palette = self._mgr.palette
        emptyish = len(palette) == 0
        if len(palette) == 1:
            if palette[0] is None:
                emptyish = True
        can_save = not emptyish
        can_clear = not emptyish
        can_remove = True
        if emptyish or self._mgr.palette.match_position is None:
            can_remove = False
        self._save_button.set_sensitive(can_save)
        self._remove_button.set_sensitive(can_remove)
        self._clear_button.set_sensitive(can_clear)

    def _palette_changed_cb(self, palette, *args, **kwargs):
        new_name = palette.get_name()
        if new_name is None:
            new_name = ""
        old_name = self._palette_name_entry.get_chars(0, -1)
        if old_name != new_name:
            self._palette_name_entry.set_text(new_name)
        self._columns_adj.set_value(palette.get_columns())
        self._update_buttons()

    def _add_btn_clicked(self, button):
        palette = self._mgr.palette
        i = palette.match_position
        if i is None:
            i = len(palette)
            palette.append(None)
            palette.match_position = i
        else:
            palette.insert(i, None)

    def _remove_btn_clicked(self, button):
        palette = self._mgr.palette
        i = palette.match_position
        if i >= 0 and i < len(palette):
            palette.pop(i)
            if len(palette) == 0:
                palette.append(None)

    def _load_btn_clicked(self, button):
        preview = _PalettePreview()
        manager = self._target_color_manager
        datapath = manager.get_data_path()
        palettes_dir = os.path.join(datapath, DATAPATH_PALETTES_SUBDIR)
        palette = palette_load_via_dialog(title=_("Load palette"),
                                          parent=self,
                                          preview=preview,
                                          shortcuts=[palettes_dir])
        if palette is not None:
            self._mgr.palette.update(palette)

    def _save_btn_clicked(self, button):
        preview = _PalettePreview()
        palette_save_via_dialog(self._mgr.palette, title=_("Save palette"),
                                parent=self, preview=preview)

    def _clear_btn_clicked(self, button):
        pal = self._mgr.palette
        pal.clear()