diff options
author | Ummu <jeff@ummu.org> | 2009-08-01 06:43:45 +0400 |
---|---|---|
committer | Ummu <jeff@ummu.org> | 2009-08-01 06:43:45 +0400 |
commit | 2f3ce227940e8abdd306672810215bd64aee5173 (patch) | |
tree | 8a591909e57925be1a7e8453d9244f1051e16056 | |
parent | d2a707149583fc54c446bdfdef4b9df73a2e0582 (diff) |
stroke color selection
-rw-r--r-- | data/glade/whiteboard_widget.glade | 40 | ||||
-rw-r--r-- | src/whiteboardwidget.py | 41 |
2 files changed, 64 insertions, 17 deletions
diff --git a/data/glade/whiteboard_widget.glade b/data/glade/whiteboard_widget.glade index f316072a3..8d85fda8e 100644 --- a/data/glade/whiteboard_widget.glade +++ b/data/glade/whiteboard_widget.glade @@ -58,6 +58,46 @@ <property name="position">2</property> </packing> </child> + <child> + <widget class="GtkHBox" id="fg_color_hbox"> + <property name="visible">True</property> + <child> + <widget class="GtkLabel" id="fg_color_label"> + <property name="visible">True</property> + <property name="xpad">1</property> + <property name="ypad">1</property> + <property name="label" translatable="yes">Foreground +Color:</property> + </widget> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <widget class="GtkColorButton" id="fg_color_button"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="color">#000000000000</property> + <signal name="color_set" handler="on_fg_color_button_color_set"/> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </widget> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">4</property> + <property name="secondary">True</property> + </packing> + </child> + <child> + <placeholder/> + </child> </widget> <packing> <property name="expand">False</property> diff --git a/src/whiteboardwidget.py b/src/whiteboardwidget.py index 4d0521610..5f6c1a617 100644 --- a/src/whiteboardwidget.py +++ b/src/whiteboardwidget.py @@ -19,8 +19,8 @@ class Whiteboard(object): self.hbox.pack_start(self.canevas) self.hbox.reorder_child(self.canevas, 0) self.canevas.set_flags(gtk.CAN_FOCUS) + self.fg_color_select_button = xml.get_widget('fg_color_button') xml.signal_autoconnect(self) - self.root = self.canevas.get_root_item() # Events @@ -31,6 +31,7 @@ class Whiteboard(object): # Config self.draw_tool = 'brush' self.line_width = 2 + self.color = str(self.fg_color_select_button.get_color()) # SVG Storage self.image = SVGObject(self.root, session) @@ -51,6 +52,9 @@ class Whiteboard(object): def on_export_button_clicked(self, widget): self.image.print_xml() + + def on_fg_color_button_color_set(self, widget): + self.color = str(self.fg_color_select_button.get_color()) def button_press_event(self, widget, event): x = event.x @@ -64,8 +68,8 @@ class Whiteboard(object): center_y=y, radius_x=1, radius_y=1, - stroke_color='black', - fill_color='black', + stroke_color=self.color, + fill_color=self.color, line_width=self.line_width) self.item_data = 'M %s,%s L ' % (x, y) @@ -83,14 +87,15 @@ class Whiteboard(object): if self.draw_tool == 'brush': self.item_data = self.item_data + '%s,%s ' % (x, y) self.item_temp = goocanvas.Path(parent=self.root, - data=self.item_data, line_width=self.line_width) + data=self.item_data, line_width=self.line_width, + stroke_color=self.color) elif self.draw_tool == 'oval': self.item_temp = goocanvas.Ellipse(parent=self.root, center_x=self.item_temp_coords[0] + (x - self.item_temp_coords[0]) / 2, center_y=self.item_temp_coords[1] + (y - self.item_temp_coords[1]) / 2, radius_x=abs(x - self.item_temp_coords[0]) / 2, radius_y=abs(y - self.item_temp_coords[1]) / 2, - stroke_color='black', + stroke_color=self.color, line_width=self.line_width) def button_release_event(self, widget, event): @@ -106,17 +111,17 @@ class Whiteboard(object): center_y=y, radius_x=1, radius_y=1, - stroke_color='black', - fill_color='black', + stroke_color=self.color, + fill_color=self.color, line_width=self.line_width) - self.image.add_path(self.item_data, self.line_width) + self.image.add_path(self.item_data, self.line_width, self.color) if self.draw_tool == 'oval': cx = self.item_temp_coords[0] + (x - self.item_temp_coords[0]) / 2 cy = self.item_temp_coords[1] + (y - self.item_temp_coords[1]) / 2 rx = abs(x - self.item_temp_coords[0]) / 2 ry = abs(y - self.item_temp_coords[1]) / 2 - self.image.add_ellipse(cx, cy, rx, ry, self.line_width) + self.image.add_ellipse(cx, cy, rx, ry, self.line_width, self.color) self.item_data = None if self.item_temp is not None: @@ -168,17 +173,17 @@ class SVGObject(): self.g.setAttr('fill', 'none') self.g.setAttr('stroke-linecap', 'round') - def add_path(self, data, line_width): + def add_path(self, data, line_width, color): ''' adds the path to the items listing, both minidom node and goocanvas object in a tuple ''' goocanvas_obj = goocanvas.Path(parent=self.root, data=data, - line_width=line_width) + line_width=line_width, stroke_color=color) node = self.g.addChild(name='path') node.setAttr('d', data) node.setAttr('stroke-width', str(line_width)) - node.setAttr('stroke', 'black') + node.setAttr('stroke', color) self.g.addChild(node=node) rids = self.session.generate_rids(4) @@ -199,8 +204,10 @@ class SVGObject(): self.items[x] = new_items[x] if node.getName() == 'path': - goocanvas_obj = goocanvas.Path(parent=self.root, data=node.getAttr('d'), - line_width=int(node.getAttr('stroke-width'))) + goocanvas_obj = goocanvas.Path(parent=self.root, + data=node.getAttr('d'), + line_width=int(node.getAttr('stroke-width')), + stroke_color=node.getAttr('stroke')) if node.getName() == 'ellipse': goocanvas_obj = goocanvas.Ellipse(parent=self.root, @@ -213,7 +220,7 @@ class SVGObject(): self.items[parent_rid]['data'].append(goocanvas_obj) - def add_ellipse(self, cx, cy, rx, ry, line_width): + def add_ellipse(self, cx, cy, rx, ry, line_width, stroke_color): ''' adds the ellipse to the items listing, both minidom node and goocanvas object in a tuple ''' @@ -222,7 +229,7 @@ class SVGObject(): center_y=cy, radius_x=rx, radius_y=ry, - stroke_color='black', + stroke_color=stroke_color, line_width=line_width) node = self.g.addChild(name='ellipse') @@ -231,7 +238,7 @@ class SVGObject(): node.setAttr('rx', str(rx)) node.setAttr('ry', str(ry)) node.setAttr('stroke-width', str(line_width)) - node.setAttr('stroke', 'black') + node.setAttr('stroke', stroke_color) self.g.addChild(node=node) rids = self.session.generate_rids(7) |