Source

wd_pys60 / wd_li.py

Full commit
# -*- coding: utf-8 -*-
second=1
minute=second*60
hour=minute*60
day=hour*24
year=day*365
argumentsKeys=["year", "day" , "hour" , "minute","second"]
arguments={"year": year, "day" :day, "hour" : hour, "minute" : minute,"second":second}
import time

NOW=int(time.time())
def getLastTime(time):
    timeList=[]
    result="-"
    t=NOW-time
    lastNum=0
    if t<0:
        return result+"right-now"
    for key in argumentsKeys:
        num=t/arguments[key]
        timeList.append(num)
        if lastNum!=0:
            result+=str(num)+key+"s"
            return result+"--ago"
        lastNum=num
        if num:
            result+=str(num)+key+"s"
        t=t%arguments[key]
    return result+"--ago"
def cn(x):
    return x.decode("utf8")
def de(x):
    return x.decode("utf8")
def en(x):
    return x.encode("utf8")
import e32,graphics
import appuifw
import clipboard_CHN
import e32dbm
import random
import time
path="e:\\wd_db_test"

def clipAndMod(key):
    global app_lock
    value=db[key]
    appuifw.app.screen='normal'
    appuifw.app.title = unicode(getLastTime(int(key)))
    appuifw.app.body = text=appuifw.Text()
    text.add(cn(value))
    clipboard_CHN.Set(value)
    app_lock.wait()

def save(key,value):
    db[key]=value
db = e32dbm.open(path, 'c')
stime=time.clock()
def generateData(value):
    #key=str(random.randint(0,1234))
    key=str(int(time.time()))
    #key=str(i)
    db[key]=value
    #print i,key
    value=de(db[key])
    popmenu.append(value[:10])
    
popmenu=[]
KEYS=[int(key) for key in db.keys()]
KEYS.sort()
def displayData():
    for key in KEYS:
        key=str(key)
        value=de(db[key])
        popmenu.append(value[:10])
        #lark.scr.link(value,color=random.randint(0,0xffffff),align='left',font=u'Sans MT 936_S60',func=lambda key=key:clipAndMod(key))


def quit():
    app_lock.signal()

def main():
    displayData()
    appuifw.app.screen='normal'
    appuifw.app.exit_key_handler = quit
    appuifw.app.title=u"li"
    appuifw.app.menu=[((cn('输入'),lambda:generateData(value=en(appuifw.query(u'\u8f93\u5165',"text")))))]
    index = appuifw.popup_menu(popmenu, u"Select:") 
    clipAndMod(str(KEYS[index]))
if __name__ == '__main__':
    app_lock = e32.Ao_lock()
    main()
    app_lock.wait()