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