/usr/lib/gdesklets/main/Control.py is in gdesklets 0.36.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | from plugin.Interface import Interface
import utils
import gobject
class Control(object):
"""
Base class for controls. Every control has to be derived from this class.
"""
# Warning : this is the only way to escape a Control
# so be carefull when allowing a method to be called
AUTHORIZED_METHODS = ('bind', )
def __init__(self):
# the handlers for property bindings
self.__handlers = {}
# flag indicating whether the control has been stopped
self.__is_stopped = False
# the path of the display file (excluding the file)
self.__display_path = ""
def _update(self, prop):
""" Issues a change of the given property. """
lst = self.__handlers.get(prop, [])
for handler, args in lst:
utils.run_in_main_thread(handler, getattr(self, prop), *args)
def bind(self, prop, handler, *args):
""" Binds a handler to property changes. """
self.__handlers.setdefault(prop, []).append((handler, args))
def _add_timer(self, interval, callback, *args):
""" Runs a timer callback at the given intervals. """
def func():
""" callback function for gobject.timeout_add """
if self.__is_stopped:
return False
return bool(callback(*args))
return gobject.timeout_add(interval, func)
def _remove_timer(self, ident):
""" Removes timer with given ID. """
gobject.source_remove(ident)
def stop(self):
""" Stops the control. """
self.__is_stopped = True
# remove bound handlers
self.__handlers.clear()
self._shutdown()
def _shutdown(self):
"""
Shutdown handler for controls. Controls should override this
method if needed.
"""
pass
def __interface(self):
"""
Returns a description of the interface of this control.
"""
return Interface.text_describe(self.__class__)
interface = property(__interface, doc = "Interface description")
|