[node-patches] Change in ovirt-node[master]: base: Pull signaling into base (from ui.Element)
fabiand at fedoraproject.org
fabiand at fedoraproject.org
Tue Dec 11 20:09:42 UTC 2012
Fabian Deutsch has uploaded a new change for review.
Change subject: base: Pull signaling into base (from ui.Element)
......................................................................
base: Pull signaling into base (from ui.Element)
Change-Id: I70530acae522ddf007ebde80b3aaaf09e30d1a39
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/base.py
M scripts/tui/src/ovirt/node/ui/__init__.py
2 files changed, 67 insertions(+), 44 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/57/9957/1
diff --git a/scripts/tui/src/ovirt/node/base.py b/scripts/tui/src/ovirt/node/base.py
index 59c974d..4db8bac 100644
--- a/scripts/tui/src/ovirt/node/base.py
+++ b/scripts/tui/src/ovirt/node/base.py
@@ -27,7 +27,11 @@
class Base(object):
- """Base class for all objects."""
+ """Base class for all objects.
+ With a logger and a simple signaling mechanism - see Gtk+
+ """
+
+ _signal_cbs = None
@property
def logger(self):
@@ -37,3 +41,65 @@
def __init__(self):
"""Contructor."""
self._logger = logging.getLogger(self.__module__)
+
+ @staticmethod
+ def signal_change(func):
+ """A decorator for methods which should emit signals
+ """
+ def wrapper(self, userdata=None, *args, **kwargs):
+ signame = func.__name__
+ self.register_signal(signame)
+ self.emit_signal(signame, userdata)
+ return func(self, userdata)
+ return wrapper
+
+ def register_signals(self, names):
+ self.logger.debug("Registering signals: %s" % names)
+ sigs = []
+ for name in names:
+ sigs.append(self.register_signal(name))
+ return sigs
+
+ def register_signal(self, name):
+ """Each signal that get's emitted must be registered using this
+ function.
+
+ This is just to have an overview over the signals.
+ """
+ if self._signal_cbs is None:
+ self._signal_cbs = {}
+ if name not in self._signal_cbs:
+ self._signal_cbs[name] = []
+ self.logger.debug("Registered new signal '%s' for '%s'" % (name,
+ self))
+ return Base.Signal(self, name)
+
+ def connect_signal(self, name, cb):
+ """Connect an callback to a signal
+ """
+ if not self._signal_cbs:
+ raise Exception("Signals not initialized %s for %s" % (name, self))
+ if name not in self._signal_cbs:
+ raise Exception("Unregistered signal %s for %s" % (name, self))
+ self._signal_cbs[name].append(cb)
+
+ def emit_signal(self, name, userdata=None):
+ """Emit a signal
+ """
+ if self._signal_cbs is None or name not in self._signal_cbs:
+ return False
+ self.logger.debug("Emitting '%s'" % name)
+ for cb in self._signal_cbs[name]:
+ self.logger.debug("... %s" % cb)
+ cb(self, userdata)
+
+ class Signal(object):
+ def __init__(self, base, name):
+ self.name = name
+ self.base = base
+
+ def emit(self, userdata=None):
+ return self.base.emit_signal(self.name, userdata)
+
+ def connect(self, cb):
+ return self.base.connect_signal(self.name,cb)
\ No newline at end of file
diff --git a/scripts/tui/src/ovirt/node/ui/__init__.py b/scripts/tui/src/ovirt/node/ui/__init__.py
index cd84465..e469f0e 100644
--- a/scripts/tui/src/ovirt/node/ui/__init__.py
+++ b/scripts/tui/src/ovirt/node/ui/__init__.py
@@ -41,49 +41,6 @@
super(Element, self).__init__()
self.logger.debug("Initializing new %s" % self)
- @staticmethod
- def signal_change(func):
- """A decorator for methods which should emit signals
- """
- def wrapper(self, userdata=None, *args, **kwargs):
- signame = func.__name__
- self._register_signal(signame)
- self.emit_signal(signame, userdata)
- return func(self, userdata)
- return wrapper
-
- def _register_signal(self, name):
- """Each signal that get's emitted must be registered using this
- function.
-
- This is just to have an overview over the signals.
- """
- if self._signal_cbs is None:
- self._signal_cbs = {}
- if name not in self._signal_cbs:
- self._signal_cbs[name] = []
- self.logger.debug("Registered new signal '%s' for '%s'" % (name,
- self))
-
- def connect_signal(self, name, cb):
- """Connect an callback to a signal
- """
- if not self._signal_cbs:
- raise Exception("Signals not initialized %s for %s" % (name, self))
- if name not in self._signal_cbs:
- raise Exception("Unregistered signal %s for %s" % (name, self))
- self._signal_cbs[name].append(cb)
-
- def emit_signal(self, name, userdata=None):
- """Emit a signal
- """
- if self._signal_cbs is None or name not in self._signal_cbs:
- return False
- self.logger.debug("Emitting '%s'" % name)
- for cb in self._signal_cbs[name]:
- self.logger.debug("... %s" % cb)
- cb(self, userdata)
-
def set_text(self, value):
"""A general way to set the "text" of a widget
"""
--
To view, visit http://gerrit.ovirt.org/9957
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I70530acae522ddf007ebde80b3aaaf09e30d1a39
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>
More information about the node-patches
mailing list