Embedded Clone Event w. references (2nd pass, part A)

This commit is contained in:
Alois Poettker
2018-04-23 10:39:13 +02:00
parent 208feceb03
commit ae322dbdc8
6 changed files with 83 additions and 19 deletions

View File

@@ -89,7 +89,9 @@ class BackRefList(EmbeddedList):
def is_empty(self): def is_empty(self):
return self.model.count == 0 return self.model.count == 0
def _create_buttons(self, share=False, move=False, jump=False, top_label=None): def _create_buttons(self,
share=False, clone=False, move=False, jump=False,
top_label=None):
""" """
Create a button box consisting of one button: Edit. Create a button box consisting of one button: Edit.
This button box is then appended hbox (self). This button box is then appended hbox (self).

View File

@@ -3,6 +3,7 @@
# #
# Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2009-2011 Gary Burton # Copyright (C) 2009-2011 Gary Burton
# Copyright (C) 2018 Alois Poettker
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@@ -70,13 +71,16 @@ class ButtonTab(GrampsTab):
'del' : _('Remove'), 'del' : _('Remove'),
'edit' : _('Edit'), 'edit' : _('Edit'),
'share' : _('Share'), 'share' : _('Share'),
'clone' : _('Clone'),
'jump' : _('Jump To'), 'jump' : _('Jump To'),
'up' : _('Move Up'), 'up' : _('Move Up'),
'down' : _('Move Down'), 'down' : _('Move Down'),
} }
def __init__(self, dbstate, uistate, track, name, share_button=False, def __init__(self, dbstate, uistate, track, name,
move_buttons=False, jump_button=False, top_label=None): share_button=False, clone_button=False,
move_buttons=False, jump_button=False,
top_label=None):
""" """
Similar to the base class, except after Build. Similar to the base class, except after Build.
@@ -95,6 +99,8 @@ class ButtonTab(GrampsTab):
@type name: str/unicode @type name: str/unicode
@param share_button: Add a share button to the Notebook tab or not @param share_button: Add a share button to the Notebook tab or not
@type name: bool @type name: bool
@param clone_button: Add a clone button to the Notebook tab or not
@type name: bool
@param move_buttons: Add up and down button to the Notebook tab or not @param move_buttons: Add up and down button to the Notebook tab or not
@type name: bool @type name: bool
@param jump_button: Add a goto button @param jump_button: Add a goto button
@@ -103,17 +109,20 @@ class ButtonTab(GrampsTab):
@type top_label: string or None for no label @type top_label: string or None for no label
""" """
self.dirty_selection = False self.dirty_selection = False
GrampsTab.__init__(self,dbstate, uistate, track, name) GrampsTab.__init__(self, dbstate, uistate, track, name)
self._create_buttons(share_button, move_buttons, jump_button, top_label) self._create_buttons(share_button, clone_button,
move_buttons, jump_button,
top_label)
def _create_buttons(self, share_button, move_buttons, jump_button, def _create_buttons(self,
top_label): share_button, clone_button, move_buttons, jump_button,
top_label):
""" """
Create a button box consisting of three buttons, one for Add, Create a button box consisting of three buttons, one for Add,
one for Edit, and one for Delete. one for Edit, and one for Delete.
Add buttons for Share, Move and Jump depending on parameters. This Add buttons for Share, Clone, Move and Jump depending on parameters.
button box is then appended hbox (self). This button box is then appended hbox (self).
Prepend a label if top_label given Prepend a label if top_label given
Note: some ButtonTab subclasses override this method. Note: some ButtonTab subclasses override this method.
@@ -141,6 +150,13 @@ class ButtonTab(GrampsTab):
else: else:
self.share_btn = None self.share_btn = None
if clone_button:
self.clone_btn = SimpleButton('gramps-clone', self.clone_button_clicked)
self.clone_btn.set_tooltip_text(self._MSG['clone'])
self.track_ref_for_deletion("clone_btn")
else:
self.clone_btn = None
if move_buttons: if move_buttons:
self.up_btn = SimpleButton('go-up', self.up_button_clicked) self.up_btn = SimpleButton('go-up', self.up_button_clicked)
self.up_btn.set_tooltip_text(self._MSG['up']) self.up_btn.set_tooltip_text(self._MSG['up'])
@@ -167,6 +183,8 @@ class ButtonTab(GrampsTab):
if share_button: if share_button:
hbox.pack_start(self.share_btn, False, True, 0) hbox.pack_start(self.share_btn, False, True, 0)
hbox.pack_start(self.edit_btn, False, True, 0) hbox.pack_start(self.edit_btn, False, True, 0)
if clone_button:
hbox.pack_start(self.clone_btn, False, True, 0)
hbox.pack_start(self.del_btn, False, True, 0) hbox.pack_start(self.del_btn, False, True, 0)
if move_buttons: if move_buttons:
hbox.pack_start(self.up_btn, False, True, 0) hbox.pack_start(self.up_btn, False, True, 0)
@@ -182,6 +200,8 @@ class ButtonTab(GrampsTab):
self.del_btn.set_sensitive(False) self.del_btn.set_sensitive(False)
if share_button: if share_button:
self.share_btn.set_sensitive(False) self.share_btn.set_sensitive(False)
if clone_button:
self.clone_btn.set_sensitive(False)
if jump_button and self.jump_btn: if jump_button and self.jump_btn:
self.jump_btn.set_sensitive(False) self.jump_btn.set_sensitive(False)
if move_buttons: if move_buttons:
@@ -246,6 +266,13 @@ class ButtonTab(GrampsTab):
""" """
print("Uncaught Share clicked") print("Uncaught Share clicked")
def clone_button_clicked(self, obj):
"""
Function called with the Clone button is clicked. This function
should be overridden by the derived class.
"""
print("Uncaught Clone clicked")
def jump_button_clicked(self, obj): def jump_button_clicked(self, obj):
""" """
Function called with the Jump button is clicked. This function Function called with the Jump button is clicked. This function
@@ -284,8 +311,8 @@ class ButtonTab(GrampsTab):
def _selection_changed(self, obj=None): def _selection_changed(self, obj=None):
""" """
Attached to the selection's 'changed' signal. Checks Attached to the selection's 'changed' signal. Checks to see
to see if anything is selected. If it is, the edit and if anything is selected. If it is, the edit, clone and
delete buttons are enabled, otherwise the are disabled. delete buttons are enabled, otherwise the are disabled.
""" """
# Comparing to None is important, as empty strings # Comparing to None is important, as empty strings
@@ -296,6 +323,8 @@ class ButtonTab(GrampsTab):
return return
if self.get_selected() is not None: if self.get_selected() is not None:
self.edit_btn.set_sensitive(True) self.edit_btn.set_sensitive(True)
if self.clone_btn:
self.clone_btn.set_sensitive(True)
if self.jump_btn: if self.jump_btn:
self.jump_btn.set_sensitive(True) self.jump_btn.set_sensitive(True)
if not self.dbstate.db.readonly: if not self.dbstate.db.readonly:
@@ -307,6 +336,8 @@ class ButtonTab(GrampsTab):
# self.down_btn.set_sensitive(True) # self.down_btn.set_sensitive(True)
else: else:
self.edit_btn.set_sensitive(False) self.edit_btn.set_sensitive(False)
if self.clone_btn:
self.clone_btn.set_sensitive(False)
if self.jump_btn: if self.jump_btn:
self.jump_btn.set_sensitive(False) self.jump_btn.set_sensitive(False)
if not self.dbstate.db.readonly: if not self.dbstate.db.readonly:

View File

@@ -76,13 +76,16 @@ class EmbeddedList(ButtonTab):
_DND_EXTRA = None _DND_EXTRA = None
def __init__(self, dbstate, uistate, track, name, build_model, def __init__(self, dbstate, uistate, track, name, build_model,
share_button=False, move_buttons=False, jump_button=False, share_button=False, clone_button=False,
move_buttons=False, jump_button=False,
top_label=None): top_label=None):
""" """
Create a new list, using the passed build_model to populate the list. Create a new list, using the passed build_model to populate the list.
""" """
ButtonTab.__init__(self, dbstate, uistate, track, name, share_button, ButtonTab.__init__(self, dbstate, uistate, track, name,
move_buttons, jump_button, top_label) share_button, clone_button,
move_buttons, jump_button,
top_label)
self.changed = False self.changed = False
self.model = None self.model = None

View File

@@ -3,6 +3,7 @@
# #
# Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2009 B. Malengier # Copyright (C) 2009 B. Malengier
# Copyright (C) 2018 Alois Poettker
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@@ -65,6 +66,7 @@ class EventEmbedList(DbGUIElement, GroupEmbeddedList):
'del' : _('Remove the selected family event'), 'del' : _('Remove the selected family event'),
'edit' : _('Edit the selected family event or edit person'), 'edit' : _('Edit the selected family event or edit person'),
'share' : _('Share an existing event'), 'share' : _('Share an existing event'),
'clone' : _('Clone an existing event'),
'up' : _('Move the selected event upwards'), 'up' : _('Move the selected event upwards'),
'down' : _('Move the selected event downwards'), 'down' : _('Move the selected event downwards'),
} }
@@ -96,7 +98,7 @@ class EventEmbedList(DbGUIElement, GroupEmbeddedList):
self._data = [] self._data = []
DbGUIElement.__init__(self, dbstate.db) DbGUIElement.__init__(self, dbstate.db)
GroupEmbeddedList.__init__(self, dbstate, uistate, track, _('_Events'), GroupEmbeddedList.__init__(self, dbstate, uistate, track, _('_Events'),
build_model, share_button=True, build_model, share_button=True, clone_button=True,
move_buttons=True, **kwargs) move_buttons=True, **kwargs)
def _connect_db_signals(self): def _connect_db_signals(self):
@@ -286,6 +288,27 @@ class EventEmbedList(DbGUIElement, GroupEmbeddedList):
key = self._groups[ref[0]][0] key = self._groups[ref[0]][0]
self.editnotworkgroup(key) self.editnotworkgroup(key)
def clone_button_clicked(self, obj):
'Function called with the Clone button is clicked.'
source_ref = self.get_selected()
if source_ref and \
source_ref[1] is not None \
and source_ref[0] == self._WORKGROUP:
source_event = self.dbstate.db.get_event_from_handle(source_ref[1].ref)
try:
ref = EventRef(source=source_ref[1])
event = Event(source=source_event)
event.set_gramps_id(self.dbstate.db.find_next_event_gramps_id())
event.set_handle(None)
self.get_ref_editor()(
self.dbstate, self.uistate, self.track,
event, ref, self.object_added)
except WindowActiveError:
pass
def object_added(self, reference, primary): def object_added(self, reference, primary):
reference.ref = primary.handle reference.ref = primary.handle
data = self.get_data()[self._WORKGROUP] data = self.get_data()[self._WORKGROUP]

View File

@@ -60,17 +60,21 @@ class GroupEmbeddedList(EmbeddedList):
_WORKGROUP = 0 _WORKGROUP = 0
def __init__(self, dbstate, uistate, track, name, build_model, def __init__(self, dbstate, uistate, track, name, build_model,
share_button=False, move_buttons=False, jump_button=False, **kwargs): share_button=False, clone_button=False,
move_buttons=False, jump_button=False, **kwargs):
""" """
Create a new list, using the passed build_model to populate the list. Create a new list, using the passed build_model to populate the list.
""" """
self.kwargs = kwargs self.kwargs = kwargs
EmbeddedList.__init__(self, dbstate, uistate, track, name, build_model, EmbeddedList.__init__(self, dbstate, uistate, track, name, build_model,
share_button, move_buttons, jump_button) share_button, clone_button,
#connect click on the first column move_buttons, jump_button)
# connect click on the first column
self.columns[0].connect('clicked', self.groupcol_click) self.columns[0].connect('clicked', self.groupcol_click)
for col in self.columns[1:]: for col in self.columns[1:]:
col.connect('clicked', self.col_click) col.connect('clicked', self.col_click)
self.dbsort = True self.dbsort = True
def construct_model(self): def construct_model(self):

View File

@@ -57,6 +57,7 @@ class PersonEventEmbedList(EventEmbedList):
'del' : _('Remove the selected personal event'), 'del' : _('Remove the selected personal event'),
'edit' : _('Edit the selected personal event or edit family'), 'edit' : _('Edit the selected personal event or edit family'),
'share' : _('Share an existing event'), 'share' : _('Share an existing event'),
'clone' : _('Clone an existing event'),
'up' : _('Move the selected event upwards or change family order'), 'up' : _('Move the selected event upwards or change family order'),
'down' : _('Move the selected event downwards or change family order'), 'down' : _('Move the selected event downwards or change family order'),
} }