本文整理汇总了Python中color.Color.rgb16方法的典型用法代码示例。如果您正苦于以下问题:Python Color.rgb16方法的具体用法?Python Color.rgb16怎么用?Python Color.rgb16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类color.Color
的用法示例。
在下文中一共展示了Color.rgb16方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ColorPicker
# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import rgb16 [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())
#.........这里部分代码省略.........