本文整理汇总了Python中adjbases.ColorManager类的典型用法代码示例。如果您正苦于以下问题:Python ColorManager类的具体用法?Python ColorManager怎么用?Python ColorManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ColorManager类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_as_icon
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)
示例2: render_as_icon
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: __init__
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)
示例4: __init__
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)
示例5: set_color_manager
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())
示例6: set_color_manager
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]))
示例7: __init__
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)
#.........这里部分代码省略.........
示例8: PaletteEditorDialog
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)
#.........这里部分代码省略.........
示例9: paint_foreground_cb
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())