From b88b9b88748543b3e86e13c3c5dc662b3f07e2d8 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Tue, 05 Apr 2011 13:50:45 +0000 Subject: Move all the controls in the indiviual tool palettes to the color palettes --- diff --git a/Area.py b/Area.py index 92f3f29..532b5e4 100644 --- a/Area.py +++ b/Area.py @@ -138,13 +138,13 @@ class Area(gtk.DrawingArea): ## - 'vertices' : a integer ## All values migth be None, execept in 'name' key. self.tool = { - 'name': 'pencil', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + 'name': 'pencil', + 'line size': 2, + 'fill color': None, + 'stroke color': None, + 'line shape': 'circle', + 'fill': True, + 'vertices': 6.0} self.desenha = False self.selmove = False @@ -167,15 +167,10 @@ class Area(gtk.DrawingArea): self.text_in_progress = False self.janela = janela self.d = Desenho(self) - self.line_size = 2 - self.line_shape = 'circle' self.last = [] self.rainbow_counter = 0 self.keep_aspect_ratio = False - self.keep_shape_ratio = { - 'line': False, - 'rectangle': False, - 'ellipse': False} + self.keep_shape_ratio = False self.font_description = pango.FontDescription() self.font_description.set_family('Sans') @@ -194,12 +189,6 @@ class Area(gtk.DrawingArea): ##pixmaps list to Undo func self.undo_list = [] - ##Number of sides for regular polygon - self.vertices = 6 - - ##Shapes will be filled or not? - self.fill = True - # variables to show the tool shape self.drawing = False self.x_cursor = 0 @@ -259,7 +248,6 @@ class Area(gtk.DrawingArea): self.enableUndo(self) # Setting a initial tool - # If not set here, cursor icon can't be load self.set_tool(self.tool) return True @@ -271,9 +259,6 @@ class Area(gtk.DrawingArea): @param size -- the size of the new line """ - #logging.debug('Area.configure_line(self, size)') - - self.line_size = size self.gc_line.set_line_attributes(size, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND) @@ -286,7 +271,6 @@ class Area(gtk.DrawingArea): @param event -- GdkEvent """ - #logging.debug('Area.expose(self, widget, event)') area = event.area if self.desenha or self.selmove: widget.window.draw_drawable(self.gc, self.pixmap_temp, @@ -361,25 +345,25 @@ class Area(gtk.DrawingArea): #Handle with the left button click event. if self.tool['name'] == 'eraser': self.last = [] - self.d.eraser(widget, coords, self.last, self.line_size, - self.tool['line shape']) + self.d.eraser(widget, coords, self.last, + self.tool['line size'], self.tool['line shape']) self.last = coords self.drawing = True elif self.tool['name'] == 'brush': self.last = [] - self.d.brush(widget, coords, self.last, self.line_size, + self.d.brush(widget, coords, self.last, self.tool['line size'], self.tool['line shape']) self.last = coords self.drawing = True elif self.tool['name'] == 'rainbow': self.last = [] self.d.rainbow(widget, coords, self.last, - self.rainbow_counter, self.line_size, + self.rainbow_counter, self.tool['line size'], self.tool['line shape']) self.last = coords self.drawing = True elif self.tool['name'] == 'freeform': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) if self.polygon_start == False: self.desenha = True if self.selmove: @@ -419,7 +403,7 @@ class Area(gtk.DrawingArea): coords = int(x), int(y) if self.tool['name'] in ['rectangle', 'ellipse', 'line']: if (state & gtk.gdk.SHIFT_MASK) or \ - self.keep_shape_ratio[self.tool['name']]: + self.keep_shape_ratio: if self.tool['name'] in ['rectangle', 'ellipse']: coords = self._keep_selection_ratio(coords) elif self.tool['name'] == 'line': @@ -428,22 +412,22 @@ class Area(gtk.DrawingArea): if state & gtk.gdk.BUTTON1_MASK and self.pixmap != None: if self.tool['name'] == 'pencil': self.d.brush(widget, coords, self.last, - self.line_size, 'circle') + self.tool['line size'], 'circle') self.last = coords elif self.tool['name'] == 'eraser': self.d.eraser(widget, coords, self.last, - self.line_size, self.tool['line shape']) + self.tool['line size'], self.tool['line shape']) self.last = coords elif self.tool['name'] == 'brush': self.d.brush(widget, coords, self.last, - self.line_size, self.tool['line shape']) + self.tool['line size'], self.tool['line shape']) self.last = coords elif self.tool['name'] == 'rainbow': self.d.rainbow(widget, coords, self.last, - self.rainbow_counter, self.line_size, + self.rainbow_counter, self.tool['line size'], self.tool['line shape']) self.rainbow_counter += 1 if self.rainbow_counter > 11: @@ -452,15 +436,15 @@ class Area(gtk.DrawingArea): if self.desenha: if self.tool['name'] == 'line': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.line(widget, coords) elif self.tool['name'] == 'ellipse': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.circle(widget, coords, True, self.tool['fill']) elif self.tool['name'] == 'rectangle': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.square(widget, event, coords, True, self.tool['fill']) @@ -477,39 +461,39 @@ class Area(gtk.DrawingArea): self.d.moveSelection(widget, coords) elif self.tool['name'] == 'freeform': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.polygon(widget, coords, True, self.tool['fill'], "motion") elif self.tool['name'] == 'triangle': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.triangle(widget, coords, True, self.tool['fill']) elif self.tool['name'] == 'trapezoid': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.trapezoid(widget, coords, True, self.tool['fill']) elif self.tool['name'] == 'arrow': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.arrow(widget, coords, True, self.tool['fill']) elif self.tool['name'] == 'parallelogram': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.parallelogram(widget, coords, True, self.tool['fill']) elif self.tool['name'] == 'star': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.star(widget, coords, self.tool['vertices'], True, self.tool['fill']) elif self.tool['name'] == 'polygon_regular': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.polygon_regular(widget, coords, self.tool['vertices'], True, self.tool['fill']) elif self.tool['name'] == 'heart': - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.heart(widget, coords, True, self.tool['fill']) else: if self.tool['name'] in ['brush', 'eraser', 'rainbow', 'pencil']: @@ -528,7 +512,7 @@ class Area(gtk.DrawingArea): elif self.tool['name'] == 'freeform' and not self.selmove: self.desenha = True - self.configure_line(self.line_size) + self.configure_line(self.tool['line size']) self.d.polygon(widget, coords, True, self.tool['fill'], "moving") @@ -545,7 +529,7 @@ class Area(gtk.DrawingArea): coords = int(event.x), int(event.y) if self.tool['name'] in ['rectangle', 'ellipse', 'line']: if (event.state & gtk.gdk.SHIFT_MASK) or \ - self.keep_shape_ratio[self.tool['name']]: + self.keep_shape_ratio: if self.tool['name'] in ['rectangle', 'ellipse']: coords = self._keep_selection_ratio(coords) if self.tool['name'] == 'line': @@ -1232,8 +1216,6 @@ class Area(gtk.DrawingArea): ''' logging.debug('Area.set_tool %s', tool) - #FIXME: self.tool should be a dict too. - self.tool = tool try: @@ -1255,17 +1237,6 @@ class Area(gtk.DrawingArea): except AttributeError: pass - if self.tool['line shape'] is not None: - self.line_shape = self.tool['line shape'] - - if self.tool['fill'] is not None: - self.fill = self.tool['fill'] - - if (self.tool['name'] is 'polygon_regular' \ - or self.tool['name'] is 'star') \ - and (self.tool['vertices'] is not None): - self.vertices = self.tool['vertices'] - # Setting the cursor try: cursors = {'pencil': 'pencil', diff --git a/Desenho.py b/Desenho.py index 00e8428..9b4c771 100644 --- a/Desenho.py +++ b/Desenho.py @@ -142,18 +142,18 @@ class Desenho: """ colormap = widget.get_colormap() rainbow_colors = [ - colormap.alloc_color('#ff0000', True, True), # vermelho - colormap.alloc_color('#ff8000', True, True), # laranja - colormap.alloc_color('#ffff00', True, True), # amarelo - colormap.alloc_color('#80ff00', True, True), # verde lima - colormap.alloc_color('#00ff00', True, True), # verde - colormap.alloc_color('#00ff80', True, True), # verde agua - colormap.alloc_color('#00ffff', True, True), # azul claro - colormap.alloc_color('#007fff', True, True), # quase azul - colormap.alloc_color('#0000ff', True, True), # azul - colormap.alloc_color('#8000ff', True, True), # anil - colormap.alloc_color('#ff00ff', True, True), # rosa violeta - colormap.alloc_color('#ff0080', True, True), # violeta + colormap.alloc_color('#ff0000', True, True), # vermelho + colormap.alloc_color('#ff8000', True, True), # laranja + colormap.alloc_color('#ffff00', True, True), # amarelo + colormap.alloc_color('#80ff00', True, True), # verde lima + colormap.alloc_color('#00ff00', True, True), # verde + colormap.alloc_color('#00ff80', True, True), # verde agua + colormap.alloc_color('#00ffff', True, True), # azul claro + colormap.alloc_color('#007fff', True, True), # quase azul + colormap.alloc_color('#0000ff', True, True), # azul + colormap.alloc_color('#8000ff', True, True), # anil + colormap.alloc_color('#ff00ff', True, True), # rosa violeta + colormap.alloc_color('#ff0080', True, True), # violeta ] widget.gc_rainbow.set_foreground(rainbow_colors[color]) @@ -372,7 +372,7 @@ class Desenho: widget.oldy + int(r * math.sin(A))), \ (widget.oldx + int(0.4 * r * math.cos(A + dA / 2)), widget.oldy + int(0.4 * r * math.sin(A + dA / 2)))] - for i in range(n - 1): + for i in range(int(n) - 1): A = A + dA p.append((widget.oldx + int(r * math.cos(A)), \ widget.oldy + int(r * math.sin(A)))) @@ -411,7 +411,7 @@ class Desenho: r = math.hypot(y, x) p = [(widget.oldx + int(r * math.cos(A)), \ widget.oldy + int(r * math.sin(A)))] - for i in range(n-1): + for i in range(int(n) - 1): A = A + dA p.append((widget.oldx + int(r * math.cos(A)), \ widget.oldy + int(r * math.sin(A)))) @@ -672,7 +672,7 @@ class Desenho: widget.pixmap_temp.draw_rectangle(widget.gc_selection, False, widget.orig_x + dx, widget.orig_y + dy, size[0], size[1]) widget.pixmap_temp.draw_rectangle(widget.gc_selection1, False, - widget.orig_x + dx-1, widget.orig_y + dy - 1, + widget.orig_x + dx - 1, widget.orig_y + dy - 1, size[0] + 2, size[1] + 2) widget.queue_draw() @@ -754,7 +754,7 @@ class Desenho: if not widget.polygon_start: pixmap.draw_line(widget.gc_line, widget.last[0], widget.last[1], coords[0], coords[1]) - elif widget.polygon_start == True: # Starting a new polygon ? + elif widget.polygon_start == True: # Starting a new polygon ? if param == "motion": # first press try: @@ -772,7 +772,7 @@ class Desenho: widget.points = [widget.first, coords] widget.enableUndo(widget) widget.last = coords - else: # param == "release" + else: # param == "release" # first release try: widget.first @@ -802,7 +802,7 @@ class Desenho: x = coords[0] - widget.first[0] y = coords[1] - widget.first[1] d = math.hypot(x, y) - if d > 20: # close the polygon ? + if d > 20: # close the polygon ? pixmap.draw_line(widget.gc_line, widget.last[0], widget.last[1], coords[0], coords[1]) widget.last = coords diff --git a/OficinaActivity.py b/OficinaActivity.py index 1733040..4096a83 100644 --- a/OficinaActivity.py +++ b/OficinaActivity.py @@ -62,13 +62,13 @@ Walter Bender (walter@laptop.org) """ import gtk +import logging from sugar.activity import activity from sugar.graphics import style -from toolbox import Toolbox from Area import Area -import logging +from toolbox import DrawToolbarBox class OficinaActivity(activity.Activity): @@ -103,9 +103,9 @@ class OficinaActivity(activity.Activity): sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.set_canvas(sw) - toolbox = Toolbox(self) - self.set_toolbox(toolbox) - toolbox.show() + toolbar_box = DrawToolbarBox(self) + + toolbar_box.show_all() self.connect("key_press_event", self.key_press) diff --git a/icons/insert-picture.svg b/icons/insert-picture.svg new file mode 100644 index 0000000..b8d4cf4 --- /dev/null +++ b/icons/insert-picture.svg @@ -0,0 +1,40 @@ + + + +]> + + + + + + + + + + + + + + + + + + + diff --git a/icons/picture.svg b/icons/picture.svg new file mode 100644 index 0000000..31c5bd9 --- /dev/null +++ b/icons/picture.svg @@ -0,0 +1,97 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/toolbox.py b/toolbox.py index a42d741..909b9c8 100644 --- a/toolbox.py +++ b/toolbox.py @@ -63,6 +63,7 @@ Walter Bender (walter@laptop.org) from gettext import gettext as _ +import gobject import gtk import pango import logging @@ -73,56 +74,15 @@ from sugar.graphics.toolbutton import ToolButton from sugar.graphics.radiotoolbutton import RadioToolButton from sugar.graphics.toggletoolbutton import ToggleToolButton from sugar.graphics.objectchooser import ObjectChooser - from sugar.graphics.colorbutton import ColorToolButton +from sugar.graphics import style + from sugar.activity.widgets import ActivityToolbarButton from sugar.graphics.toolbarbox import ToolbarButton, ToolbarBox from sugar.activity.widgets import StopButton -class ButtonFillColor(ColorToolButton): - """Class to manage the Fill Color of a Button""" - - def __init__(self, activity): - ColorToolButton.__init__(self) - self._activity = activity - self.connect('notify::color', self._color_button_cb) - - def _color_button_cb(self, widget, pspec): - color = self.get_color() - self.set_fill_color(color) - - def alloc_color(self, color): - colormap = self._activity.area.get_colormap() - return colormap.alloc_color(color.red, color.green, color.blue) - - def set_fill_color(self, color): - new_color = self.alloc_color(color) - self._activity.area.set_fill_color(new_color) - - -class ButtonStrokeColor(ColorToolButton): - """Class to manage the Stroke Color of a Button""" - - def __init__(self, activity): - ColorToolButton.__init__(self) - self._activity = activity - self.connect('notify::color', self._color_button_cb) - - def _color_button_cb(self, widget, pspec): - color = self.get_color() - self.set_stroke_color(color) - - def alloc_color(self, color): - colormap = self._activity.area.get_colormap() - return colormap.alloc_color(color.red, color.green, color.blue) - - def set_stroke_color(self, color): - new_color = self.alloc_color(color) - self._activity.area.set_stroke_color(new_color) - - class DrawToolbarBox(ToolbarBox): """Create toolbars for the activity""" @@ -242,8 +202,6 @@ class DrawEditToolbar(EditToolbar): def _clear_all_cb(self, widget, data=None): self._activity.area.clear() -##Determine Tools of the Toolbar - class DrawToolButton(RadioToolButton): @@ -255,77 +213,130 @@ class DrawToolButton(RadioToolButton): self.set_tooltip(tooltip) -class ToolsToolbarBuilder(): +class ButtonStrokeColor(ColorToolButton): + """Class to manage the Stroke Color of a Button""" - #Tool default definitions - _TOOL_PENCIL = {'name': 'pencil', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + def __init__(self, activity): + ColorToolButton.__init__(self) + self._activity = activity + self.properties = self._activity.area.tool + self.connect('notify::color', self._color_button_cb) - _TOOL_BRUSH = {'name': 'brush', - 'line size': 10, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + def _color_button_cb(self, widget, pspec): + color = self.get_color() + self.set_stroke_color(color) - _TOOL_ERASER = {'name': 'eraser', - 'line size': 20, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + def alloc_color(self, color): + colormap = self._activity.area.get_colormap() + return colormap.alloc_color(color.red, color.green, color.blue) - _TOOL_BUCKET = {'name': 'bucket', - 'line size': None, - 'fill color': None, - 'stroke color': None, - 'line shape': None, - 'fill': None, - 'vertices': None} + def set_stroke_color(self, color): + new_color = self.alloc_color(color) + self._activity.area.set_stroke_color(new_color) - _TOOL_MARQUEE_ELLIPTICAL = {'name': 'marquee-elliptical', - 'line size': None, - 'fill color': None, - 'stroke color': None, - 'line shape': None, - 'fill': None, - 'vertices': None} + def create_palette(self): + self._palette = self.get_child().create_palette() - _TOOL_MARQUEE_FREEFORM = {'name': 'marquee-freeform', - 'line size': None, - 'fill color': None, - 'stroke color': None, - 'line shape': None, - 'fill': None, - 'vertices': None} + color_palette_hbox = self._palette._picker_hbox - _TOOL_MARQUEE_RECTANGULAR = {'name': 'marquee-rectangular', - 'line size': None, - 'fill color': None, - 'stroke color': None, - 'line shape': None, - 'fill': None, - 'vertices': None} + content_box = gtk.VBox() + # We can set size when using either - _TOOL_MARQUEE_SMART = {'name': 'marquee-smart', - 'line size': None, - 'fill color': None, - 'stroke color': None, - 'line shape': None, - 'fill': None, - 'vertices': None} + size_spinbutton = gtk.SpinButton() + + # This is where we set restrictions for size: + # Initial value, minimum value, maximum value, step + adj = gtk.Adjustment(self.properties['line size'], 1.0, 100.0, 1.0) + size_spinbutton.set_adjustment(adj) + + size_spinbutton.set_numeric(True) + + label = gtk.Label(_('Size: ')) + + hbox = gtk.HBox() + content_box.pack_start(hbox) + + hbox.pack_start(label) + hbox.pack_start(size_spinbutton) + + size_spinbutton.connect('value-changed', self._on_value_changed) + + # User is able to choose Shapes for 'Brush' and 'Eraser' + + # Changing to gtk.RadioButton + item1 = gtk.RadioButton(None, _('Circle')) + item1.set_active(True) + + image1 = gtk.Image() + pixbuf1 = gtk.gdk.pixbuf_new_from_file_at_size( + './icons/tool-shape-ellipse.svg', + style.SMALL_ICON_SIZE, + style.SMALL_ICON_SIZE) + image1.set_from_pixbuf(pixbuf1) + item1.set_image(image1) + + item2 = gtk.RadioButton(item1, _('Square')) + + image2 = gtk.Image() + pixbuf2 = gtk.gdk.pixbuf_new_from_file_at_size( + './icons/tool-shape-rectangle.svg', + style.SMALL_ICON_SIZE, + style.SMALL_ICON_SIZE) + image2.set_from_pixbuf(pixbuf2) + item2.set_image(image2) + + item1.connect('toggled', self._on_toggled, self.properties, 'circle') + item2.connect('toggled', self._on_toggled, self.properties, 'square') + + label = gtk.Label(_('Shape')) + + content_box.pack_start(label) + content_box.pack_start(item1) + content_box.pack_start(item2) + + # Creating a CheckButton + keep_aspect_checkbutton = gtk.CheckButton(_('Keep aspect')) + ratio = self._activity.area.keep_aspect_ratio + keep_aspect_checkbutton.set_active(ratio) + keep_aspect_checkbutton.connect('toggled', + self._keep_aspect_checkbutton_toggled) + content_box.pack_start(keep_aspect_checkbutton) + + color_palette_hbox.pack_start(gtk.VSeparator(), + padding=style.DEFAULT_SPACING) + color_palette_hbox.pack_start(content_box) + color_palette_hbox.show_all() + + return self._palette + + def _keep_aspect_checkbutton_toggled(self, checkbutton): + logging.debug('Keep aspect is Active: %s', checkbutton.get_active()) + self._activity.area.keep_aspect_ratio = checkbutton.get_active() + + def _on_value_changed(self, spinbutton): + size = spinbutton.get_value_as_int() + self.properties['line size'] = size + self._activity.area.set_tool(self.properties) + + def _on_toggled(self, radiobutton, tool, shape): + if radiobutton.get_active(): + self.properties['line shape'] = shape + + +class ToolsToolbarBuilder(): + + #Tool default definitions + _TOOL_PENCIL_NAME = 'pencil' + _TOOL_BRUSH_NAME = 'brush' + _TOOL_ERASER_NAME = 'eraser' + _TOOL_BUCKET_NAME = 'bucket' + _TOOL_MARQUEE_RECT_NAME = 'marquee-rectangular' ##The Constructor def __init__(self, toolbar, activity): self._activity = activity + self.properties = self._activity.area.tool self._stroke_color = ButtonStrokeColor(activity) self._stroke_color.set_icon_name('icon-stroke') @@ -342,26 +353,14 @@ class ToolsToolbarBuilder(): activity.tool_group, _('Pencil')) toolbar.insert(self._tool_pencil, -1) activity.tool_group = self._tool_pencil - try: - self._configure_palette(self._tool_pencil, self._TOOL_PENCIL) - except: - logging.debug('Could not create palette for tool Pencil') self._tool_brush = DrawToolButton('tool-brush', activity.tool_group, _('Brush')) toolbar.insert(self._tool_brush, -1) - try: - self._configure_palette(self._tool_brush, self._TOOL_BRUSH) - except: - logging.debug('Could not create palette for tool Brush') self._tool_eraser = DrawToolButton('tool-eraser', activity.tool_group, _('Eraser')) toolbar.insert(self._tool_eraser, -1) - try: - self._configure_palette(self._tool_eraser, self._TOOL_ERASER) - except: - logging.debug('Could not create palette for tool Eraser') self._tool_bucket = DrawToolButton('tool-bucket', activity.tool_group, _('Bucket')) @@ -372,130 +371,24 @@ class ToolsToolbarBuilder(): activity.tool_group, _('Select Area')) toolbar.insert(self._tool_marquee_rectangular, -1) - try: - self._configure_palette(self._tool_marquee_rectangular, - self._TOOL_MARQUEE_RECTANGULAR) - except: - logging.debug('Could not create palette for tool selection area') - separator = gtk.SeparatorToolItem() separator.set_draw(True) toolbar.insert(separator, -1) # New connect method # Using dictionnaries to control tool's properties - self._tool_pencil.connect('clicked', self.set_tool, self._TOOL_PENCIL) - self._tool_brush.connect('clicked', self.set_tool, self._TOOL_BRUSH) - self._tool_eraser.connect('clicked', self.set_tool, self._TOOL_ERASER) - self._tool_bucket.connect('clicked', self.set_tool, self._TOOL_BUCKET) + self._tool_pencil.connect('clicked', self.set_tool, + self.properties, self._TOOL_PENCIL_NAME) + self._tool_brush.connect('clicked', self.set_tool, + self.properties, self._TOOL_BRUSH_NAME) + self._tool_eraser.connect('clicked', self.set_tool, + self.properties, self._TOOL_ERASER_NAME) + self._tool_bucket.connect('clicked', self.set_tool, + self.properties, self._TOOL_BUCKET_NAME) self._tool_marquee_rectangular.connect('clicked', self.set_tool, - self._TOOL_MARQUEE_RECTANGULAR) + self.properties, self._TOOL_MARQUEE_RECT_NAME) - def _configure_palette(self, widget, tool=None): - """Set palette for a tool - @param self -- gtk.Toolbar - @param widget - the widget which Palette will be set, - a ToolButton object - @param tool - the reference tool for Palette creation. - Its values are restricted to Class constants - """ - - logging.debug('setting a palette for %s', tool['name']) - - palette = widget.get_palette() - - content_box = gtk.VBox() - palette.set_content(content_box) - - if tool is None: - raise TypeError - - # We can set size when using either - #Pencil, Free Polygon, Brush or Eraser - if tool['name'] is self._TOOL_PENCIL['name'] or \ - tool['name'] is self._TOOL_BRUSH['name'] or \ - tool['name'] is self._TOOL_ERASER['name']: - - size_spinbutton = gtk.SpinButton() - - # This is where we set restrictions for size: - # Initial value, minimum value, maximum value, step - adj = gtk.Adjustment(tool['line size'], 1.0, 100.0, 1.0) - size_spinbutton.set_adjustment(adj) - - size_spinbutton.set_numeric(True) - - label = gtk.Label(_('Size: ')) - - # Palette's action_bar should pack buttons only - #palette.action_bar.pack_start(label) - #palette.action_bar.pack_start(size_spinbutton) - hbox = gtk.HBox() - content_box.pack_start(hbox) - - hbox.pack_start(label) - hbox.pack_start(size_spinbutton) - - size_spinbutton.connect('value-changed', - self._on_value_changed, tool) - - # User is able to choose Shapes for 'Brush' and 'Eraser' - if tool['name'] is self._TOOL_BRUSH['name'] or \ - tool['name'] is self._TOOL_ERASER['name']: - - # Changing to gtk.RadioButton - item1 = gtk.RadioButton(None, _('Circle')) - item1.set_active(True) - - image1 = gtk.Image() - image1.set_from_file('./icons/tool-shape-ellipse.svg') - item1.set_image(image1) - - item2 = gtk.RadioButton(item1, _('Square')) - - image2 = gtk.Image() - image2.set_from_file('./icons/tool-shape-rectangle.svg') - item2.set_image(image2) - - item1.connect('toggled', self._on_toggled, tool, 'circle') - item2.connect('toggled', self._on_toggled, tool, 'square') - - label = gtk.Label(_('Shape')) - - content_box.pack_start(label) - content_box.pack_start(item1) - content_box.pack_start(item2) - - if tool['name'] is self._TOOL_MARQUEE_RECTANGULAR['name']: - # Creating a CheckButton named "Fill". - keep_aspect_checkbutton = gtk.CheckButton(_('Keep aspect')) - ratio = self._activity.area.keep_aspect_ratio - keep_aspect_checkbutton.set_active(ratio) - keep_aspect_checkbutton.connect('toggled', - self._keep_aspect_checkbutton_toggled, widget) - content_box.pack_start(keep_aspect_checkbutton) - - content_box.show_all() - - def _keep_aspect_checkbutton_toggled(self, checkbutton, button=None): - logging.debug('Keep aspect is Active: %s', checkbutton.get_active()) - self._activity.area.keep_aspect_ratio = checkbutton.get_active() - - def set_shape(self, widget=None, tool=None, shape=None): - """ - Set a tool shape according to user choice at Tool Palette - - @param self -- gtk.Toolbar - @param widget -- The connected widget, if any; - necessary in case this method is used in a connect() - @param tool -- A dictionnary to determine which tool is been using - @param shape -- Determine which shape Brush and Erase will use - """ - - tool['line shape'] = shape - self.set_tool(tool=tool) - - def set_tool(self, widget=None, tool=None): + def set_tool(self, widget, tool, tool_name): """ Set tool to the Area object. Configures tool's color and size. @@ -505,27 +398,13 @@ class ToolsToolbarBuilder(): @param tool -- A dictionnary to determine which tool is been using """ - # New method to set tools; using dict - + tool['name'] = tool_name # Color must be allocated; if not, it will be displayed as black new_color = self._stroke_color.get_color() tool['stroke color'] = self._stroke_color.alloc_color(new_color) self._activity.area.set_tool(tool) - #setting cursor: Moved to Area - -# def _on_fill_checkbutton_map(self, checkbutton, data=None): -# """ -# Update checkbutton condition to agree with Area.Area object; -# this prevents tools to have fill checked but be drawed not filled. -# -# @param self -- gtk.Toolbar -# @param checkbutton -# @param data -# """ -# self._activity.area.fill = checkbutton.get_active() - def _on_color_set(self, colorbutton, tool): logging.debug('toolbox.ToolsToolbar._on_color_set') @@ -534,120 +413,114 @@ class ToolsToolbarBuilder(): tool['fill color'] = colorbutton.alloc_color(new_color) self.set_tool(tool=tool) - def _on_value_changed(self, spinbutton, tool): - size = spinbutton.get_value_as_int() - tool['line size'] = size - self.set_tool(tool=tool) + def _tool_props_updated(self): + logging.error('Setting tool') + self._activity.area.set_tool(self.properties) - def _on_toggled(self, radiobutton, tool, shape): - if radiobutton.get_active(): - self.set_shape(tool=tool, shape=shape) +class ButtonFillColor(ColorToolButton): + """Class to manage the Fill Color of a Button""" -##Make the Shapes Toolbar -class ShapesToolbar(gtk.Toolbar): + def __init__(self, activity): + ColorToolButton.__init__(self) + self._activity = activity + self.properties = self._activity.area.tool + self.connect('notify::color', self._color_button_cb) - _SHAPE_ARROW = {'name': 'arrow', - 'line size': 5, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': 5} + def _color_button_cb(self, widget, pspec): + color = self.get_color() + self.set_fill_color(color) - _SHAPE_CURVE = {'name': 'curve', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + def alloc_color(self, color): + colormap = self._activity.area.get_colormap() + return colormap.alloc_color(color.red, color.green, color.blue) - _SHAPE_ELLIPSE = {'name': 'ellipse', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + def set_fill_color(self, color): + new_color = self.alloc_color(color) + self._activity.area.set_fill_color(new_color) - _SHAPE_FREEFORM = {'name': 'freeform', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + def create_palette(self): + self._palette = self.get_child().create_palette() + color_palette_hbox = self._palette._picker_hbox - _SHAPE_HEART = {'name': 'heart', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + content_box = gtk.VBox() - _SHAPE_LINE = {'name': 'line', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + # Fill option + fill_checkbutton = gtk.CheckButton(_('Fill')) + fill_checkbutton.set_active(self.properties['fill']) + fill_checkbutton.connect('toggled', + self._on_fill_checkbutton_toggled) + content_box.pack_start(fill_checkbutton) + + keep_aspect_checkbutton = gtk.CheckButton(_('Keep Aspect')) + logging.error('Create palette : tool name %s', self.properties['name']) + ratio = self._activity.area.keep_shape_ratio + keep_aspect_checkbutton.set_active(ratio) + keep_aspect_checkbutton.connect('toggled', + self._on_keep_aspect_checkbutton_toggled) + content_box.pack_start(keep_aspect_checkbutton) - _SHAPE_PARALLELOGRAM = {'name': 'parallelogram', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + # We want choose the number of sides to our polygon + spin = gtk.SpinButton() - _SHAPE_POLYGON = {'name': 'polygon_regular', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': 6} + # This is where we set restrictions for sides in Regular Polygon: + # Initial value, minimum value, maximum value, step + adj = gtk.Adjustment(self.properties['vertices'], 3.0, 50.0, 1.0) + spin.set_adjustment(adj) + spin.set_numeric(True) - _SHAPE_RECTANGLE = {'name': 'rectangle', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + label = gtk.Label(_('Sides: ')) + #For stars + #label = gtk.Label(_('Points: ')) - _SHAPE_STAR = {'name': 'star', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': 5} + hbox = gtk.HBox() + hbox.show_all() + hbox.pack_start(label) + hbox.pack_start(spin) - _SHAPE_TRAPEZOID = {'name': 'trapezoid', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + content_box.pack_start(hbox) + hbox.show_all() + spin.connect('value-changed', self._on_vertices_value_changed) - _SHAPE_TRIANGLE = {'name': 'triangle', - 'line size': 2, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + color_palette_hbox.pack_start(gtk.VSeparator(), + padding=style.DEFAULT_SPACING) + color_palette_hbox.pack_start(content_box) + color_palette_hbox.show_all() + return self._palette + + def _on_vertices_value_changed(self, spinbutton): + self.properties['vertices'] = spinbutton.get_value_as_int() + + def _on_fill_checkbutton_toggled(self, checkbutton): + logging.debug('Checkbutton is Active: %s', checkbutton.get_active()) + self.properties['fill'] = checkbutton.get_active() + + def _on_keep_aspect_checkbutton_toggled(self, checkbutton): + self._activity.area.keep_shape_ratio = checkbutton.get_active() + + +##Make the Shapes Toolbar +class ShapesToolbar(gtk.Toolbar): + + _SHAPE_ARROW_NAME = 'arrow' + _SHAPE_CURVE_NAME = 'curve' + _SHAPE_ELLIPSE_NAME = 'ellipse' + _SHAPE_FREEFORM_NAME = 'freeform' + _SHAPE_HEART_NAME = 'heart' + _SHAPE_LINE_NAME = 'line' + _SHAPE_PARALLELOGRAM_NAME = 'parallelogram' + _SHAPE_POLYGON_NAME = 'polygon_regular' + _SHAPE_RECTANGLE_NAME = 'rectangle' + _SHAPE_STAR_NAME = 'star' + _SHAPE_TRAPEZOID_NAME = 'trapezoid' + _SHAPE_TRIANGLE_NAME = 'triangle' ##The Constructor def __init__(self, activity): gtk.Toolbar.__init__(self) self._activity = activity + self.properties = self._activity.area.tool self._fill_color = ButtonFillColor(activity) self._fill_color.set_icon_name('icon-fill') @@ -656,311 +529,88 @@ class ShapesToolbar(gtk.Toolbar): item.add(self._fill_color) self.insert(item, -1) - self._stroke_color = ButtonStrokeColor(activity) - self._stroke_color.set_icon_name('icon-stroke') - self._stroke_color.set_title(_('Stroke Color')) - item = gtk.ToolItem() - item.add(self._stroke_color) - self.insert(item, -1) - separator = gtk.SeparatorToolItem() separator.set_draw(True) self.insert(separator, -1) + # self._configure_palette_shape_ellipse() + self._shape_ellipse = DrawToolButton('tool-shape-ellipse', activity.tool_group, _('Ellipse')) self.insert(self._shape_ellipse, -1) - try: - self._configure_palette_shape_ellipse() - except: - logging.debug('Could not create palette for Shape Ellipse') self._shape_rectangle = DrawToolButton('tool-shape-rectangle', activity.tool_group, _('Rectangle')) self.insert(self._shape_rectangle, -1) - try: - self._configure_palette_shape_rectangle() - except: - logging.debug('Could not create palette for Shape Ellipse') self._shape_line = DrawToolButton('tool-shape-line', activity.tool_group, _('Line')) self.insert(self._shape_line, -1) - try: - self._configure_palette_shape_line() - except: - logging.debug('Could not create palette for Shape Line') self._shape_freeform = DrawToolButton('tool-shape-freeform', activity.tool_group, _('Free form')) self.insert(self._shape_freeform, -1) - try: - self._create_simple_palette(self._shape_freeform, - self._SHAPE_FREEFORM) - except: - logging.debug('Could not create palette for Shape Free Form') self._shape_polygon = DrawToolButton('tool-shape-polygon', activity.tool_group, _('Polygon')) self.insert(self._shape_polygon, -1) - try: - self._configure_palette_shape_polygon() - except: - logging.debug('Could not create palette for Regular Polygon') self._shape_heart = DrawToolButton('tool-shape-heart', activity.tool_group, _('Heart')) self.insert(self._shape_heart, -1) - try: - self._configure_palette_shape_heart() - except: - logging.debug('Could not create palette for Shape Heart') self._shape_parallelogram = DrawToolButton('tool-shape-parallelogram', activity.tool_group, _('Parallelogram')) self.insert(self._shape_parallelogram, -1) - try: - self._configure_palette_shape_parallelogram() - except: - logging.debug('Could not create palette for Shape Parallelogram') self._shape_arrow = DrawToolButton('tool-shape-arrow', activity.tool_group, _('Arrow')) self.insert(self._shape_arrow, -1) - try: - self._configure_palette_shape_arrow() - except: - logging.debug('Could not create palette for Shape Arrow') self._shape_star = DrawToolButton('tool-shape-star', activity.tool_group, _('Star')) self.insert(self._shape_star, -1) - try: - self._configure_palette_shape_star() - except: - logging.debug('Could not create palette for Shape Star') self._shape_trapezoid = DrawToolButton('tool-shape-trapezoid', activity.tool_group, _('Trapezoid')) self.insert(self._shape_trapezoid, -1) - try: - self._configure_palette_shape_trapezoid() - except: - logging.debug('Could not create palette for Shape Trapezoid') self._shape_triangle = DrawToolButton('tool-shape-triangle', activity.tool_group, _('Triangle')) self.insert(self._shape_triangle, -1) - try: - self._configure_palette_shape_triangle() - except: - logging.debug('Could not create palette for Shape Triangle') - self._shape_arrow.connect('clicked', self.set_tool, self._SHAPE_ARROW) - self._shape_ellipse.connect('clicked', self.set_tool, - self._SHAPE_ELLIPSE) + self._shape_arrow.connect('clicked', self.set_tool, self.properties, + self._SHAPE_ARROW_NAME) + self._shape_ellipse.connect('clicked', self.set_tool, self.properties, + self._SHAPE_ELLIPSE_NAME) self._shape_freeform.connect('clicked', self.set_tool, - self._SHAPE_FREEFORM) - self._shape_heart.connect('clicked', self.set_tool, self._SHAPE_HEART) - self._shape_line.connect('clicked', self.set_tool, self._SHAPE_LINE) + self.properties, self._SHAPE_FREEFORM_NAME) + self._shape_heart.connect('clicked', self.set_tool, + self.properties, self._SHAPE_HEART_NAME) + self._shape_line.connect('clicked', self.set_tool, + self.properties, self._SHAPE_LINE_NAME) self._shape_parallelogram.connect('clicked', self.set_tool, - self._SHAPE_PARALLELOGRAM) + self.properties, self._SHAPE_PARALLELOGRAM_NAME) self._shape_polygon.connect('clicked', self.set_tool, - self._SHAPE_POLYGON) + self.properties, self._SHAPE_POLYGON_NAME) self._shape_rectangle.connect('clicked', self.set_tool, - self._SHAPE_RECTANGLE) - self._shape_star.connect('clicked', self.set_tool, self._SHAPE_STAR) + self.properties, self._SHAPE_RECTANGLE_NAME) + self._shape_star.connect('clicked', self.set_tool, + self.properties, self._SHAPE_STAR_NAME) self._shape_trapezoid.connect('clicked', self.set_tool, - self._SHAPE_TRAPEZOID) + self.properties, self._SHAPE_TRAPEZOID_NAME) self._shape_triangle.connect('clicked', self.set_tool, - self._SHAPE_TRIANGLE) + self.properties, self._SHAPE_TRIANGLE_NAME) self.show_all() - def set_tool(self, widget=None, tool=None): - # New method to set tools; using dict - - # Color must be allocated; if not, it will be displayed as black - stroke_color = self._stroke_color.get_color() - tool['stroke color'] = self._stroke_color.alloc_color(stroke_color) + def set_tool(self, widget, tool, tool_name): + tool['name'] = tool_name fill_color = self._fill_color.get_color() tool['fill color'] = self._fill_color.alloc_color(fill_color) self._activity.area.set_tool(tool) - #setting cursor: moved to Area - - def _on_vertices_value_changed(self, spinbutton, tool): - #self._activity.area.polygon_sides = spinbutton.get_value_as_int() - tool['vertices'] = spinbutton.get_value_as_int() - self.set_tool(tool=tool) - - def _on_line_size_value_changed(self, spinbutton, tool): - tool['line size'] = spinbutton.get_value_as_int() - self.set_tool(tool=tool) - - def _on_fill_checkbutton_toggled(self, checkbutton, tool): - logging.debug('Checkbutton is Active: %s', checkbutton.get_active()) - - #self._activity.area.fill = checkbutton.get_active() - tool['fill'] = checkbutton.get_active() - self.set_tool(tool=tool) - - def _on_keep_aspect_checkbutton_toggled(self, checkbutton, tool): - self._activity.area.keep_shape_ratio[tool['name']] = \ - checkbutton.get_active() - self.set_tool(tool=tool) - - def _configure_palette_shape_ellipse(self): - logging.debug('Creating palette to shape ellipse') - self._create_simple_palette(self._shape_ellipse, self._SHAPE_ELLIPSE) - - def _configure_palette_shape_rectangle(self): - logging.debug('Creating palette to shape rectangle') - self._create_simple_palette(self._shape_rectangle, - self._SHAPE_RECTANGLE) - - def _configure_palette_shape_polygon(self): - logging.debug('Creating palette to shape polygon') - - # Enable 'Size' and 'Fill' option - self._create_simple_palette(self._shape_polygon, self._SHAPE_POLYGON) - - # We want choose the number of sides to our polygon - palette = self._shape_polygon.get_palette() - - spin = gtk.SpinButton() - - # This is where we set restrictions for sides in Regular Polygon: - # Initial value, minimum value, maximum value, step - adj = gtk.Adjustment(self._SHAPE_POLYGON['vertices'], 3.0, 50.0, 1.0) - spin.set_adjustment(adj) - spin.set_numeric(True) - - label = gtk.Label(_('Sides: ')) - - hbox = gtk.HBox() - hbox.show_all() - hbox.pack_start(label) - hbox.pack_start(spin) - - palette.content_box.pack_start(hbox) - hbox.show_all() - spin.connect('value-changed', self._on_vertices_value_changed, - self._SHAPE_POLYGON) - - def _configure_palette_shape_heart(self): - logging.debug('Creating palette to shape heart') - self._create_simple_palette(self._shape_heart, self._SHAPE_HEART) - - def _configure_palette_shape_parallelogram(self): - logging.debug('Creating palette to shape parallelogram') - self._create_simple_palette(self._shape_parallelogram, - self._SHAPE_PARALLELOGRAM) - - def _configure_palette_shape_arrow(self): - logging.debug('Creating palette to shape arrow') - self._create_simple_palette(self._shape_arrow, self._SHAPE_ARROW) - - def _configure_palette_shape_star(self): - logging.debug('Creating palette to shape star') - - # Enable 'Size' and 'Fill' option - self._create_simple_palette(self._shape_star, self._SHAPE_STAR) - - # We want choose the number of sides to our star - palette = self._shape_star.get_palette() - - spin = gtk.SpinButton() - - # This is where we set restrictions for Star: - # Initial value, minimum value, maximum value, step - adj = gtk.Adjustment(self._SHAPE_STAR['vertices'], 3.0, 50.0, 1.0) - spin.set_adjustment(adj) - spin.set_numeric(True) - - label = gtk.Label(_('Points: ')) - - hbox = gtk.HBox() - hbox.show_all() - hbox.pack_start(label) - hbox.pack_start(spin) - - # changing layout due to problems with palette's action_bar - palette.content_box.pack_start(hbox) - hbox.show_all() - spin.connect('value-changed', self._on_vertices_value_changed, - self._SHAPE_STAR) - - def _configure_palette_shape_trapezoid(self): - logging.debug('Creating palette to shape trapezoid') - self._create_simple_palette(self._shape_trapezoid, - self._SHAPE_TRAPEZOID) - - def _configure_palette_shape_triangle(self): - logging.debug('Creating palette to shape triangle') - self._create_simple_palette(self._shape_triangle, - self._SHAPE_TRIANGLE) - - def _create_simple_palette(self, button, tool, line_size_only=False): - """ - Create a simple palette with an CheckButton named "Fill" and - a SpinButton to represent the line size. Most tools use only this. - @param self -- toolbox.ShapesToolbar - @param button -- a ToolButton to associate the palette. - @param tool -- a dictionnary describing tool's properties. - @param line_size_only -- indicates if palette should only display - Line Size option. Default value is False. - """ - palette = button.get_palette() - palette.content_box = gtk.VBox() - palette.set_content(palette.content_box) - - # Fill option - if not line_size_only: - fill_checkbutton = gtk.CheckButton(_('Fill')) - fill_checkbutton.set_active(tool['fill']) - fill_checkbutton.connect('toggled', - self._on_fill_checkbutton_toggled, tool) - palette.content_box.pack_start(fill_checkbutton) - - size_spinbutton = gtk.SpinButton() - - # This is where we set restrictions for size: - # Initial value, minimum value, maximum value, step - adj = gtk.Adjustment(tool['line size'], 1.0, 100.0, 1.0) - size_spinbutton.set_adjustment(adj) - - size_spinbutton.set_numeric(True) - - label = gtk.Label(_('Size: ')) - - hbox = gtk.HBox() - hbox.pack_start(label) - hbox.pack_start(size_spinbutton) - - # Creating a public content box - # palette's action_bar should pack only buttons; changing layout - - palette.content_box.pack_start(hbox) - - size_spinbutton.connect('value-changed', - self._on_line_size_value_changed, tool) - - if tool['name'] in ['rectangle', 'ellipse', 'line']: - keep_aspect_checkbutton = gtk.CheckButton(_('Keep Aspect')) - ratio = self._activity.area.keep_shape_ratio[tool['name']] - keep_aspect_checkbutton.set_active(ratio) - keep_aspect_checkbutton.connect('toggled', - self._on_keep_aspect_checkbutton_toggled, tool) - palette.content_box.pack_start(keep_aspect_checkbutton) - - palette.content_box.show_all() - - def _configure_palette_shape_line(self): - logging.debug('Creating palette to shape line') - self._create_simple_palette(self._shape_line, self._SHAPE_LINE, True) - ##Make the Text Toolbar class TextToolbar(gtk.Toolbar): @@ -1089,26 +739,12 @@ class TextToolbar(gtk.Toolbar): ##Make the Images Toolbar class ImageToolbar(gtk.Toolbar): - _OBJECT_HEIGHT = 'height' - _OBJECT_INSERT = 'insert' - _OBJECT_ROTATE_LEFT = 'rotate-left' - _OBJECT_ROTATE_RIGHT = 'rotate-right' - _OBJECT_WIDTH = 'width' - - _EFFECT_GRAYSCALE = 'grayscale' - _INVERT_COLOR = 'invert-colors' - # Rainbow acts as a tool in Area, and it has to be described as a dict - _EFFECT_RAINBOW = {'name': 'rainbow', - 'line size': 10, - 'fill color': None, - 'stroke color': None, - 'line shape': 'circle', - 'fill': True, - 'vertices': None} + _EFFECT_RAINBOW_NAME = 'rainbow' def __init__(self, activity): gtk.Toolbar.__init__(self) self._activity = activity + self.properties = self._activity.area.tool self._object_insert = ToolButton('insert-picture') self.insert(self._object_insert, -1) @@ -1176,7 +812,6 @@ class ImageToolbar(gtk.Toolbar): self._effect_rainbow = DrawToolButton('effect-rainbow', activity.tool_group, _('Rainbow')) self.insert(self._effect_rainbow, -1) - self._configure_palette(self._effect_rainbow, self._EFFECT_RAINBOW) self._invert_colors = ToolButton('invert-colors') self.insert(self._invert_colors, -1) @@ -1317,83 +952,7 @@ class ImageToolbar(gtk.Toolbar): ##Like the brush, but change it color when painting def rainbow(self, widget): - self._activity.area.set_tool(self._EFFECT_RAINBOW) + self.properties['name'] = self._EFFECT_RAINBOW_NAME def invert_colors(self, widget): self._activity.area.invert_colors(widget) - - def _configure_palette(self, button, tool=None): - """Set palette for a tool - @param self -- toolbox.EffectsToolbar - @param widget - the ToolButton which Palette will be set - @param tool -- a dictionnary describing tool's properties. - """ - - logging.debug('setting a palette for %s', tool) - - palette = button.get_palette() - - if tool is None: - return - elif tool is self._EFFECT_RAINBOW: - # We can adjust 'Line Size' and 'Line Shape' here - - # Line Size - size_spinbutton = gtk.SpinButton() - - # This is where we set restrictions for Rainbow: - # Initial value, minimum value, maximum value, step - adj = gtk.Adjustment(tool['line size'], 1.0, 100.0, 1.0) - size_spinbutton.set_adjustment(adj) - - size_spinbutton.set_numeric(True) - - label = gtk.Label(_('Size: ')) - - hbox = gtk.HBox() - hbox.pack_start(label) - hbox.pack_start(size_spinbutton) - - vbox = gtk.VBox() - vbox.pack_start(hbox) - - size_spinbutton.connect('value-changed', - self._on_size_value_changed, tool) - - # Line Shape - item1 = gtk.RadioButton(None, _('Circle')) - item1.set_active(True) - - image1 = gtk.Image() - image1.set_from_file('./icons/tool-shape-ellipse.svg') - item1.set_image(image1) - - item2 = gtk.RadioButton(item1, _('Square')) - - image2 = gtk.Image() - image2.set_from_file('./icons/tool-shape-rectangle.svg') - item2.set_image(image2) - - item1.connect('toggled', self._on_radio_toggled, tool, 'circle') - item2.connect('toggled', self._on_radio_toggled, tool, 'square') - - label = gtk.Label(_('Shape')) - - vbox.pack_start(label) - vbox.pack_start(item1) - vbox.pack_start(item2) - vbox.show_all() - - palette.set_content(vbox) - - def _on_size_value_changed(self, spinbutton, tool): -# size = spinbutton.get_value_as_int() -# self._activity.area.configure_line(size) - - tool['line size'] = spinbutton.get_value_as_int() - self.rainbow(self._effect_rainbow) - - def _on_radio_toggled(self, radiobutton, tool, shape): - if radiobutton.get_active(): - tool['line shape'] = shape - self.rainbow(self._effect_rainbow) -- cgit v0.9.1