PageRenderTime 65ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/python/setupui/__init__.py

http://scim-python.googlecode.com/
Python | 95 lines | 62 code | 8 blank | 25 comment | 15 complexity | c55b44fbe6cea42638df96756729b709 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 os import path
  29. from glob import glob
  30. from gettext import dgettext
  31. _ = lambda (a) : dgettext ("scim-python", a)
  32. N_ = lambda (a) : a
  33. window = None
  34. setup_uis = None
  35. def create_ui ():
  36. global window
  37. global setup_uis
  38. if window != None:
  39. return window
  40. window = gtk.Notebook ()
  41. wildcast = path.join (path.dirname (__file__), "*")
  42. setup_uis = []
  43. for name in [name for name in glob (wildcast) if path.isdir(name)]:
  44. try:
  45. name = path.basename (name)
  46. mod = __import__ (name, globals (), locals (), [])
  47. for ui in mod.SetupUI:
  48. widget = ui ()
  49. window.append_page (widget, gtk.Label (widget.get_name ()))
  50. setup_uis.append (widget)
  51. except Exception, e:
  52. print e
  53. about_page = gtk.Label (_("scim-python\n\nAuthor : Huang Peng <shawn.p.huang@gmail.com>\n Version : %s") % scim.get_version ())
  54. about_page.set_justify (gtk.JUSTIFY_CENTER)
  55. window.append_page (about_page, gtk.Label(_("About")))
  56. window.show_all ()
  57. return window
  58. def load_config (config):
  59. for widget in setup_uis:
  60. try:
  61. widget.load_config (config)
  62. except:
  63. import traceback
  64. traceback.print_exc ()
  65. def save_config (config):
  66. for widget in setup_uis:
  67. try:
  68. widget.save_config (config)
  69. except:
  70. import traceback
  71. traceback.print_exc ()
  72. def query_changed ():
  73. for widget in setup_uis:
  74. try:
  75. if widget.query_changed ():
  76. return True
  77. except:
  78. import traceback
  79. traceback.print_exc ()
  80. return False
  81. if __name__ == "__main__":
  82. w = gtk.Window ()
  83. w.add (create_ui ())
  84. w.connect ("delete-event", gtk.main_quit)
  85. w.resize (400, 400)
  86. w.show_all ()
  87. gtk.main ()