This commit is contained in:
Huang Peng 2008-07-15 16:37:07 +08:00
Родитель b92c71a7d0
Коммит 7155f30d2e
1 изменённых файлов: 53 добавлений и 52 удалений

Просмотреть файл

@ -32,85 +32,86 @@ import dbus.mainloop.glib
VISIBLE_COLUMN,
ICON_COLUMN,
DATA_COLUMN,
) = range (5)
) = range(5)
class Setup:
def __init__ (self):
self._conn = ibus.Connection ()
self._ibus = self._conn.get_ibus ()
glade_file = path.join (path.dirname (__file__), "./setup.glade")
self._xml = glade.XML (glade_file)
self._dialog = self._xml.get_widget ("dialog_setup")
self._tree = self._xml.get_widget ("treeview_engines")
model = self.__create_model ()
self._tree.set_model (model)
class Setup(object):
def __init__(self):
super(Setup, self).__init__()
self._conn = ibus.Connection()
self._ibus = self._conn.get_ibus()
glade_file = path.join(path.dirname(__file__), "./setup.glade")
self._xml = glade.XML(glade_file)
self._dialog = self._xml.get_widget("dialog_setup")
self._tree = self._xml.get_widget("treeview_engines")
model = self.__create_model()
self._tree.set_model(model)
# add icon search path
icon_theme = gtk.icon_theme_get_default ()
dir = path.dirname (__file__)
icondir = path.join (dir, "..", "icons")
icon_theme.prepend_search_path (icondir)
icon_theme = gtk.icon_theme_get_default()
dir = path.dirname(__file__)
icondir = path.join(dir, "..", "icons")
icon_theme.prepend_search_path(icondir)
# column for holiday names
column = gtk.TreeViewColumn ()
column.set_title ("Name")
column = gtk.TreeViewColumn()
column.set_title("Name")
renderer = gtk.CellRendererPixbuf()
renderer.set_property("xalign", 0.5)
column.pack_start (renderer)
column.set_attributes (renderer, icon_name = ICON_COLUMN, visible = VISIBLE_COLUMN)
column.pack_start(renderer)
column.set_attributes(renderer, icon_name = ICON_COLUMN, visible = VISIBLE_COLUMN)
renderer = gtk.CellRendererText()
renderer.set_property("xalign", 0.0)
# column.set_clickable(True)
column.pack_start (renderer)
column.set_attributes (renderer, text = NAME_COLUMN)
column.pack_start(renderer)
column.set_attributes(renderer, text = NAME_COLUMN)
self._tree.append_column(column)
# column for holiday names
renderer = gtk.CellRendererToggle()
renderer.set_data ('column', ENABLE_COLUMN)
renderer.set_data('column', ENABLE_COLUMN)
renderer.set_property("xalign", 0.5)
renderer.connect("toggled", self.__item_toggled_cb, model)
#col_offset = gtk.TreeViewColumn("Holiday", renderer, text=HOLIDAY_NAME_COLUMN)
column = gtk.TreeViewColumn("Started", renderer, active = ENABLE_COLUMN, visible = VISIBLE_COLUMN)
column.set_clickable (True)
column.set_resizable (False)
column.set_fixed_width (50)
column.set_clickable(True)
column.set_resizable(False)
column.set_fixed_width(50)
self._tree.append_column(column)
def _init_ui (self):
model = self.__create_model ()
def _init_ui(self):
model = self.__create_model()
def __item_toggled_cb (self, cell, path_str, model):
def __item_toggled_cb(self, cell, path_str, model):
# get toggled iter
iter = model.get_iter_from_string(path_str)
data = model.get_value (iter, DATA_COLUMN)
data = model.get_value(iter, DATA_COLUMN)
# do something with the value
if data[6] == False:
try:
self._ibus.RegisterStartEngine (data[1], data[0])
self._ibus.RegisterStartEngine(data[1], data[0])
except Exception, e:
dlg = gtk.MessageDialog (type = gtk.MESSAGE_ERROR,
dlg = gtk.MessageDialog(type = gtk.MESSAGE_ERROR,
buttons = gtk.BUTTONS_CLOSE,
message_format = str(e))
dlg.run ()
dlg.run()
return
else:
try:
self._ibus.RegisterStopEngine (data[1], data[0])
self._ibus.RegisterStopEngine(data[1], data[0])
except Exception, e:
dlg = gtk.MessageDialog (type = gtk.MESSAGE_ERROR,
dlg = gtk.MessageDialog(type = gtk.MESSAGE_ERROR,
buttons = gtk.BUTTONS_CLOSE,
message_format = str(e))
dlg.run ()
dlg.run()
return
data[6] = not data[6]
@ -118,37 +119,37 @@ class Setup:
model.set(iter, ENABLE_COLUMN, data[6])
def __create_model (self):
def __create_model(self):
# create tree store
model = gtk.TreeStore (
model = gtk.TreeStore(
gobject.TYPE_STRING,
gobject.TYPE_BOOLEAN,
gobject.TYPE_BOOLEAN,
gobject.TYPE_STRING,
gobject.TYPE_PYOBJECT)
langs = {}
langs = dict()
for name, lang, icon, author, credits, _exec, started in self._ibus.RegisterListEngines ():
_lang = ibus.LANGUAGES.get (lang, "other")
for name, lang, icon, author, credits, _exec, started in self._ibus.RegisterListEngines():
_lang = ibus.LANGUAGES.get(lang, "other")
if _lang not in langs:
langs[_lang] = []
langs[_lang].append ([name, lang, icon, author, credits, _exec, started])
langs[_lang].append([name, lang, icon, author, credits, _exec, started])
keys = langs.keys ()
keys.sort ()
keys = langs.keys()
keys.sort()
for key in keys:
iter = model.append (None)
model.set (iter,
iter = model.append(None)
model.set(iter,
NAME_COLUMN, key,
ENABLE_COLUMN, False,
VISIBLE_COLUMN, False,
ICON_COLUMN, None,
DATA_COLUMN, None)
langs[key].sort ()
langs[key].sort()
for name, lang, icon, author, credits, _exec, started in langs[key]:
child_iter = model.append (iter)
model.set (child_iter,
child_iter = model.append(iter)
model.set(child_iter,
NAME_COLUMN, name,
ENABLE_COLUMN, started,
VISIBLE_COLUMN, True,
@ -159,9 +160,9 @@ class Setup:
return model
def run (self):
return self._dialog.run ()
def run(self):
return self._dialog.run()
if __name__ == "__main__":
dbus.mainloop.glib.DBusGMainLoop (set_as_default = True)
Setup ().run ()
dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
Setup().run()