Make gconf as DefaultConfig.
This commit is contained in:
Родитель
1cc99dd271
Коммит
1e09758b22
|
@ -20,6 +20,7 @@
|
|||
# Boston, MA 02111-1307 USA
|
||||
ibusdaemon_PYTHON = \
|
||||
bus.py \
|
||||
defaultconfig.py \
|
||||
config.py \
|
||||
connection.py \
|
||||
contextmanager.py \
|
||||
|
|
|
@ -27,7 +27,7 @@ from contextmanager import ContextManager
|
|||
from factorymanager import FactoryManager
|
||||
from connection import Connection
|
||||
from panel import Panel, DummyPanel
|
||||
from config import Config, DummyConfig
|
||||
from config import Config, DefaultConfig
|
||||
from register import Register
|
||||
|
||||
class IBus(ibus.Object):
|
||||
|
@ -36,7 +36,7 @@ class IBus(ibus.Object):
|
|||
self.__context_manager = ContextManager()
|
||||
self.__factory_manager = FactoryManager()
|
||||
self.__panel = DummyPanel()
|
||||
self.__config = DummyConfig()
|
||||
self.__config = DefaultConfig()
|
||||
self.__register = Register()
|
||||
self.__config_watch = dict()
|
||||
|
||||
|
@ -306,9 +306,9 @@ class IBus(ibus.Object):
|
|||
# methods for panel
|
||||
##########################################################
|
||||
def register_config(self, object_path, replace, conn):
|
||||
if not isinstance(self.__config, DummyConfig) and replace == False:
|
||||
if not isinstance(self.__config, DefaultConfig) and replace == False:
|
||||
raise ibus.Exception("has have a config!")
|
||||
if not isinstance(self.__config, DummyConfig):
|
||||
if not isinstance(self.__config, DefaultConfig):
|
||||
self.__config.destroy()
|
||||
self.__config = Config(conn, object_path)
|
||||
self.__config.connect("value-changed", self.__config_value_changed_cb)
|
||||
|
@ -345,7 +345,7 @@ class IBus(ibus.Object):
|
|||
|
||||
def __config_destroy_cb(self, config):
|
||||
if config == self.__config:
|
||||
self.__config = DummyConfig()
|
||||
self.__config = DefaultConfig()
|
||||
|
||||
##########################################################
|
||||
# engine register methods
|
||||
|
|
|
@ -19,9 +19,15 @@
|
|||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
# Boston, MA 02111-1307 USA
|
||||
|
||||
__all__ = (
|
||||
"Config",
|
||||
"DefaultConfig"
|
||||
)
|
||||
|
||||
import weakref
|
||||
import gobject
|
||||
import ibus
|
||||
import defaultconfig
|
||||
|
||||
class Config(ibus.Object):
|
||||
__gsignals__ = {
|
||||
|
@ -69,7 +75,7 @@ class Config(ibus.Object):
|
|||
|
||||
gobject.type_register(Config)
|
||||
|
||||
class DummyConfig(ibus.Object):
|
||||
class DefaultConfig(ibus.Object):
|
||||
__gsignals__ = {
|
||||
"value-changed" : (
|
||||
gobject.SIGNAL_RUN_FIRST,
|
||||
|
@ -77,44 +83,44 @@ class DummyConfig(ibus.Object):
|
|||
(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
super(DefaultConfig, self).__init__()
|
||||
self.__config = defaultconfig.Config()
|
||||
self.__handler_id = self.__config.connect("value-changed", self.__value_changed_cb)
|
||||
|
||||
def get_value(self, key, **kargs):
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"](0)
|
||||
else:
|
||||
return 0
|
||||
try:
|
||||
value = self.__config.get_value(key)
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"](value)
|
||||
else:
|
||||
return value
|
||||
except Exception, e:
|
||||
if "error_handler" in kargs:
|
||||
kargs["error_handler"](e)
|
||||
else:
|
||||
raise e
|
||||
|
||||
def set_value(self, key, **kargs):
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"]()
|
||||
def set_value(self, key, value, **kargs):
|
||||
try:
|
||||
self.__config.set_value(key, value)
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"]()
|
||||
else:
|
||||
return
|
||||
except Exception, e:
|
||||
if "error_handler" in kargs:
|
||||
kargs["error_handler"](e)
|
||||
else:
|
||||
raise e
|
||||
|
||||
def get_string(self, key, **kargs):
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"]("")
|
||||
else:
|
||||
return ""
|
||||
def __value_changed_cb(self, config, key, value):
|
||||
self.emit("value-changed", key, value)
|
||||
|
||||
def get_int(self, key, **kargs):
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"](0)
|
||||
else:
|
||||
return 0
|
||||
def do_destroy(self):
|
||||
if self.__config:
|
||||
self.__config.disconnect(self.__handler_id)
|
||||
self.__config.destroy()
|
||||
self.__config = None
|
||||
|
||||
def get_bool(self, key, **kargs):
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"](True)
|
||||
else:
|
||||
return True
|
||||
|
||||
def set_string(self, key, value, **kargs):
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"]()
|
||||
|
||||
def set_int(self, key, value, **kargs):
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"]()
|
||||
|
||||
def set_bool(self, key, value, **kargs):
|
||||
if "reply_handler" in kargs:
|
||||
kargs["reply_handler"]()
|
||||
|
||||
gobject.type_register(DummyConfig)
|
||||
gobject.type_register(DefaultConfig)
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
# Boston, MA 02111-1307 USA
|
||||
|
||||
__all__ = (
|
||||
"Config",
|
||||
)
|
||||
|
||||
import gobject
|
||||
import gconf
|
||||
import ibus
|
||||
from ibus import interface
|
||||
|
@ -26,6 +31,13 @@ from ibus import interface
|
|||
GCONF_IBUS_PATH = "/desktop/ibus"
|
||||
|
||||
class Config(ibus.Object):
|
||||
__gsignals__ = {
|
||||
"value-changed" : (
|
||||
gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE,
|
||||
(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)),
|
||||
}
|
||||
|
||||
def __init__ (self, conn = None, path = None):
|
||||
super(Config, self).__init__()
|
||||
self.__proxy = ConfigProxy(self, conn, path)
|
||||
|
@ -108,12 +120,15 @@ class Config(ibus.Object):
|
|||
|
||||
print key, type(value), value
|
||||
print key, type(value), self.__to_gconf_value(value)
|
||||
self.__proxy.ValueChanged(key, value)
|
||||
self.emit("value-changed", key, value)
|
||||
|
||||
gobject.type_register(Config)
|
||||
|
||||
class ConfigProxy(interface.IConfig):
|
||||
def __init__ (self, config, conn, object_path):
|
||||
super(ConfigProxy, self).__init__(conn, object_path)
|
||||
self.__config = config
|
||||
self.__config.connect("value-changed", lambda c, k, v: self.ValueChanged(k, v))
|
||||
|
||||
def GetValue(self, key):
|
||||
return self.__config.get_value(key)
|
||||
|
|
Загрузка…
Ссылка в новой задаче