Cleanup warnings: unused imports, etc
[public/pyceo-broken.git] / ceo / urwid / main.py
1 import random, ldap, urwid.curses_display
2 from ceo import members
3 from ceo.urwid.widgets import *
4 from ceo.urwid.window import *
5 from ceo.urwid import newmember, renew, info, search, positions, groups
6
7 ui = urwid.curses_display.Screen()
8
9 ui.register_palette([
10     # name, foreground, background, mono
11     ('banner', 'light gray', 'default', None),
12     ('menu', 'light gray', 'default', 'bold'),
13     ('selected', 'black', 'light gray', 'bold'),
14 ])
15
16
17 def program_name():
18     cwords = [ "CSC" ] * 20 + [ "Club" ] * 10 + [ "Campus" ] * 5 + \
19         [ "Communist", "Canadian", "Celestial", "Cryptographic", "Calum's",
20           "Canonical", "Capitalist", "Catastrophic", "Ceremonial", "Chaotic", "Civic",
21           "City", "County", "Caffeinated" ]
22     ewords = [ "Embellished", "Ergonomic", "Electric", "Eccentric", "European", "Economic",
23         "Evil", "Egotistical", "Elliptic", "Emasculating", "Embalming",
24         "Embryonic", "Emigrant", "Emissary's", "Emoting", "Employment", "Emulated",
25         "Enabling", "Enamoring", "Encapsulated", "Enchanted", "Encoded", "Encrypted",
26         "Encumbered", "Endemic", "Enhanced", "Enigmatic", "Enlightened", "Enormous",
27         "Enrollment", "Enshrouded", "Ephemeral", "Epidemic", "Episodic", "Epsilon",
28         "Equitable", "Equestrian", "Equilateral", "Erroneous", "Erratic",
29         "Espresso", "Essential", "Estate", "Esteemed", "Eternal", "Ethical", "Eucalyptus",
30         "Euphemistic", "Evangelist", "Evasive", "Everyday", "Evidence", "Eviction", "Evildoer's",
31         "Evolution", "Exacerbation", "Exalted", "Examiner's", "Excise", "Exciting", "Exclusion",
32         "Exec", "Executioner's", "Exile", "Existential", "Expedient", "Expert", "Expletive",
33         "Exploiter's", "Explosive", "Exponential", "Exposing", "Extortion", "Extraction",
34         "Extraneous", "Extravaganza", "Extreme", "Extraterrestrial", "Extremist", "Eerie" ]
35     owords = [ "Office" ] * 50 + [ "Outhouse", "Outpost" ]
36
37     cword = random.choice(cwords)
38     eword = random.choice(ewords)
39     oword = random.choice(owords)
40
41     return "%s %s %s" % (cword, eword, oword)
42
43 office_data = {
44     "name" : "Office Staff",
45     "group" : "office",
46     "groups" : [ "office", "cdrom", "audio", "video", "www" ],
47 }
48
49 syscom_data = {
50     "name" : "Systems Committee",
51     "group" : "syscom",
52     "groups" : [ "office", "staff", "adm", "src" ],
53 }
54
55 def menu_items(items):
56     return [ urwid.AttrWrap( ButtonText( cb, data, txt ), 'menu', 'selected') for (txt, cb, data) in items ]
57
58 def main_menu():
59     menu = [
60         ("New Member", new_member, None),
61         ("Renew Membership", renew_member, None),
62         ("Create Club Account", new_club, None),
63         ("Display Member", display_member, None),
64         ("Search", search_members, None),
65         ("Manage Club or Group Members", manage_group, None),
66         ("Manage Positions", manage_positions, None),
67         ("Manage Office Staff", groups.group_members, office_data),
68         ("Manage Systems Committee", groups.group_members, syscom_data),
69         ("Exit", raise_abort, None),
70     ]
71
72     listbox = urwid.ListBox( menu_items( menu ) )
73     return listbox
74
75 def new_member(*args, **kwargs):
76     push_wizard("New Member", [
77         newmember.IntroPage,
78         newmember.InfoPage,
79         newmember.SignPage,
80         newmember.PassPage,
81         newmember.EndPage,
82     ])
83
84 def new_club(*args, **kwargs):
85     push_wizard("New Club Account", [
86         newmember.ClubIntroPage,
87         newmember.ClubInfoPage,
88         (newmember.EndPage, "club"),
89     ], (60, 15))
90
91 def manage_group(*args, **kwargs):
92     push_wizard("Manage Club or Group Members", [
93         groups.IntroPage,
94         groups.InfoPage,
95     ], (60, 15))
96
97 def renew_member(*args, **kwargs):
98     push_wizard("Renew Membership", [
99         renew.IntroPage,
100         renew.UserPage,
101         renew.TermPage,
102         renew.PayPage,
103         renew.EndPage,
104     ])
105
106 def display_member(data):
107     push_wizard("Display Member", [
108         renew.UserPage,
109         info.InfoPage,
110     ], (60, 15))
111
112 def search_members(data):
113     menu = [
114         ("Members by term", search_term, None),
115         ("Members by name", search_name, None),
116         ("Members by group", search_group, None),
117         ("Back", raise_back, None),
118     ]
119
120     listbox = urwid.ListBox( menu_items( menu ) )
121     push_window(listbox, "Search")
122
123 def search_name(data):
124     push_wizard("By Name", [ search.NamePage ])
125
126 def search_term(data):
127     push_wizard("By Term", [ search.TermPage ])
128
129 def search_group(data):
130     push_wizard("By Group", [ search.GroupPage ])
131
132 def manage_positions(data):
133     push_wizard("Manage Positions", [
134         positions.IntroPage,
135         positions.InfoPage,
136         positions.EndPage,
137     ], (50, 15))
138
139 def run():
140     members.connect()
141
142     push_window( main_menu(), program_name() )
143     event_loop( ui )
144
145 def start():
146     try:
147         ui.run_wrapper( run )
148     except ldap.LOCAL_ERROR, e:
149         print e[0]['info']
150         print "Hint: You may need to run 'kinit'"
151
152 if __name__ == '__main__':
153     start()