First go at drawing UI

This commit is contained in:
Marco Pesenti Gritti 2006-05-20 18:50:39 -04:00
parent dc276e7b7f
commit 41ec035dc7
3 changed files with 73 additions and 11 deletions

View File

@ -43,17 +43,22 @@ class Chat(activity.Activity):
self._plug.show_all()
def _create_toolbox(self):
vbox = gtk.VBox()
vbox = gtk.VBox(False, 12)
toolbox = Toolbox()
toolbox.connect('tool-selected', self._tool_selected)
vbox.pack_start(toolbox, False)
toolbox.show()
button_box = gtk.HButtonBox()
send_button = gtk.Button('Send')
vbox.pack_start(send_button, False)
button_box.pack_start(send_button, False)
send_button.connect('clicked', self.__send_button_clicked_cb)
vbox.pack_start(button_box, False)
button_box.show()
return vbox
def __send_button_clicked_cb(self, button):
@ -390,7 +395,7 @@ class GroupChat(Chat):
def _ui_setup(self, base):
Chat._ui_setup(self, base)
vbox = gtk.VBox()
vbox = gtk.VBox(False, 12)
sidebar = self._create_sidebar()
vbox.pack_start(sidebar)

View File

@ -26,6 +26,13 @@ class SketchPad(gtk.DrawingArea):
rect = self.get_allocation()
ctx = widget.window.cairo_create()
ctx.set_source_rgb(0.6, 1, 0.4)
ctx.rectangle(0, 0, rect.width, rect.height)
ctx.fill_preserve()
ctx.set_source_rgb(0, 0.3, 0.2)
ctx.stroke()
for sketch in self._sketches:
sketch.draw(ctx)

View File

@ -3,6 +3,31 @@ pygtk.require('2.0')
import gtk
import gobject
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()
drawing_area.set_size_request(16, 16)
drawing_area.connect('expose_event', self.expose)
self.add(drawing_area)
drawing_area.show()
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
class Toolbox(gtk.VBox):
__gsignals__ = {
'tool-selected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
@ -10,17 +35,28 @@ class Toolbox(gtk.VBox):
}
def __init__(self):
gtk.VBox.__init__(self)
gtk.VBox.__init__(self, False, 12)
self._tool_hbox = gtk.HBox()
self._tools_group = None
self._colors_group = None
self._add_tool('FreeHand', 'freehand')
self._add_tool('Text', 'text')
self._tool_hbox = gtk.HBox(False, 2)
spring = gtk.Label()
self._tool_hbox.pack_start(spring, True)
spring.show()
self._add_tool('stock_draw-text', 'text')
self._add_tool('stock_draw-freeform-line', 'freehand')
spring = gtk.Label()
self._tool_hbox.pack_start(spring, True)
spring.show()
self.pack_start(self._tool_hbox)
self._tool_hbox.show()
self._color_hbox = gtk.HBox()
self._color_hbox = gtk.HBox(False, 2)
self._add_color([0, 0, 0])
self._add_color([1, 0, 0])
@ -30,16 +66,30 @@ class Toolbox(gtk.VBox):
self.pack_start(self._color_hbox)
self._color_hbox.show()
def _add_tool(self, label, tool_id):
tool = gtk.Button(label)
def _add_tool(self, icon, tool_id):
image = gtk.Image()
image.set_from_icon_name(icon, gtk.ICON_SIZE_LARGE_TOOLBAR)
tool = gtk.RadioButton(self._tools_group)
tool.set_mode(False)
tool.set_relief(gtk.RELIEF_NONE)
tool.set_image(image)
tool.connect('clicked', self.__tool_clicked_cb, tool_id)
self._tool_hbox.pack_start(tool, False)
if self._tools_group == None:
self._tools_group = tool
tool.show()
def _add_color(self, rgb):
color = gtk.Button('Color')
color = ColorButton(self._colors_group, rgb)
color.connect('clicked', self.__color_clicked_cb, rgb)
self._color_hbox.pack_start(color, False)
if self._colors_group == None:
self._colors_group = color
color.show()
def __tool_clicked_cb(self, button, tool_id):