Add create club account menu item
[public/pyceo-broken.git] / pylib / csc / apps / urwid / main.py
1 import random, time
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
11 from csc.adm import accounts, members, terms
12 from csc.common.excep import InvalidArgument
13
14 ui = urwid.curses_display.Screen()
15
16 ui.register_palette([
17     # name, foreground, background, mono
18     ('banner', 'light gray', 'default', None),
19     ('menu', 'light gray', 'default', 'bold'),
20     ('selected', 'black', 'light gray', 'bold'),
21 ])
22
23
24 def program_name():
25     cwords = [ "CSC" ] * 20 + [ "Club" ] * 10 + [ "Campus" ] * 5 + \
26         [ "Communist", "Canadian", "Celestial", "Cryptographic", "Calum's",
27           "Canonical", "Capitalist", "Catastrophic", "Ceremonial", "Chaotic", "Civic",
28           "City", "County", "Caffeinated" ]
29     ewords = [ "Embellished", "Ergonomic", "Electric", "Eccentric", "European", "Economic",
30         "Evil", "Egotistical", "Elliptic", "Emasculating", "Embalming",
31         "Embryonic", "Emigrant", "Emissary's", "Emoting", "Employment", "Emulated",
32         "Enabling", "Enamoring", "Encapsulated", "Enchanted", "Encoded", "Encrypted",
33         "Encumbered", "Endemic", "Enhanced", "Enigmatic", "Enlightened", "Enormous",
34         "Enrollment", "Enshrouded", "Ephermal", "Epidemic", "Episodic", "Epsilon",
35         "Equitable", "Equestrian", "Equilateral", "Erroneous", "Erratic",
36         "Espresso", "Essential", "Estate", "Esteemed", "Eternal", "Ethical", "Eucalyptus",
37         "Euphemistic", "Envangelist", "Evasive", "Everyday", "Evidence", "Eviction", "Evildoer's",
38         "Evolution", "Exacerbation", "Exalted", "Examiner's", "Excise", "Exciting", "Exclusion",
39         "Exec", "Executioner's", "Exile", "Existential", "Expedient", "Expert", "Expletive",
40         "Exploiter's", "Explosive", "Exponential", "Exposing", "Extortion", "Extraction",
41         "Extraneous", "Extravaganza", "Extreme", "Extraterrestrial", "Extremist", "Eerie" ]
42     owords = [ "Office" ] * 50 + [ "Outhouse", "Outpost" ]
43
44     cword = random.choice(cwords)
45     eword = random.choice(ewords)
46     oword = random.choice(owords)
47
48     return "%s %s %s" % (cword, eword, oword)
49
50 def menu_items(items):
51     return [ urwid.AttrWrap( ButtonText( cb, txt ), 'menu', 'selected') for (txt, cb) in items ]
52
53 def main_menu():
54     menu = [
55         ("New Member", new_member),
56         ("Renew Membership", renew_member),
57         ("Create Club Account", new_club),
58         ("Display Member", display_member),
59         ("Search", search_members),
60         ("Exit", raise_abort),
61     ]
62
63     listbox = urwid.ListBox( menu_items( menu ) )
64     return listbox
65
66 def push_wizard(name, pages, dimensions=(50, 10)):
67     state = {}
68     wiz = Wizard()
69     for page in pages:
70         if type(page) != tuple:
71             page = (page, )
72         wiz.add_panel( page[0](state, *page[1:]) )
73     push_window( urwid.Filler( urwid.Padding(
74         urwid.LineBox(wiz), 'center', dimensions[0]),
75         'middle', dimensions[1] ), name )
76     
77 def new_member(*args, **kwargs):
78     push_wizard("New Member", [
79         newmember.IntroPage,
80         newmember.InfoPage,
81         newmember.SignPage,
82         newmember.PassPage,
83         newmember.EndPage,
84     ])
85
86 def new_club(*args, **kwargs):
87     push_wizard("New Club Account", [
88         newmember.ClubIntroPage,
89         newmember.ClubInfoPage,
90         (newmember.EndPage, "club"),
91     ], (60,15))
92
93 def renew_member(*args, **kwargs):
94     push_wizard("Renew Membership", [
95         renew.IntroPage,
96         renew.UserPage,
97         renew.TermPage,
98         renew.PayPage,
99         renew.EndPage,
100     ])
101
102 def display_member(a):
103     push_wizard("Display Member", [
104         renew.UserPage,
105         info.InfoPage,
106     ], (60, 15))
107
108 def search_members(a):
109     menu = [
110         ("Members by term", search_term),
111         ("Members by name", search_name),
112         ("Back", raise_back),
113     ]
114
115     listbox = urwid.ListBox( menu_items( menu ) )
116     push_window(listbox, "Search")
117
118 def search_name(a):
119     push_wizard("By Name", [ search.NamePage ])
120
121 def search_term(a):
122     push_wizard("By Term", [ search.TermPage ])
123
124 def run():
125     push_window( main_menu(), program_name() )
126     event_loop( ui )
127
128 def start():
129     ui.run_wrapper( run )
130
131 if __name__ == '__main__':
132     start()