XklWrapper provides read-only data and is initialized with system-wide data, so it doesn't make sense to have multiple instances. --- pyanaconda/ui/gui/spokes/keyboard.py | 8 ++++---- pyanaconda/xklavier.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pyanaconda/ui/gui/spokes/keyboard.py b/pyanaconda/ui/gui/spokes/keyboard.py index f2d471c..bc2023c 100644 --- a/pyanaconda/ui/gui/spokes/keyboard.py +++ b/pyanaconda/ui/gui/spokes/keyboard.py @@ -43,9 +43,9 @@ class AddLayoutDialog(UIObject): mainWidgetName = "addLayoutDialog" uiFile = "spokes/keyboard.ui" - def __init__(self, xkl_wrapper, *args): - self._xkl_wrapper = xkl_wrapper + def __init__(self, *args): UIObject.__init__(self, *args) + self._xkl_wrapper = xklavier.XklWrapper.get_instance() def matches_entry(self, model, itr, user_data=None): value = model[itr][0] @@ -128,7 +128,7 @@ class KeyboardSpoke(NormalSpoke): def __init__(self, *args): NormalSpoke.__init__(self, *args) self._remove_last_attempt = False - self._xkl_wrapper = xklavier.XklWrapper() + self._xkl_wrapper = xklavier.XklWrapper.get_instance() def apply(self): self.data.keyboard.keyboard = None @@ -179,7 +179,7 @@ class KeyboardSpoke(NormalSpoke): # Signal handlers. def on_add_clicked(self, button): - dialog = AddLayoutDialog(self._xkl_wrapper, self.data) + dialog = AddLayoutDialog(self.data) dialog.refresh() dialog.initialize() diff --git a/pyanaconda/xklavier.py b/pyanaconda/xklavier.py index 0e4af17..d0ac444 100755 --- a/pyanaconda/xklavier.py +++ b/pyanaconda/xklavier.py @@ -51,7 +51,23 @@ class _Layout(object): return self.desc class XklWrapper(object): - """Class wrapping the libxklavier functionality""" + """ + Class wrapping the libxklavier functionality + + Use this class as a singleton class because it provides read-only data + and initialization (that takes quite a lot of time) reads always the + same data. It doesn't have sense to make multiple instances + + """ + + _instance = None + + @staticmethod + def get_instance(): + if not XklWrapper._instance: + XklWrapper._instance = XklWrapper() + + return XklWrapper._instance def __init__(self): #initialize Xkl-related stuff -- 1.7.4.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list