diff --git a/.gitignore b/.gitignore index ed208d6..d6211bf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ libchewing-0.3.2.tar.bz2 /libchewing.spec /libchewing-0.3.5.tar.bz2 /v0.4.0.tar.gz +/v0.5.0.tar.gz diff --git a/chewing.py b/chewing.py index 6bedcb8..a9f17ec 100644 --- a/chewing.py +++ b/chewing.py @@ -1,33 +1,55 @@ from ctypes import * from functools import partial +import sys + +_libchewing = None +if sys.platform == "win32": # Windows + import os.path + # find in current dir first + dll_path = os.path.join(os.path.dirname(__file__), "chewing.dll") + if not os.path.exists(dll_path): + dll_path = "chewing.dll" # search in system path + _libchewing = CDLL(dll_path) +else: # UNIX-like systems + _libchewing = CDLL('libchewing.so.3') -_libchewing = CDLL('libchewing.so.3') _libchewing.chewing_commit_String.restype = c_char_p _libchewing.chewing_buffer_String.restype = c_char_p _libchewing.chewing_cand_String.restype = c_char_p _libchewing.chewing_zuin_String.restype = c_char_p _libchewing.chewing_aux_String.restype = c_char_p +_libchewing.chewing_get_KBString.restype = c_char_p + def Init(datadir, userdir): return _libchewing.chewing_Init(datadir, userdir) + class ChewingContext: - def __init__(self): - self.ctx = _libchewing.chewing_new() + def __init__(self, **kwargs): + if not kwargs: + self.ctx = _libchewing.chewing_new() + else: + syspath = kwargs.get("syspath", None) + userpath = kwargs.get("userpath", None) + self.ctx = _libchewing.chewing_new2( + syspath, + userpath, + None, + None) + def __del__(self): - _libchewing.chewing_free(self.ctx) + _libchewing.chewing_delete(self.ctx) + def __getattr__(self, name): func = 'chewing_' + name - if func in _libchewing.__dict__: - wrap = partial(_libchewing.__dict__[func], self.ctx) - setattr(self, name, wrap) - return wrap - elif hasattr(_libchewing, func): - wrap = partial(_libchewing.__getattr__(func), self.ctx) + if hasattr(_libchewing, func): + wrap = partial(getattr(_libchewing, func), self.ctx) setattr(self, name, wrap) return wrap else: - raise AttributeError, name + raise AttributeError(name) + def Configure(self, cpp, maxlen, direction, space, kbtype): self.set_candPerPage(cpp) self.set_maxChiSymbolLen(maxlen) diff --git a/libchewing.spec b/libchewing.spec index 0946310..2c2a6ad 100644 --- a/libchewing.spec +++ b/libchewing.spec @@ -5,8 +5,8 @@ %global name_zh_TW %{im_name_zh_TW}函式庫 Name: libchewing -Version: 0.4.0 -Release: 6%{?dist} +Version: 0.5.0 +Release: 1%{?dist} Summary: Intelligent phonetic input method library for Traditional Chinese Summary(zh_TW): %{name_zh_TW} @@ -116,6 +116,9 @@ fi %{libchewing_python_dir} %changelog +* Sat May 07 2016 Ding-Yi Chen - 0.5.0-1 +- Upstream update to 0.5.0 + * Thu Feb 04 2016 Fedora Release Engineering - 0.4.0-6 - Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild diff --git a/sources b/sources index f446dbb..8bd0618 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -2537d7c7b890973c594bac6c598f20bc v0.4.0.tar.gz +553b1c85a037958af9c872790add16f3 v0.5.0.tar.gz