]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added CListBox convenience class to python r0-50-24
authorcrutcher <crutcher>
Wed, 6 Jun 2001 22:19:46 +0000 (22:19 +0000)
committercrutcher <crutcher>
Wed, 6 Jun 2001 22:19:46 +0000 (22:19 +0000)
newt.spec
snack.py

index 4de2ebbf0ec550f9fb69a75b2dfb2ec2967efe9f..32e66d38d26db90451a5889316555ed46e131830 100644 (file)
--- a/newt.spec
+++ b/newt.spec
@@ -1,6 +1,6 @@
 Summary: A development library for text mode user interfaces.
 Name: newt
-%define version 0.50.23
+%define version 0.50.24
 Version: %{version}
 Release: 1
 Copyright: LGPL
@@ -105,6 +105,9 @@ rm -rf $RPM_BUILD_ROOT
 %endif
 
 %changelog
+* Wed Jun  6 2001 Crutcher Dunnavant <crutcher@redhat.com>
+- added CListBox python convenience class
+
 * Tue May 15 2001 Michael Fulbright <msf@redhat.com>
 - added python binding for CompactButton()
 
index 6c509aa08cb10697f96389c74e79cd57b3da667d..fe330eafec02857709527e66b45820140dea2ca8 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -10,6 +10,12 @@ import string
 
 from _snack import FLAG_DISABLED, FLAGS_SET, FLAGS_RESET, FLAGS_TOGGLE, FD_READ, FD_WRITE, FD_EXCEPT
 
+LEFT = (-1, 0)
+DOWN = (-1, -1)
+CENTER = (0, 0)
+UP = (1, 1)
+RIGHT = (1, 0)
+
 snackArgs = {"append":-1}
 
 class Widget:
@@ -571,3 +577,91 @@ def EntryWindow(screen, title, text, prompts, allowCancel = 1, width = 40,
        count = count + 1
 
     return (bb.buttonPressed(result), tuple(entryValues))
+
+class CListBox(Grid):
+       def __init__(self, height, cols, col_widths, scroll = 0, returnExit = 0,
+                       width = 0, col_pad = 1, col_text_align = None,
+                       col_labels = None, col_label_align = None):
+
+               self.cols = cols
+               self.col_widths = col_widths[:]
+               self.col_pad = col_pad
+               self.col_text_align = col_text_align
+
+               if col_labels != None:          
+                       Grid.__init__(self, 1, 2)
+                       box_y = 1
+
+                       lstr = self.colFormText(col_labels, col_label_align)
+                       self.label = Label(lstr)
+
+                       self.setField(self.label, 0, 0)
+
+               else:
+                       Grid.__init__(self, 1, 1)
+                       box_y = 1
+                       
+
+               self.listbox = Listbox(height, scroll, returnExit, width)
+               self.setField(self.listbox, 0, box_y)
+
+       def colFormText(self, col_text, align = None):
+               i = 0
+               str = ""
+               c_len = len(col_text)
+               while (i < self.cols) and (i < c_len):
+               
+                       cstr = col_text[i][:self.col_widths[i]] 
+                       delta = self.col_widths[i] - len(cstr)
+                       if delta > 0:
+                               if align == None:
+                                       a = LEFT
+                               else:
+                                       a = align[i]
+
+                               if a == LEFT:
+                                       cstr = cstr + (" " * delta)
+                               if a == CENTER:
+                                       cstr = (" " * (delta / 2)) + cstr + \
+                                               (" " * ((delta + 1) / 2))
+                               if a == RIGHT:
+                                       cstr = (" " * delta) + cstr
+
+                       if i != c_len - 1:
+                               pstr = (" " * self.col_pad)
+                       else:
+                               pstr = ""
+
+                       str = str + cstr + pstr
+       
+                       i = i + 1
+       
+               return str
+
+       def append(self, col_text, item, col_text_align = None):
+               if col_text_align == None:
+                       col_text_align = self.col_text_align
+               text = self.colFormText(col_text, col_text_align)
+               self.listbox.append(text, item)
+
+       def insert(self, col_text, item, before, col_text_align = None):
+               if col_text_align == None:
+                       col_text_align = self.col_text_align
+               text = self.colFormText(col_text, col_text_align)
+               self.listbox.insert(text, item, before)
+
+       def delete(self, item):
+               self.listbox.delete(item)
+
+       def replace(self, col_text, item, col_text_align = None):
+               if col_text_align == None:
+                       col_text_align = self.col_text_align
+               text = self.colFormText(col_text, col_text_align)
+               self.listbox.replace(text, item, before)
+
+       def current(self):
+               return self.listbox.current()
+
+       def setCurrent(self, item):
+               self.listbox.setCurrent(item)
+