3 ## (C) 2008 Thorsten P. 'dGhvcnN0ZW5wIEFUIHltYWlsIGNvbQ==\n'.decode("base64")
5 ## This file is part of Gajim.
7 ## Gajim is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published
9 ## by the Free Software Foundation; version 3 only.
11 ## Gajim is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
25 gboolean
= ctypes
.c_int
26 gchar_p
= ctypes
.c_char_p
27 gerror_p
= ctypes
.c_void_p
28 gobject_p
= ctypes
.c_void_p
29 gtkspell_p
= ctypes
.c_void_p
30 gtktextview_p
= ctypes
.c_void_p
33 class PyGObject(ctypes
.Structure
):
35 ("PyObject_HEAD", ctypes
.c_byte
* object.__basicsize
__),
40 libgtkspell_path
= ctypes
.util
.find_library("gtkspell")
41 if libgtkspell_path
== None:
42 raise ImportError("libgtkspell not found")
43 libgtkspell
= ctypes
.cdll
.LoadLibrary(libgtkspell_path
)
44 libgtkspell
.gtkspell_new_attach
.restype
= gtkspell_p
45 libgtkspell
.gtkspell_new_attach
.argtypes
= [gtktextview_p
, gchar_p
, gerror_p
]
46 libgtkspell
.gtkspell_set_language
.restype
= gboolean
47 libgtkspell
.gtkspell_set_language
.argtypes
= [gtkspell_p
, gchar_p
, gerror_p
]
48 libgtkspell
.gtkspell_recheck_all
.argtypes
= [gtkspell_p
]
49 libgtkspell
.gtkspell_get_from_text_view
.restype
= gtkspell_p
50 libgtkspell
.gtkspell_get_from_text_view
.argtypes
= [gtktextview_p
]
51 libgtkspell
.gtkspell_detach
.argtypes
= [gtkspell_p
]
54 def ensure_attached(func
):
55 def f(self
, *args
, **kwargs
):
57 func(self
, *args
, **kwargs
)
59 raise RuntimeError("Spell object is already detached")
65 def __init__(self
, textview
, language
=None, create
=True):
66 if not isinstance(textview
, gtk
.TextView
):
67 raise TypeError("Textview must be derived from gtk.TextView")
68 tv
= PyGObject
.from_address(id(textview
)).obj
69 spell
= libgtkspell
.gtkspell_get_from_text_view(tv
)
72 raise RuntimeError("Textview has already a Spell obj attached")
73 self
.spell
= libgtkspell
.gtkspell_new_attach(tv
, language
, None)
75 raise OSError("Unable to attach spell object. "
76 "Language: '%s'" % str(language
))
81 raise RuntimeError("Textview has no Spell object attached")
84 def set_language(self
, language
):
85 if libgtkspell
.gtkspell_set_language(self
.spell
, language
, None) == 0:
86 raise OSError("Unable to set language '%s'" % str(language
))
89 def recheck_all(self
):
90 libgtkspell
.gtkspell_recheck_all(self
.spell
)
94 libgtkspell
.gtkspell_detach(self
.spell
)
98 def get_from_text_view(textview
):
99 return Spell(textview
, create
=False)