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