changeset 62:2b600cccf95e

Add scrolling in entry list to be able to select all entries Fixes #1571
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 25 May 2011 11:00:46 +0200
parents 4b58763e75c1
children 652149e7ef09
files getan/view.py
diffstat 1 files changed, 41 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/getan/view.py	Thu May 19 13:04:21 2011 +0200
+++ b/getan/view.py	Wed May 25 11:00:46 2011 +0200
@@ -22,21 +22,37 @@
 class ListWidget(urwid.BoxWidget):
     def _update_view(self):
         logger.debug("ListWidget: update view now.")
+        if self.size and len(self.rows) > self.size[1]:
+            start_idx = self.top
+            end_idx   = start_idx + self.size[1] - 6
+        else:
+            start_idx = self.top
+            end_idx   = start_idx + len(self.rows)
+        listbox = urwid.LineBox(urwid.Padding(
+            urwid.ListBox(urwid.SimpleListWalker(self.rows[start_idx:
+                                                           end_idx])),
+            ('fixed left', 1),
+            ('fixed right', 1)))
+
+        self.body = urwid.AttrWrap(listbox, 'body')
+
         self.frame.set_body(self.body)
         self.frame.set_footer(self.footer)
         self.frame.set_header(self.header)
 
     def update_focus(self, focus, unfocus=-1):
-        logger.debug("ListWidget: focus row (index = %d)" % focus)
-        logger.debug("ListWidget: unfocus row (index = %d)" % unfocus)
+        self.focused = focus
         if focus >= 0 and focus <= len(self.rows)-1:
             self.rows[focus].focus = True
             self.rows[focus].update_w()
         if unfocus >= 0:
             self.rows[unfocus].focus = False
             self.rows[unfocus].update_w()
+        if self.size:
+            self.validate_view()
 
     def render(self, size, focus=False):
+        self.size = size
         maxcol, maxrow = size
         return self.frame.render((maxcol, maxrow), focus)
 
@@ -60,16 +76,24 @@
         return None
 
     def up(self):
-        logger.debug("ListWidget: navigate to upper row.")
         if self.focused > 0:
-            self.focused = self.focused - 1
-            self.update_focus(self.focused, self.focused+1)
+            logger.debug("ListWidget: navigate to upper row.")
+            self.update_focus(self.focused-1, self.focused)
 
     def down(self):
-        logger.debug("ListWidget: navigate to lower row.")
         if self.focused < len(self.rows) - 1:
-            self.focused = self.focused + 1
-            self.update_focus(self.focused, self.focused-1)
+            logger.debug("ListWidget: navigate to lower row.")
+            self.update_focus(self.focused+1, self.focused)
+
+    def validate_view(self):
+        if self.focused < self.top:
+            self.top = self.focused
+            self._update_view()
+        if self.focused + 8 >= self.top + self.size[1]:
+            self.top = self.focused - (self.size[1]) + 9
+        if self.top < 0:
+            self.top = 0
+        self._update_view()
 
     def select(self):
         if not self.rows: return None
@@ -170,8 +194,10 @@
     def __init__(self, controller, rows):
         self.selection    = []
         self.focused      = 0
+        self.size         = ()
+        self.top          = 0
         self.controller   = controller
-        self.raw_projects = rows
+        self.raw_rows     = rows
 
         self.header    = urwid.LineBox(urwid.AttrWrap(urwid.Text("\n%s\n" %
             _('List of registered projects')),'project_header'))
@@ -276,6 +302,8 @@
 class EntryList(ListWidget):
     def __init__(self, rows):
         self.selection = []
+        self.top       = 0
+        self.size      = ()
         self.focused   = 0
         self.rows      = [EntryNode(x) for x in rows]
         listbox        = urwid.ListBox(urwid.SimpleListWalker(self.rows))
@@ -290,11 +318,10 @@
                                      footer=self.footer)
 
     def set_rows(self, rows):
-        logger.debug("EntryList: set new entries.")
-        self.rows = [EntryNode(x) for x in rows]
-        listbox      = urwid.LineBox(urwid.ListBox(urwid.SimpleListWalker(
-            self.rows)))
-        self.body    = urwid.AttrWrap(listbox, 'entry_body')
+        if rows:
+            self.rows = [EntryNode(x) for x in rows]
+        else:
+            self.rows = []
         self._update_view()
 
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)