From 9a0bc027fe0a6b12ee0bd17c2768a550b5e42993 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Mon, 27 May 2013 19:59:27 +0000 Subject: [PATCH] 6781: Allow editing in displaytabs for some fields svn: r22437 --- .../gui/editors/displaytabs/embeddedlist.py | 31 ++++++++++++-- .../editors/displaytabs/srcattrembedlist.py | 41 ++++++++++++++++++- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/gramps/gui/editors/displaytabs/embeddedlist.py b/gramps/gui/editors/displaytabs/embeddedlist.py index 51875dfe0..5dcb077b7 100644 --- a/gramps/gui/editors/displaytabs/embeddedlist.py +++ b/gramps/gui/editors/displaytabs/embeddedlist.py @@ -61,6 +61,7 @@ from .buttontab import ButtonTab TEXT_COL = 0 MARKUP_COL = 1 ICON_COL = 2 +TEXT_EDIT_COL = 3 #------------------------------------------------------------------------- # @@ -458,6 +459,18 @@ class EmbeddedList(ButtonTab): """ raise NotImplementedError + def setup_editable_col(self): + """ + inherit this and set the variables needed for editable columns + Variable edit_col_funcs needs to be a dictionary from model col_nr to + function to call for + Example: + self.edit_col_funcs ={1: {'edit_start': self.on_edit_start, + 'edited': self.on_edited + }} + """ + self.edit_col_funcs ={} + def build_columns(self): """ Builds the columns and inserts them into the TreeView. Any @@ -470,9 +483,9 @@ class EmbeddedList(ButtonTab): list(map(self.tree.remove_column, self.columns)) self.columns = [] + self.setup_editable_col() # loop through the values returned by column_order - for pair in self.column_order(): # if the first value isn't 1, then we skip the values @@ -484,10 +497,13 @@ class EmbeddedList(ButtonTab): # from the model column specified in pair[1] name = self._column_names[pair[1]][0] col_icon = self._column_names[pair[1]][5] - if (self._column_names[pair[1]][3] in [TEXT_COL, MARKUP_COL]): + model_col = self._column_names[pair[1]][1] + type_col = self._column_names[pair[1]][3] + + if (type_col in [TEXT_COL, MARKUP_COL, TEXT_EDIT_COL]): renderer = Gtk.CellRendererText() renderer.set_property('ellipsize', Pango.EllipsizeMode.END) - if self._column_names[pair[1]][3] == 0: + if type_col == TEXT_COL or type_col == TEXT_EDIT_COL: column = Gtk.TreeViewColumn(name, renderer, text=pair[1]) else: column = Gtk.TreeViewColumn(name, renderer, markup=pair[1]) @@ -495,6 +511,15 @@ class EmbeddedList(ButtonTab): #apply weight attribute column.add_attribute(renderer, "weight", self._column_names[pair[1]][4]) + #set up editable + if type_col == TEXT_EDIT_COL: + #model col must have functions defined + callbacks = self.edit_col_funcs[model_col] + for renderer in column.get_cells(): + renderer.set_property('editable', not self.dbstate.db.readonly) + renderer.connect('editing_started', + callbacks['edit_start'], model_col) + renderer.connect('edited', callbacks['edited'], model_col) elif self._column_names[pair[1]][3] == ICON_COL: self.col_icons[pair[1]] = col_icon self.pb_renderer = Gtk.CellRendererPixbuf() diff --git a/gramps/gui/editors/displaytabs/srcattrembedlist.py b/gramps/gui/editors/displaytabs/srcattrembedlist.py index c47b81fd4..9ca5f9302 100644 --- a/gramps/gui/editors/displaytabs/srcattrembedlist.py +++ b/gramps/gui/editors/displaytabs/srcattrembedlist.py @@ -38,7 +38,8 @@ from gramps.gen.lib import SrcAttribute from gramps.gen.errors import WindowActiveError from ...ddtargets import DdTargets from .attrmodel import AttrModel -from .embeddedlist import EmbeddedList, TEXT_COL, MARKUP_COL, ICON_COL +from .embeddedlist import (EmbeddedList, TEXT_COL, MARKUP_COL, ICON_COL, + TEXT_EDIT_COL) #------------------------------------------------------------------------- # @@ -62,7 +63,7 @@ class SrcAttrEmbedList(EmbeddedList): # (name, sortcol in model, width, markup/text, weigth_col, icon _column_names = [ (_('Type'), 0, 250, TEXT_COL, -1, None), - (_('Value'), 1, 200, TEXT_COL, -1, None), + (_('Value'), 1, 200, TEXT_EDIT_COL, -1, None), (_('Private'), 2, 30, ICON_COL, -1, 'gramps-lock') ] @@ -93,6 +94,42 @@ class SrcAttrEmbedList(EmbeddedList): def column_order(self): return ((1, 2), (1, 0), (1, 1)) + def setup_editable_col(self): + """ + inherit this and set the variables needed for editable columns + Variable edit_col_funcs needs to be a dictionary from model col_nr to + function to call for + Example: + self.edit_col_funcs ={1: {'edit_start': self.on_edit_start, + 'edited': self.on_edited + }} + """ + self.edit_col_funcs ={1: {'edit_start': self.on_value_edit_start, + 'edited': self.on_value_edited}} + + def on_value_edit_start(self, cellr, celle, path, colnr): + """ + Start of editing. Store stuff so we know when editing ends where we + are + """ + pass + #self.curr_col = colnr + #self.curr_cellr = cellr + #self.curr_celle = celle + + def on_value_edited(self, cell, path, new_text, colnr): + """ + Edit happened. The model is updated and the attr objects updated. + colnr must be the column in the model. + """ + node = self.model.get_iter(path) + self.model.set_value(node, colnr, new_text) + ## Now we need to update the data in the object driving the editor. + #path appears to be a string + path = int(path) + attr = self.data[path] + attr.set_value(new_text) + def add_button_clicked(self, obj): pname = '' attr = SrcAttribute()