* src/EditFamily.py: Complete save operation, handle new family

* src/EditMedia.py: Add file selector button
* src/FamilyList.py: Save properly
* src/edit_person.glade: lock icon
* src/gramps.glade: file selector button


svn: r5892
This commit is contained in:
Don Allingham 2006-02-06 23:44:09 +00:00
parent 8f979710ec
commit 8b8d359062
7 changed files with 270 additions and 159 deletions

View File

@ -1,3 +1,10 @@
2006-02-06 Don Allingham <don@gramps-project.org>
* src/EditFamily.py: Complete save operation, handle new family
* src/EditMedia.py: Add file selector button
* src/FamilyList.py: Save properly
* src/edit_person.glade: lock icon
* src/gramps.glade: file selector button
2006-02-06 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_GrampsBSDDB.py (transaction_commit): Typo.

View File

@ -30,11 +30,22 @@ import os
import sys
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# 2.4 provides a built in set. We want to use this, but need to handle
# older versions of python as well
#
#-------------------------------------------------------------------------
try:
set()
except:
from sets import Set as set
#-------------------------------------------------------------------------
#
# enable logging for error handling
#
#-------------------------------------------------------------------------
import logging
log = logging.getLogger(".")
@ -70,6 +81,10 @@ from GrampsWidgets import *
from ObjectSelector import PersonSelector,PersonFilterSpec
class ChildEmbedList(EmbeddedList):
"""
The child embed list is specific to the Edit Family dialog, so it
is contained here instead of in DisplayTabs.
"""
_HANDLE_COL = 10
_DND_TYPE = DdTargets.PERSON_LINK
@ -88,11 +103,20 @@ class ChildEmbedList(EmbeddedList):
]
def __init__(self,dbstate,uistate,track,family):
"""
Create the object, storing the passed family value
"""
self.family = family
EmbeddedList.__init__(self, dbstate, uistate, track,
_('Children'), ChildModel)
def build_columns(self):
"""
We can't use the default build_columns in the base class, because
we are using the custom TypeCellRenderer to handle father parent
relationships. The Paternal and Maternal columns (columns 4 and 5)
use this.
"""
for column in self.columns:
self.tree.remove_column(column)
self.columns = []
@ -115,12 +139,19 @@ class ChildEmbedList(EmbeddedList):
self.tree.append_column(column)
def get_icon_name(self):
return 'gramps-person'
return 'gramps-family'
def is_empty(self):
"""
The list is considered empty if the child list is empty.
"""
return len(self.family.get_child_handle_list()) == 0
def get_data(self):
"""
Normally, get_data returns a list. However, we return family
object here instead.
"""
return self.family
def column_order(self):
@ -173,8 +204,7 @@ class EditFamily(DisplayState.ManagedWindow):
return
self.build_interface()
if self.family:
self.load_data()
self.load_data()
self.mname = None
self.fname = None
@ -207,7 +237,10 @@ class EditFamily(DisplayState.ManagedWindow):
return ('Edit Family','Undefined Submenu')
def build_window_key(self,obj):
return id(self.family.handle)
if self.family.handle:
return id(self.family.handle)
else:
return id(self)
def build_interface(self):
@ -248,7 +281,8 @@ class EditFamily(DisplayState.ManagedWindow):
private.connect('toggled', self.privacy_toggled)
gid = self.top.get_widget('gid')
gid.set_text(self.family.get_gramps_id())
if self.family.get_gramps_id():
gid.set_text(self.family.get_gramps_id())
gid.connect('changed',
lambda x: self.family.set_gramps_id(x.get_text()))
@ -338,11 +372,13 @@ class EditFamily(DisplayState.ManagedWindow):
self.mdeath, self.mbutton)
def on_change_mother(self, selector_window, select_result):
print select_result
if select_result.is_person():
try:
self.update_mother(
self.dbstate.db.get_person_from_gramps_id(
select_result.get_gramps_id()).get_handle())
gid = select_result.get_gramps_id()
person = self.dbstate.db.get_person_from_gramps_id(gid)
self.family.set_mother_handle(person.get_handle())
self.update_mother(person.get_handle())
except:
log.warn(
"Failed to update mother: \n"
@ -391,9 +427,10 @@ class EditFamily(DisplayState.ManagedWindow):
def on_change_father(self, selector_window, select_result):
if select_result.is_person():
try:
self.update_father(
self.dbstate.db.get_person_from_gramps_id(
select_result.get_gramps_id()).get_handle())
gid = select_result.get_gramps_id()
person = self.dbstate.db.get_person_from_gramps_id(gid)
self.family.set_father_handle(person.get_handle())
self.update_father(person.get_handle())
except:
log.warn("Failed to update father: \n"
"gramps_id returned from selector was: %s\n"
@ -483,7 +520,7 @@ class EditFamily(DisplayState.ManagedWindow):
birth_obj.set_text(birth)
death_obj.set_text(death)
def fix_parent_handles(self,orig_handle, new_handle):
def fix_parent_handles(self,orig_handle, new_handle, trans):
if orig_handle != new_handle:
if orig_handle:
person = self.dbstate.db.get_person_from_handle(orig_handle)
@ -496,16 +533,24 @@ class EditFamily(DisplayState.ManagedWindow):
self.dbstate.db.commit_person(person,trans)
def apply_changes(self,obj):
original = self.dbstate.db.get_family_from_handle(self.family.handle)
if self.family.handle:
original = self.dbstate.db.get_family_from_handle(self.family.handle)
else:
original = None
if cmp(original.serialize(),self.family.serialize()):
if not original:
print self.family.serialize()
trans = self.dbstate.db.transaction_begin()
self.dbstate.db.add_family(self.family,trans)
self.dbstate.db.transaction_commit(trans,_("Edit Family"))
elif cmp(original.serialize(),self.family.serialize()):
trans = self.dbstate.db.transaction_begin()
self.fix_parent_handles(original.get_father_handle(),
self.family.get_father_handle())
self.family.get_father_handle(),trans)
self.fix_parent_handles(original.get_mother_handle(),
self.family.get_mother_handle())
self.family.get_mother_handle(),trans)
orig_set = set(original.get_child_handle_list())
new_set = set(self.family.get_child_handle_list())
@ -513,7 +558,10 @@ class EditFamily(DisplayState.ManagedWindow):
# remove the family from children which have been removed
for handle in orig_set.difference(new_set):
person = self.dbstate.db.get_person_from_handle(handle)
print person.get_primary_name().get_name()
print person.get_parent_family_handle_list()
person.remove_parent_family_handle(self.family.handle)
print person.get_parent_family_handle_list()
self.dbstate.db.commit_person(person,trans)
# add the family from children which have been removed
@ -522,9 +570,11 @@ class EditFamily(DisplayState.ManagedWindow):
#person.remove_parent_family_handle(self.family.handle)
#self.dbstate.db.commit_person(person,trans)
self.dbstate.db.commit_family(self.family,trans)
self.dbstate.db.transaction_commit(trans,_("Edit Family"))
self.close_window()
def close_window(self,obj):
def close_window(self,*obj):
for key in self.signal_keys:
self.dbstate.db.disconnect(key)
self.close()

View File

@ -26,6 +26,7 @@
#
#-------------------------------------------------------------------------
from gettext import gettext as _
import os
#-------------------------------------------------------------------------
#
@ -70,7 +71,6 @@ _drag_targets = [
class EditMedia(DisplayState.ManagedWindow):
def __init__(self,state,uistate,track,obj):
#self.parent = parent
self.dp = DateHandler.parser
self.dd = DateHandler.displayer
@ -108,6 +108,9 @@ class EditMedia(DisplayState.ManagedWindow):
title = _('Media Properties Editor')
self.window = self.change_dialog.get_widget('change_global')
self.select = self.change_dialog.get_widget('file_select')
self.select.connect('clicked', self.select_file)
self.date_entry = self.change_dialog.get_widget('date')
self.date_entry.set_editable(mode)
@ -186,6 +189,25 @@ class EditMedia(DisplayState.ManagedWindow):
def on_delete_event(self,obj,b):
self.close()
def select_file(self,obj):
f = gtk.FileChooserDialog(_('Select Media Object'),
action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,
gtk.RESPONSE_OK))
text = self.file_path.get_text()
name = os.path.basename(text)
path = os.path.dirname(text)
f.set_filename(path)
status = f.run()
if status == gtk.RESPONSE_OK:
self.file_path.set_text(f.get_filename())
f.destroy()
def close_window(self,obj):
if self.idle != None:
gobject.source_remove(self.idle)
@ -193,7 +215,8 @@ class EditMedia(DisplayState.ManagedWindow):
def update_info(self):
fname = self.obj.get_path()
self.change_dialog.get_widget("path").set_text(fname)
self.file_path = self.change_dialog.get_widget("path")
self.file_path.set_text(fname)
def on_apply_clicked(self, obj):
desc = unicode(self.descr_window.get_text())

View File

@ -113,7 +113,8 @@ class FamilyListView(PageView.ListView):
def add(self,obj):
import EditFamily
EditFamily.EditFamily(self.dbstate,self.uistate,[],None)
family = RelLib.Family()
EditFamily.EditFamily(self.dbstate,self.uistate,[],family)
def remove(self,obj):
return

View File

@ -7,6 +7,8 @@ from Models import \
PersonTreeModel, PersonListModel, PersonFilterModel
from NameDisplay import displayer
import Utils
display_given = displayer.display_given
@ -19,15 +21,14 @@ class PersonTreeView(gtk.TreeView):
# Add the Name column
cols = (\
(_("Family Name"),300,self._family_name),\
(_("Name"),300,self._family_name),\
(_("ID"),100,self._object_id),\
(_("Given Name"),300,self._given_name),\
(_("Gender"),100,self._gender),\
(_("Birth Date"),200,self._birth_date),\
(_("Birth Place"),200,self._birth_place),\
(_("Death Date"),200,self._death_date),\
(_("Death Place"),200,self._death_place),\
(_("Spouce"),200,self._spouce),\
(_("Spouse"),200,self._spouce),\
(_("Last Change"),200,self._last_change),\
(_("Cause of Death"),300,self._death_cause))
@ -71,30 +72,39 @@ class PersonTreeView(gtk.TreeView):
cell.set_property('text', "")
def _family_name(self, column, cell, model, iter, user_data=None):
(o,rowref) = model.get_value(iter, 0)
cell.set_property('text', str(rowref) + " " + o.get_primary_name().get_surname())
def _given_name(self, column, cell, model, iter, user_data=None):
(o,rowref) = model.get_value(iter, 0)
if len(rowref) > 1:
cell.set_property('text', "")
cell.set_property('text', displayer(o))
else:
cell.set_property('text', "")
cell.set_property('text',o.primary_name.surname)
def _gender(self, column, cell, model, iter, user_data=None):
(o,rowref) = model.get_value(iter, 0)
if len(rowref) > 1:
cell.set_property('text', "")
cell.set_property('text', Utils.gender[o.gender])
else:
cell.set_property('text', "")
def _birth_date(self, column, cell, model, iter, user_data=None):
(o,rowref) = model.get_value(iter, 0)
cell_value = ''
if len(rowref) > 1:
cell.set_property('text', "")
else:
cell.set_property('text', "")
b = o.get_birth_ref()
if b:
birth = self.db.get_event_from_handle(b.ref)
date_str = DateHandler.get_date(birth)
if date_str != "":
cell_value = cgi.escape(date_str)
else:
for er in o.get_event_ref_list():
event = self.db.get_event_from_handle(er.ref)
etype = event.get_type()[0]
date_str = DateHandler.get_date(event)
if (etype in [Event.BAPTISM, Event.CHRISTEN]
and date_str != ""):
return
cell_value = "<i>" + cgi.escape(date_str) + "</i>"
cell.set_property('text', cell_value)
def _birth_place(self, column, cell, model, iter, user_data=None):
(o,rowref) = model.get_value(iter, 0)

View File

@ -713,7 +713,8 @@ Unknown</property>
<child>
<widget class="GtkImage" id="image2262">
<property name="visible">True</property>
<property name="pixbuf">unlocked.png</property>
<property name="icon_size">4</property>
<property name="icon_name">gtk-dialog-authentication</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>

View File

@ -8645,7 +8645,7 @@ Very High</property>
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="n_rows">4</property>
<property name="n_columns">3</property>
<property name="n_columns">4</property>
<property name="homogeneous">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
@ -8707,27 +8707,6 @@ Very High</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="description">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label422">
<property name="visible">True</property>
@ -8741,6 +8720,7 @@ Very High</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="mnemonic_widget">date</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
@ -8756,87 +8736,6 @@ Very High</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox99">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkEntry" id="date">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="date_edit">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Invoke date editor</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="focus_on_click">True</property>
<child>
<widget class="GtkImage" id="image2264">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options">fill</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="gid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label180">
<property name="visible">True</property>
@ -8865,27 +8764,6 @@ Very High</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="path">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="type">
<property name="visible">True</property>
@ -8965,6 +8843,147 @@ Very High</property>
<property name="y_options">fill</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="path">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="description">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">4</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="gid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkButton" id="date_edit">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Invoke date editor</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="focus_on_click">True</property>
<child>
<widget class="GtkImage" id="image2264">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="date">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkButton" id="file_select">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NONE</property>
<property name="focus_on_click">True</property>
<child>
<widget class="GtkImage" id="image2673">
<property name="visible">True</property>
<property name="stock">gtk-open</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>