changeset 510:3e4bb2c9556c

Lazy loading of save game snapshots.
author Simon Cross <hodgestar@gmail.com>
date Thu, 26 Nov 2009 23:15:04 +0000
parents 77a3f7f1c856
children 57f9077fb7fb
files gamelib/savegame.py
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/savegame.py	Thu Nov 26 23:02:10 2009 +0000
+++ b/gamelib/savegame.py	Thu Nov 26 23:15:04 2009 +0000
@@ -136,6 +136,9 @@
         title = gui.Label(title_txt, cls=cls + ".title.label")
         gui.Dialog.__init__(self, title, body)
 
+        if games:
+            self.save_list.group.value = games[0]
+
     def get_fullpath(self):
         """Return the fullpath of the select save game file or None."""
         if self.value is None:
@@ -151,7 +154,7 @@
                 continue
             if ext != ".xml":
                 continue
-            self.save_games[root] = self._create_image_widget(fullpath)
+            self.save_games[root] = (fullpath, None)
 
     def _create_image_widget(self, fullpath):
         """Create an image showing the contents of a save game file."""
@@ -187,8 +190,13 @@
         for w in self.image_container.widgets:
             self.image_container.remove(w)
 
-        image_widget = self.save_games[self.save_list.value]
-        self.image_container.add(image_widget, 0, 0)
+        name = self.save_list.value
+        fullpath, widget = self.save_games[name]
+        if widget is None:
+            widget = self._create_image_widget(fullpath)
+            self.save_games[name] = (fullpath, widget)
+
+        self.image_container.add(widget, 0, 0)
 
     def _click_ok(self):
         if self.name_input: