E71:PyS60でテキストエディタを作ってみる のバックアップ(No.1)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- ソース を表示
- E71:PyS60でテキストエディタを作ってみる へ行く。
- 1 (2009-08-27 (木) 00:33:51)
- 2 (2009-08-27 (木) 00:39:28)
E71:PyS60でテキストエディタを作ってみる †
PyS60のアプリ作成の勉強がてら、テキストエディタを作ってみました。
勉強要素としては、
- 基本的なPyS60アプリの作り方について
- メニューの作り方について
- appuifw.Textについて
- PyS60の文字コードについて
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()