トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

E71:PyS60でテキストエディタを作ってみる の変更点

Top / E71:PyS60でテキストエディタを作ってみる

*E71:PyS60でテキストエディタを作ってみる [#qb5edbb9]

PyS60のアプリ作成の勉強がてら、テキストエディタを作ってみました。

■出来ること&br;
ファイルは固定で「e:\other\text.txt」を使い
-ファイルのオープン
-編集内容の保存

ができます。

勉強要素としては、

-基本的な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