From 05e9648640120a7523aee558bd730fb938ac381d Mon Sep 17 00:00:00 2001 From: Alexandre Antonino Gonçalves Martinazzo Date: Fri, 27 Jul 2007 19:34:50 +0000 Subject: Colors now are choosen from a ColorButton --- diff --git a/Area.py b/Area.py index e10b6c1..7a5fced 100644 --- a/Area.py +++ b/Area.py @@ -567,8 +567,6 @@ class Area(gtk.DrawingArea): color -- a gdk.Color object """ - #self.color_ = color - #self.gc.set_foreground(self.cores[color]) self.gc.set_foreground(color) @@ -580,15 +578,7 @@ class Area(gtk.DrawingArea): color -- a gdk.Color object """ - ''' - self.color_line = color - self.gc_line.set_foreground(self.cores[color]) - 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(self.cores[color]) - self.color_dec = self.cores[color].pixel - ''' - #self.color_line = color self.gc_line.set_foreground(color) 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) diff --git a/Desenho.py b/Desenho.py index 146ef26..fe468fc 100644 --- a/Desenho.py +++ b/Desenho.py @@ -381,7 +381,7 @@ class Desenho: self.d.newx_ = coords0 - self.d.oldx self.d.newy_ = coords1 - self.d.oldy - print "coords0", coords0 + #print "coords0", coords0 if self.d.newx_ >= 0: self.d.newx = self.d.oldx diff --git a/OficinaActivity.py b/OficinaActivity.py index b308b04..a75810b 100644 --- a/OficinaActivity.py +++ b/OficinaActivity.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -Desenho.py +OficinaActivity.py Create Oficina Activity @@ -63,9 +63,7 @@ from sugar.activity import activity #from Oficina import Oficina from toolbox import Toolbox from Area import Area - -# DRAW_WIDTH = 1195 -# DRAW_HEIGHT = 800 +import logging class OficinaActivity(activity.Activity): def __init__(self, handle): @@ -77,6 +75,8 @@ class OficinaActivity(activity.Activity): """ activity.Activity.__init__(self, handle) + + logging.debug('Starting Paint activity (Oficina)') os.chdir(activity.get_bundle_path()) #print activity.get_bundle_path() @@ -90,17 +90,17 @@ class OficinaActivity(activity.Activity): sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - self._fixed = gtk.Fixed() - self._area = Area(self) + self._fixed = gtk.Fixed() + self._area = Area(self) color = gtk.gdk.color_parse("white") self._fixed.modify_bg(gtk.STATE_NORMAL, color) - self.bg = gtk.Image() - self.bg.set_from_file('./icons/bg.svg') - self._fixed.put(self.bg, 200, 100) + self.bg = gtk.Image() + self.bg.set_from_file('./icons/bg.svg') + self._fixed.put(self.bg, 200, 100) self.bg.show() - #FIXME: use a textview instead of a Entry + #FIXME: use a textview instead of an Entry #self._textview = gtk.TextView() self._textview = gtk.Entry() self._area.tool = 2 @@ -123,14 +123,17 @@ class OficinaActivity(activity.Activity): '''Read file from Sugar Journal. self -- - file_path -- + file_path -- ''' - print 'read file...' - print file_path + logging.debug('reading file') + logging.debug(file_path) + #self._area.d.limpatudo() #self._area.d.clear() self._area.d.loadImage(file_path, self._area) + + # Does this work? self._area.undo_times = 1 self._area.redo_times = 0 @@ -138,13 +141,15 @@ class OficinaActivity(activity.Activity): def write_file(self, file_path): '''Save file on Sugar Journal. - self -- - file_path -- + self -- + file_path -- ''' - print file_path + logging.debug('writting file') + logging.debug(file_path) + width, height = self._area.window.get_size() pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height) pixbuf.get_from_drawable(self._area.pixmap, gtk.gdk.colormap_get_system(), 0, 0, 0, 0, -1, -1) - pixbuf.save(file_path, 'png', {}) + pixbuf.save(file_path, 'png', {}) diff --git a/toolbox.py b/toolbox.py index 9d28390..7698185 100644 --- a/toolbox.py +++ b/toolbox.py @@ -54,7 +54,7 @@ Roseli de Deus Lopes (roseli@lsi.usp.br) from gettext import gettext as _ -import gtk +import gtk, logging from sugar.activity.activity import ActivityToolbox, EditToolbar from sugar.graphics import color @@ -164,11 +164,22 @@ class ToolsToolbar(gtk.Toolbar): self._icon_stroke = ToolButton('icon-stroke') self.insert(self._icon_stroke, -1) self._icon_stroke.show() - + + # Changing widget: using toolbox.ButtonStrokeColor instead of toolbox.ComboStrokeColors + ''' self._stroke_color = ComboStrokeColors(activity) self.insert(self._stroke_color, -1) self._stroke_color.show() - + ''' + self._stroke_color = ButtonStrokeColor(activity) + self._stroke_color.show() +# self._stroke_color.set_tooltip(_('Stroke Color')) + item = gtk.ToolItem() + item.add(self._stroke_color) + self.insert(item, -1) + item.show() + + self._stroke_size = ComboStrokeSize(activity) self.insert(self._stroke_size, -1) self._stroke_size.show() @@ -231,18 +242,6 @@ class ToolsToolbar(gtk.Toolbar): self._tool_marquee_rectangular.show() self._tool_marquee_rectangular.set_tooltip(_('Rectangular Marquee')) - ''' - self._tool_polygon.connect('clicked', set_tool, activity, 'tool-polygon', self._TOOL_POLYGON) - self._tool_pencil.connect('clicked', set_tool, activity, 'tool-pencil', self._TOOL_PENCIL) - self._tool_brush.connect('clicked', set_tool, activity, 'tool-brush', self._TOOL_BRUSH) - self._tool_eraser.connect('clicked', set_tool, activity, 'tool-eraser', self._TOOL_ERASER) - self._tool_bucket.connect('clicked', set_tool, activity, 'tool-bucket', self._TOOL_BUCKET) - #self._tool_marquee_elliptical.connect('clicked', set_tool, activity, 'tool-marquee-elliptical', self._TOOL_MARQUEE_ELLIPTICAL) - #self._tool_marquee_freeform.connect('clicked', set_tool, activity, 'tool-marquee-freeform', self._TOOL_MARQUEE_FREEFORM) - self._tool_marquee_rectangular.connect('clicked', set_tool, activity, 'tool-marquee-rectangular', self._TOOL_MARQUEE_RECTANGULAR) - #self._tool_marquee_smart.connect('clicked', set_tool, activity, 'tool-marquee-smart', self._TOOL_MARQUEE_SMART) - ''' - # New connect method self._tool_polygon.connect('clicked', self.set_tool, self._TOOL_POLYGON) self._tool_pencil.connect('clicked', self.set_tool, self._TOOL_PENCIL) @@ -306,6 +305,16 @@ class ToolsToolbar(gtk.Toolbar): cursor = None self._activity._area.window.set_cursor(cursor) + +# def _color_button_cb(self, widget): +# newcolor = self._color_button.get_color() +# # colormap = gtk.gdk.colormap_get_system() +# colormap = self._activity._area.get_colormap() +# +# color = colormap.alloc_color(newcolor.red, newcolor.green, newcolor.blue) +# self._activity._area._set_stroke_color(color) + + class ComboFillColors(ToolComboBox): """Class to manage Fill colors """ @@ -506,6 +515,49 @@ class ComboStrokeSize(ToolComboBox): active = self.combo.get_active() return model[active][0] + +class ButtonFillColor(gtk.ColorButton): + + def __init__(self, activity): + gtk.ColorButton.__init__(self) + self._activity = activity + + self.connect('color-set', self._color_button_cb) + + def _color_button_cb(self, widget): + 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(gtk.ColorButton): + + def __init__(self, activity): + gtk.ColorButton.__init__(self) + self._activity = activity + + self.connect('color-set', self._color_button_cb) + + def _color_button_cb(self, widget): + 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 ShapesToolbar(gtk.Toolbar): _TOOL_SHAPE_ARROW = 'arrow' @@ -530,23 +582,43 @@ class ShapesToolbar(gtk.Toolbar): self.insert(self._icon_fill, -1) self._icon_fill.show() + # Changing widget: using toolbox.ButtonFillColor instead of toolbox.ComboFillColors + ''' self._fill_color = ComboFillColors(activity) self.insert(self._fill_color, -1) self._fill_color.show() - + ''' + self._fill_color = ButtonFillColor(activity) + self._fill_color.show() + item = gtk.ToolItem() + item.add(self._fill_color) + self.insert(item, -1) + item.show() + self._icon_stroke = ToolButton('icon-stroke') self.insert(self._icon_stroke, -1) self._icon_stroke.show() - + + # Changing widget: using toolbox.ButtonStrokeColor instead of toolbox.ComboStrokeColors + ''' self._stroke_color = ComboStrokeColors(activity) self.insert(self._stroke_color, -1) self._stroke_color.show() - + ''' + self._stroke_color = ButtonStrokeColor(activity) + self._stroke_color.show() + item = gtk.ToolItem() + item.add(self._stroke_color) + self.insert(item, -1) + item.show() + + self._stroke_size = ComboStrokeSize(activity) self.insert(self._stroke_size, -1) self._stroke_size.show() separator = gtk.SeparatorToolItem() + separator.set_draw(True) self.insert(separator, -1) separator.show() @@ -667,12 +739,24 @@ class TextToolbar(gtk.Toolbar): self._activity = activity - self._text = ToggleToolButton('text') + self._text = ToolButton('text') self.insert(self._text, -1) self._text.show() self._text.set_tooltip(_('Type')) self._text.connect('clicked', self.set_tool, self._ACTION_TEXT) + separator = gtk.SeparatorToolItem() + separator.set_draw(True) + self.insert(separator, -1) + separator.show() + + self._text_color = ButtonFillColor(activity) + self._text_color.show() + item = gtk.ToolItem() + item.add(self._text_color) + self.insert(item, -1) + item.show() + """ #FIXME: this button is not connected to the right callback self._bold = ToggleToolButton('format-text-bold') @@ -705,14 +789,17 @@ class TextToolbar(gtk.Toolbar): self._text_color.show() """ - def type_text(self, activity): - set_tool(self._ACTION_TEXT, activity, 'text') - activity._textview.show() - def set_tool(self, widget, tool): #FIXME: this callback must change as others buttons get enabled self._activity._area.tool = tool + color = self._text_color.get_color() + self._text_color.set_fill_color(color) + + # setting cursor + pixbuf = gtk.gdk.pixbuf_new_from_file('./images/text.png') + cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pixbuf, 6, 21) + self._activity._area.window.set_cursor(cursor) class ImageToolbar(gtk.Toolbar): @@ -772,21 +859,26 @@ class ImageToolbar(gtk.Toolbar): def insertImage(self, widget, activity): + # TODO: add a filter to display images only. dialog = gtk.FileChooserDialog(title=(_('Open File...')), action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) - dialog.show_all() + dialog.show_all() + + logging.debug('Importing image from file') response = dialog.run() + if response == gtk.RESPONSE_OK: - print dialog.get_filename(), 'selected' - #gtk28 = False file_path = dialog.get_filename() + logging.debug('file selected') + logging.debug(file_path) #file_path = decode_path((file_path,))[0] #open(activity, file_path) activity._area.d.loadImage(file_path,widget) elif response == gtk.RESPONSE_CANCEL: - print 'Closed, no files selected' + logging.debug('Closed, no files selected') + dialog.destroy() @@ -805,11 +897,10 @@ class EffectsToolbar(gtk.Toolbar): self._effect_grayscale = ToolButton('effect-grayscale') self.insert(self._effect_grayscale, -1) self._effect_grayscale.show() - self._effect_grayscale.connect('clicked', test_connect, activity, 'effect-grayscale') self._effect_grayscale.set_tooltip(_('Grayscale')) """ - #FIXME: Must be implemented + #FIXME: Must be implemented self._black_and_white = ToolButton('black_and_white') self.insert(self._black_and_white, -1) self._black_and_white.show() @@ -873,130 +964,15 @@ class ViewToolbar(gtk.Toolbar): self._zoom_minus.show() self._zoom_minus.set_tooltip(_('ZOOM -')) + ''' + # FIXME: these callbacks are not implemented self._zoom_plus.connect('clicked', test_connect, activity, 'zoom_plus') self._zoom_minus.connect('clicked', test_connect, activity, 'zoom_minus') - + ''' + def _combo_changed_cb(self, combo): if combo == self._view_percent: print 'treeeter' -# def set_tool(widget, activity, data=None, tool=None): -# activity._area.tool = tool -# #setting cursor -# print data -# if data == 'tool-pencil': -# pix = gtk.gdk.pixbuf_new_from_file("./images/lapis_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# -# elif data == 'tool-eraser': -# pix = gtk.gdk.pixbuf_new_from_file("./images/borracha_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# -# elif data == 'tool-shape-ellipse': -# pix = gtk.gdk.pixbuf_new_from_file("./images/circulo_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# -# elif data == 'tool-shape-rectangle': -# pix = gtk.gdk.pixbuf_new_from_file("./images/quadrado_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# -# elif data == 'tool-marquee-rectangular': -# cursor = gtk.gdk.Cursor(gtk.gdk.CROSSHAIR) -# activity._area.move = False - -# elif data == 'text': -# pix = gtk.gdk.pixbuf_new_from_file("./images/letra_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# -# elif data == 'tool-shape-line': -# pix = gtk.gdk.pixbuf_new_from_file("./images/linha_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) - -# elif data == 'tool-brush': -# pix = gtk.gdk.pixbuf_new_from_file("./images/brush_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) - -# elif data == 'tool-bucket': -# pix = gtk.gdk.pixbuf_new_from_file("./images/bucket_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) - -# elif data == 'tool-polygon': -# pix = gtk.gdk.pixbuf_new_from_file("./images/poligono_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) - -# elif data == 'tool-shape-triangle': -# pix = gtk.gdk.pixbuf_new_from_file("./images/triangle_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) - -# elif data == 'tool-shape-trapezoid': -# pix = gtk.gdk.pixbuf_new_from_file("./images/trapezoid_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# -# elif data == 'tool-shape-star': -# pix = gtk.gdk.pixbuf_new_from_file("./images/star_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# -# elif data == 'tool-shape-heart': -# pix = gtk.gdk.pixbuf_new_from_file("./images/heart_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# -# elif data == 'tool-shape-parallelogram': -# pix = gtk.gdk.pixbuf_new_from_file("./images/parallelogram_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# -# elif data == 'tool-shape-arrow': -# pix = gtk.gdk.pixbuf_new_from_file("./images/arrow_cursor.png") -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) - -# else: -# # Uses toolbar icon as cursor -# #FIXME: invert cursor color. Toolbar icons are white -# try: -# archive = './icons/' + data + '.svg' -# pix = gtk.gdk.pixbuf_new_from_file(archive) -# print archive, pix -# cursor = gtk.gdk.Cursor(gtk.gdk.display_get_default() , pix, 6, 21) -# except: -# cursor = None - -# -# activity._area.window.set_cursor(cursor) -# #print cursor - - -#move to class ComboStrokeSize -#def set_stroke_size(activity, size): - #activity._area.configure_line(size) - -def undo(widget, activity): - activity._area.undo() - -def redo(widget, activity): - activity._area.redo() - -def test_connect(widget, activity, data=None): - ''' Dummy callback for testing''' - string = data + ' button clicked\n' - #activity.textview.get_buffer().insert_at_cursor(string) - -def insertImage(widget, activity): - dialog = gtk.FileChooserDialog(title=(_('Open File...')), - action=gtk.FILE_CHOOSER_ACTION_OPEN, - buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, - gtk.STOCK_OK, gtk.RESPONSE_OK)) - dialog.show_all() - response = dialog.run() - if response == gtk.RESPONSE_OK: - print dialog.get_filename(), 'selected' - #gtk28 = False - file_path = dialog.get_filename() - #file_path = decode_path((file_path,))[0] - #open(activity, file_path) - activity._area.d.loadImage(file_path) - elif response == gtk.RESPONSE_CANCEL: - print 'Closed, no files selected' - dialog.destroy() - - -- cgit v0.9.1