86
86
properties and calls a hook function when any of them are
89
def __init__(self, proxy_object=None, *args, **kwargs):
89
def __init__(self, proxy_object=None, properties=None, **kwargs):
90
90
self.proxy = proxy_object # Mandos Client proxy object
92
self.properties = dict()
91
self.properties = dict() if properties is None else properties
93
92
self.property_changed_match = (
94
93
self.proxy.connect_to_signal("PropertyChanged",
95
self.property_changed,
94
self._property_changed,
99
self.properties.update(
100
self.proxy.GetAll(client_interface,
101
dbus_interface = dbus.PROPERTIES_IFACE))
103
#XXX This breaks good super behaviour
104
# super(MandosClientPropertyCache, self).__init__(
98
if properties is None:
99
self.properties.update(
100
self.proxy.GetAll(client_interface,
102
= dbus.PROPERTIES_IFACE))
104
super(MandosClientPropertyCache, self).__init__(**kwargs)
106
def _property_changed(self, property, value):
107
"""Helper which takes positional arguments"""
108
return self.property_changed(property=property, value=value)
107
110
def property_changed(self, property=None, value=None):
108
111
"""This is called whenever we get a PropertyChanged signal
111
114
# Update properties dict with new value
112
115
self.properties[property] = value
114
def delete(self, *args, **kwargs):
115
118
self.property_changed_match.remove()
116
super(MandosClientPropertyCache, self).__init__(
120
121
class MandosClientWidget(urwid.FlowWidget, MandosClientPropertyCache):
124
125
def __init__(self, server_proxy_object=None, update_hook=None,
125
delete_hook=None, logger=None, *args, **kwargs):
126
delete_hook=None, logger=None, **kwargs):
126
127
# Called on update
127
128
self.update_hook = update_hook
128
129
# Called on delete
139
140
self._text_widget = urwid.Text("")
140
141
# The widget shown when we have focus
141
142
self._focus_text_widget = urwid.Text("")
142
super(MandosClientWidget, self).__init__(
143
update_hook=update_hook, delete_hook=delete_hook,
143
super(MandosClientWidget, self).__init__(**kwargs)
146
145
self.opened = False
345
344
return True # Keep calling this
347
def delete(self, *args, **kwargs):
346
def delete(self, **kwargs):
348
347
if self._update_timer_callback_tag is not None:
349
348
gobject.source_remove(self._update_timer_callback_tag)
350
349
self._update_timer_callback_tag = None
353
352
self.match_objects = ()
354
353
if self.delete_hook is not None:
355
354
self.delete_hook(self)
356
return super(MandosClientWidget, self).delete(*args, **kwargs)
355
return super(MandosClientWidget, self).delete(**kwargs)
358
357
def render(self, maxcolrow, focus=False):
359
358
"""Render differently if we have focus.
404
def property_changed(self, property=None, value=None,
403
def property_changed(self, property=None, **kwargs):
406
404
"""Call self.update() if old value is not new value.
407
405
This overrides the method from MandosClientPropertyCache"""
408
406
property_name = unicode(property)
409
407
old_value = self.properties.get(property_name)
410
408
super(MandosClientWidget, self).property_changed(
411
property=property, value=value, *args, **kwargs)
409
property=property, **kwargs)
412
410
if self.properties.get(property_name) != old_value:
418
416
"down" key presses, thus not allowing any containing widgets to
419
417
use them as an excuse to shift focus away from this widget.
421
def keypress(self, maxcolrow, key):
422
ret = super(ConstrainedListBox, self).keypress(maxcolrow, key)
419
def keypress(self, *args, **kwargs):
420
ret = super(ConstrainedListBox, self).keypress(*args, **kwargs)
423
421
if ret in ("up", "down"):