changeset 718:ab489f7e87f8 pyntnclick

Make filechooser widget presistent, to avoid constantly descending directory trees
author Neil Muller <neil@dip.sun.ac.za>
date Mon, 06 Aug 2012 11:17:27 +0200
parents 3b2d1adca59c
children 3aa6163f0775
files pyntnclick/tools/rect_drawer.py pyntnclick/widgets/filechooser.py
diffstat 2 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pyntnclick/tools/rect_drawer.py	Sun Aug 05 21:50:34 2012 +0200
+++ b/pyntnclick/tools/rect_drawer.py	Mon Aug 06 11:17:27 2012 +0200
@@ -136,6 +136,7 @@
         self.draw_anim = False
         self.zoom_offset = (600, 600)
         self.clear_display = False
+        self.filechooser = None
         if self._detail:
             w, h = self._scene.get_detail_size()
             rect = pygame.rect.Rect(0, 0, w, h)
@@ -347,9 +348,13 @@
         print
 
     def image_load(self, ev, widget):
-        filechooser = FileChooser((0, 0), self.gd, os.curdir,
-                self.do_load_image)
-        self._parent.add(filechooser)
+        if self.filechooser is None:
+            self.filechooser = FileChooser((0, 0), self.gd, os.curdir,
+                    self.do_load_image)
+        else:
+            self.filechooser.refresh()
+        self.invalidate()
+        self._parent.add(self.filechooser)
 
     def do_load_image(self, filename):
         try:
--- a/pyntnclick/widgets/filechooser.py	Sun Aug 05 21:50:34 2012 +0200
+++ b/pyntnclick/widgets/filechooser.py	Mon Aug 06 11:17:27 2012 +0200
@@ -36,6 +36,12 @@
             else:
                 self.files.append(entry)
 
+    def refresh(self):
+        self.page = 0
+        self.selected = None
+        self.get_lists()
+        self.fill_page()
+
     def _dir_button(self, entry):
         widget = TextButton((0, 0), self.gd, entry + '/',
                 fontname=self.gd.constants.bold_font,