- 追加された行はこの色です。
- 削除された行はこの色です。
*E71:PyS60でテキストエディタを作ってみる [#qb5edbb9]
PyS60のアプリ作成の勉強がてら、テキストエディタを作ってみました。
■出来ること&br;
ファイルは固定で「e:\other\text.txt」を使い
-ファイルのオープン
-編集内容の保存
ができます。
勉強要素としては、
-基本的なPyS60アプリの作り方について
-メニューの作り方について
-appuifw.Textについて
-PyS60の文字コードについて
-PyS60(Python)のエラー処理
-appuifw.Text
-PyS60の文字コード
以下はソースコード
■testedit.py
import appuifw
import e32
import sys
sys.setdefaultencoding('utf-8')
text = appuifw.Text()
appuifw.app.body = text
appuifw.app.screen = 'normal'
filename = "e:/others/text.txt"
lock = e32.Ao_lock()
def exit():
lock.signal()
def menu_new():
text.set('')
def menu_open():
try:
f = open(filename,'r')
text.set('')
for line in f:
text.add(unicode(line,'utf-8'))
f.close()
except IOError:
appuifw.note(u'Cannot open file.','error')
# appuifw.note(str(IOError),'error')
# text.set(unicode(str(IOError),'utf-8'))
def menu_save():
out = text.get()
# if out == None:
# out = ''
try:
f = open(filename,'w')
f.write(out)
f.flush()
f.close()
except IOError:
appuifw.note(u'Cannot save file.','error')
appuifw.app.exit_key_handler = exit
appuifw.app.menu = [(u'new',menu_new),(u'open',menu_open),(u'save',menu_save)]
lock.wait()
*参考にしたサイト [#u1cbb459]
ライブラリリファレンス(公式?:日本語)のファイルオブジェクト
-http://www.python.jp/doc/release/lib/bltin-file-objects.html
Textの使い方とか
-http://mp.unoji.com/docs/pys60/tutorial/textui.html
ダイアログの使い方
-http://www.leninsgodson.com/courses/pys60/info_dialogue_notes.htm
ファイルの読み書きについて
-http://d.hatena.ne.jp/kakurasan/20090309/p1
文字コードのエンコーディング設定について
-http://morchin.sakura.ne.jp/effective_python/encoding.html