Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Antonino Gonçalves Martinazzo <alexandremartinazzo@gmail.com>2007-08-06 18:14:02 (GMT)
committer Alexandre Antonino Gonçalves Martinazzo <alexandremartinazzo@gmail.com>2007-08-06 18:14:02 (GMT)
commite28ee58054e4248ac916b2f1d4a4bfe557d45f16 (patch)
tree460e8217db097bfeb39ab99b818d8f1e4d67e1ca
parent61b8778e4abdbece8de2225ed2190bd1bbe94b45 (diff)
New signals added in Area.py: undo & redo
-rw-r--r--Area.py108
-rw-r--r--[-rwxr-xr-x]NEWS0
-rw-r--r--OficinaActivity.py22
-rw-r--r--[-rwxr-xr-x]locale/de/LC_MESSAGES/drawing.mobin2036 -> 2036 bytes
-rw-r--r--[-rwxr-xr-x]locale/es/LC_MESSAGES/drawing.mobin2057 -> 2057 bytes
-rw-r--r--[-rwxr-xr-x]locale/pt_BR/LC_MESSAGES/drawing.mobin2050 -> 2050 bytes
-rw-r--r--toolbox.py23
7 files changed, 119 insertions, 34 deletions
diff --git a/Area.py b/Area.py
index f42da06..879ca13 100644
--- a/Area.py
+++ b/Area.py
@@ -53,11 +53,11 @@ Roseli de Deus Lopes (roseli@lsi.usp.br)
"""
-import pygtk
-pygtk.require('2.0')
-import gtk
-import sys, gobject, socket
-from gtk import gdk
+# import pygtk
+# pygtk.require('2.0')
+import gtk, gobject, logging
+# import sys, socket
+# from gtk import gdk
import math
import pango
from fill import *
@@ -68,6 +68,15 @@ WIDTH = 800
HEIGHT = 600
class Area(gtk.DrawingArea):
+
+ __gsignals__ = {
+ 'undo' : (gobject.SIGNAL_ACTION, gobject.TYPE_NONE, ([])),
+ 'redo' : (gobject.SIGNAL_ACTION, gobject.TYPE_NONE, ([])),
+ #TODO: these signals still not used.
+# 'copy' : (gobject.SIGNAL_ACTION, gobject.TYPE_NONE, ([])),
+# 'selected' : (gobject.SIGNAL_ACTION, gobject.TYPE_NONE, ([])),
+ }
+
def __init__(self, janela):
""" Initialize the object from class Area which is derived from gtk.DrawingArea.
@@ -76,6 +85,8 @@ class Area(gtk.DrawingArea):
janela -- the parent window
"""
+ logging.debug('Area.__init__(self, janela)')
+
gtk.DrawingArea.__init__(self)
self.set_size_request(WIDTH, HEIGHT)
self.set_events(gtk.gdk.POINTER_MOTION_MASK |
@@ -123,8 +134,6 @@ class Area(gtk.DrawingArea):
self.eraser_shape = 'circle'
self.font = pango.FontDescription('Sans 9')
- #self.mensagem = Mensagens(self)
- #self.mensagem.criaConexao()
#start of UNDO and REDO
self.first_undo = True
@@ -144,6 +153,8 @@ class Area(gtk.DrawingArea):
event -- GdkEvent
"""
+ logging.debug('Area.configure_event(self, widget, event)')
+
win = widget.window
width = win.get_geometry()[2]
height = win.get_geometry()[3]
@@ -176,9 +187,13 @@ class Area(gtk.DrawingArea):
self.gc_selection1 = widget.window.new_gc() #this make another white line out of the black line
self.gc_selection1.set_line_attributes(1, gtk.gdk.LINE_ON_OFF_DASH, gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)
self.gc_selection1.set_foreground(white)
- print 'configure event'
+
self.enableUndo(widget)
+ # forcing self.undo_times to zero; self.enableUndo() increases it
+ # wrongly at this point... bad hacking, I know.
+ #self.undo_times = 0
+ #self.emit('undo')
return True
@@ -191,6 +206,8 @@ class Area(gtk.DrawingArea):
size --
"""
+ #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)
@@ -202,7 +219,9 @@ class Area(gtk.DrawingArea):
widget -- the Area object (GtkDrawingArea)
event -- GdkEvent
- """
+ """
+ #logging.debug('Area.expose(self, widget, event)')
+
area = event.area
if self.desenha:
if self.selmove :
@@ -434,6 +453,8 @@ class Area(gtk.DrawingArea):
self -- the Area object (GtkDrawingArea)
"""
+ logging.debug('Area.undo(self)')
+
if self.first_undo:#if is the first time you click on UNDO
self.undo_times -= 1
@@ -459,7 +480,16 @@ class Area(gtk.DrawingArea):
if self.tool == 'polygon':
self.polygon_start = True #start the polygon again
-
+ # emits 'undo' and 'redo' signals only in case of first action,
+ # (first undo or first redo) or no actions available
+ # FIXME: this way, things work strangely; emiting signals everytime
+# if self.undo_times <= 1:
+# self.emit('undo')
+# if self.redo_times <= 1:
+# self.emit('redo')
+ self.emit('undo')
+ self.emit('redo')
+
def redo(self):
"""Redo the last undo operation.
@@ -467,6 +497,8 @@ class Area(gtk.DrawingArea):
self -- the Area object (GtkDrawingArea)
"""
+ logging.debug('Area.redo(self)')
+
#print "REDO no.%d" %(self.redo_times)
if (self.redo_times>0):
self.redo_times -= 1
@@ -479,7 +511,16 @@ class Area(gtk.DrawingArea):
print "Can't draw"
self.undo_times-=1
self.queue_draw()
-
+
+ # emits 'undo' and 'redo' signals only in case of first action,
+ # (first undo or first redo) or no actions available
+ # FIXME: this way, things work strangely; emiting signals everytime
+# if self.undo_times <= 1:
+# self.emit('undo')
+# if self.redo_times <= 1:
+# self.emit('redo')
+ self.emit('undo')
+ self.emit('redo')
def enableUndo(self,widget):
"""Keep the last change in a list for Undo/Redo commands.
@@ -489,6 +530,8 @@ class Area(gtk.DrawingArea):
widget -- the Area object (GtkDrawingArea)
"""
+ logging.debug('Area.enableUndo(self,widget)')
+
if self.undo_surf:
self.undo_times += 1
@@ -506,9 +549,22 @@ class Area(gtk.DrawingArea):
self.undo_times-=1
#print "estourou"
+ # emits 'undo' and 'redo' signals only in case of first action,
+ # (first undo or first redo) or no actions available
+ # FIXME: this way, things work strangely; emiting signals everytime
+# if self.undo_times <= 1:
+# self.emit('undo')
+# if self.redo_times <= 1:
+# self.emit('redo')
+ self.emit('undo')
+ self.emit('redo')
+
+
def copy(self):
""" Copy Image.
When the tool selection is working make the change the copy of selectioned area"""
+ logging.debug('Area.copy(self)')
+
if self.selmove:
if self.sx > self.oldx:
@@ -538,6 +594,8 @@ class Area(gtk.DrawingArea):
def past(self):
""" Past image.
Past image that is in pixmap_copy"""
+ logging.debug('Area.past(self)')
+
if self.pixmap_copy != None :
@@ -570,6 +628,8 @@ class Area(gtk.DrawingArea):
color -- a gdk.Color object
"""
+ logging.debug('Area._set_fill_color(self, color)')
+
self.gc.set_foreground(color)
@@ -581,6 +641,7 @@ class Area(gtk.DrawingArea):
color -- a gdk.Color object
"""
+ logging.debug('Area._set_stroke_color(self, 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)
@@ -594,6 +655,8 @@ class Area(gtk.DrawingArea):
self -- the Area object (GtkDrawingArea)
"""
+ logging.debug('Area._set_grayscale(self,widget)')
+
pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, WIDTH, HEIGHT)
pix_ = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, WIDTH, HEIGHT)
pix.get_from_drawable(self.pixmap, gtk.gdk.colormap_get_system(), 0, 0, 0, 0, WIDTH, HEIGHT)
@@ -612,6 +675,8 @@ class Area(gtk.DrawingArea):
self -- the Area object (GtkDrawingArea)
"""
+ logging.debug('Area._rotate_left(self)')
+
pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, WIDTH, HEIGHT)
pix_ = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, WIDTH, HEIGHT)
pix.get_from_drawable(self.pixmap, gtk.gdk.colormap_get_system(), 0, 0, 0, 0, -1, -1)
@@ -619,4 +684,25 @@ class Area(gtk.DrawingArea):
self.pixmap.draw_pixbuf(self.gc, pix_, 0, 0, 0, 0, width=-1, height=-1, dither=gtk.gdk.RGB_DITHER_NORMAL, x_dither=0, y_dither=0)
self.queue_draw()
+ def can_undo(self):
+ '''
+ Indicate if is there some action to undo
+ '''
+ logging.debug('Area.can_undo(self)')
+
+ if self.undo_times < 1:
+ return False
+ else:
+ return True
+
+ def can_redo(self):
+ '''
+ Indicate if is there some action to redo
+ '''
+ logging.debug('Area.can_redo(self)')
+
+ if self.redo_times < 1:
+ return False
+ else:
+ return True
diff --git a/NEWS b/NEWS
index b313d58..b313d58 100755..100644
--- a/NEWS
+++ b/NEWS
diff --git a/OficinaActivity.py b/OficinaActivity.py
index a75810b..4169554 100644
--- a/OficinaActivity.py
+++ b/OficinaActivity.py
@@ -60,7 +60,6 @@ import gtk
from sugar.activity import activity
-#from Oficina import Oficina
from toolbox import Toolbox
from Area import Area
import logging
@@ -81,17 +80,18 @@ class OficinaActivity(activity.Activity):
os.chdir(activity.get_bundle_path())
#print activity.get_bundle_path()
+ self._fixed = gtk.Fixed()
+ self._area = Area(self)
+
toolbox = Toolbox(self)
self.set_toolbox(toolbox)
toolbox.show()
- # addind a textview widget
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self._fixed = gtk.Fixed()
- self._area = Area(self)
+
color = gtk.gdk.color_parse("white")
self._fixed.modify_bg(gtk.STATE_NORMAL, color)
@@ -126,16 +126,14 @@ class OficinaActivity(activity.Activity):
file_path --
'''
- logging.debug('reading file')
- logging.debug(file_path)
+ logging.debug('reading file %s', file_path)
+# 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
+# self._area.undo_times = 1
+# self._area.redo_times = 0
def write_file(self, file_path):
@@ -145,8 +143,8 @@ class OficinaActivity(activity.Activity):
file_path --
'''
- logging.debug('writting file')
- logging.debug(file_path)
+ logging.debug('saving as PNG')
+ logging.debug('writting file %s', file_path)
width, height = self._area.window.get_size()
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
diff --git a/locale/de/LC_MESSAGES/drawing.mo b/locale/de/LC_MESSAGES/drawing.mo
index c57437d..c57437d 100755..100644
--- a/locale/de/LC_MESSAGES/drawing.mo
+++ b/locale/de/LC_MESSAGES/drawing.mo
Binary files differ
diff --git a/locale/es/LC_MESSAGES/drawing.mo b/locale/es/LC_MESSAGES/drawing.mo
index 9c6a1d7..9c6a1d7 100755..100644
--- a/locale/es/LC_MESSAGES/drawing.mo
+++ b/locale/es/LC_MESSAGES/drawing.mo
Binary files differ
diff --git a/locale/pt_BR/LC_MESSAGES/drawing.mo b/locale/pt_BR/LC_MESSAGES/drawing.mo
index 251bcbc..251bcbc 100755..100644
--- a/locale/pt_BR/LC_MESSAGES/drawing.mo
+++ b/locale/pt_BR/LC_MESSAGES/drawing.mo
Binary files differ
diff --git a/toolbox.py b/toolbox.py
index 7698185..aae342a 100644
--- a/toolbox.py
+++ b/toolbox.py
@@ -57,7 +57,6 @@ from gettext import gettext as _
import gtk, logging
from sugar.activity.activity import ActivityToolbox, EditToolbar
-from sugar.graphics import color
from sugar.graphics.toolcombobox import ToolComboBox
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.toggletoolbutton import ToggleToolButton
@@ -105,18 +104,14 @@ class DrawEditToolbar(EditToolbar):
self._activity = activity
-# self.undo.connect('clicked', undo, activity)
-# self.redo.connect('clicked', redo, activity)
self.undo.connect('clicked', self._undo_cb)
self.redo.connect('clicked', self._redo_cb)
-# self.copy.connect('clicked', test_connect, activity, 'copy')
-# self.paste.connect('clicked', test_connect, activity, 'paste')
self.copy.connect('clicked', self._copy_cb)
self.paste.connect('clicked', self._paste_cb)
-
-# self.copy.hide()
-# self.paste.hide()
+
+ self._activity._area.connect('undo', self._enable_undo_button_cb)
+ self._activity._area.connect('redo', self._enable_redo_button_cb)
def _undo_cb(self, widget, data=None):
self._activity._area.undo()
@@ -129,7 +124,13 @@ class DrawEditToolbar(EditToolbar):
def _paste_cb(self, widget, data=None):
self._activity._area.past()
-
+
+ def _enable_undo_button_cb(self, widget, data=None):
+ self.undo.set_sensitive( self._activity._area.can_undo() )
+
+ def _enable_redo_button_cb(self, widget, data=None):
+ self.redo.set_sensitive( self._activity._area.can_redo() )
+
class ToolsToolbar(gtk.Toolbar):
@@ -198,14 +199,14 @@ class ToolsToolbar(gtk.Toolbar):
self.insert(self._tool_brush, -1)
self._tool_brush.show()
#self._tool_brush.set_tooltip(_('Brush'))
- self._brush_palette = self.create_palette('Brush')
+ self._brush_palette = self.create_palette(_('Brush'))
self._tool_brush.set_palette(self._brush_palette)
self._tool_eraser = ToolButton('tool-eraser')
self.insert(self._tool_eraser, -1)
self._tool_eraser.show()
#self._tool_eraser.set_tooltip(_('Eraser'))
- self._eraser_palette = self.create_palette('Eraser')
+ self._eraser_palette = self.create_palette(_('Eraser'))
self._tool_eraser.set_palette(self._eraser_palette)
self._tool_polygon = ToolButton('tool-polygon')