[gnome-games/applygsoc2009: 27/76] XXX: Split tracker-box into separate file



commit b369e50a0a7869132e1f44d019a57f6c0f168170
Author: Pablo Castellano <pablog src gnome org>
Date:   Thu Aug 26 12:39:32 2010 +0200

    XXX: Split tracker-box into separate file

 gnome-sudoku/src/lib/Makefile.am    |    1 +
 gnome-sudoku/src/lib/main.py        |  284 +---------------------------------
 gnome-sudoku/src/lib/tracker_box.py |  294 +++++++++++++++++++++++++++++++++++
 3 files changed, 297 insertions(+), 282 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/Makefile.am b/gnome-sudoku/src/lib/Makefile.am
index 9b9380c..ceedad0 100644
--- a/gnome-sudoku/src/lib/Makefile.am
+++ b/gnome-sudoku/src/lib/Makefile.am
@@ -23,6 +23,7 @@ gnomesudoku_PYTHON = \
 	sudoku_thumber.py \
 	sudoku.py	\
 	timer.py	\
+	tracker_box.py \
 	tracker_info.py
 
 -include $(top_srcdir)/git.mk
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 00a53e8..10f6e14 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -21,6 +21,7 @@ import printing
 import saver
 import sudoku_maker
 import timer
+import tracker_box
 import tracker_info
 from defaults import (APPNAME, APPNAME_SHORT, AUTHORS, COPYRIGHT, DESCRIPTION, DOMAIN, 
         IMAGE_DIR, LICENSE, MIN_NEW_PUZZLES, UI_DIR, VERSION, WEBSITE, WEBSITE_LABEL)
@@ -29,22 +30,6 @@ from gtk_goodies import gconf_wrapper, Undo, dialog_extras
 logging.basicConfig()
 logger = logging.getLogger("main")
 
-ICON_FACTORY = gtk.IconFactory()
-STOCK_PIXBUFS = {}
-for filename, stock_id in [('footprints.png', 'tracks'), ]:
-    try:
-        pb = gtk.gdk.pixbuf_new_from_file(os.path.join(IMAGE_DIR, filename))
-    except gobject.GError, e:
-        print 'Failed to load pixbuf: %s' % e
-        continue
-    STOCK_PIXBUFS[stock_id] = pb
-    iconset = gtk.IconSet(pb)
-    ICON_FACTORY.add(stock_id, iconset)
-    ICON_FACTORY.add_default()
-
-gtk.stock_add([('tracks',
-                _('Track moves'),
-                0, 0, ""), ])
 
 class UI (gconf_wrapper.GConfWrapper):
 
@@ -494,7 +479,7 @@ class UI (gconf_wrapper.GConfWrapper):
             self.gsd.hide_impossible_implications()
 
     def setup_tracker_interface (self):
-        self.tracker_ui = TrackerBox(self)
+        self.tracker_ui = tracker_box.TrackerBox(self)
         self.tracker_ui.show_all()
         self.tracker_ui.hide()
         self.tinfo = tracker_info.TrackerInfo()
@@ -589,271 +574,6 @@ class UI (gconf_wrapper.GConfWrapper):
         gp = printing.GamePrinter(self.sudoku_maker, self.gconf)
         gp.run_dialog()
 
-class TrackerBox (gtk.VBox):
-
-    def __init__ (self, main_ui):
-
-        gtk.VBox.__init__(self)
-        self.builder = gtk.Builder()
-        self.builder.set_translation_domain(DOMAIN)
-        self.builder.add_from_file(os.path.join(UI_DIR, 'tracker.ui'))
-        self.main_ui = main_ui
-        self.tinfo = tracker_info.TrackerInfo()
-        self.tinfo.ui = self
-        self.vb = self.builder.get_object('vbox1')
-        self.vb.unparent()
-        self.pack_start(self.vb, expand = True, fill = True)
-        self._setup_actions()
-        self._setup_tree()
-        self.show_all()
-
-    def reset (self):
-
-        for tree in self.tracker_model:
-            if tree[0] > -1:
-                self.tracker_model.remove(tree.iter)
-        self.tinfo.reset()
-        self.tracker_actions.set_sensitive(False)
-
-    def _setup_tree (self):
-        self.tracker_tree = self.builder.get_object('TrackerTreeView')
-        self.tracker_model = gtk.ListStore(int, gtk.gdk.Pixbuf, str)
-        self.tracker_model.set_sort_column_id(0, gtk.SORT_ASCENDING)
-        self.tracker_tree.set_model(self.tracker_model)
-        col1 = gtk.TreeViewColumn("", gtk.CellRendererPixbuf(), pixbuf = 1)
-        rend = gtk.CellRendererText()
-        col2 = gtk.TreeViewColumn("", rend, text = 2)
-        col2.set_cell_data_func(rend, self.draw_tracker_name)
-        self.tracker_tree.append_column(col2)
-        self.tracker_tree.append_column(col1)
-        # Our initial row...
-        pixbuf = self._pixbuf_transform_color(
-            STOCK_PIXBUFS['tracks'],
-            (0, 0, 0)
-            )
-        self.tracker_model.append([-1, pixbuf, _('Untracked')])
-        self.tracker_tree.get_selection().connect('changed', self._selection_changed_cb)
-
-    def _setup_actions (self):
-        self.tracker_actions = gtk.ActionGroup('tracker_actions')
-        self.tracker_actions.add_actions(
-            [('Remove',
-              gtk.STOCK_CLEAR,
-              _('_Remove'),
-              None, _('Delete selected tracker.'),
-              self.remove_tracker_cb
-              ),
-             ('Hide',
-              gtk.STOCK_CLEAR,
-              _('H_ide'),
-              None, _('Hide current tracker entries.'),
-              self.hide_tracker_cb
-              ),
-             ('Apply',
-              gtk.STOCK_APPLY,
-              _('A_pply'),
-              None, _('Apply all tracked values and remove the tracker.'),
-              self.apply_tracker_cb
-              ),
-             ]
-            )
-        a = self.tracker_actions.get_action('Remove')
-        a.connect_proxy(self.builder.get_object('RemoveTrackerButton'))
-        a = self.tracker_actions.get_action('Hide')
-        a.connect_proxy(self.builder.get_object('HideTrackerButton'))
-        a = self.tracker_actions.get_action('Apply')
-        a.connect_proxy(self.builder.get_object('ApplyTrackerButton'))
-        self.builder.get_object('AddTrackerButton').connect('clicked',
-                                                          self.add_tracker)
-        # Default to insensitive (they only become sensitive once a tracker is added)
-        self.tracker_actions.set_sensitive(False)
-
-    def draw_tracker_name(self, column, cell, model, iter):
-        if model.get_value(iter, 0) == self.tinfo.showing_tracker:
-            cell.set_property('weight', pango.WEIGHT_BOLD)
-        else:
-            cell.set_property('weight', pango.WEIGHT_NORMAL)
-
-    def add_tracker (self, *args, **keys):
-        if keys and keys.has_key('tracker_id'):
-            tracker_id = self.tinfo.create_tracker(keys['tracker_id'])
-        else:
-            tracker_id = self.tinfo.create_tracker()
-        pixbuf = self._pixbuf_transform_color(
-            STOCK_PIXBUFS['tracks'],
-            self.tinfo.get_color(tracker_id)
-            )
-        # select our new tracker
-        self.tracker_tree.get_selection().select_iter(
-            self.tracker_model.append([tracker_id,
-                                  pixbuf,
-                                  _("Tracker %s") % (tracker_id + 1)]
-                                  )
-            )
-        self.tinfo.set_tracker(tracker_id)
-
-    def _pixbuf_transform_color (self, pixbuf, color):
-        """Return new pixbuf with color changed to color"""
-        pixbuf_str = pixbuf.get_pixels()
-        pixbuf_str_new = ""
-
-        for alpha in pixbuf_str[3::4]:
-            pixbuf_str_new += chr(int(color[0]*255))
-            pixbuf_str_new += chr(int(color[1]*255))
-            pixbuf_str_new += chr(int(color[2]*255))
-            pixbuf_str_new += alpha
-
-        return gtk.gdk.pixbuf_new_from_data(pixbuf_str_new, gtk.gdk.COLORSPACE_RGB, True, 8, 
-                                            pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride())
-
-    def find_tracker (self, tracker_id):
-        for row in self.tracker_model:
-            if row[0] == tracker_id:
-                return row
-        return None
-
-    def select_tracker (self, tracker_id):
-        track_row = self.find_tracker(tracker_id)
-        if track_row:
-            self.tracker_tree.get_selection().select_iter(track_row.iter)
-            self.tinfo.set_tracker(tracker_id)
-
-    def redraw_row(self, tracker_id):
-        track_row = self.find_tracker(tracker_id)
-        if track_row:
-            self.tracker_model.row_changed(self.tracker_model.get_path(track_row.iter), track_row.iter)
-
-    def set_tracker_action_sense(self, enabled):
-        self.tracker_actions.set_sensitive(True)
-        for action in self.tracker_actions.list_actions():
-            action.set_sensitive(self.tinfo.showing_tracker != tracker_info.NO_TRACKER)
-
-    def _selection_changed_cb (self, selection):
-        mod, itr = selection.get_selected()
-        if itr:
-            selected_tracker_id = mod.get_value(itr, 0)
-        else:
-            selected_tracker_id = tracker_info.NO_TRACKER
-        if selected_tracker_id != tracker_info.NO_TRACKER:
-            self.main_ui.gsd.cover_track()
-        # Remove the underline on the showing_tracker
-        self.redraw_row(self.tinfo.showing_tracker)
-        self.tinfo.set_tracker(selected_tracker_id)
-        self.set_tracker_action_sense(self.tinfo.showing_tracker != tracker_info.NO_TRACKER)
-        # Show the tracker
-        if selected_tracker_id != tracker_info.NO_TRACKER:
-            self.main_ui.gsd.show_track()
-        self.main_ui.gsd.update_all_notes()
-        if self.main_ui.gconf['always_show_hints']:
-            self.main_ui.gsd.update_all_hints()
-
-    def remove_tracker_cb (self, action):
-        mod, itr = self.tracker_tree.get_selection().get_selected()
-        # This should only be called if there is an itr, but we'll
-        # double-check just in case.
-        if itr:
-            clearer = Undo.UndoableObject(
-                self.do_delete_tracker,
-                self.undo_delete_tracker,
-                self.main_ui.history
-                )
-            clearer.perform()
-
-    def hide_tracker_cb (self, action):
-        hiding_tracker = self.tinfo.showing_tracker
-        self.select_tracker(tracker_info.NO_TRACKER)
-        self.main_ui.gsd.cover_track(True)
-        self.main_ui.gsd.update_all_notes()
-        self.set_tracker_action_sense(False)
-        self.redraw_row(hiding_tracker)
-        self.redraw_row(tracker_info.NO_TRACKER)
-
-    def apply_tracker_cb (self, action):
-        '''Apply Tracker button action
-        '''
-        # Shouldn't be here if no tracker is showing
-        if self.tinfo.showing_tracker == tracker_info.NO_TRACKER:
-            return
-        # Apply the tracker in undo-able fashion
-        applyer = Undo.UndoableObject(
-            self.do_apply_tracker,
-            self.undo_apply_tracker,
-            self.main_ui.history
-            )
-        applyer.perform()
-
-    def do_apply_tracker(self):
-        '''Apply the showing tracker to untracked
-
-        All of the values and notes will be transferred to untracked and
-        the tracker is deleted.
-        '''
-        track_row = self.find_tracker(self.tinfo.showing_tracker)
-        if not track_row:
-            return
-        # Delete the tracker
-        cleared_values, cleared_notes = self.do_delete_tracker(True)
-        # Apply the values
-        for x, y, val, tid in cleared_values:
-            self.main_ui.gsd.set_value(x, y, val)
-        # Then apply the notes
-        self.main_ui.gsd.apply_notelist(cleared_notes, True)
-        # Store the undo counts
-        self.main_ui.cleared.append(len(cleared_values))
-        self.main_ui.cleared_notes.append(len(cleared_notes))
-
-    def undo_apply_tracker(self):
-        '''Undo a previous tracker apply
-
-        The number of cleared values and notes are stored during the apply.
-        The undo is called for each of them, then the tracker delete is
-        undone.
-        '''
-        # Undo all of the applied values and notes
-        value_count = self.main_ui.cleared.pop()
-        note_count = self.main_ui.cleared_notes.pop()
-        count = 0
-        while count < (value_count + note_count):
-            self.main_ui.history.undo()
-            count += 1
-        # Undo the tracker delete
-        self.undo_delete_tracker()
-
-    def do_delete_tracker(self, for_apply = False):
-        '''Delete the current tracker
-        '''
-        track_row = self.find_tracker(self.tinfo.showing_tracker)
-        if not track_row:
-            return
-        ui_row = [track_row[0], track_row[1], track_row[2]]
-        # For the values, store it like (tracker_id, list_of_cleared_values)
-        cleared_values = self.main_ui.gsd.delete_by_tracker()
-        self.main_ui.cleared.append((self.tinfo.showing_tracker, ui_row, cleared_values))
-        # The notes already have tracker info in them, so just store the list
-        cleared_notes = self.main_ui.gsd.clear_notes(tracker = self.tinfo.showing_tracker)
-        self.main_ui.cleared_notes.append(cleared_notes)
-        # Delete it from tracker_info
-        self.hide_tracker_cb(None)
-        self.tracker_model.remove(track_row.iter)
-        self.tinfo.delete_tracker(ui_row[0])
-        # Return all of the data for "Apply Tracker" button
-        if for_apply:
-            return (cleared_values, cleared_notes)
-
-    def undo_delete_tracker(self):
-        '''Undo a tracker delete
-        '''
-        # Values are stored like (tracker_id, list_of_cleared_values)
-        tracker_id, ui_row, cleared_values = self.main_ui.cleared.pop()
-        # Recreate it in tracker_info
-        self.tinfo.create_tracker(tracker_id)
-        # Add it to the tree
-        self.tracker_tree.get_selection().select_iter(self.tracker_model.append(ui_row))
-        # Add all the values
-        for value in cleared_values:
-            self.main_ui.gsd.add_value(*value)
-        # The notes already have tracker info in them, so just store the list
-        self.main_ui.gsd.apply_notelist(self.main_ui.cleared_notes.pop())
 
 def start_game (debug=False):
     if debug:
diff --git a/gnome-sudoku/src/lib/tracker_box.py b/gnome-sudoku/src/lib/tracker_box.py
new file mode 100644
index 0000000..83c7be0
--- /dev/null
+++ b/gnome-sudoku/src/lib/tracker_box.py
@@ -0,0 +1,294 @@
+# -*- coding: utf-8 -*-
+
+import os.path
+
+import gtk
+import gobject
+from gettext import gettext as _
+
+import defaults
+from gtk_goodies import Undo
+
+ICON_FACTORY = gtk.IconFactory()
+STOCK_PIXBUFS = {}
+for filename, stock_id in [('footprints.png', 'tracks'), ]:
+    try:
+        pb = gtk.gdk.pixbuf_new_from_file(os.path.join(IMAGE_DIR, filename))
+    except gobject.GError, e:
+        print 'Failed to load pixbuf: %s' % e
+        continue
+    STOCK_PIXBUFS[stock_id] = pb
+    iconset = gtk.IconSet(pb)
+    ICON_FACTORY.add(stock_id, iconset)
+    ICON_FACTORY.add_default()
+
+gtk.stock_add([('tracks',
+                _('Track moves'),
+                0, 0, ""), ])
+
+
+class TrackerBox (gtk.VBox):
+
+    def __init__ (self, main_ui):
+
+        gtk.VBox.__init__(self)
+        self.builder = gtk.Builder()
+        self.builder.set_translation_domain(DOMAIN)
+        self.builder.add_from_file(os.path.join(UI_DIR, 'tracker.ui'))
+        self.main_ui = main_ui
+        self.tinfo = tracker_info.TrackerInfo()
+        self.tinfo.ui = self
+        self.vb = self.builder.get_object('vbox1')
+        self.vb.unparent()
+        self.pack_start(self.vb, expand = True, fill = True)
+        self._setup_actions()
+        self._setup_tree()
+        self.show_all()
+
+    def reset (self):
+
+        for tree in self.tracker_model:
+            if tree[0] > -1:
+                self.tracker_model.remove(tree.iter)
+        self.tinfo.reset()
+        self.tracker_actions.set_sensitive(False)
+
+    def _setup_tree (self):
+        self.tracker_tree = self.builder.get_object('TrackerTreeView')
+        self.tracker_model = gtk.ListStore(int, gtk.gdk.Pixbuf, str)
+        self.tracker_model.set_sort_column_id(0, gtk.SORT_ASCENDING)
+        self.tracker_tree.set_model(self.tracker_model)
+        col1 = gtk.TreeViewColumn("", gtk.CellRendererPixbuf(), pixbuf = 1)
+        rend = gtk.CellRendererText()
+        col2 = gtk.TreeViewColumn("", rend, text = 2)
+        col2.set_cell_data_func(rend, self.draw_tracker_name)
+        self.tracker_tree.append_column(col2)
+        self.tracker_tree.append_column(col1)
+        # Our initial row...
+        pixbuf = self._pixbuf_transform_color(
+            STOCK_PIXBUFS['tracks'],
+            (0, 0, 0)
+            )
+        self.tracker_model.append([-1, pixbuf, _('Untracked')])
+        self.tracker_tree.get_selection().connect('changed', self._selection_changed_cb)
+
+    def _setup_actions (self):
+        self.tracker_actions = gtk.ActionGroup('tracker_actions')
+        self.tracker_actions.add_actions(
+            [('Remove',
+              gtk.STOCK_CLEAR,
+              _('_Remove'),
+              None, _('Delete selected tracker.'),
+              self.remove_tracker_cb
+              ),
+             ('Hide',
+              gtk.STOCK_CLEAR,
+              _('H_ide'),
+              None, _('Hide current tracker entries.'),
+              self.hide_tracker_cb
+              ),
+             ('Apply',
+              gtk.STOCK_APPLY,
+              _('A_pply'),
+              None, _('Apply all tracked values and remove the tracker.'),
+              self.apply_tracker_cb
+              ),
+             ]
+            )
+        a = self.tracker_actions.get_action('Remove')
+        a.connect_proxy(self.builder.get_object('RemoveTrackerButton'))
+        a = self.tracker_actions.get_action('Hide')
+        a.connect_proxy(self.builder.get_object('HideTrackerButton'))
+        a = self.tracker_actions.get_action('Apply')
+        a.connect_proxy(self.builder.get_object('ApplyTrackerButton'))
+        self.builder.get_object('AddTrackerButton').connect('clicked',
+                                                          self.add_tracker)
+        # Default to insensitive (they only become sensitive once a tracker is added)
+        self.tracker_actions.set_sensitive(False)
+
+    def draw_tracker_name(self, column, cell, model, iter):
+        if model.get_value(iter, 0) == self.tinfo.showing_tracker:
+            cell.set_property('weight', pango.WEIGHT_BOLD)
+        else:
+            cell.set_property('weight', pango.WEIGHT_NORMAL)
+
+    def add_tracker (self, *args, **keys):
+        if keys and keys.has_key('tracker_id'):
+            tracker_id = self.tinfo.create_tracker(keys['tracker_id'])
+        else:
+            tracker_id = self.tinfo.create_tracker()
+        pixbuf = self._pixbuf_transform_color(
+            STOCK_PIXBUFS['tracks'],
+            self.tinfo.get_color(tracker_id)
+            )
+        # select our new tracker
+        self.tracker_tree.get_selection().select_iter(
+            self.tracker_model.append([tracker_id,
+                                  pixbuf,
+                                  _("Tracker %s") % (tracker_id + 1)]
+                                  )
+            )
+        self.tinfo.set_tracker(tracker_id)
+
+    def _pixbuf_transform_color (self, pixbuf, color):
+        """Return new pixbuf with color changed to color"""
+        pixbuf_str = pixbuf.get_pixels()
+        pixbuf_str_new = ""
+
+        for alpha in pixbuf_str[3::4]:
+            pixbuf_str_new += chr(int(color[0]*255))
+            pixbuf_str_new += chr(int(color[1]*255))
+            pixbuf_str_new += chr(int(color[2]*255))
+            pixbuf_str_new += alpha
+
+        return gtk.gdk.pixbuf_new_from_data(pixbuf_str_new, gtk.gdk.COLORSPACE_RGB, True, 8, 
+                                            pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride())
+
+    def find_tracker (self, tracker_id):
+        for row in self.tracker_model:
+            if row[0] == tracker_id:
+                return row
+        return None
+
+    def select_tracker (self, tracker_id):
+        track_row = self.find_tracker(tracker_id)
+        if track_row:
+            self.tracker_tree.get_selection().select_iter(track_row.iter)
+           self.tinfo.set_tracker(tracker_id)
+
+    def redraw_row(self, tracker_id):
+        track_row = self.find_tracker(tracker_id)
+        if track_row:
+            self.tracker_model.row_changed(self.tracker_model.get_path(track_row.iter), track_row.iter)
+
+    def set_tracker_action_sense(self, enabled):
+        self.tracker_actions.set_sensitive(True)
+        for action in self.tracker_actions.list_actions():
+            action.set_sensitive(self.tinfo.showing_tracker != tracker_info.NO_TRACKER)
+
+    def _selection_changed_cb (self, selection):
+        mod, itr = selection.get_selected()
+        if itr:
+            selected_tracker_id = mod.get_value(itr, 0)
+        else:
+            selected_tracker_id = tracker_info.NO_TRACKER
+        if selected_tracker_id != tracker_info.NO_TRACKER:
+            self.main_ui.gsd.cover_track()
+        # Remove the underline on the showing_tracker
+        self.redraw_row(self.tinfo.showing_tracker)
+        self.tinfo.set_tracker(selected_tracker_id)
+        self.set_tracker_action_sense(self.tinfo.showing_tracker != tracker_info.NO_TRACKER)
+       # Show the tracker
+        if selected_tracker_id != tracker_info.NO_TRACKER:
+            self.main_ui.gsd.show_track()
+        self.main_ui.gsd.update_all_notes()
+        if self.main_ui.gconf['always_show_hints']:
+            self.main_ui.gsd.update_all_hints()
+
+    def remove_tracker_cb (self, action):
+        mod, itr = self.tracker_tree.get_selection().get_selected()
+        # This should only be called if there is an itr, but we'll
+        # double-check just in case.
+        if itr:
+            clearer = Undo.UndoableObject(
+                self.do_delete_tracker,
+                self.undo_delete_tracker,
+                self.main_ui.history
+                )
+            clearer.perform()
+
+    def hide_tracker_cb (self, action):
+        hiding_tracker = self.tinfo.showing_tracker
+        self.select_tracker(tracker_info.NO_TRACKER)
+        self.main_ui.gsd.cover_track(True)
+        self.main_ui.gsd.update_all_notes()
+        self.set_tracker_action_sense(False)
+        self.redraw_row(hiding_tracker)
+        self.redraw_row(tracker_info.NO_TRACKER)
+
+    def apply_tracker_cb (self, action):
+        '''Apply Tracker button action
+        '''
+        # Shouldn't be here if no tracker is showing
+        if self.tinfo.showing_tracker == tracker_info.NO_TRACKER:
+            return
+        # Apply the tracker in undo-able fashion
+        applyer = Undo.UndoableObject(
+            self.do_apply_tracker,
+            self.undo_apply_tracker,
+            self.main_ui.history
+            )
+        applyer.perform()
+
+   def do_apply_tracker(self):
+        '''Apply the showing tracker to untracked
+
+        All of the values and notes will be transferred to untracked and
+        the tracker is deleted.
+        '''
+        track_row = self.find_tracker(self.tinfo.showing_tracker)
+        if not track_row:
+           return
+        # Delete the tracker
+        cleared_values, cleared_notes = self.do_delete_tracker(True)
+        # Apply the values
+        for x, y, val, tid in cleared_values:
+            self.main_ui.gsd.set_value(x, y, val)
+       # Then apply the notes
+        self.main_ui.gsd.apply_notelist(cleared_notes, True)
+        # Store the undo counts
+        self.main_ui.cleared.append(len(cleared_values))
+        self.main_ui.cleared_notes.append(len(cleared_notes))
+
+    def undo_apply_tracker(self):
+       '''Undo a previous tracker apply
+
+        The number of cleared values and notes are stored during the apply.
+        The undo is called for each of them, then the tracker delete is
+        undone.
+        '''
+        # Undo all of the applied values and notes
+        value_count = self.main_ui.cleared.pop()
+        note_count = self.main_ui.cleared_notes.pop()
+       count = 0
+        while count < (value_count + note_count):
+            self.main_ui.history.undo()
+            count += 1
+        # Undo the tracker delete
+        self.undo_delete_tracker()
+
+    def do_delete_tracker(self, for_apply = False):
+        '''Delete the current tracker
+        '''
+        track_row = self.find_tracker(self.tinfo.showing_tracker)
+        if not track_row:
+            return
+        ui_row = [track_row[0], track_row[1], track_row[2]]
+        # For the values, store it like (tracker_id, list_of_cleared_values)
+        cleared_values = self.main_ui.gsd.delete_by_tracker()
+        self.main_ui.cleared.append((self.tinfo.showing_tracker, ui_row, cleared_values))
+        # The notes already have tracker info in them, so just store the list
+        cleared_notes = self.main_ui.gsd.clear_notes(tracker = self.tinfo.showing_tracker)
+        self.main_ui.cleared_notes.append(cleared_notes)
+        # Delete it from tracker_info
+        self.hide_tracker_cb(None)
+        self.tracker_model.remove(track_row.iter)
+        self.tinfo.delete_tracker(ui_row[0])
+        # Return all of the data for "Apply Tracker" button
+        if for_apply:
+            return (cleared_values, cleared_notes)
+
+    def undo_delete_tracker(self):
+        '''Undo a tracker delete
+        '''
+        # Values are stored like (tracker_id, list_of_cleared_values)
+        tracker_id, ui_row, cleared_values = self.main_ui.cleared.pop()
+        # Recreate it in tracker_info
+        self.tinfo.create_tracker(tracker_id)
+        # Add it to the tree
+        self.tracker_tree.get_selection().select_iter(self.tracker_model.append(ui_row))
+        # Add all the values
+        for value in cleared_values:
+            self.main_ui.gsd.add_value(*value)
+        # The notes already have tracker info in them, so just store the list
+        self.main_ui.gsd.apply_notelist(self.main_ui.cleared_notes.pop())



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]