anatoly techtonik committed df8ad46

FilePanel: Move all related logic into the class.

Comments (0)

Files changed (1)

 Use MIT License if public domain doesn't make sense for you.
+import os
 import pyglet
         if self.item_idx - self.offset == self.height:
             self.offset += 1
+    def draw(self):
+        for idx, (name, label) in enumerate(self.items):
+            if idx >= self.offset and idx < self.offset + self.height:
+                label.draw()
+    # --- content methods
+    def update(self, directory='.'):
+        self.title = os.path.abspath(directory)
+        for name in os.listdir(directory):
+            self.add_entry(name)
 filepanel = FilePanel(80, 25)
 # add handler for on_draw event of the window with a decorator
 def on_draw():
     # clear to the default black background color
-    # draw panel
-    for idx, (name, label) in enumerate(filepanel.items):
-        if idx >= filepanel.offset and idx < filepanel.offset + filepanel.height:
-            label.draw()
+    filepanel.draw()
 def on_text_motion(motion):
     if motion == MOTION_DOWN:
-import os
-for name in os.listdir('.'):
-    filepanel.add_entry(name)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.