From c4fcd98fdc33fee03e29f5c02328299b749cf9e0 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 19 Mar 2006 06:49:03 +0000 Subject: [PATCH] object sharing support svn: r6178 --- gramps2/ChangeLog | 8 +++ gramps2/src/DisplayTabs.py | 38 ++++++++--- gramps2/src/Editors/_EditFamily.py | 90 ++++++++++++++++--------- gramps2/src/ListModel.py | 18 +++-- gramps2/src/SelectEvent.py | 9 ++- gramps2/src/SelectSource.py | 104 +++++++++++++++++++++++++++++ gramps2/src/glade/gramps.glade | 2 +- 7 files changed, 215 insertions(+), 54 deletions(-) create mode 100644 gramps2/src/SelectSource.py diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 7355fa23f..267873a59 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,11 @@ +2006-03-18 Don Allingham + * src/Editors/_EditFamily.py: add add_person functionality + * src/DisplayTabs.py: add share option to sources + * src/glade/gramps.glade: change dialog size + * src/ListModel.py: fixed column widths, ellipses + * src/SelectEvent.py: grab correct field + * src/SelectSource.py: added + 2006-03-18 Alex Roitman * configure.in: Remove scrollkeeper checks and other unused statements. diff --git a/gramps2/src/DisplayTabs.py b/gramps2/src/DisplayTabs.py index 281ae8a39..c651802c1 100644 --- a/gramps2/src/DisplayTabs.py +++ b/gramps2/src/DisplayTabs.py @@ -622,16 +622,17 @@ class EventEmbedList(EmbeddedList): sel = SelectEvent.SelectEvent(self.dbstate.db,"Event Select") event = sel.run() - try: - ref = RelLib.EventRef() - if self.obj.__class__.__name__ == 'Person': - ref.set_role((RelLib.EventRef.PRIMARY,'')) - else: - ref.set_role((RelLib.EventRef.FAMILY,'')) - EditEventRef(self.dbstate,self.uistate,self.track, - event, ref, self.obj, self.event_added) - except Errors.WindowActiveError: - pass + if event: + try: + ref = RelLib.EventRef() + if self.obj.__class__.__name__ == 'Person': + ref.set_role((RelLib.EventRef.PRIMARY,'')) + else: + ref.set_role((RelLib.EventRef.FAMILY,'')) + EditEventRef(self.dbstate,self.uistate,self.track, + event, ref, self.obj, self.event_added) + except Errors.WindowActiveError: + pass def edit_button_clicked(self,obj): ref = self.get_selected() @@ -1371,7 +1372,7 @@ class SourceEmbedList(EmbeddedList): def __init__(self,dbstate,uistate,track,obj): self.obj = obj EmbeddedList.__init__(self, dbstate, uistate, track, - _('Sources'), SourceRefModel) + _('Sources'), SourceRefModel, True) def get_icon_name(self): return 'gramps-event' @@ -1393,6 +1394,21 @@ class SourceEmbedList(EmbeddedList): except Errors.WindowActiveError: pass + def share_button_clicked(self,obj): + from Editors import EditSourceRef + import SelectSource + + sel = SelectSource.SelectSource(self.dbstate.db,"Source Select") + src = sel.run() + sref = RelLib.SourceRef() + if src: + try: + ref = RelLib.SourceRef() + EditSourceRef(self.dbstate,self.uistate,self.track, + src, sref, self.add_callback) + except Errors.WindowActiveError: + pass + def add_callback(self,reference, primary): self.get_data().append(reference) self.changed = True diff --git a/gramps2/src/Editors/_EditFamily.py b/gramps2/src/Editors/_EditFamily.py index 317144169..860bd3007 100644 --- a/gramps2/src/Editors/_EditFamily.py +++ b/gramps2/src/Editors/_EditFamily.py @@ -105,7 +105,7 @@ class ChildEmbedList(EmbeddedList): """ self.family = family EmbeddedList.__init__(self, dbstate, uistate, track, - _('Children'), ChildModel) + _('Children'), ChildModel, True) def find_index(self,obj): """ @@ -184,41 +184,67 @@ class ChildEmbedList(EmbeddedList): return [(1,0),(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(0,8),(0,9)] def add_button_clicked(self,obj): - # we could workout the death years of the parents here and - # set a suitable filter_spec on the PersonSelector - # we might also be able to set a filter that only includes - # people that are not already listed as children in another - # family. - selector = PersonSelector(self.dbstate,self.uistate,self.track) + from Editors import EditPerson - # this need the window handle of the main EditFamily window - # to make the PersonSelector transient to it. I am not sure - # want the best way is to get that handle from here. - #selector.set_transient_for(self.window) + person = RelLib.Person() + EditPerson(self.dbstate,self.uistate,[],person, self.new_child_added) - # Connect this to the method used to add a new child. - #selector.connect('add-object',self.on_add_child) + def new_child_added(self, person): + self.family.add_child_handle(person.get_handle()) + self.rebuild() + + def share_button_clicked(self,obj): + from SelectPerson import SelectPerson + + # it only makes sense to skip those who are already in the family - selector.connect('add-object',self.on_change_child) + skip = [self.family.get_father_handle(), + self.family.get_mother_handle()] + self.family.get_child_handle_list() - def on_change_child(self, selector_window, obj): - if obj.__class__ == RelLib.Person: - try: - person = obj - self.family.add_child_handle(person.get_handle()) - self.rebuild() - except: - log.warn( - "Failed to update child: \n" - "obj returned from selector was: %s\n" - % (repr(obj),)) - raise - else: - log.warn( - "Object selector returned obj.__class__ = %s, it should " - "have been of type %s." % (obj.__class__.__name__, - RelLib.Person.__name__)) - selector_window.close() + sel = SelectPerson(self.dbstate.db, "Select Child", + skip=[ x for x in skip if x]) + person = sel.run() + + if person: + self.family.add_child_handle(person.get_handle()) + self.rebuild() + +# def add_button_clicked(self,obj): +# # we could workout the death years of the parents here and +# # set a suitable filter_spec on the PersonSelector +# # we might also be able to set a filter that only includes +# # people that are not already listed as children in another +# # family. +# selector = PersonSelector(self.dbstate,self.uistate,self.track) + +# # this need the window handle of the main EditFamily window +# # to make the PersonSelector transient to it. I am not sure +# # want the best way is to get that handle from here. +# #selector.set_transient_for(self.window) + +# # Connect this to the method used to add a new child. +# #selector.connect('add-object',self.on_add_child) + +# selector.connect('add-object',self.on_change_child) + +# def on_change_child(self, selector_window, obj): +# if obj.__class__ == RelLib.Person: +# try: +# person = obj +# self.family.add_child_handle(person.get_handle()) +# self.rebuild() +# except: +# log.warn( +# "Failed to update child: \n" +# "obj returned from selector was: %s\n" +# % (repr(obj),)) +# raise +# else: +# log.warn( +# "Object selector returned obj.__class__ = %s, it should " +# "have been of type %s." % (obj.__class__.__name__, +# RelLib.Person.__name__)) +# selector_window.close() def del_button_clicked(self,obj): handle = self.get_selected() diff --git a/gramps2/src/ListModel.py b/gramps2/src/ListModel.py index f4b575e4d..48dbd90f0 100644 --- a/gramps2/src/ListModel.py +++ b/gramps2/src/ListModel.py @@ -18,8 +18,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -from gobject import TYPE_STRING, TYPE_PYOBJECT, TYPE_OBJECT, TYPE_BOOLEAN import gtk +import pango import const gtk26 = gtk.pygtk_version >= (2,6,0) @@ -39,15 +39,16 @@ class ListModel: def __init__(self,tree,dlist,select_func=None, event_func=None,mode=gtk.SELECTION_SINGLE): self.tree = tree + self.tree.set_fixed_height_mode(True) self.mylist = [] self.data_index = 0 for l in dlist: if len(l)>3 and l[3] == TOGGLE: - self.mylist.append(TYPE_BOOLEAN) + self.mylist.append(bool) else: - self.mylist.append(TYPE_STRING) + self.mylist.append(str) self.data_index += 1 - self.mylist.append(TYPE_PYOBJECT) + self.mylist.append(object) self.function = {} self.tree.set_rules_hint(True) @@ -62,6 +63,9 @@ class ListModel: cnum = 0 for name in dlist: + if not name[2]: + continue + if len(name) == 3: name = (name[0],name[1],name[2],TEXT,False, None) elif len(name) == 4: @@ -73,7 +77,7 @@ class ListModel: column.add_attribute(renderer,'active',cnum) elif gtk26 and name[3] == COMBO: store = gtk.ListStore(str) - model = gtk.ListStore(str,TYPE_OBJECT) + model = gtk.ListStore(str, object) for val in name[4]: model.append((val,store)) self.function[cnum] = name[5] @@ -88,6 +92,7 @@ class ListModel: else: renderer = gtk.CellRendererText() renderer.set_fixed_height_from_font(True) + renderer.set_property('ellipsize', pango.ELLIPSIZE_END) if name[5]: renderer.set_property('editable',True) renderer.connect('edited',self.edited_cb, cnum) @@ -108,6 +113,9 @@ class ListModel: column.set_clickable(True) column.set_sort_column_id(name[1]) + column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) + column.set_fixed_width(name[2]) + cnum += 1 self.cids.append(name[1]) if name[0] != '': diff --git a/gramps2/src/SelectEvent.py b/gramps2/src/SelectEvent.py index f66a10dc7..2e73b8534 100644 --- a/gramps2/src/SelectEvent.py +++ b/gramps2/src/SelectEvent.py @@ -64,9 +64,8 @@ class SelectEvent: Utils.set_titles(self.top,title_label,title) - titles = [(_('Description'),4,150), (_('ID'),1,50), - (_('Type'),2,70), (_('Date'),3,50), (_('Place'),3,150), - (_('Cause'),3,50), ('',4,0) ] + titles = [(_('Description'),4,250), (_('ID'),1,75), + (_('Type'),2,75), (_('Date'),3,150), ('',4,0) ] self.ncols = len(titles) self.model = ListModel.ListModel(self.elist,titles) @@ -98,7 +97,7 @@ class SelectEvent: pname = u'' date = DateHandler.get_date(event) cause = event.get_cause() - self.model.add([desc,the_id,name,date,pname,cause],handle) + self.model.add([desc,the_id,name,date],handle) self.model.connect_model() @@ -109,7 +108,7 @@ class SelectEvent: store,node = self.model.get_selected() if node: data = self.model.get_data(node,range(self.ncols)) - handle = data[6] + handle = data[4] return_value = self.db.get_event_from_handle(handle) else: return_value = None diff --git a/gramps2/src/SelectSource.py b/gramps2/src/SelectSource.py new file mode 100644 index 000000000..73c96b8b8 --- /dev/null +++ b/gramps2/src/SelectSource.py @@ -0,0 +1,104 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2003-2005 Donald N. Allingham +# +# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id: SelectEvent.py 6155 2006-03-16 20:24:27Z rshura $ + +#------------------------------------------------------------------------- +# +# internationalization +# +#------------------------------------------------------------------------- +from TransUtils import sgettext as _ + +#------------------------------------------------------------------------- +# +# GTK/Gnome modules +# +#------------------------------------------------------------------------- + +import gtk +import gtk.glade + +#------------------------------------------------------------------------- +# +# gramps modules +# +#------------------------------------------------------------------------- +import const +import Utils +import ListModel +import RelLib +import DateHandler + +#------------------------------------------------------------------------- +# +# SelectEvent +# +#------------------------------------------------------------------------- +class SelectSource: + + def __init__(self,db,title,parent_window=None): + + self.db = db + self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps") + self.top = self.glade.get_widget('select_person') + title_label = self.glade.get_widget('title') + self.elist = self.glade.get_widget('plist') + + Utils.set_titles(self.top,title_label,title) + + titles = [(_('Title'),4,350), (_('ID'),1,50), ('',0,0)] + self.ncols = len(titles) + + self.model = ListModel.ListModel(self.elist,titles) + + self.redraw() + self.top.show() + + if parent_window: + self.top.set_transient_for(parent_window) + + def redraw(self): + self.model.clear() + self.model.new_model() + + for handle in self.db.get_source_handles(): + source = self.db.get_source_from_handle(handle) + desc = source.get_title() + the_id = source.get_gramps_id() + self.model.add([desc,the_id,handle]) + self.model.connect_model() + + def run(self): + val = self.top.run() + + if val == gtk.RESPONSE_OK: + store,node = self.model.get_selected() + if node: + data = self.model.get_data(node,range(self.ncols)) + handle = data[2] + return_value = self.db.get_source_from_handle(handle) + else: + return_value = None + self.top.destroy() + return return_value + else: + self.top.destroy() + return None diff --git a/gramps2/src/glade/gramps.glade b/gramps2/src/glade/gramps.glade index a8796b3f8..207f5d1ff 100644 --- a/gramps2/src/glade/gramps.glade +++ b/gramps2/src/glade/gramps.glade @@ -4023,7 +4023,7 @@ Text Beside Icons GTK_WINDOW_TOPLEVEL GTK_WIN_POS_CENTER_ON_PARENT True - 500 + 600 450 True False