Merge commit 'public/master' into ceod
[public/pyceo-broken.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, \
5     shell, library, databases
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" : [ "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 new_member(*args, **kwargs):
56     push_wizard("New Member", [
57         newmember.IntroPage,
58         newmember.InfoPage,
59         newmember.SignPage,
60         newmember.PassPage,
61         newmember.EndPage,
62     ])
63
64 def new_club(*args, **kwargs):
65     push_wizard("New Club Account", [
66         newmember.ClubIntroPage,
67         newmember.ClubInfoPage,
68         (newmember.EndPage, "club"),
69     ], (60, 15))
70
71 def new_club_user(*args, **kwargs):
72     push_wizard("New Club Rep Account", [
73         newmember.ClubUserIntroPage,
74         newmember.InfoPage,
75         newmember.SignPage,
76         newmember.PassPage,
77         (newmember.EndPage, "clubuser"),
78     ], (60, 15))
79
80 def manage_group(*args, **kwargs):
81     push_wizard("Manage Club or Group Members", [
82         groups.IntroPage,
83         groups.InfoPage,
84     ], (60, 15))
85
86 def renew_member(*args, **kwargs):
87     push_wizard("Renew Membership", [
88         renew.IntroPage,
89         renew.UserPage,
90         renew.TermPage,
91         renew.PayPage,
92         renew.EndPage,
93     ])
94
95 def renew_club_user(*args, **kwargs):
96     push_wizard("Renew Club Rep Account", [
97         renew.ClubUserIntroPage,
98         renew.UserPage,
99         (renew.TermPage, "clubuser"),
100         (renew.EndPage, "clubuser"),
101     ], (60, 15))
102
103 def display_member(data):
104     push_wizard("Display Member", [
105         renew.UserPage,
106         info.InfoPage,
107     ], (60, 15))
108
109 def search_members(data):
110     menu = make_menu([
111         ("Members by term", search_term, None),
112         ("Members by name", search_name, None),
113         ("Members by group", search_group, None),
114         ("Back", raise_back, None),
115     ])
116     push_window(menu, "Search")
117
118 def search_name(data):
119     push_wizard("By Name", [ search.NamePage ])
120
121 def search_term(data):
122     push_wizard("By Term", [ search.TermPage ])
123
124 def search_group(data):
125     push_wizard("By Group", [ search.GroupPage ])
126
127 def manage_positions(data):
128     push_wizard("Manage Positions", [
129         positions.IntroPage,
130         positions.InfoPage,
131         positions.EndPage,
132     ], (50, 15))
133
134 def change_shell(data):
135     push_wizard("Change Shell", [
136         shell.IntroPage,
137         shell.YouPage,
138         shell.ShellPage,
139         shell.EndPage
140     ], (50, 20))
141
142 def run():
143     menu = make_menu([
144         ("New Member", new_member, None),
145         ("New Club Rep", new_club_user, None),
146         ("Renew Membership", renew_member, None),
147         ("Renew Club Rep", renew_club_user, None),
148         ("New Club", new_club, None),
149         ("Display Member", display_member, None),
150         ("Change Shell", change_shell, None),
151         ("Search", search_members, None),
152         ("Manage Club or Group Members", manage_group, None),
153         ("Manage Positions", manage_positions, None),
154         ("Manage Office Staff", groups.group_members, office_data),
155         ("Manage Systems Committee", groups.group_members, syscom_data),
156         ("Library", library.library, None),
157         ("Databases", databases.databases, None),
158         ("Exit", raise_abort, None),
159     ])
160     push_window( menu, program_name() )
161     event_loop( ui )
162
163 def start():
164     ui.run_wrapper( run )
165
166 if __name__ == '__main__':
167     start()