Thanks Manu,<br>I did a few comments in the ticket.<br><br>Gonzalo<br><br><div class="gmail_quote">2011/6/16 manuel quiñones <span dir="ltr"><<a href="mailto:manuel.por.aca@gmail.com">manuel.por.aca@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">This is for Paint activity, ticket #10771<br>
<br>
<a href="http://dev.laptop.org/ticket/10771" target="_blank">http://dev.laptop.org/ticket/10771</a><br>
<br>
I still have to learn git send-email :/<br>
<br>
Regards,<br>
<br>
El día 16 de junio de 2011 09:03, Manuel Quiñones <<a href="mailto:manuq@laptop.org">manuq@laptop.org</a>> escribió:<br>
<div><div></div><div class="h5">> ---<br>
> Area.py | 114 ++++++++++++++++++++++----------------------------------------<br>
> 1 files changed, 41 insertions(+), 73 deletions(-)<br>
><br>
> diff --git a/Area.py b/Area.py<br>
> index 5011fd3..71ef6aa 100644<br>
> --- a/Area.py<br>
> +++ b/Area.py<br>
> @@ -177,16 +177,9 @@ class Area(gtk.DrawingArea):<br>
><br>
> self._set_selection_bounds(0, 0, 0, 0)<br>
><br>
> - #start of UNDO and REDO<br>
> - ## This flag is used when is the first time you click on Undo<br>
> - self.first_undo = True<br>
> - ## When you are just clicking on undo or redo and not<br>
> - # drawing undo_surf is True<br>
> - self.undo_surf = False<br>
> - self.undo_times = 0<br>
> - self.redo_times = 0<br>
> - ##pixmaps list to Undo func<br>
> + # List of pixmaps for the Undo function:<br>
> self.undo_list = []<br>
> + self.undo_index = None<br>
><br>
> # variables to show the tool shape<br>
> self.drawing = False<br>
> @@ -197,6 +190,7 @@ class Area(gtk.DrawingArea):<br>
> """Configure the Area object."""<br>
><br>
> if self.pixmap:<br>
> + # Already set up<br>
> return<br>
><br>
> logging.debug('Area.setup: w=%s h=%s' % (width, height))<br>
> @@ -244,7 +238,7 @@ class Area(gtk.DrawingArea):<br>
> gtk.gdk.CAP_ROUND, gtk.gdk.JOIN_ROUND)<br>
> self.gc_selection1.set_foreground(self.white)<br>
><br>
> - self.enableUndo(self)<br>
> + self.enableUndo(self, size=(width, height))<br>
><br>
> # Setting a initial tool<br>
> self.set_tool(self.tool)<br>
> @@ -711,27 +705,15 @@ class Area(gtk.DrawingArea):<br>
> logging.debug('Area.undo(self)')<br>
> width, height = self.window.get_size()<br>
><br>
> - # if is the first time you click on UNDO<br>
> - # (because undo_list always wait for the NEXT image)<br>
> - if self.first_undo:<br>
> - self.undo_times -= 1<br>
> -<br>
> - #print "Undo no.%d" %(self.undo_times)<br>
> - if self.undo_times > 0:<br>
> - self.undo_times -= 1<br>
> - self.redo_times += 1<br>
> - try: # to not try paint someting wrong<br>
> - self.pixmap.draw_drawable(self.gc,<br>
> - self.undo_list[self.undo_times], 0, 0, 0, 0, width, height)<br>
> - except:<br>
> - logging.debug('Cant draw')<br>
> - pass<br>
> - self.queue_draw()<br>
> - else:<br>
> - self.undo_times = 0<br>
> + if self.undo_index == 0:<br>
> + # first undo:<br>
> + pass<br>
> + elif self.undo_index > 0:<br>
> + self.undo_index -= 1<br>
><br>
> - self.first_undo = False<br>
> - self.undo_surf = True<br>
> + undo_pix = self.undo_list[self.undo_index]<br>
> + self.pixmap.draw_drawable(self.gc, undo_pix, 0, 0, 0, 0, width, height)<br>
> + self.queue_draw()<br>
><br>
> #special case for func polygon<br>
> if self.tool['name'] == 'freeform':<br>
> @@ -747,50 +729,47 @@ class Area(gtk.DrawingArea):<br>
> logging.debug('Area.redo(self)')<br>
> width, height = self.window.get_size()<br>
><br>
> - #print "REDO no.%d" %(self.redo_times)<br>
> - if self.redo_times > 0:<br>
> - self.redo_times -= 1<br>
> - self.undo_times += 1<br>
> + if self.undo_index < len(self.undo_list)-1:<br>
> + self.undo_index += 1<br>
><br>
> - try: # to not try paint someting wrong<br>
> - self.pixmap.draw_drawable(self.gc,<br>
> - self.undo_list[self.undo_times], 0, 0, 0, 0,<br>
> - width, height)<br>
> - except:<br>
> - logging.debug('Cant draw')<br>
> - self.undo_times -= 1<br>
> + undo_pix = self.undo_list[self.undo_index]<br>
> + self.pixmap.draw_drawable(self.gc, undo_pix, 0, 0, 0, 0, width, height)<br>
> self.queue_draw()<br>
><br>
> self.emit('redo')<br>
><br>
> - def enableUndo(self, widget):<br>
> + def enableUndo(self, widget, size=None):<br>
> """Keep the last change in a list for Undo/Redo commands.<br>
><br>
> @param self -- the Area object (GtkDrawingArea)<br>
> @param widget -- the Area object (GtkDrawingArea)<br>
><br>
> """<br>
> - #logging.debug('Area.enableUndo(self,widget)')<br>
> + logging.debug('Area.enableUndo(self,widget)')<br>
><br>
> width, height = self.window.get_size()<br>
> -<br>
> - if self.undo_surf:<br>
> - self.undo_times += 1<br>
> -<br>
> - self.undo_list.append(None) # alloc memory<br>
> - self.undo_list[self.undo_times] = gtk.gdk.Pixmap(widget.window,<br>
> - width, height, -1) # define type<br>
> - self.undo_list[self.undo_times].draw_drawable(self.gc, self.pixmap,<br>
> - 0, 0, 0, 0, width, height) # copy workarea<br>
> - self.undo_times += 1<br>
> - self.redo_times = 0<br>
> - self.first_undo = True<br>
> - self.undo_surf = False<br>
> -<br>
> - #This is the part where we can limit the steps of undo/redo<br>
> - if self.undo_times == 12:<br>
> + # We need to pass explicitly the size on set up, because the<br>
> + # window size is not allocated yet.<br>
> + if size is not None:<br>
> + width, height = size<br>
> +<br>
> + if len(self.undo_list) == 0:<br>
> + # first_undo:<br>
> + self.undo_index = 0<br>
> + elif len(self.undo_list) == 12:<br>
> + #This is the part where we can limit the steps of<br>
> + #undo/redo:<br>
> self.undo_list.pop(0)<br>
> - self.undo_times -= 1<br>
> + else:<br>
> + self.undo_index += 1<br>
> + # Forget the redos after this one:<br>
> + self.undo_list = self.undo_list[:self.undo_index]<br>
> +<br>
> + undo_pix = gtk.gdk.Pixmap(widget.window, width, height, -1)<br>
> + undo_pix.draw_drawable(self.gc, self.pixmap,<br>
> + 0, 0, 0, 0, width, height)<br>
> +<br>
> + self.undo_list.append(undo_pix)<br>
><br>
> self.emit('action-saved')<br>
><br>
> @@ -1168,25 +1147,14 @@ class Area(gtk.DrawingArea):<br>
> Indicate if is there some action to undo<br>
> @param self -- the Area object (GtkDrawingArea)<br>
> """<br>
> - undo_times = self.undo_times<br>
> -<br>
> - if self.first_undo:<br>
> - undo_times -= 1<br>
> -<br>
> - if undo_times < 1:<br>
> - return False<br>
> - else:<br>
> - return True<br>
> + return self.undo_index > 0<br>
><br>
> def can_redo(self):<br>
> """<br>
> Indicate if is there some action to redo<br>
> @param self -- the Area object (GtkDrawingArea)<br>
> """<br>
> - if self.redo_times < 1:<br>
> - return False<br>
> - else:<br>
> - return True<br>
> + return self.undo_index < len(self.undo_list) - 1<br>
><br>
> def is_selected(self):<br>
> """<br>
> --<br>
> 1.7.4.4<br>
><br>
><br>
<br>
<br>
<br>
</div></div><font color="#888888">--<br>
.. manuq ..<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Sugar-devel mailing list<br>
<a href="mailto:Sugar-devel@lists.sugarlabs.org">Sugar-devel@lists.sugarlabs.org</a><br>
<a href="http://lists.sugarlabs.org/listinfo/sugar-devel" target="_blank">http://lists.sugarlabs.org/listinfo/sugar-devel</a><br>
</div></div></blockquote></div><br>