PageRenderTime 39ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/python/setupui/EnglishWriter/English.py

http://scim-python.googlecode.com/
Python | 84 lines | 50 code | 9 blank | 25 comment | 8 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. #
  26. import scim
  27. import gtk
  28. from gettext import dgettext
  29. _ = lambda (a) : dgettext ("scim-python", a)
  30. N_ = lambda (a) : a
  31. class EnglishSetupUI (gtk.VBox):
  32. __options__ = [
  33. ("/IMEngine/Python/EnglishWriter/AlwaysShowCandidates", bool, False,
  34. N_("Always show candidates window"), N_("Always show candidates, even if the spelling is right.")),
  35. ("/IMEngine/Python/EnglishWriter/CommitSpace", bool, True,
  36. N_("Commit a space with preedit string"), N_("Commit preedit string or a candidates with a space.")),
  37. ]
  38. def __init__ (self):
  39. gtk.VBox.__init__ (self)
  40. self._values = {}
  41. self._create_ui (EnglishSetupUI.__options__)
  42. self.show_all ()
  43. def _create_ui (self, options):
  44. tooltips = gtk.Tooltips ()
  45. for opt in options:
  46. widget = None
  47. if opt[1] == bool:
  48. widget = gtk.CheckButton (_(opt[3]))
  49. tooltips.set_tip (widget, _(opt[4]))
  50. widget.get_value = widget.get_active
  51. widget.set_value = widget.set_active
  52. widget.set_value (opt[2])
  53. self._values[opt[0]] = (widget, opt[2])
  54. if widget:
  55. self.pack_start (widget, False, False)
  56. def get_name (self):
  57. return _("English Writer")
  58. def save_config (self, config):
  59. for key, v in self._values.items ():
  60. new_value = v[0].get_value ()
  61. config.write (key, new_value)
  62. self._values[key] = (v[0], new_value)
  63. def load_config (self, config):
  64. for key, v in self._values.items ():
  65. new_value = config.read (key, v[1])
  66. v[0].set_value (new_value)
  67. self._values[key] = (v[0], new_value)
  68. def query_changed (self):
  69. for k, v in self._values.items ():
  70. if v[1] != v[0].get_value ():
  71. return True
  72. return False
  73. def _toggled_cb (self, widget, id):
  74. if id == 0:
  75. widget.get_active ()