comparison gamelib/misc.py @ 553:7963fc09fac2

Make checkdialog take strings to show as input. Add possiblity of 3rd button on dialog
author Neil Muller <drnlmuller@gmail.com>
date Sat, 28 Nov 2009 17:45:28 +0000
parents 27c09c58d89d
children 95c71a13468c
comparison
equal deleted inserted replaced
552:11c4cebfe4c5 553:7963fc09fac2
80 if roll < weight: 80 if roll < weight:
81 return item 81 return item
82 roll -= weight 82 roll -= weight
83 83
84 class CheckDialog(gui.Dialog): 84 class CheckDialog(gui.Dialog):
85 def __init__(self, sure_func, **params): 85 def __init__(self, sure_func, message, yes_choice, no_choice,
86 maybe_choice, **params):
86 self._sure_func = sure_func 87 self._sure_func = sure_func
87 title = gui.Label('Are You Sure?') 88 title = gui.Label('Are You Sure?')
88 tbl = gui.Table() 89 tbl = gui.Table()
89 tbl.tr() 90 tbl.tr()
90 tbl.td(gui.Label("Do you REALLY want to exit this game?"), colspan=2) 91 tbl.td(gui.Label(message), colspan=3)
91 tbl.tr() 92 tbl.tr()
92 tbl.td(gui.Spacer(0, 15), colspan=2) 93 tbl.td(gui.Spacer(0, 15), colspan=3)
93 tbl.tr() 94 tbl.tr()
94 yes_button = gui.Button('Yes') 95 no_button = gui.Button(no_choice)
95 yes_button.connect(gui.CLICK, self.clicked, True) 96 no_button.connect(gui.CLICK, self.clicked, 0)
96 no_button = gui.Button('No')
97 no_button.connect(gui.CLICK, self.clicked, False)
98 tbl.td(no_button, align=-1) 97 tbl.td(no_button, align=-1)
98 if maybe_choice:
99 maybe_button = gui.Button(maybe_choice)
100 maybe_button.connect(gui.CLICK, self.clicked, 2)
101 tbl.td(maybe_button, align=1)
102 else:
103 tbl.td(gui.Spacer(0, 15))
104 yes_button = gui.Button(yes_choice)
105 yes_button.connect(gui.CLICK, self.clicked, 1)
99 tbl.td(yes_button, align=1) 106 tbl.td(yes_button, align=1)
100 gui.Dialog.__init__(self, title, tbl, **params) 107 gui.Dialog.__init__(self, title, tbl, **params)
101 108
102 def clicked(self, val): 109 def clicked(self, val):
103 self._sure_func(val) 110 self._sure_func(val)