Coverage for /home/antoine/projects/xpra-git/dist/python3/lib64/python/xpra/gtk_common/gobject_util.py : 96%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of Xpra.
2# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com>
3# Copyright (C) 2013-2020 Antoine Martin <antoine@xpra.org>
4# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
5# later version. See the file COPYING for details.
8from gi.repository import GObject
9SIGNAL_RUN_LAST = GObject.SignalFlags.RUN_LAST
10def n_arg_signal(n):
11 return (SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_PYOBJECT,) * n)
12no_arg_signal = n_arg_signal(0)
13one_arg_signal = n_arg_signal(1)
14two_arg_signal = n_arg_signal(2)
17class AutoPropGObjectMixin:
18 """Mixin for automagic property support in GObjects.
20 Make sure this is the first entry on your parent list, so super().__init__
21 will work right."""
22 def __init__(self):
23 self._gproperties = {}
25 def do_get_property(self, pspec):
26 return self._gproperties.get(pspec.name)
28 def do_set_property(self, pspec, value):
29 self._internal_set_property(pspec.name, value)
31 # Exposed for subclasses that wish to set readonly properties --
32 # .set_property (the public api) will fail, but the property can still be
33 # modified via this method.
34 def _internal_set_property(self, name, value):
35 setter = "do_set_property_" + name.replace("-", "_")
36 if hasattr(self, setter):
37 getattr(self, setter)(name, value)
38 else:
39 self._gproperties[name] = value
40 self.notify(name)
43# Collects the results from signal handlers for a given signal into a list,
44# ignoring all handlers that return None. (This filtering is useful because
45# the intended use of this method is to "poll" all connected objects, so it's
46# pretty useless to call a default do_* method... but even if such a method is
47# not defined, a default implementation will still be called automatically,
48# and that implementation simply returns None.)
49def non_none_list_accumulator(_ihint, return_accu, handler_return):
50 if return_accu is None:
51 return_accu = []
52 if handler_return is not None:
53 return_accu += [handler_return]
54 return True, return_accu