Changeset 150
- Timestamp:
- 04/20/08 21:10:28 (6 months ago)
- Files:
-
- sucrose/trunk/python/keypad_tk.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sucrose/trunk/python/keypad_tk.py
r143 r150 2 2 3 3 import Tkinter 4 import sys 5 import os 4 import logging, os, sys 6 5 7 6 from api import user_interface, authenticator … … 11 10 A Tkinter frontend for selecting an item in a classic keypad manner 12 11 """ 12 13 # XXX change to use SysLogHandler? 14 logging.basicConfig(level=logging.DEBUG, 15 format='%(asctime)s %(levelname)-8s %(message)s', 16 datefmt='%F %T') 13 17 14 18 class TkinterUI(user_interface.UserInterface): … … 37 41 38 42 self.window = Tkinter.Tk() 43 self.window.title('Sucrose') 44 self.window.geometry('800x600+0+0') 39 45 if __name__ != '__main__': 40 46 cursor_file = os.path.join(os.path.dirname(__file__), 41 47 'emptycursor.xbm') 42 48 self.window.config(cursor='@%s white' % cursor_file) 43 self.window.title('Sucrose') 44 self.window.geometry('800x600+0+0') 45 self.window.resizable(False, False) 49 self.window.resizable(False, False) 50 self.window.after(10, lambda: 51 self.window.event_generate('<<Motion>>', 52 warp=True, x=0, y=0)) 46 53 self.window.focus_set() 47 54 … … 69 76 font=('helvetica', 24, 'bold'), command=self.destroy).\ 70 77 grid(row=0, column=1, sticky=Tkinter.E) 78 79 Tkinter.Label(self.window, text='Vending error? Suggestions? ' 80 'Email sucrose@acm.uiuc.edu', 81 font=('helvetica', 12, 'bold')).\ 82 grid(row=2, column=0, columnspan=2, sticky=Tkinter.NSEW) 83 84 logging.info('%s - Authenticated' % self.auth) 71 85 self.window.mainloop() 72 86 … … 98 112 self.window.destroy() 99 113 del self.window 114 # XXX we sometimes don't exit here, can't reproduce it though 100 115 101 116 … … 121 136 122 137 self.sucrose = sucrose 123 self.d istruct = exit138 self.destruct = exit 124 139 self.location = location 125 140 self.tray = None … … 191 206 self.update_f = update_f 192 207 self.sucrose = sucrose 193 self.d istruct = exit208 self.destruct = exit 194 209 self.location = location 195 210 … … 249 264 return lambda: self.button_callback(number) 250 265 251 def report_exception(self, e): 266 def report_exception(self, e=''): 267 if e and not isinstance(e, ValueError): 268 logging.exception('Unexpected exception') 252 269 self.location.config(text=self.item_location) 253 270 self.name.config(text=str(e), fg='red') … … 260 277 261 278 tray = self.sucrose.tray_from_location(self.item_location) 262 263 except ValueError, e: 279 except Exception, e: 264 280 self.report_exception(e) 265 281 tray = None 266 except Exception, e:267 import traceback; traceback.print_exc()268 self.report_exception(e)269 tray = None270 282 271 283 self.update_f(tray) 272 284 273 285 def reset(self): 274 self.item_location="00" 275 self.location.config(text=self.item_location) 276 self.name.config(text="") 277 self.vend.config(state=Tkinter.DISABLED) 278 286 self.item_location = '00' 287 self.report_exception() 288 289 self.update_f(None) 279 290 280 291 def vend(self): # Vend Sucrose, and exit 281 292 self.name.config(text='Vending: %s' % self.item_name()) 293 logging.info('%s - Vending %s' % (self.auth, self.item.name)) 282 294 try: 283 295 self.sucrose.vend(self.tray,self.auth.uin) 296 self.auth = None # make sure we can't use auth again 284 297 except Exception, e: 285 import traceback; traceback.print_exc()298 logging.exception('Failed to vend') 286 299 self.name.config(text=str(e), fg='red') 287 300 return 288 301 289 self.d istruct()302 self.destruct() 290 303 291 304 … … 297 310 self.update_f = update_f 298 311 self.sucrose = sucrose 299 self.d istruct = exit312 self.destruct = exit 300 313 self.location = location 301 314 self.item = None … … 317 330 for y in range(0,4): 318 331 for x in range(0,3): 319 i =3*y+x+1332 i = 3*y+x+1 320 333 if i >= 10: 321 334 continue … … 330 343 331 344 # Special objects 332 reset =Tkinter.Button(self, text="Reset", command=self.reset,333 font=("helvetica", 24))345 reset = Tkinter.Button(self, text="Reset", command=self.reset, 346 font=("helvetica", 24)) 334 347 reset.grid(row=4,column=2,columnspan=2,sticky=Tkinter.NSEW) 335 348 336 self.vend =Tkinter.Button(self, text="Vend", command=self.vend,337 state=Tkinter.DISABLED,338 font=("helvetica", 24, 'bold'))349 self.vend = Tkinter.Button(self, text="Vend", command=self.vend, 350 state=Tkinter.DISABLED, 351 font=("helvetica", 24, 'bold')) 339 352 self.vend.grid(row=4,column=4,columnspan=2,sticky=Tkinter.NSEW) 340 353 … … 345 358 if __name__ == "__main__": 346 359 from api import sucrose 347 from dummy import Cardswipe360 from dummy import DummyAuthenticator 348 361 349 362 s = sucrose.Sucrose(db, dbonly=True) 350 # import pdb 351 # pdb.set_trace() 352 353 TkinterUI(s, Cardswipe(s)) 363 364 TkinterUI(s, DummyAuthenticator(s))
