object sharing support

svn: r6178
This commit is contained in:
Don Allingham 2006-03-19 06:49:03 +00:00
parent 0b3ce97a46
commit c4fcd98fdc
7 changed files with 215 additions and 54 deletions

View File

@ -1,3 +1,11 @@
2006-03-18 Don Allingham <don@gramps-project.org>
* 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 <shura@gramps-project.org>
* configure.in: Remove scrollkeeper checks and other unused
statements.

View File

@ -622,6 +622,7 @@ class EventEmbedList(EmbeddedList):
sel = SelectEvent.SelectEvent(self.dbstate.db,"Event Select")
event = sel.run()
if event:
try:
ref = RelLib.EventRef()
if self.obj.__class__.__name__ == 'Person':
@ -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

View File

@ -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)
selector.connect('add-object',self.on_change_child)
def on_change_child(self, selector_window, obj):
if obj.__class__ == RelLib.Person:
try:
person = obj
def new_child_added(self, person):
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 share_button_clicked(self,obj):
from SelectPerson import SelectPerson
# it only makes sense to skip those who are already in the family
skip = [self.family.get_father_handle(),
self.family.get_mother_handle()] + self.family.get_child_handle_list()
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()

View File

@ -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] != '':

View File

@ -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

104
gramps2/src/SelectSource.py Normal file
View File

@ -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

View File

@ -4023,7 +4023,7 @@ Text Beside Icons</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="modal">True</property>
<property name="default_width">500</property>
<property name="default_width">600</property>
<property name="default_height">450</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>