class FieldSet(object): def __init__(self, delegate, schema_type): from pygtkhelpers.proxy import ProxyGroup, proxy_for self.delegate = delegate self.schema = schema_type() self.proxies = ProxyGroup() self.fields = OrderedDict() self.proxies.connect('changed', self._on_proxies_changed) for name, element in self.schema.items(): self._setup_widget(name, element) def _setup_widget(self, name, element): widget = getattr(self.delegate, name, None) #XXX (AA) this will always be the case, we are running too soon if widget is None: widget = widget_for(element) setattr(self.delegate, name, widget) field = self.fields[name] = Field(element, widget=widget) field_name = element.properties.get('label', name) field.set_label(field_name.capitalize()) self.proxies.add_proxy(name, field.proxy) def _on_proxies_changed(self, group, proxy, name, value): self.schema[name].set(value) def layout_as_table(self): # XXX: turn to utility function table = gtk.Table(len(self.fields), 2) table.set_row_spacings(6) table.set_col_spacings(6) table.set_border_width(6) for i, field_i in enumerate(self.fields.itervalues()): field_i.layout_as_table(table, i) return table
def test_add_proxy_for(): m = ProxyGroup() e = gtk.Entry() m.add_proxy_for('foo', e) check = CheckCalled(m, 'changed') e.set_text('a') refresh_gui() assert check.called_count == 1
def test_add_proxy(): m = ProxyGroup() e = gtk.Entry() p = GtkEntryProxy(e) m.add_proxy('foo', p) check = CheckCalled(m, 'changed') e.set_text('a') refresh_gui() assert check.called_count == 1 p.update('b') refresh_gui() assert check.called_count == 2
def __init__(self, delegate, schema_type): from pygtkhelpers.proxy import ProxyGroup, proxy_for self.delegate = delegate self.schema = schema_type() self.proxies = ProxyGroup() self.fields = OrderedDict() self.proxies.connect('changed', self._on_proxies_changed) for name, element in self.schema.items(): self._setup_widget(name, element)
def test_add_group(): m = ProxyGroup() e = gtk.Entry() m.add_proxy_for('foo', e) m2 = ProxyGroup() m2.add_group(m) check = CheckCalled(m2, 'changed') e.set_text('a') assert check.called_count == 1