def on_object_edit(self, tree_iter, attr, new_value): section = tree_iter._obj cmd = commands.ChangeValue(object=section, attr="name", new_value=new_value) self.execute(cmd)
def on_close(self, window): import commands buffer = self.text.get_buffer() start, end = buffer.get_bounds() text = buffer.get_text(start, end) cmd = commands.ChangeValue(object=self.obj, attr=self.attr, new_value=text) self.execute(cmd)
def on_object_edit(self, tree_iter, column_name, new_text): """ called upon an edit event of the list view updates the underlying model property that corresponds to the edited cell """ section = self.section prop = tree_iter._obj # are we editing the first_row of a <multi> value? first_row = not tree_iter.parent first_row_of_multi = first_row and tree_iter.has_child # can only edit the subvalues, but not <multi> itself if first_row_of_multi and column_name == "value": return if not first_row and column_name == "name": return cmd = None # if we edit another attribute (e.g. unit), set this for all values of this property if first_row_of_multi and column_name != "name": # editing multiple values of a property at once cmds = [] for value in prop.values: cmds.append( commands.ChangeValue(object=value, attr=[column_name, "value"], new_value=new_text)) cmd = commands.Multiple(cmds=cmds) else: # first row edit event for the value, so switch the object if column_name != "name" and first_row: prop = prop.values[0] if not (column_name == "name" and first_row): column_name = [column_name, "value"] # backup the value attribute too cmd = commands.ChangeValue(object=prop, attr=column_name, new_value=new_text) if cmd: self.execute(cmd)
def on_edited(self, widget, row, new_value, col): store = self._store iter = store.get_iter(row) k = store.get_value(iter, COL_KEY) cmd = commands.ChangeValue(object=self._model, attr=self._fmt.map(k), new_value=new_value) self.execute(cmd)
class PropertyView(TerminologyPopupTreeView): """ The Main treeview for editing properties and their value-attributes """ _section = None def __init__(self, registry): super(PropertyView, self).__init__() tv = self._treeview for name, (id, propname) in PropertyModel.ColMapper.sort_iteritems(): column = self.add_column(name=name, edit_func=self.on_edited, id=id, data=propname) if name == "Value": tv.set_expander_column(column) tv.set_headers_visible(True) tv.set_rules_hint(True) tv.show() # set up our drag provider dp = DragProvider(self._treeview) _exec = lambda cmd: self.execute(cmd) vd = ValueDrop(exec_func=_exec) pd = PropertyDrop(exec_func=_exec) sd = SectionDrop(exec_func=_exec) for target in [ OdmlDrag(mime="odml/property-ref", inst=odml.property.Property), TextDrag(mime="odml/property", inst=odml.property.Property), OdmlDrag(mime="odml/value-ref", inst=odml.value.Value), TextDrag(mime="odml/value", inst=odml.value.Value), TextDrag(mime="TEXT"), OdmlDrop(mime="odml/value-ref", target=vd, registry=registry, exec_func=_exec), OdmlDrop(mime="odml/property-ref", target=pd, registry=registry, exec_func=_exec), OdmlDrop(mime="odml/section-ref", target=sd, registry=registry, exec_func=_exec), TextDrop(mime="odml/value", target=vd), TextDrop(mime="odml/property", target=pd), TextDrop(mime="odml/section", target=sd), TextGenericDropForPropertyTV(exec_func=_exec), ]: dp.append(target) dp.execute = _exec @property def section(self): return self._section @section.setter def section(self, section): if self._section is section: return self._section = section if self.model: self.model.destroy() self.model = PropertyModel.PropertyModel(section) @property def model(self): return self._treeview.get_model() @model.setter def model(self, new_value): self._treeview.set_model(new_value) def on_selection_change(self, tree_selection): (model, tree_iter) = tree_selection.get_selected() if not tree_iter: return obj = model.get_object(tree_iter) self.on_property_select(obj) def on_property_select(self, prop): """called when a different property is selected""" pass def on_get_tooltip(self, model, path, iter, tooltip): """ set the tooltip text, if the gui queries for it """ obj = model.get_object(iter) doc = obj.document if doc and hasattr(doc, "validation_result"): errors = doc.validation_result[obj] if len(errors) > 0: tooltip.set_text("\n".join([e.msg for e in errors])) return True def on_object_edit(self, tree_iter, column_name, new_text): """ called upon an edit event of the list view updates the underlying model property that corresponds to the edited cell """ section = self.section prop = tree_iter._obj # are we editing the first_row of a <multi> value? first_row = not tree_iter.parent first_row_of_multi = first_row and tree_iter.has_child # can only edit the subvalues, but not <multi> itself if first_row_of_multi and column_name == "value": return if not first_row and column_name == "name": return cmd = None # if we edit another attribute (e.g. unit), set this for all values of this property if first_row_of_multi and column_name != "name": # editing multiple values of a property at once cmds = [] for value in prop.values: cmds.append( commands.ChangeValue(object=value, attr=[column_name, "value"], new_value=new_text)) cmd = commands.Multiple(cmds=cmds) else: # first row edit event for the value, so switch the object if column_name != "name" and first_row: prop = prop.values[0] if not (column_name == "name" and first_row): column_name = [column_name, "value"] # backup the value attribute too cmd = commands.ChangeValue(object=prop, attr=column_name, new_value=new_text) if cmd: self.execute(cmd) def on_set_mapping(self, menu, (prop, mapping_obj)): """ popup menu action: set mapping for a property """ mapstr = "%s#%s:%s" % (prop.parent.get_repository(), mapping_obj.parent.type, mapping_obj.name) cmd = commands.ChangeValue(object=prop, attr="mapping", new_value=mapstr) self.execute(cmd)