Ticket #3105: spin-undo-list-test.patch

File spin-undo-list-test.patch, 5.1 KB (added by humitos, 12 years ago)
  • Area.py

    diff --git a/Area.py b/Area.py
    index fa841df..b33e3b1 100644
    a b class Area(gtk.DrawingArea): 
    796796        logging.debug('Area.undo(self)')
    797797        width, height = self.window.get_size()
    798798
     799        logging.debug('self._undo_list: (%s) %s',
     800                      len(self._undo_list),
     801                      self._undo_list)
     802        logging.debug('self._undo_index: %s', self._undo_index)
     803
    799804        if self.selmove:
    800805            self.getout(undo=True)
    801806
    class Area(gtk.DrawingArea): 
    814819        if self.tool['name'] == 'freeform':
    815820                self.polygon_start = True  # start the polygon again
    816821
     822        logging.debug('self._undo_list: (%s) %s',
     823                      len(self._undo_list),
     824                      self._undo_list)
     825        logging.debug('self._undo_index: %s', self._undo_index)
     826
    817827        self.emit('undo')
    818828
    819829    def redo(self):
    class Area(gtk.DrawingArea): 
    824834        logging.debug('Area.redo(self)')
    825835        width, height = self.window.get_size()
    826836
     837        logging.debug('self._undo_list: (%s) %s',
     838                      len(self._undo_list),
     839                      self._undo_list)
     840        logging.debug('self._undo_index: %s', self._undo_index)
     841
    827842        if self.selmove:
    828843            self.getout()
    829844
    830845        if self._undo_index < len(self._undo_list) - 1:
     846        # if self._undo_index < MAX_UNDO_STEPS:
    831847            self._undo_index += 1
    832848
    833849        undo_pix = self._undo_list[self._undo_index]
    834850        self.pixmap.draw_drawable(self.gc, undo_pix, 0, 0, 0, 0, -1, -1)
    835851        self.queue_draw()
    836852
     853        logging.debug('self._undo_list: (%s) %s',
     854                      len(self._undo_list),
     855                      self._undo_list)
     856        logging.debug('self._undo_index: %s', self._undo_index)
     857
    837858        self.emit('redo')
    838859
    839860    def enableUndo(self, widget, size=None, overrite=False):
    class Area(gtk.DrawingArea): 
    845866        """
    846867        #logging.debug('Area.enableUndo(self,widget)')
    847868
     869        logging.debug('self._undo_list: (%s) %s',
     870                      len(self._undo_list),
     871                      self._undo_list)
     872        logging.debug('self._undo_index: %s', self._undo_index)
     873
    848874        width, height = self.window.get_size()
    849875        # We need to pass explicitly the size on set up, because the
    850876        # window size is not allocated yet.
    class Area(gtk.DrawingArea): 
    854880        if len(self._undo_list) == 0:
    855881            # first undo pix, start index:
    856882            self._undo_index = 0
     883            logging.debug('self._undo_list: empty')
    857884        elif len(self._undo_list) == MAX_UNDO_STEPS:
    858885            # drop the oldest undo pix:
    859886            self._undo_list.pop(0)
    860887
     888            logging.debug('self._undo_list: MAX_UNDO_STEPS')
     889
    861890            # it could be at the middle of the list (clicked many
    862891            # times undo) and after that draw anything, so we should
    863892            # discart the next redos because they are obsolete now.
    864893            self._undo_list = self._undo_list[:self._undo_index]
    865894        else:
    866895            self._undo_index += 1
     896
     897            logging.debug('self._undo_list: common case')
     898
    867899            # Forget the redos after this one:
    868900            self._undo_list = self._undo_list[:self._undo_index]
    869901
    class Area(gtk.DrawingArea): 
    879911
    880912        self._undo_list.append(undo_pix)
    881913
     914        logging.debug('self._undo_list: (%s) %s',
     915                      len(self._undo_list),
     916                      self._undo_list)
     917        logging.debug('self._undo_index: %s', self._undo_index)
     918
    882919        self.emit('action-saved')
    883920
     921    def spin_undo(self, value):
     922        logging.debug('VALUE: %s', value)
     923        undo_pix = self._undo_list[value]
     924        self.pixmap.draw_drawable(self.gc, undo_pix, 0, 0, 0, 0, -1, -1)
     925        self.queue_draw()
     926
    884927    def copy(self):
    885928        """ Copy Image.
    886929            When the tool selection is working make the change
  • toolbox.py

    diff --git a/toolbox.py b/toolbox.py
    index f781b4a..9069778 100644
    a b class DrawEditToolbar(EditToolbar): 
    168168        self._clear_all.set_tooltip(_('Clear'))
    169169        self._clear_all.show()
    170170
     171        self._spin_undo_list = gtk.SpinButton()
     172        adj = gtk.Adjustment(0, 0, 11, 1)
     173        self._spin_undo_list.set_adjustment(adj)
     174        self._spin_undo_list.set_numeric(True)
     175        self._spin_undo_list.connect('notify::value',
     176                                     self._spin_undo_changed_cb)
     177        self._spin_undo_list.show()
     178
     179        item = gtk.ToolItem()
     180        item.add(self._spin_undo_list)
     181        item.show()
     182
     183        self.insert(item, -1)
     184
    171185        self.undo.connect('clicked', self._undo_cb)
    172186        self.redo.connect('clicked', self._redo_cb)
    173187
    class DrawEditToolbar(EditToolbar): 
    181195        self._activity.area.connect('action-saved',
    182196            self._on_signal_action_saved_cb)
    183197
     198    def _spin_undo_changed_cb(self, *args, **kwargs):
     199        self._activity.area.spin_undo(self._spin_undo_list.get_value_as_int())
     200
    184201    def _undo_cb(self, widget, data=None):
    185202        self._activity.area.undo()
    186203