Handle spell attributes on textarea

Add option for spell checking
This commit is contained in:
Cédric Krier committed 2008-08-29 18:59:04 +02:00
1 parent 0993ba725a
commit 0dbd17f119
4 files changed
+61 -6

No files matched your search

+8
View File
@@ -694,6 +694,14 @@
<signal name="activate" handler="on_opt_tree_width_activate"/>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="opt_spellcheck">
<property name="visible">True</property>
<property name="label" translatable="yes">Activate spell checking</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_opt_spellcheck_activate"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="forms_tab">
<property name="visible">True</property>
+1
View File
@@ -73,6 +73,7 @@ class ConfigManager(object):
'client.form_tab': 'left',
'client.form_tab_orientation': 90,
'client.tree_width': True,
'client.spellcheck': False,
'client.lang': 'en_US',
'client.actions': {
'odt': {0: find_path(['ooffice', 'ooffice2'], '%s'),
+2
View File
@@ -168,6 +168,8 @@ class Main(object):
'opt_form_toolbar'),
'on_opt_tree_width_activate': (fnc_menuitem, 'client.tree_width',
'opt_tree_width'),
'on_opt_spellcheck_activate': (fnc_menuitem, 'client.spellcheck',
'opt_spellcheck'),
}
self.glade.get_widget('menubar_'+(CONFIG['client.toolbar'] or \
'both')).set_active(True)
@@ -2,6 +2,13 @@
import gtk
from interface import WidgetInterface
import tryton.rpc as rpc
from tryton.config import CONFIG
HAS_GTKSPELL = True
try:
import gtkspell
except:
HAS_GTKSPELL = False
class TextBox(WidgetInterface):
@@ -23,12 +30,6 @@ class TextBox(WidgetInterface):
self.textview.set_accepts_tab(False)
self.textview.connect('focus-in-event', lambda x, y: self._focus_in())
self.textview.connect('focus-out-event', lambda x, y: self._focus_out())
try:
import gtkspell
gtkspell.Spell(self.textview).set_language(
rpc.CONTEXT.get('language', 'en_US'))
except:
pass
self.scrolledwindow.add(self.textview)
self.scrolledwindow.show_all()
@@ -41,6 +42,27 @@ class TextBox(WidgetInterface):
super(TextBox, self)._readonly_set(value)
self.textview.set_editable(not value)
self.textview.set_sensitive(not value)
if HAS_GTKSPELL:
spell = None
try:
spell = gtkspell.get_from_text_view(self.textview)
except:
pass
if spell:
spell.detach()
del spell
if not value and self.attrs.get('spell') \
and CONFIG['client.spellcheck']:
language = self._view.model.expr_eval(self.attrs['spell'])
try:
spell = gtkspell.Spell(self.textview)
try:
spell.set_language(language)
except:
spell.detach()
del spell
except:
pass
def _color_widget(self):
return self.textview
@@ -61,3 +83,25 @@ class TextBox(WidgetInterface):
buf.delete(buf.get_start_iter(), buf.get_end_iter())
iter_start = buf.get_start_iter()
buf.insert(iter_start, value)
if HAS_GTKSPELL:
spell = None
try:
spell = gtkspell.get_from_text_view(self.textview)
except:
pass
if spell:
spell.detach()
del spell
if self.attrs.get('spell') and CONFIG['client.spellcheck']:
language = self._view.model.expr_eval(self.attrs['spell'])
try:
spell = gtkspell.Spell(self.textview)
try:
spell.set_language(language)
except:
spell.detach()
del spell
except:
pass