def _reset_widget(self, attribute, widget): if self._model is None: # if we have no model, leave value unset so we pick up # the widget default below. value = ValueUnset else: # if we have a model, grab its value to update the widgets self._register_proxy_in_model(attribute) value = kgetattr(self._model, attribute, ValueUnset) self.update(attribute, value, block=True) from kiwi.ui.widgets.combo import ProxyComboBox # FIXME: If the initial value is None and it is not a valid option, # the ProxyComboBox may ignore it and keep the currently selected # value instead. See ProxyComboBox.update for more information. # Remove this when fixing the callsites or finding a better solution if (isinstance(widget, ProxyComboBox) and self._model is not None and value is None): self._update_attribute(widget, attribute, widget.read()) # The initial value of the model is set, at this point # do a read, it'll trigger a validation for widgets who # supports it. if not IValidatableProxyWidget.providedBy(widget): return widget.validate(force=True)
def do_search(self, entry): text = self.entry_pesq.get_text().lower() if text: self.view_items = [item for item in self.recordset.items if text in kgetattr(item, 'nome')] else: self.view_items = self.recordset.items self.lista.add_list(self.view_items)
def _parse_row(sellable, columns): data = [] for col in columns: value = kgetattr(sellable, col) if value is None: value = '' elif isinstance(value, str): value = strip_accents(value) data.append(value) return data
def append_row(row, extra_indent=0): inst = row[0] cols = [] cols = [repr(kgetattr(inst, col.attribute, None)) for col in objectlist.get_columns()] extra.append("%srow: %s" % ( ' ' * extra_indent, ', '.join(cols))) if is_tree: extra_indent = extra_indent + 2 for child in row.iterchildren(): append_row(child, extra_indent=extra_indent)
def _parse_row(sellable, columns): data = [] for col in columns: value = kgetattr(sellable, col) if value is None: value = '' elif isinstance(value, str): # XXX: glabels is not working with unicode caracters value = strip_accents(value) data.append(value) return data
def append_row(row, extra_indent=0): inst = row[0] cols = [] cols = [ repr(kgetattr(inst, col.attribute, None)) for col in objectlist.get_columns() ] extra.append("%srow: %s" % (' ' * extra_indent, ', '.join(cols))) if is_tree: extra_indent = extra_indent + 2 for child in row.iterchildren(): append_row(child, extra_indent=extra_indent)
def activate(self, titulo = "", parent = None): """ Exibe o diálogo para a seleção do registro. Retorna None se o diálogo foi cancelado ou a tupla com campos_retorno caso tenha escolhido um item. """ self.dialog = self.create_dialog(titulo or "Pesquisa", parent) self.lista.add_list(self.view_items) ret = None response = self.dialog.run() if response == gtk.RESPONSE_OK: selected = self.lista.get_selected() ret = [kgetattr(selected, campo) for campo in self.campos_retorno] self.dialog.hide() return ret
def _reset_widget(self, attribute, widget): if self._model is None: # if we have no model, leave value unset so we pick up # the widget default below. value = ValueUnset else: # if we have a model, grab its value to update the widgets self._register_proxy_in_model(attribute) value = kgetattr(self._model, attribute, ValueUnset) self.update(attribute, value, block=True) # The initial value of the model is set, at this point # do a read, it'll trigger a validation for widgets who # supports it. if not IValidatableProxyWidget.providedBy(widget): return widget.validate(force=True)
def get_cell(self, obj, column): #XXX Maybe the default value should be '' return column.as_string(kgetattr(obj, column.attribute, None), obj)
def update(self, attribute, value=ValueUnset, block=False): """ Generic frontend function to update the contentss of a widget based on its model attribute name using the internal update functions. :param attribute: the name of the attribute whose widget we wish to updated. If accessing a radiobutton, specify its group name. :param value: specifies the value to set in the widget. If unspecified, it defaults to the current model's value (through an accessor, if it exists, or getattr). :param block: defines if we are to block cascading proxy updates triggered by this update. You should use block if you are calling update on *the same attribute that is currently being updated*. This means if you have hooked to a signal of the widget associated to that attribute, and you call update() for the *same attribute*, use block=True. And pray. 8). If block is set to False, the normal update mechanism will occur (the model being updated in the end, hopefully). """ if value is ValueUnset: # We want to obtain a value from our model if self._model is None: # We really want to avoid trying to update our UI if our # model doesn't exist yet and no value was provided. # update() is also called by user code, but it should be # safe to return here since you shouldn't need to code # around the lack of a model in your callbacks if you # can help it. value = ValueUnset else: value = kgetattr(self._model, attribute, ValueUnset) widget = self._model_attributes.get(attribute, None) if widget is None: raise AttributeError( "Called update for `%s', which isn't " "attached to the proxy %s. Valid " "attributes are: %s (you may have " "forgetten to add `:' to the name in " "the widgets list)" % (attribute, self, self._model_attributes.keys()) ) # The type of value should match the data-type property. The two # exceptions to this rule are ValueUnset and None if not (value is ValueUnset or value is None): data_type = _get_widget_data_type(widget) if not isinstance(value, data_type) and issubclass(data_type, basestring): if data_type is basestring: # basestring cannot be instantiated, so use str instead data_type = str try: value = data_type(value) except UnicodeDecodeError: raise TypeError( "attribute %s of model %r cannot be converted " "to %s" % (attribute, self._model, data_type.__name__) ) elif not isinstance(value, data_type): value_type = type(value) raise TypeError( "attribute %s of model %r requires a value of " "type %s, not %s" % (attribute, self._model, data_type.__name__, value_type.__name__) ) if block: block_widget(widget) self._view.handler_block(attribute) widget.update(value) self._view.handler_unblock(attribute) unblock_widget(widget) else: widget.update(value) return True
def update(self, attribute, value=ValueUnset, block=False): """ Generic frontend function to update the contentss of a widget based on its model attribute name using the internal update functions. :param attribute: the name of the attribute whose widget we wish to updated. If accessing a radiobutton, specify its group name. :param value: specifies the value to set in the widget. If unspecified, it defaults to the current model's value (through an accessor, if it exists, or getattr). :param block: defines if we are to block cascading proxy updates triggered by this update. You should use block if you are calling update on *the same attribute that is currently being updated*. This means if you have hooked to a signal of the widget associated to that attribute, and you call update() for the *same attribute*, use block=True. And pray. 8). If block is set to False, the normal update mechanism will occur (the model being updated in the end, hopefully). """ if value is ValueUnset: # We want to obtain a value from our model if self._model is None: # We really want to avoid trying to update our UI if our # model doesn't exist yet and no value was provided. # update() is also called by user code, but it should be # safe to return here since you shouldn't need to code # around the lack of a model in your callbacks if you # can help it. value = ValueUnset else: value = kgetattr(self._model, attribute, ValueUnset) widget = self._model_attributes.get(attribute, None) if widget is None: raise AttributeError("Called update for `%s', which isn't " "attached to the proxy %s. Valid " "attributes are: %s (you may have " "forgetten to add `:' to the name in " "the widgets list)" % (attribute, self, self._model_attributes.keys())) # The type of value should match the data-type property. The two # exceptions to this rule are ValueUnset and None if not (value is ValueUnset or value is None): data_type = _get_widget_data_type(widget) if (not isinstance(value, data_type) and issubclass(data_type, basestring)): if data_type is basestring: # basestring cannot be instantiated, so use str instead data_type = str try: value = data_type(value) except UnicodeDecodeError: raise TypeError( "attribute %s of model %r cannot be converted " "to %s" % (attribute, self._model, data_type.__name__)) elif not isinstance(value, data_type): value_type = type(value) raise TypeError( "attribute %s of model %r requires a value of " "type %s, not %s" % ( attribute, self._model, data_type.__name__, value_type.__name__)) if block: block_widget(widget) self._view.handler_block(attribute) widget.update(value) self._view.handler_unblock(attribute) unblock_widget(widget) else: widget.update(value) return True
def get_cell(self, obj, column): value = kgetattr(obj, column.attribute, None) if column.attribute == 'is_adjusted': return _(u"Yes") if value else _(u"No") return column.as_string(value)
def get_row(self, obj): row = [] for c in self._columns: data_source = c.as_string(kgetattr(obj, c.attribute, None)) row.append(data_source) return row