Changeset 306
- Timestamp:
- 05/10/09 14:46:07 (3 years ago)
- Location:
- trunk/sandbox/jhb
- Files:
-
- 2 modified
-
mobile/ocwallet.py (modified) (19 diffs)
-
oc2/wallet.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sandbox/jhb/mobile/ocwallet.py
r305 r306 1 import appuifw,e32,httplib, urllib 2 from graphics import * 3 from key_codes import EKeyLeftArrow, EKeyRightArrow 4 import encodings 5 from oc2 import storage,wallet, transports 6 import sys 7 import audio 8 9 icon = appuifw.Icon(u'e:\\python\\coin_icon.mif',16384,16385) 10 coinsound = audio.Sound.open('e:\\python\\coinsound.wav') 11 1 import appuifw,e32 12 2 13 3 class WalletClient: … … 18 8 self.wallet.getApproval = self.getApproval 19 9 self.wallet.feedback = self.feedback 20 self.makeWalletMenu()21 10 self.displayWalletMenu() 22 11 self.actions=[(u'Send',u'Send coins to someone',self.spendCoins), … … 48 37 self.wallet_menu.bind(EKeyRightArrow,self.displayActionMenu) 49 38 50 def feedback(self,message): 51 appuifw.note(unicode(message)) 52 39 def feedback(self,text): 40 #appuifw.note(unicode(message)) 41 status(unicode(text)) 42 #i = i=appuifw.InfoPopup() 43 #i.show(unicode(message), (0, 0), timeout*1000, 0, appuifw.EHCenterVCenter) 44 45 53 46 54 47 def displayWalletMenu(self): 48 self.makeWalletMenu() 55 49 appuifw.app.body = self.wallet_menu 56 appuifw.app.title = u'opencoin - main\nchoose your currency'50 appuifw.app.title = u'opencoin wallet\nall currencies' 57 51 appuifw.app.menu = [(u'add Currency',self.addCurrency), 58 52 (u'delete Currency',self.delCurrency)] … … 65 59 self.action_menu.bind(EKeyLeftArrow,self.displayWalletMenu) 66 60 appuifw.app.body = self.action_menu 67 appuifw.app.title = u'opencoin - currency\nSelect the action' 61 cdd,amount = self.getCurrentCurrency() 62 appuifw.app.title = u'%ss\nactions' % cdd.currencyId 68 63 #print 'displayActionMenu' 69 64 … … 117 112 self.currency_menu.bind(EKeyLeftArrow,self.displayActionMenu) 118 113 appuifw.app.body = self.currency_menu 119 appuifw.app.title = u' opencoin - currency\nCoins in wallet'114 appuifw.app.title = u'%ss\ncoin list' % id 120 115 121 116 def inspectCoin(self): … … 133 128 self.coin_menu.bind(EKeyLeftArrow,self.inspectCurrency) 134 129 appuifw.app.body = self.coin_menu 135 appuifw.app.title = u' opencoin - coin\nDetails of coin'130 appuifw.app.title = u'%ss\ncoin details' % id 136 131 137 132 def addCurrency(self): … … 140 135 transport = self.getHTTPTransport(url) 141 136 self.wallet.addCurrency(transport) 142 self.makeWalletMenu()143 137 self.displayWalletMenu() 144 138 … … 153 147 if result: 154 148 self.wallet.deleteCurrency(id) 155 self.makeWalletMenu()156 149 self.displayWalletMenu() 157 150 … … 171 164 self.wallet.mintCoins(transport,amount,target) 172 165 coinsound.play() 173 self.makeWalletMenu()174 166 self.displayWalletMenu() 175 167 … … 189 181 transport = self.getHTTPTransport(url) 190 182 self.wallet.redeemCoins(transport,amount,target) 191 self.makeWalletMenu()192 183 self.displayWalletMenu() 193 184 … … 198 189 self.wallet.freshenUp(transport,cdd) 199 190 coinsound.play() 200 self.makeWalletMenu()201 191 self.displayWalletMenu() 202 192 … … 207 197 208 198 def receiveCoins(self): 209 methodlist = [u' internet',u'bluetooth']210 method = appuifw.popup_menu(methodlist )199 methodlist = [u'bluetooth',u'internet'] 200 method = appuifw.popup_menu(methodlist,u'how to connect?') 211 201 212 202 cdd,alreadythere = self.getCurrentCurrency() 213 203 transport = self.getHTTPTransport(cdd.issuerServiceLocation) 214 204 215 if method == 1:205 if method ==0: 216 206 self.receiveCoinsBT(transport) 217 207 else: … … 219 209 220 210 coinsound.play() 221 self.makeWalletMenu()222 211 self.displayWalletMenu() 223 212 … … 259 248 260 249 httpd = BaseHTTPServer.HTTPServer(("",port),OCHandler) 261 appuifw.note(u'waiting at %s:%s' % ('localhost',port),'conf')250 self.feedback(u'waiting at %s:%s' % ('localhost',port),'conf') 262 251 httpd.handle_request() 263 252 httpd.handle_request() … … 292 281 btsocket.bt_advertise_service( u"opencoin", server_socket, True, btsocket.RFCOMM) 293 282 btsocket.set_security(server_socket, btsocket.AUTH) 294 self.feedback(u' waiting for bt connection')283 self.feedback(u'Receive coins: ready to receive...') 295 284 (sock,peer_addr) = server_socket.accept() 296 285 … … 326 315 return 327 316 328 methodlist = [u' internet',u'bluetooth']329 method = appuifw.popup_menu(methodlist )317 methodlist = [u'bluetooth',u'internet'] 318 method = appuifw.popup_menu(methodlist,u'how to connect?') 330 319 331 320 332 321 cdd,alreadythere = self.getCurrentCurrency() 333 if method == 0:322 if method == 1: 334 323 url = appuifw.query(u'url','text',u'http://192.168.2.105:9091') 335 324 transport = self.getHTTPTransport(url) 325 self.wallet.spendCoins(transport,cdd.currencyId,amount,target) 336 326 else: 337 transport = self.getBTTransport() 338 339 self.wallet.spendCoins(transport,cdd.currencyId,amount,target) 340 self.makeWalletMenu() 327 ready =self.query('Is the other side ready to receive?') 328 if ready: 329 transport = self.getBTTransport() 330 self.wallet.spendCoins(transport,cdd.currencyId,amount,target) 331 341 332 self.displayWalletMenu() 342 333 … … 347 338 amount = message.amount 348 339 target = message.target 349 return appuifw.query(u'Accept %s (ref "%s")?' % (amount,target),'query') 350 351 340 return self.query(u'"%s": accept %s coins?' % (target,amount)) 341 342 def query(self,text): 343 return appuifw.query(unicode(text),'query') 352 344 353 345 … … 359 351 import sys 360 352 if sys.platform == 'symbian_s60': 353 self.feedback(u'Preparing internet access:searching access points') 354 e32.ao_sleep(1) 361 355 import socket 362 appuifw.note(u'Preparing access points')363 356 aps = [ap['name'] for ap in socket.access_points()] 364 357 aps.sort() 365 358 apid = appuifw.popup_menu(aps,u'select access point') 359 self.feedback(u'Preparing internet access:setting access point') 360 e32.ao_sleep(1) 361 366 362 socket.set_default_access_point(aps[apid]) 367 363 self.ip = 'some ip, s60' … … 375 371 pass 376 372 377 378 373 def status(text): 374 if ':' in text: 375 appuifw.app.body = appuifw.Listbox([tuple([unicode(p.strip()) for p in text.split(':')]),], lambda:None) 376 else: 377 appuifw.app.body = appuifw.Listbox([unicode(text)], lambda: None) 378 379 def startup(text): 380 status('Welcome to opencoin!:loading... '+text) 381 ############################### main code ############################ 382 app_lock = e32.Ao_lock() 383 appuifw.app.screen='normal' 384 appuifw.app.exit_key_handler = app_lock.signal 385 386 startup('network') 387 import httplib, urllib 388 startup('graphics') 389 from graphics import * 390 startup('ui') 391 import audio 392 import sys 393 import encodings 394 from key_codes import EKeyLeftArrow, EKeyRightArrow 395 396 startup('storage') 397 from oc2 import storage 398 startup('oc wallet') 399 from oc2 import wallet 400 startup('transports') 401 from oc2 import transports 402 403 404 startup('media') 405 icon = appuifw.Icon(u'e:\\python\\coin_icon.mif',16384,16385) 406 coinsound = audio.Sound.open('e:\\python\\coinsound.wav') 407 379 408 380 409 #appuifw.app.screen='full' 381 app_lock = e32.Ao_lock()410 startup('coins') 382 411 storage = storage.Storage() 383 412 storage.setFilename('wallet.bin') 384 413 storage.restore() 385 414 startup('done') 386 415 w = WalletClient(storage) 387 appuifw.app.screen='normal'388 appuifw.app.exit_key_handler = app_lock.signal389 416 import time 390 417 app_lock.wait() 418 status('Shut down:saving data...') 391 419 storage.save() 392 print 'fini' 420 status('Shut down:exit') 421 time.sleep(1) -
trunk/sandbox/jhb/oc2/wallet.py
r305 r306 37 37 38 38 def askLatestCDD(self,transport): 39 self.feedback(' fetching latest CDD')39 self.feedback('Talking to issuer: fetching latest CDD') 40 40 response = transport(messages.AskLatestCDD()) 41 41 return response.cdd … … 50 50 message.denominations = [str(d) for d in denominations] 51 51 message.keyids = keyids 52 self.feedback(' fetching mintkeys')52 self.feedback('Talking to issuer: fetching mintkeys') 53 53 response = transport(message) 54 54 if response.header == 'MINTING_KEY_FAILURE': … … 74 74 message.coins = coins 75 75 message.options = dict(type=requesttype).items() 76 self.feedback(' request %s' % requesttype)76 self.feedback('Talking to issuer: request %s' % requesttype) 77 77 response = transport(message) 78 78 return response … … 312 312 tid = self.makeSerial() 313 313 314 self.feedback(u' Announcing transfer')314 self.feedback(u'Spending coins: wating for confirmation') 315 315 self.announceSum(transport,tid,amount,target) 316 self.feedback(u' Transferring coins. Wating for other side...')316 self.feedback(u'Spending coins: wating for other side') 317 317 response = self.requestSpend(transport,tid,picked) 318 318 if response == True:
