PageRenderTime 286ms CodeModel.GetById 110ms app.highlight 7ms RepoModel.GetById 116ms app.codeStats 1ms

/python/setupui/__init__.py

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