Surname Editor; fix loss of data if using mouse to change fields
Fixes #9868, #6828, #6257
This commit is contained in:
parent
ba4b3eaef6
commit
462b0ea20b
@ -42,6 +42,7 @@ from gi.repository import Pango
|
||||
# Gramps classes
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ...widgets.cellrenderertextedit import CellRendererTextEdit
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
from ...utils import is_right_click
|
||||
@ -482,7 +483,10 @@ class EmbeddedList(ButtonTab):
|
||||
type_col = self._column_names[pair[1]][3]
|
||||
|
||||
if (type_col in [TEXT_COL, MARKUP_COL, TEXT_EDIT_COL]):
|
||||
renderer = Gtk.CellRendererText()
|
||||
if type_col == TEXT_EDIT_COL:
|
||||
renderer = CellRendererTextEdit()
|
||||
else:
|
||||
renderer = Gtk.CellRendererText()
|
||||
renderer.set_property('ellipsize', Pango.EllipsizeMode.END)
|
||||
if type_col == TEXT_COL or type_col == TEXT_EDIT_COL:
|
||||
column = Gtk.TreeViewColumn(name, renderer, text=pair[1])
|
||||
|
@ -45,7 +45,7 @@ _ENTER = Gdk.keyval_from_name("Enter")
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from .surnamemodel import SurnameModel
|
||||
from .embeddedlist import EmbeddedList, TEXT_COL, MARKUP_COL, ICON_COL
|
||||
from .embeddedlist import EmbeddedList, TEXT_EDIT_COL
|
||||
from ...ddtargets import DdTargets
|
||||
from gramps.gen.lib import Surname, NameOriginType
|
||||
from ...utils import get_primary_mask
|
||||
@ -71,9 +71,9 @@ class SurnameTab(EmbeddedList):
|
||||
#index = column in model. Value =
|
||||
# (name, sortcol in model, width, markup/text
|
||||
_column_names = [
|
||||
(_('Prefix'), -1, 150, TEXT_COL, -1, None),
|
||||
(_('Surname'), -1, 250, TEXT_COL, -1, None),
|
||||
(_('Connector'), -1, 100, TEXT_COL, -1, None),
|
||||
(_('Prefix'), 0, 150, TEXT_EDIT_COL, -1, None),
|
||||
(_('Surname'), 1, -1, TEXT_EDIT_COL, -1, None),
|
||||
(_('Connector'), 2, 100, TEXT_EDIT_COL, -1, None),
|
||||
]
|
||||
_column_combo = (_('Origin'), -1, 150, 3) # name, sort, width, modelcol
|
||||
_column_toggle = (_('Name|Primary'), -1, 80, 4)
|
||||
@ -94,14 +94,6 @@ class SurnameTab(EmbeddedList):
|
||||
#first the standard text columns with normal method
|
||||
EmbeddedList.build_columns(self)
|
||||
|
||||
# Need to add attributes to renderers
|
||||
# and connect renderers to the 'edited' signal
|
||||
for colno in range(len(self.columns)):
|
||||
for renderer in self.columns[colno].get_cells():
|
||||
renderer.set_property('editable', not self.dbstate.db.readonly)
|
||||
renderer.connect('editing_started', self.on_edit_start, colno)
|
||||
renderer.connect('edited', self.on_edit_inline, self.column_order()[colno][1])
|
||||
|
||||
# now we add the two special columns
|
||||
# combobox for type
|
||||
colno = len(self.columns)
|
||||
@ -161,6 +153,24 @@ class SurnameTab(EmbeddedList):
|
||||
## svalue = self.cmborigmap[second]
|
||||
## return glocale.strcoll(fvalue, svalue)
|
||||
|
||||
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 = {
|
||||
0: {'edit_start': self.on_edit_start,
|
||||
'edited': self.on_edit_inline},
|
||||
1: {'edit_start': self.on_edit_start,
|
||||
'edited': self.on_edit_inline},
|
||||
2: {'edit_start': self.on_edit_start,
|
||||
'edited': self.on_edit_inline}}
|
||||
|
||||
def get_data(self):
|
||||
return self.obj.get_surname_list()
|
||||
|
||||
|
70
gramps/gui/widgets/cellrenderertextedit.py
Normal file
70
gramps/gui/widgets/cellrenderertextedit.py
Normal file
@ -0,0 +1,70 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2017 Paul Culley
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Python Modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Gtk
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Gramps Modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
class CellRendererTextEdit(Gtk.CellRendererText):
|
||||
""" To be used where you normally use Gtk.CellRendererText and you want to
|
||||
avoid losing the text if the user clicks outside the cell (Like an 'OK'
|
||||
button. """
|
||||
|
||||
__gtype_name__ = 'CellRendererTextEdit'
|
||||
|
||||
def __init__(self):
|
||||
Gtk.CellRendererText.__init__(self)
|
||||
|
||||
def do_start_editing(
|
||||
self, event, treeview, path, background_area, cell_area, flags):
|
||||
if not self.get_property('editable'):
|
||||
return
|
||||
entry = Gtk.Entry()
|
||||
entry.set_has_frame(False)
|
||||
xalign, yalign = self.get_alignment()
|
||||
entry.set_alignment(xalign)
|
||||
entry.set_width_chars(5)
|
||||
entry.set_text(self.get_property("text")) # get original cell text
|
||||
entry.add_events(Gdk.EventMask.FOCUS_CHANGE_MASK)
|
||||
entry.connect('focus-out-event', self.focus_out, path)
|
||||
entry.connect('key-press-event', self._key_press)
|
||||
entry.show()
|
||||
return entry
|
||||
|
||||
def focus_out(self, entry, event, path):
|
||||
self.emit('edited', path, entry.get_text())
|
||||
return False
|
||||
|
||||
def _key_press(self, entry, event):
|
||||
if event.type == Gdk.EventType.KEY_PRESS:
|
||||
if event.keyval == Gdk.KEY_Escape:
|
||||
# get original cell text
|
||||
entry.set_text(self.get_property("text"))
|
||||
return False
|
@ -431,6 +431,7 @@ gramps/gui/views/treemodels/test/node_test.py
|
||||
#
|
||||
gramps/gui/widgets/__init__.py
|
||||
gramps/gui/widgets/basicentry.py
|
||||
gramps/gui/widgets/cellrenderertextedit.py
|
||||
gramps/gui/widgets/dateentry.py
|
||||
gramps/gui/widgets/fanchart2way.py
|
||||
gramps/gui/widgets/fanchartdesc.py
|
||||
|
Loading…
Reference in New Issue
Block a user