暂时没有时间去研究中文的问题了。看到版里很多人多python写手机程序有兴趣就把源码发出来了。写的很乱。可以参考参考。 QQ:103315444 MSN:[email][email protected][/email]
#author:smallfish
#for:s60 python notebook
import appuifw
import e32
import os
import time
diary_root="e:/diary/"
title,content="",appuifw.Text()
def info(msg):
appuifw.note(unicode(msg),'info')
def error(msg):
appuifw.note(unicode(msg),'error')
def conf(msg):
appuifw.note(unicode(msg),'conf')
def init():
global diary_root
if os.path.isdir(diary_root):
info("Diary was inited!")
else:
os.makedirs(diary_root)
info("init success!")
def home_ui():
global title,content
title=''
content=appuifw.Text()
appuifw.app.title=u'Diary v1.0'
view_txt=appuifw.Text()
view_txt.set(u'Name:\t Diary\nVersion:\t 1.0\nAuthor:\t smallfish')
appuifw.app.body=view_txt
def save_diary():
global diary_root,title,content
if title!="" and content.get()!="":
result={}
result['title']=title
result['content']=content.get()
try:
file=diary_root+time.strftime("%Y%m%d%H%S%M")+".txt"
f=open(file,'w')
f.write(repr(result))
f.close()
conf("save success!\n"+file)
home_ui()
except:
info("save faile!\n"+file)
else:
info("no data to save!")
def write_ui():
global title,content
title_txt=appuifw.query(u'input diary title:','text')
content=appuifw.Text()
appuifw.app.title=title_txt
appuifw.app.body=content
title=title_txt
def view_ui():
global diary_root
appuifw.app.title=u'View Diary'
try:
diary_list=map(unicode,os.listdir(diary_root))
index=appuifw.selection_list(choices=diary_list,search_field=1)
file=diary_root+diary_list[index]
try:
f=open(file,'r')
result=f.read()
f.close();
data=eval(result)
title=data.get("title","")
content=data.get("content","")
appuifw.app.title=title
content_txt=appuifw.Text()
content_txt.set(content)
appuifw.app.body=content_txt
except:
info("open file faile!\n"+file)
except:
info("Error!please init!")
def quit():
if appuifw.query(u'Be Sure to Quit?','query'):
appuifw.app.set_exit()
app_lock=e32.Ao_lock()
home_ui()
appuifw.app.title=u'Diary v1.0'
appuifw.app.screen='normal'
appuifw.app.menu=[(u'init diary',init),(u'home',home_ui),(u'write diary',write_ui),(u'save diary',save_diary),
(u'view diary',view_ui),(u'quit',quit)]
appuifw.app.exit_key_handler=quit
app_lock.wait()
[ 本帖最后由 wolfg 于 2006-6-7 15:13 编辑 ]
wolfg 回复于:2006-06-07 15:12:35
菜单里想使用中文的话可以这样:
u'init diary' 改成
'初始化'.decode('utf8')
在S60 SDK的模拟器里试了你的程序,提示保存成功但找不到保存的文件,退出时会造成Python解释器也异常退出
[ 本帖最后由 wolfg 于 2006-6-7 15:16 编辑 ]
wolfg 回复于:2006-06-07 16:15:19
又试了一下,日记保存的目录需要改一下,模拟器里没有e盘,改成c就行了。 最好可以判断一下,根据具体情况设定保存目录,比如有的手机可以也没有e盘
退出时的异常还没找到原因
wolfg 回复于:2006-06-07 16:56:28
退出的代码改成这样就可以了,但不知道在手机上运行的效果
def quit():
if appuifw.query(u'Be Sure to Quit?','query'):
appuifw.app.exit_key_handler = None
app_lock.signal()
|