PageRenderTime 81ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 25ms app.codeStats 0ms

/python/setupui/EnglishWriter/English.py

http://scim-python.googlecode.com/
Python | 84 lines | 50 code | 9 blank | 25 comment | 12 complexity | 7b2f3fbd986af3fb4f352fd788bf84b8 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2# vim:set noet ts=4:
 3#
 4# scim-python
 5#
 6# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
 7#
 8#
 9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; either
12# version 2 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU Lesser General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public
20# License along with this program; if not, write to the
21# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22# Boston, MA  02111-1307  USA
23#
24# $Id: $
25#
26import scim
27import gtk 
28
29from gettext import dgettext
30_ = lambda (a) : dgettext ("scim-python", a)
31N_ = lambda (a) : a
32
33class EnglishSetupUI (gtk.VBox):
34	__options__ = [
35		("/IMEngine/Python/EnglishWriter/AlwaysShowCandidates", bool, False, 
36			N_("Always show candidates window"), N_("Always show candidates, even if the spelling is right.")),
37		("/IMEngine/Python/EnglishWriter/CommitSpace", bool, True, 
38			N_("Commit a space with preedit string"), N_("Commit preedit string or a candidates with a space.")),
39	]
40	def __init__ (self):
41		gtk.VBox.__init__ (self)
42		self._values = {}
43		self._create_ui (EnglishSetupUI.__options__)
44
45		self.show_all ()
46
47	def _create_ui (self, options):
48		tooltips = gtk.Tooltips ()
49		for opt in options:
50			widget = None
51			if opt[1] == bool:
52				widget = gtk.CheckButton (_(opt[3]))
53				tooltips.set_tip (widget, _(opt[4]))
54				widget.get_value = widget.get_active
55				widget.set_value = widget.set_active
56				widget.set_value (opt[2])
57				self._values[opt[0]] = (widget, opt[2])
58			if widget:
59				self.pack_start (widget, False, False)
60
61	def get_name (self):
62		return _("English Writer")
63	
64	def save_config (self, config):
65		for key, v in self._values.items ():
66			new_value = v[0].get_value ()
67			config.write (key, new_value)
68			self._values[key] = (v[0], new_value)
69
70	def load_config (self, config):
71		for key, v in self._values.items ():
72			new_value = config.read (key, v[1])
73			v[0].set_value (new_value)
74			self._values[key] = (v[0], new_value)
75
76	def query_changed (self):
77		for k, v in self._values.items ():
78			if v[1] != v[0].get_value ():
79				return True
80		return False
81
82	def _toggled_cb (self, widget, id):
83		if id == 0:
84			widget.get_active ()