Changeset 118
- Timestamp:
- 04/13/08 21:39:27 (5 months ago)
- Files:
-
- sucrose/trunk/python/keypad_tk.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sucrose/trunk/python/keypad_tk.py
r114 r118 20 20 setattr(self, view_name, view) 21 21 button = Tkinter.Button(self.switcher, text=view_name, 22 font=('helvetica', 24 , 'bold'),22 font=('helvetica', 24), 23 23 command=lambda: self.switch_view(view)) 24 24 button.pack(side=Tkinter.LEFT, expand=True) … … 49 49 50 50 self.current_view = None 51 self.make_view('Nutrition', Nutrition(sucrose, auth, self.update, 52 exit=self.destroy)) 51 53 self.make_view('Statistics', Statistics(sucrose, auth, self.update, 52 54 exit=self.destroy)) 53 self.make_view('Nutrition', Nutrition(sucrose, auth, self.update,54 exit=self.destroy))55 55 56 56 self.switch_view(self.current_view) … … 87 87 88 88 class Statistics(Tkinter.Frame): 89 ROWS = (('NetID', lambda self: self.user.netid), 90 ('Balance', lambda self: 91 '$%.2f' % self.sucrose.balance_for_user(self.user))) 92 89 93 def update(self, tray): 90 return 94 pass 95 # self.tray = tray 96 # for name, func in self.ROWS: 97 # label = self.labels[name] 98 # label.config(text=func(self)) 91 99 92 100 def __init__(self, sucrose, auth, update_f, exit=None, location=None, … … 100 108 self.distruct = exit 101 109 self.location = location 102 103 user = auth.authenticated_user() 104 105 vending = self.sucrose.vending.filter_by(uid=self.user.uid) 106 transactions = self.sucrose.transactions.filter_by(user_id=self.user.uid) 107 110 self.tray = None 111 112 self.user = auth.authenticated_user() 113 self.labels = {} 108 114 109 115 # { BEGIN statistics GUI 110 Tkinter.Label(self, text=self.user.netid, font=("helvetica", 36)) \ 111 .grid(row=0,column=0,sticky=Tkinter.NSEW) 112 113 Tkinter.Label(self, text="Balance", font=("helvetica", 36)) \ 114 .grid(row=1,column=0,sticky=Tkinter.NSEW) 115 Tkinter.Label(self, text="$"+self.vending.balance, font=("helvetica", 36)) \ 116 117 .grid(row=1,column=1,sticky=Tkinter.NSEW) 118 Tkinter.Label(self, text="Last 5 Purchases:", font=("helvetica", 36)) \ 119 .grid(row=1,column=0,sticky=Tkinter.NSEW) 120 for i in range(0,4): 121 item = self.sucrose.items.filter_by(item_id=transactions[i].item_id) 122 Tkinter.Label(self, text=item.name, font=("helvetica", 36)) \ 123 .grid(row=1,column=0,sticky=Tkinter.NSEW) 124 Tkinter.Label(self, text=item_id=transactions[i].cost, font=("helvetica", 36)) \ 125 .grid(row=1,column=1,sticky=Tkinter.NSEW) 116 for row, (name, func) in enumerate(self.ROWS): 117 Tkinter.Label(self, text=name + ' ', anchor=Tkinter.W, 118 font=("helvetica", 24, 'bold'), bg='white').grid( 119 row=row, column=0, columnspan=2, sticky=Tkinter.EW) 120 val_label = \ 121 Tkinter.Label(self, text=func(self), anchor=Tkinter.E, 122 font=("helvetica", 24), bg='white') 123 val_label.grid(row=row, column=2, columnspan=2, sticky=Tkinter.EW) 124 125 self.labels[name] = val_label 126 127 purchases = self.sucrose.recent_purchases_for_user(self.user) 128 if not purchases: 129 return 130 131 Tkinter.Label(self, text='', font=('helvetica', 24, 'bold')).grid( 132 row=row+1, column=0, columnspan=2, sticky=Tkinter.NSEW) 133 Tkinter.Label(self, text='Recent Purchases', font=('helvetica', 13, 'bold')\ 134 ).grid(row=row+2, column=0, columnspan=2, sticky=Tkinter.NSEW) 135 136 offset = row + 3 137 for row, (name, price) in enumerate(purchases): 138 Tkinter.Label(self, text=name, font=('helvetica', 13), 139 anchor=Tkinter.W, justify=Tkinter.LEFT, wraplength=200, 140 bg='white').grid(row=offset + row, column=0, columnspan=3, 141 sticky=Tkinter.EW) 142 Tkinter.Label(self, text='$%.2f' % price, font=('helvetica', 13), 143 anchor=Tkinter.E, justify=Tkinter.RIGHT, 144 bg='white').grid(row=offset + row, column=3, 145 sticky=Tkinter.EW) 126 146 # } END statistics GUI 127 147 … … 184 204 return 185 205 186 self.item_location=str(tray.machine_tray_id)187 206 self.item = self.sucrose.item_from_tray(self.tray) 188 207 … … 191 210 text=getattr(self.item, 'name', '').replace('(', '\n('), 192 211 fg='black') 212 self.price.config(text='$%.2f' % self.tray.cur_price) 193 213 194 214 self.auth.authenticate_purchase(self.item_location) … … 210 230 self.location.config(text=self.item_location) 211 231 self.name.config(text=str(e), fg='red') 232 self.price.config(text='') 212 233 tray = None 213 except :234 except Exception, e: 214 235 import traceback; traceback.print_exc() 215 236 self.location.config(text=self.item_location) 216 237 self.name.config(text=str(e), fg='red') 238 self.price.config(text='') 217 239 tray = None 218 240 … … 220 242 221 243 def reset(self): 222 # If the location is 00, quit, else reset the display 223 if self.item_location == "00": 224 self.distruct() 225 else: 226 self.item_location="00" 227 self.location.config(text=self.item_location) 228 self.name.config(text="") 229 self.vend.config(state=Tkinter.DISABLED) 244 self.item_location="00" 245 self.location.config(text=self.item_location) 246 self.name.config(text="") 247 self.vend.config(state=Tkinter.DISABLED) 230 248 231 249 … … 248 266 249 267 # { BEGIN keypad GUI 250 Tkinter.Button(self, text=" 0 ", command=self.make_button_callback(0), 251 font=("helvetica",48)).grid( 252 row=4,column=0,sticky=Tkinter.NSEW) 268 269 self.item_location="00" 270 self.location=Tkinter.Label(self, text=self.item_location, 271 font=("helvetica", 48)) 272 self.location.grid(row=0,column=0,sticky=Tkinter.NSEW) 273 274 self.name = Tkinter.Label(self, text="", 275 font=('helvetica', 13, 'bold'), 276 wraplength=200) 277 self.name.grid(row=0,column=1,columnspan=4,sticky=Tkinter.NSEW) 278 279 self.price = Tkinter.Label(self, text='', 280 font=('helvetica', 24, '')) 281 self.price.grid(row=0, column=5, sticky=Tkinter.E) 253 282 254 283 for y in range(0,4): … … 259 288 callback=self.make_button_callback(i) 260 289 Tkinter.Button(self, text=' %d ' % i, command=callback, 261 font=("helvetica", 48)).grid( 262 row=y+1,column=x,sticky=Tkinter.NSEW) 290 font=("helvetica", 72)).grid( 291 row=y+1,column=x*2,columnspan=2,sticky=Tkinter.NSEW) 292 293 Tkinter.Button(self, text=" 0 ", command=self.make_button_callback(0), 294 font=("helvetica",72)).grid( 295 row=4,column=0,columnspan=2,sticky=Tkinter.NSEW) 263 296 264 297 # Special objects 265 298 reset=Tkinter.Button(self, text="Reset", command=self.reset, 266 299 font=("helvetica", 24)) 267 reset.grid(row=4,column= 1,sticky=Tkinter.NSEW)300 reset.grid(row=4,column=2,columnspan=2,sticky=Tkinter.NSEW) 268 301 269 302 self.vend=Tkinter.Button(self, text="Vend", command=self.vend, 270 303 state=Tkinter.DISABLED, 271 304 font=("helvetica", 24, 'bold')) 272 self.vend.grid(row=4,column=2,sticky=Tkinter.NSEW) 273 274 self.item_location="00" 275 self.location=Tkinter.Label(self, text=self.item_location, 276 font=("helvetica", 48)) 277 self.location.grid(row=0,column=0,sticky=Tkinter.NSEW) 278 279 self.name = Tkinter.Label(self, text="", 280 font=('helvetica', 13, ''), 281 wraplength=180) 282 self.name.grid(row=0,column=1,columnspan=3,sticky=Tkinter.NSEW) 305 self.vend.grid(row=4,column=4,columnspan=2,sticky=Tkinter.NSEW) 283 306 284 307 self.grid()
