Changeset 315

Show
Ignore:
Timestamp:
05/20/09 16:52:51 (3 years ago)
Author:
ocjhb
Message:

improving input forms

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/sandbox/jhb/mobile/ocwallet.py

    r314 r315  
    4040 
    4141    def feedback(self,text): 
    42         #appuifw.note(unicode(message)) 
    4342        status(unicode(text)) 
    44         #i = i=appuifw.InfoPopup() 
    45         #i.show(unicode(message), (0, 0), timeout*1000, 0, appuifw.EHCenterVCenter) 
    46          
    47       
     43         
    4844 
    4945    def displayWalletMenu(self): 
     
    7167 
    7268 
    73     def getAmount(self): 
    74         amount = appuifw.query(u'Amount','number') 
    75         amount = int(amount) 
     69    def getAmount(self,min=1,max=-1): 
     70        ok = False   
     71        text = ['Amount'] 
     72        text.append('min %s' % min) 
     73        if max != -1: 
     74            text.append('max %s' % max) 
     75        text = u', '.join([unicode(t) for t in text])                 
     76        while not ok: 
     77            amount = appuifw.query(text,'number') 
     78            if amount: 
     79                amount = int(amount) 
     80                if amount < min: 
     81                    appuifw.note(u'amount to small','error') 
     82                    continue 
     83                if max != -1 and amount > max: 
     84                    appuifw.note(u'amount to large','error') 
     85                    continue 
     86            ok = True                     
     87 
    7688        self.todo['amount'] = amount 
    7789        return amount 
     
    8395        self.todo['target'] = target 
    8496        return target             
    85  
    86     def getDetails(self): 
    87          
    88         amount = self.getAmount() 
    89         if not amount: 
    90             return 
    91  
    92         target = self.getTarget() 
    93         if not target: 
    94             return 
    95  
    96         method = self.getMethod() 
    97         if method ==1: 
    98             url = appuifw.query(u'url','text',u'http://') 
    99             self.todo['url'] = url 
    100  
    101         self.execute() 
    10297 
    10398 
     
    170165 
    171166    def redeemCoins(self): 
    172         amount = self.getAmount() 
     167        cdd,alreadythere = self.getCurrentCurrency() 
     168        amount = self.getAmount(max=alreadythere) 
    173169        if not amount: 
    174170            return 
     
    178174            return 
    179175 
    180         cdd,alreadythere = self.getCurrentCurrency() 
    181176        url = cdd.issuerServiceLocation 
    182177 
     
    194189 
    195190 
    196     def execute(self): 
    197         #print 'execute' 
    198         print self.todo 
    199  
    200191    def receiveCoins(self): 
    201192        methodlist = [u'bluetooth',u'internet'] 
     
    207198            self.receiveCoinsBT(transport) 
    208199        else: 
    209             port = int(appuifw.query(u'port','number',9091)) 
    210200            transport = self.getHTTPTransport(cdd.issuerServiceLocation) 
    211             self.receiveCoinsHTTP(transport,port) 
     201            self.receiveCoinsHTTP(transport,walletport) 
    212202 
    213203        coinsound.play()  
     
    250240        #ip = urllib.urlopen('http://opencoin.org/myownip').read() 
    251241        httpd = BaseHTTPServer.HTTPServer(("",port),OCHandler) 
    252         self.feedback(u'Receiving coins: waiting at %s:%s' % (self.ip,port)) 
     242        self.feedback(u'Receiving coins: waiting at %s' % (self.ip)) 
    253243        httpd.handle_request() 
    254244        httpd.handle_request() 
     
    338328    def spendCoins(self): 
    339329 
    340         amount = self.getAmount() 
     330        cdd,alreadythere = self.getCurrentCurrency() 
     331         
     332        amount = self.getAmount(max=alreadythere) 
    341333        if not amount: 
    342334            return 
     
    350342 
    351343 
    352         cdd,alreadythere = self.getCurrentCurrency() 
    353344        if method == 1: 
    354             url = appuifw.query(u'url','text',u'http://192.168.2.105:9091') 
     345            url = appuifw.query(u'address','text',u'192.168.2.105') 
     346            if not url: 
     347                return                 
     348            else:      
     349                url = 'http://%s:%s' % (url,walletport) 
    355350            transport = self.getHTTPTransport(url) 
    356351            self.wallet.spendCoins(transport,cdd.currencyId,amount,target) 
     
    381376        if not self.ip: 
    382377            import sys 
     378            import socket 
    383379            if sys.platform == 'symbian_s60': 
    384380                self.feedback(u'Preparing internet access:searching access points') 
    385                 import socket 
    386381                aps = [ap['name'] for ap in socket.access_points()] 
    387382                aps.sort() 
     
    390385 
    391386                socket.set_default_access_point(aps[apid]) 
    392                 #one time socket, for just finding out our ip 
    393                 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    394                 #anonymity issue here 
    395                 s.connect(('www.google.com',80)) 
    396                 self.ip = s.getsockname()[0] 
    397  
     387            
    398388            else: 
    399389                import socket 
    400390                self.ip = 'some ip' 
    401391             
     392            #one time socket, for just finding out our ip 
     393            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
     394            #anonymity issue here 
     395            s.connect(('www.google.com',80)) 
     396            self.ip = s.getsockname()[0] 
     397 
    402398 
    403399    def stopInternet(self): 
     
    424420 
    425421def startup(text): 
    426     status('opencoin: loading '+text,icons['restore']) 
     422    if sys.platform == 'symbian_s60': 
     423        status('opencoin: loading '+text,icons['restore']) 
     424 
     425 
     426 
    427427############################### main code ############################         
     428walletport = 9091 
    428429app_lock = e32.Ao_lock() 
    429430appuifw.app.screen='normal'