Changeset 306

Show
Ignore:
Timestamp:
05/10/09 14:46:07 (3 years ago)
Author:
ocjhb
Message:

more ui improvements

Location:
trunk/sandbox/jhb
Files:
2 modified

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  
     1import appuifw,e32 
    122 
    133class WalletClient: 
     
    188        self.wallet.getApproval = self.getApproval 
    199        self.wallet.feedback = self.feedback 
    20         self.makeWalletMenu() 
    2110        self.displayWalletMenu()         
    2211        self.actions=[(u'Send',u'Send coins to someone',self.spendCoins), 
     
    4837            self.wallet_menu.bind(EKeyRightArrow,self.displayActionMenu) 
    4938 
    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      
    5346 
    5447    def displayWalletMenu(self): 
     48        self.makeWalletMenu() 
    5549        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' 
    5751        appuifw.app.menu = [(u'add Currency',self.addCurrency), 
    5852                            (u'delete Currency',self.delCurrency)] 
     
    6559        self.action_menu.bind(EKeyLeftArrow,self.displayWalletMenu) 
    6660        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 
    6863        #print 'displayActionMenu' 
    6964 
     
    117112        self.currency_menu.bind(EKeyLeftArrow,self.displayActionMenu) 
    118113        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 
    120115  
    121116    def inspectCoin(self): 
     
    133128        self.coin_menu.bind(EKeyLeftArrow,self.inspectCurrency) 
    134129        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 
    136131  
    137132    def addCurrency(self): 
     
    140135        transport = self.getHTTPTransport(url)  
    141136        self.wallet.addCurrency(transport) 
    142         self.makeWalletMenu() 
    143137        self.displayWalletMenu() 
    144138 
     
    153147        if result: 
    154148            self.wallet.deleteCurrency(id) 
    155         self.makeWalletMenu() 
    156149        self.displayWalletMenu() 
    157150 
     
    171164        self.wallet.mintCoins(transport,amount,target) 
    172165        coinsound.play()  
    173         self.makeWalletMenu() 
    174166        self.displayWalletMenu() 
    175167 
     
    189181        transport = self.getHTTPTransport(url) 
    190182        self.wallet.redeemCoins(transport,amount,target) 
    191         self.makeWalletMenu() 
    192183        self.displayWalletMenu() 
    193184 
     
    198189        self.wallet.freshenUp(transport,cdd) 
    199190        coinsound.play()  
    200         self.makeWalletMenu() 
    201191        self.displayWalletMenu() 
    202192 
     
    207197 
    208198    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?') 
    211201 
    212202        cdd,alreadythere = self.getCurrentCurrency() 
    213203        transport = self.getHTTPTransport(cdd.issuerServiceLocation) 
    214204 
    215         if method ==1: 
     205        if method ==0: 
    216206            self.receiveCoinsBT(transport) 
    217207        else: 
     
    219209 
    220210        coinsound.play()  
    221         self.makeWalletMenu() 
    222211        self.displayWalletMenu() 
    223212     
     
    259248         
    260249        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') 
    262251        httpd.handle_request() 
    263252        httpd.handle_request() 
     
    292281            btsocket.bt_advertise_service( u"opencoin", server_socket, True, btsocket.RFCOMM) 
    293282            btsocket.set_security(server_socket, btsocket.AUTH) 
    294             self.feedback(u'waiting for bt connection') 
     283            self.feedback(u'Receive coins: ready to receive...') 
    295284            (sock,peer_addr) = server_socket.accept() 
    296285 
     
    326315            return 
    327316             
    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?') 
    330319 
    331320 
    332321        cdd,alreadythere = self.getCurrentCurrency() 
    333         if method == 0: 
     322        if method == 1: 
    334323            url = appuifw.query(u'url','text',u'http://192.168.2.105:9091') 
    335324            transport = self.getHTTPTransport(url) 
     325            self.wallet.spendCoins(transport,cdd.currencyId,amount,target) 
    336326        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 
    341332        self.displayWalletMenu() 
    342333 
     
    347338        amount = message.amount 
    348339        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') 
    352344     
    353345 
     
    359351            import sys 
    360352            if sys.platform == 'symbian_s60': 
     353                self.feedback(u'Preparing internet access:searching access points') 
     354                e32.ao_sleep(1) 
    361355                import socket 
    362                 appuifw.note(u'Preparing access points') 
    363356                aps = [ap['name'] for ap in socket.access_points()] 
    364357                aps.sort() 
    365358                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 
    366362                socket.set_default_access_point(aps[apid]) 
    367363                self.ip = 'some ip, s60' 
     
    375371        pass 
    376372 
    377  
    378      
     373def 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 
     379def startup(text): 
     380    status('Welcome to opencoin!:loading... '+text) 
     381############################### main code ############################         
     382app_lock = e32.Ao_lock() 
     383appuifw.app.screen='normal' 
     384appuifw.app.exit_key_handler = app_lock.signal 
     385 
     386startup('network') 
     387import httplib, urllib 
     388startup('graphics') 
     389from graphics import * 
     390startup('ui') 
     391import audio 
     392import sys 
     393import encodings 
     394from key_codes import EKeyLeftArrow, EKeyRightArrow 
     395 
     396startup('storage') 
     397from oc2 import storage 
     398startup('oc wallet') 
     399from oc2 import wallet 
     400startup('transports') 
     401from oc2 import transports 
     402 
     403 
     404startup('media') 
     405icon = appuifw.Icon(u'e:\\python\\coin_icon.mif',16384,16385) 
     406coinsound = audio.Sound.open('e:\\python\\coinsound.wav') 
     407 
    379408 
    380409#appuifw.app.screen='full' 
    381 app_lock = e32.Ao_lock() 
     410startup('coins') 
    382411storage = storage.Storage() 
    383412storage.setFilename('wallet.bin') 
    384413storage.restore() 
    385  
     414startup('done') 
    386415w = WalletClient(storage) 
    387 appuifw.app.screen='normal' 
    388 appuifw.app.exit_key_handler = app_lock.signal 
    389416import time 
    390417app_lock.wait() 
     418status('Shut down:saving data...') 
    391419storage.save() 
    392 print 'fini' 
     420status('Shut down:exit') 
     421time.sleep(1) 
  • trunk/sandbox/jhb/oc2/wallet.py

    r305 r306  
    3737 
    3838    def askLatestCDD(self,transport): 
    39         self.feedback('fetching latest CDD') 
     39        self.feedback('Talking to issuer: fetching latest CDD') 
    4040        response = transport(messages.AskLatestCDD()) 
    4141        return response.cdd 
     
    5050        message.denominations = [str(d) for d in denominations] 
    5151        message.keyids = keyids 
    52         self.feedback('fetching mintkeys') 
     52        self.feedback('Talking to issuer: fetching mintkeys') 
    5353        response = transport(message) 
    5454        if response.header == 'MINTING_KEY_FAILURE': 
     
    7474        message.coins = coins 
    7575        message.options = dict(type=requesttype).items() 
    76         self.feedback('request %s' % requesttype) 
     76        self.feedback('Talking to issuer: request %s' % requesttype) 
    7777        response = transport(message) 
    7878        return response 
     
    312312        tid = self.makeSerial() 
    313313         
    314         self.feedback(u'Announcing transfer') 
     314        self.feedback(u'Spending coins: wating for confirmation') 
    315315        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') 
    317317        response = self.requestSpend(transport,tid,picked) 
    318318        if response == True: