本文整理汇总了Python中color.Color.set_rgb方法的典型用法代码示例。如果您正苦于以下问题:Python Color.set_rgb方法的具体用法?Python Color.set_rgb怎么用?Python Color.set_rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类color.Color
的用法示例。
在下文中一共展示了Color.set_rgb方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import set_rgb [as 别名]
def load(self, filename):
"""
Load the palette from a file
The filename should be given as a the full path.
"""
self.colors = []
self.load_errors = []
self.filename = filename
try:
with open(filename) as f:
# Check that file is a palette file
if f.readline().strip() != 'GIMP Palette':
self.load_errors.append("Invalid file format.".format(filename))
return False
lineno = 0
for line in f:
lineno += 1
if line[0] == '#': continue
elif line[0:5] == 'Name:':
self.name = line[5:].strip()
elif line[0:8] == 'Columns:':
try:
self.columns = int(line[8:].strip())
except ValueError:
self.load_errors.append("Columns value (line {0}) must be integer. Using default value.".format(lineno))
self.columns = 0
else:
try:
r = int(line[0:3])
g = int(line[4:7])
b = int(line[8:11])
cname = line[12:].strip()
c = Color()
c.name = cname
c.set_rgb(r,g,b)
self.colors.append(c)
except: #XXX handle specific exceptions only
self.load_errors.append("Invalid color entry on line {0}. Skipping.\n".format(lineno))
self.emit('changed')
except IOError:
#if nonexistant filename is passed in, assume we want to save to that in the future
pass
return (len(self.load_errors) == 0)
示例2: ColorPicker
# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import set_rgb [as 别名]
class ColorPicker(gtk.Widget):
"""
A widget to select colors from the screen
This displays the currently selected color and handles grabbing a color
from anywhere on screen.
It also allows dragging and dropping of colors from and onto the widget.
Signals:
'save-color' - save the current color
"""
data_path = os.path.join(os.path.dirname(__file__), 'data')
icon_path = os.path.join(data_path, 'icons')
__gsignals__ = {
'save-color': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ())
}
def __init__(self):
""" Initialize color picker """
super(ColorPicker, self).__init__()
self.pick_rate = 60
self.color = Color()
self.mag = None
self.picking = 0
self.pick_timeout = None
self.save_on_release = False
def set_magnifier(self, mag):
"""
Set the magnifier widget
This is needed so that we can pick colors directly from the magnified
image when possible
"""
self.mag = mag
def set_color(self, color):
"""
Set the color object to store selected colors in
This color object is updated when a new color is selected or dropped
on the widget.
To explicitly change the selected color, do not use this function, but
instead call set_rgb() or set_hsv() on the current color object.
"""
self.color = color
self.color.connect('changed', self.color_changed)
def color_changed(self, color):
""" Callback for color changes """
if not self.flags() & gtk.REALIZED: return
r,g,b = self.color.rgb16()
col = self.gc.get_colormap().alloc_color(r, g, b, False, False)
self.gc.set_foreground(col)
self.queue_draw()
def pick_immediate(self, x, y, magnifier):
"""
Select the color at the specified pixel
The coordinates are relative to the screen.
"""
if self.flags() & gtk.REALIZED == False: return
if magnifier:
r,g,b = self.mag.raw_pixbuf.get_pixels_array()[y,x]
else:
# grab raw screen data
self.raw_pixbuf.get_from_drawable(
gdk.get_default_root_window(),
gdk.colormap_get_system(),
x, y,
0, 0,
self.raw_width, self.raw_height)
#pull out rgb value
#XXX first time this is called generates a warning and doesn't work.
# all subsequent times are fine. why?
r,g,b = self.raw_pixbuf.get_pixels_array()[0,0]
self.color.set_rgb(r,g,b)
def cb_pick_timeout(self):
""" Callback for pick timeout """
# repeat time until we've realized the widget
if self.flags() & gtk.REALIZED == False:
return True
# widget is realized, so grab data and end timer
self.pick_immediate(self.pick_x, self.pick_y, self.pick_mag)
self.pick_timeout = None
return False
def cb_drag_set_color(self, color, x, y):
""" Drag set color callback """
self.color.set_rgb(*color.rgb())
#.........这里部分代码省略.........
示例3: picker_save_color
# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import set_rgb [as 别名]
def picker_save_color(self, picker):
c = Color()
c.set_rgb(*picker.color.rgb())
self.palette.append(c)
self.palette_view.select(c)