2006-05-20 00:05:00 +02:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
2006-05-21 00:50:39 +02:00
|
|
|
class ColorButton(gtk.RadioButton):
|
|
|
|
def __init__(self, group, rgb):
|
|
|
|
gtk.RadioButton.__init__(self, group)
|
|
|
|
|
|
|
|
self._rgb = rgb
|
|
|
|
|
|
|
|
self.set_mode(False)
|
|
|
|
self.set_relief(gtk.RELIEF_NONE)
|
|
|
|
|
|
|
|
drawing_area = gtk.DrawingArea()
|
2006-06-22 15:22:23 +02:00
|
|
|
drawing_area.set_size_request(24, 24)
|
2006-05-21 00:50:39 +02:00
|
|
|
drawing_area.connect('expose_event', self.expose)
|
|
|
|
self.add(drawing_area)
|
|
|
|
drawing_area.show()
|
|
|
|
|
2006-05-22 04:21:42 +02:00
|
|
|
def color(self):
|
|
|
|
return self._rgb
|
|
|
|
|
2006-05-21 00:50:39 +02:00
|
|
|
def expose(self, widget, event):
|
|
|
|
rect = widget.get_allocation()
|
|
|
|
ctx = widget.window.cairo_create()
|
|
|
|
|
|
|
|
ctx.set_source_rgb(self._rgb[0], self._rgb[1] , self._rgb[2])
|
|
|
|
ctx.rectangle(0, 0, rect.width, rect.height)
|
|
|
|
ctx.fill()
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2006-06-18 21:35:44 +02:00
|
|
|
class Toolbox(gtk.HBox):
|
2006-05-20 00:05:00 +02:00
|
|
|
__gsignals__ = {
|
2006-05-22 04:21:42 +02:00
|
|
|
'color-selected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
|
|
|
([gobject.TYPE_PYOBJECT]))
|
2006-05-20 00:05:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
2006-06-18 21:35:44 +02:00
|
|
|
gtk.HBox.__init__(self, False, 6)
|
2006-05-20 00:05:00 +02:00
|
|
|
|
2006-05-21 00:50:39 +02:00
|
|
|
self._colors_group = None
|
2006-05-20 00:05:00 +02:00
|
|
|
|
|
|
|
self._add_color([0, 0, 0])
|
|
|
|
self._add_color([1, 0, 0])
|
|
|
|
self._add_color([0, 1, 0])
|
|
|
|
self._add_color([0, 0, 1])
|
|
|
|
|
|
|
|
def _add_color(self, rgb):
|
2006-05-21 00:50:39 +02:00
|
|
|
color = ColorButton(self._colors_group, rgb)
|
2006-05-20 00:05:00 +02:00
|
|
|
color.connect('clicked', self.__color_clicked_cb, rgb)
|
2006-06-18 21:35:44 +02:00
|
|
|
self.pack_start(color, False)
|
2006-05-21 00:50:39 +02:00
|
|
|
|
|
|
|
if self._colors_group == None:
|
|
|
|
self._colors_group = color
|
|
|
|
|
2006-05-20 00:05:00 +02:00
|
|
|
color.show()
|
|
|
|
|
|
|
|
def __color_clicked_cb(self, button, rgb):
|
2006-05-22 04:21:42 +02:00
|
|
|
self.emit("color-selected", button.color())
|