用Python + OpenVanilla寫輸入法
繼Ruby-based OpenVanilla filter module後,OV和script language相關的進展又一彈:用Python撰寫輸入法。
orcas先前先是幫OpenVanilla撰寫了Python-based、可動態載入的filter module。後來又開始研究用SWIG來包裝OV的C++物件,讓Python也可以拿來撰寫輸入法。於是我們有了以下的code:
# -*- coding: utf-8 -*-
import sys
import OVIMPython
class PYIMTestContext(OVIMPython.OVInputMethodContext):
def keyEvent(self, keycode, buf, candidate, srv):
char = chr(keycode.code())
buf.append(char).update()
srv.notify(char)
candidate.show()
candidate.append(char).update()
return 0
class PYIMTest(OVIMPython.OVInputMethod):
def identifier(self):
return "OVIMTest"
編譯方法
目前Python-based input method module僅能在OS X上編譯。請先安裝SWIG(可用port安裝),然後使用最新的OV trunk,然後在OVIMPython目錄下,執行 make ; make DSTROOT=~ install 即可將編完的 OVIMPython 安裝到 ~/Library/OpenVanilla/0.7.2/Modules 中。
使用 Intel Mac 的朋友可能得看一下 Makefile 第三行,把中間那一大串關於 PowerPC 的字樣,改成你 build/ 目錄下(會在第一次 make 後出現)的某個名字。如何自動化處理 Makefile 的字串代換會是建立此類型模組的build system的關鍵所在。
Enjoy!
lukhnos :: Jul.14.2007 :: tekhnologia 技術或者藝術 :: 3 Comments »