From f3a3965e9b1baac7e30c0e55eb851fc2b30aa836 Mon Sep 17 00:00:00 2001 From: Alexandre Antonino Gonçalves Martinazzo Date: Mon, 10 Sep 2007 21:23:51 +0000 Subject: Squashed commit of the following: commit e1108821e698adc06a10ed18e9d4caec35c811d2 Author: Alexandre Antonino Gonçalves Martinazzo Date: Mon Sep 10 18:17:35 2007 -0300 Bug #3172 fixed. Paint now start with 'Pencil' tool selected Minor changes in Area, new tool structure is comming. --- diff --git a/Area.py b/Area.py index 9c72ae4..e2ffa62 100644 --- a/Area.py +++ b/Area.py @@ -256,11 +256,12 @@ class Area(gtk.DrawingArea): try: # This works for a gtk.Entry text = self.janela._textview.get_text() - except: + except AttributeError: # This works for a gtk.TextView buf = self.janela._textview.get_buffer() start, end = buf.get_bounds() text = buf.get_text(start, end) + if text is not None: self.d.text(widget,event) self.estadoTexto = 0 @@ -706,7 +707,7 @@ class Area(gtk.DrawingArea): self.queue_draw() - def _set_fill_color(self, color): + def set_fill_color(self, color): """Set fill color. Keyword arguments: @@ -719,7 +720,7 @@ class Area(gtk.DrawingArea): self.gc.set_foreground(color) - def _set_stroke_color(self, color): + def set_stroke_color(self, color): """Set stroke color. Keyword arguments: @@ -733,7 +734,7 @@ class Area(gtk.DrawingArea): self.gc_line.set_line_attributes(1, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) self.gc_brush.set_foreground(color) - def _set_grayscale(self,widget): + def grayscale(self,widget): """Apply grayscale effect. Keyword arguments: @@ -881,3 +882,62 @@ class Area(gtk.DrawingArea): self.d.clear() self.enableUndo(self) + # Changing to public methods + def _set_fill_color(self, color): + self.set_fill_color(color) + + def _set_stroke_color(self, color): + self.set_stroke_color(color) + + def _set_grayscale(self,widget): + self.grayscale(widget) + + def set_tool(self, tool): + ''' + Method to configure all tools. + + @param - tool: a dictionary with the following keys: + 'name': a string + 'size': a integer + 'fill color': a gtk.gdk.Color object + 'stroke color': a gtk.gdk.Color object + 'shape': a string - 'circle' or 'square', for now + 'fill': a Boolean value + 'sides': a integer (used when drawing regular polygons) + 'points': a integer (used when drawing stars) + ''' + logging.debug('Area.set_tool') + + #FIXME: self.tool should be a dict too. + print tool + + self.tool = tool['name'] + self.configure_line(tool['size']) + + if tool['fill color'] is not None: + self.set_fill_color(tool['fill color']) + else: + # use black + self.set_fill_color( gtk.gdk.Color(0,0,0) ) + + if tool['stroke color'] is not None: + self.set_stroke_color(tool['stroke color']) + else: + # use black + self.set_stroke_color( gtk.gdk.Color(0,0,0) ) + + #FIXME: this is ugly! + if tool['name'] is 'brush': + self.brush_shape = tool['shape'] + elif tool['name'] is 'eraser': + self.eraser_shape = tool['shape'] + + self.fill = tool['fill'] + + if tool['name'] is 'polygon_regular' and (tool['sides'] is not None): + self.polygon_sides = tool['sides'] + if tool['name'] is 'star' and (tool['points'] is not None): + self.polygon_sides = tool['points'] + + #TODO: set cursors (?) + diff --git a/Desenho.py b/Desenho.py index c73d62d..a08243c 100644 --- a/Desenho.py +++ b/Desenho.py @@ -520,6 +520,8 @@ class Desenho: event -- GdkEvent """ + + #print self.d.estadoTexto if self.d.estadoTexto == 0: self.d.estadoTexto = 1 @@ -536,28 +538,27 @@ class Desenho: try: # This works for a gtk.Entry text = self.d.janela._textview.get_text() - except: + except AttributeError: # This works for a gtk.TextView buf = self.d.janela._textview.get_buffer() start, end = buf.get_bounds() text = buf.get_text(start, end) layout = self.d.create_pango_layout(text) - layout.set_font_description(self.d.font) + #layout.set_font_description(self.d.font) self.d.pixmap.draw_layout(self.d.gc, self.d.oldx, self.d.oldy, layout) self.d.pixmap_temp.draw_layout(self.d.gc, self.d.oldx, self.d.oldy, layout) self.d.janela._textview.hide() try: self.d.janela._textview.set_text('') - except: + except AttributeError: buf.set_text('') self.d.enableUndo(widget) widget.queue_draw() - #print self.d.estadoTexto def selection(self, widget, coords, temp, fill): """Make a selection. diff --git a/OficinaActivity.py b/OficinaActivity.py index d76664a..6e9dea7 100644 --- a/OficinaActivity.py +++ b/OficinaActivity.py @@ -74,6 +74,7 @@ class OficinaActivity(activity.Activity): """ activity.Activity.__init__(self, handle) + self.set_title(_('Paint')) logging.debug('Starting Paint activity (Oficina)') @@ -121,7 +122,9 @@ class OficinaActivity(activity.Activity): # setting scrolledwindow as activity canvas... self.set_canvas(sw) - + + # Setting a default tool + self._area.tool = 'pencil' def read_file(self, file_path): '''Read file from Sugar Journal. diff --git a/toolbox.py b/toolbox.py index 8e643e5..7baf85f 100644 --- a/toolbox.py +++ b/toolbox.py @@ -115,7 +115,7 @@ class DrawEditToolbar(EditToolbar): self.insert(separator, -1) separator.show() - self._clear_all = ToolButton('clear') + self._clear_all = ToolButton('edit-clear') self.insert(self._clear_all, -1) self._clear_all.show() self._clear_all.set_tooltip(_('Clear')) @@ -182,6 +182,16 @@ class ToolsToolbar(gtk.Toolbar): _TOOL_MARQUEE_RECTANGULAR = 'marquee-rectangular' _TOOL_MARQUEE_SMART = 'marquee-smart' + _tool = { + 'name' : '', + 'size' : 5, + 'fill color' : None, + 'stroke color' : None, + 'shape' : 'circle', + 'fill' : True, + 'sides' : None, + 'points' : None + } def __init__(self, activity): gtk.Toolbar.__init__(self) @@ -292,6 +302,8 @@ class ToolsToolbar(gtk.Toolbar): #self._tool_marquee_freeform.connect('clicked', self.set_tool, self._TOOL_MARQUEE_FREEFORM) self._tool_marquee_rectangular.connect('clicked', self.set_tool, self._TOOL_MARQUEE_RECTANGULAR) #self._tool_marquee_smart.connect('clicked', self.set_tool, self._TOOL_MARQUEE_SMART) + + def _configure_palette(self, widget, tool=None): '''Set palette for a tool @@ -333,8 +345,8 @@ class ToolsToolbar(gtk.Toolbar): fill_checkbutton.set_active(self._activity._area.fill) fill_checkbutton.connect('toggled', self._on_fill_checkbutton_toggled, widget) - - fill_checkbutton.connect('map', self._on_fill_checkbutton_map) + # is this necessary? + #fill_checkbutton.connect('map', self._on_fill_checkbutton_map) palette.set_content(fill_checkbutton) @@ -344,11 +356,11 @@ class ToolsToolbar(gtk.Toolbar): Set a tool shape according to user choice at Tool Palette ''' - if tool == self._TOOL_BRUSH: - self._activity._area.brush_shape = shape - elif tool == self._TOOL_ERASER: - self._activity._area.eraser_shape = shape - +# if tool == self._TOOL_BRUSH: +# self._activity._area.brush_shape = shape +# elif tool == self._TOOL_ERASER: +# self._activity._area.eraser_shape = shape + self._tool['shape'] = shape self.set_tool(widget, tool) def set_tool(self, widget, tool): @@ -356,15 +368,22 @@ class ToolsToolbar(gtk.Toolbar): Set tool to the Area object. Configures tool's color and size. ''' - # setting tool - self._activity._area.tool = tool +# # setting tool +# self._activity._area.tool = tool +# +# # setting size and color +# size = self._stroke_size.get_size() +# self._stroke_size.set_stroke_size(size) +# +# color = self._stroke_color.get_color() +# self._stroke_color.set_stroke_color(color) - # setting size and color - size = self._stroke_size.get_size() - self._stroke_size.set_stroke_size(size) + # New method to set tools + self._tool['name'] = tool + self._tool['size'] = self._stroke_size.get_size() + self._tool['stroke color'] = self._stroke_color.get_color() - color = self._stroke_color.get_color() - self._stroke_color.set_stroke_color(color) + self._activity._area.set_tool(self._tool) #setting cursor try: @@ -380,10 +399,13 @@ class ToolsToolbar(gtk.Toolbar): def _on_fill_checkbutton_toggled(self, checkbutton, button=None): logging.debug('Checkbutton is Active: %s', checkbutton.get_active() ) - self._activity._area.fill = checkbutton.get_active() + # New method for setting tools + #self._activity._area.fill = checkbutton.get_active() + self._tool['fill'] = checkbutton.get_active() + try: button.emit('clicked') - except: + except AttributeError: pass def _on_fill_checkbutton_map(self, checkbutton, data=None): @@ -1215,25 +1237,20 @@ class EffectsToolbar(gtk.Toolbar): spin.set_numeric(True) - frame = gtk.Frame(_('Size')) - frame.add(spin) - frame.show() - #palette.set_content(frame) + label = gtk.Label(_('Size: ')) + label.show() - vbox = gtk.VBox() - vbox.show() - palette.action_bar.pack_start(vbox) - - vbox.pack_start(frame) + palette.action_bar.pack_start(label) + palette.action_bar.pack_start(spin) spin.connect('value-changed', self._on_value_changed) def _on_value_changed(self, spinbutton, data=None): - size = spinbutton.get_value_as_int() - self._activity._area.configure_line(size) - - self.rainbow(self._effect_rainbow) - + size = spinbutton.get_value_as_int() + self._activity._area.configure_line(size) + + self.rainbow(self._effect_rainbow) + class ViewToolbar(gtk.Toolbar): -- cgit v0.9.1