Commits

anatoly techtonik  committed 025786b

FilePanel: Add border

  • Participants
  • Parent commits d548415

Comments (0)

Files changed (1)

 #!/bin/env python
+# -*- coding: utf-8 -*-
 """
 Directory browser in Python (OpenGL through pyglet)
 
 class Palette(object):
     foreground = (255, 255, 255, 255)
     background = (0, 0, 0, 0)
-    active = (255, 0, 255, 255)
+    active = (255, 255, 0, 255)
     background_active = (255, 0, 255, 255)
 
 class DNPalette(Palette):
     background = (85, 85, 85, 255)
     active = (22, 0, 85, 255)
 
-palette = DNPalette
+palette = Palette #DNPalette
 
 
 class FilePanel(object):
     # [ ] background color (pyglet bug)
     # [x] up/down arrows move cursor
     # [x] scrolling
+    # [x] border
     def __init__(self, width, height):
-        # file panel dimensions with the border
+        # file panel dimensions with the border (in symbols)
         self.height = height
         self.width = width
         
         # offset of starting visible element from the items list
         self.offset = 0
         # [ ] resize - correct offset when window height shrinked
+        
+        # precalculate border labels
+        self.border_labels = []
+        label = pyglet.text.Label('╔'+ '═'*(self.width-2) + '╗', anchor_y='top',
+                    font_name=font_family, x=0, y=font_height*self.height)
+        self.border_labels.append(label)
+        for x in range(1, self.height-1):
+            label = pyglet.text.Label('║' + ' '*(self.width-2) + '║',
+                        anchor_y='top', font_name=font_family, x=0, y=font_height*(x+1))
+            self.border_labels.append(label)
+        label = pyglet.text.Label('╚'+ '═'*(self.width-2) + '╝', anchor_y='top',
+                    font_name=font_family, x=0, y=font_height)
+        self.border_labels.append(label)
 
     def _is_item_visible(self, idx):
         """True if item with given idx is visible in panel"""
             self._refresh_label_positions()
             
     def draw_border(self):
-        pass        
-        
+        for label in self.border_labels:
+            label.draw()
+
     def draw(self):
+        self.draw_border()
         yspace = self.height-2
         for idx, (name, label) in enumerate(self.items):
             if idx >= self.offset and idx < self.offset + yspace: