Re-build so debian.csclub include library as a dependency
[public/pyceo-broken.git] / ceo / urwid / search.py
1 import urwid
2 from ceo import members, terms
3 from ceo.urwid.widgets import *
4 from ceo.urwid.window import *
5
6 class TermPage(WizardPanel):
7     def init_widgets(self):
8         self.term = SingleEdit("Term: ")
9
10         self.widgets = [
11             urwid.Text( "Terms Members" ),
12             urwid.Divider(),
13             self.term,
14         ]
15     def check(self):
16         try:
17             self.state['term'] = self.term.get_edit_text()
18             terms.parse( self.state['term'] )
19         except:
20             self.focus_widget( self.term )
21             set_status( "Invalid term" )
22             return True
23         mlist = members.list_term( self.state['term'] ).values()
24         pop_window()
25         member_list( mlist )
26
27 class NamePage(WizardPanel):
28     def init_widgets(self):
29         self.name = SingleEdit("Name: ")
30
31         self.widgets = [
32             urwid.Text( "Members by Name" ),
33             urwid.Divider(),
34             self.name,
35         ]
36     def check(self):
37         self.state['name'] = self.name.get_edit_text()
38         if not self.state['name']:
39             self.focus_widget( self.name )
40             set_status( "Invalid name" )
41             return True
42         mlist = members.list_name( self.state['name'] ).values()
43         pop_window()
44         member_list( mlist )
45
46 class GroupPage(WizardPanel):
47     def init_widgets(self):
48         self.group = SingleEdit("Group: ")
49
50         self.widgets = [
51             urwid.Text( "Members by Group" ),
52             urwid.Divider(),
53             self.group,
54         ]
55     def check(self):
56         self.state['group'] = self.group.get_edit_text()
57         if not self.state['group']:
58             self.focus_widget( self.group )
59             set_status( "Invalid group" )
60             return True
61         mlist = members.list_group( self.state['group'] ).values()
62         pop_window()
63         member_list( mlist )
64
65 def member_list(mlist):
66     mlist = list(mlist)
67     mlist.sort( lambda x, y: cmp(x['uid'], y['uid']) )
68     buf = ''
69     for member in mlist:
70         if 'uid' in member:
71             uid = member['uid'][0]
72         else:
73             uid = None
74         if 'program' in member:
75             program = member['program'][0]
76         else:
77             program = None
78         attrs = ( uid, member['cn'][0], program )
79         buf += "%10s %30s\n%41s\n\n" % attrs
80     set_status("Press escape to return to the menu")
81     push_window(urwid.ListBox([urwid.Text(buf)]))
82
83