From 2f2037f4981f69156d304c564df02b40bcedf0b2 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 16 Oct 2001 15:04:25 +0000 Subject: [PATCH] Converted several dialogs from gramps_main into objects, and placed them in AddMedia.py and SelectChild.py svn: r476 --- gramps/src/AddMedia.py | 112 +++++++++ gramps/src/EditPlace.py | 61 ++++- gramps/src/SelectChild.py | 320 +++++++++++++++++++++++ gramps/src/gramps_main.py | 515 +++++--------------------------------- gramps/src/utils.py | 11 + 5 files changed, 562 insertions(+), 457 deletions(-) create mode 100644 gramps/src/AddMedia.py create mode 100644 gramps/src/SelectChild.py diff --git a/gramps/src/AddMedia.py b/gramps/src/AddMedia.py new file mode 100644 index 000000000..fe493aa5f --- /dev/null +++ b/gramps/src/AddMedia.py @@ -0,0 +1,112 @@ +#! /usr/bin/python -O +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 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 +# + +#------------------------------------------------------------------------- +# +# Standard python modules +# +#------------------------------------------------------------------------- +import string +import os + +#------------------------------------------------------------------------- +# +# internationalization +# +#------------------------------------------------------------------------- +import intl +_ = intl.gettext + +#------------------------------------------------------------------------- +# +# GTK/Gnome modules +# +#------------------------------------------------------------------------- +from gtk import * +from gnome.ui import * +import libglade + +#------------------------------------------------------------------------- +# +# gramps modules +# +#------------------------------------------------------------------------- +from RelLib import * + +import const +import utils +import RelImage + +class AddMediaObject: + + def __init__(self,db,update): + self.db = db + self.glade = libglade.GladeXML(const.imageselFile,"imageSelect") + self.window = self.glade.get_widget("imageSelect") + self.description = self.glade.get_widget("photoDescription") + self.image = self.glade.get_widget("image") + self.update = update + + self.glade.signal_autoconnect({ + "on_savephoto_clicked" : self.on_savephoto_clicked, + "on_name_changed" : self.on_name_changed, + "destroy_passed_object" : utils.destroy_passed_object + }) + + self.window.editable_enters(self.description) + self.window.show() + + def on_savephoto_clicked(self,obj): + filename = self.glade.get_widget("photosel").get_full_path(0) + description = self.description.get_text() + external = self.glade.get_widget("private") + + if os.path.exists(filename) == 0: + err = _("%s is not a valid file name or does not exist.") % filename + GnomeErrorDialog(err) + return + + type = utils.get_mime_type(filename) + mobj = Photo() + if description == "": + description = os.path.basename(filename) + mobj.setDescription(description) + mobj.setMimeType(type) + self.db.addObject(mobj) + + if external.get_active() == 0: + path = self.db.getSavePath() + name = RelImage.import_media_object(filename,path,mobj.getId()) + mobj.setPath(name) + + utils.modified() + self.update() + utils.destroy_passed_object(obj) + + def on_name_changed(self,obj): + filename = self.glade.get_widget("fname").get_text() + if os.path.isfile(filename): + type = utils.get_mime_type(filename) + if type[0:5] == "image": + image = RelImage.scale_image(filename,const.thumbScale) + self.image.load_imlib(image) + else: + self.image.load_file(utils.find_icon(type)) diff --git a/gramps/src/EditPlace.py b/gramps/src/EditPlace.py index 15759cd56..b3a60387a 100644 --- a/gramps/src/EditPlace.py +++ b/gramps/src/EditPlace.py @@ -23,8 +23,8 @@ # Standard python modules # #------------------------------------------------------------------------- -import os import string +import Config #------------------------------------------------------------------------- # @@ -55,8 +55,6 @@ _ = intl.gettext # Constants # #------------------------------------------------------------------------- -_PLACE = "p" - class EditPlace: def __init__(self,place,db,func): @@ -314,3 +312,60 @@ def disp_loc(loc): def src_changed(parent): parent.lists_changed = 1 + + +class DeletePlaceQuery: + + def __init__(self,db,place,update,pevent,fevent): + self.db = db + self.place = place + self.update = update + self.pevent = pevent + self.fevent = fevent + + msg = [] + self.xml = libglade.GladeXML(const.gladeFile,"place_query") + self.xml.signal_autoconnect({ + 'on_force_delete_clicked': self.on_force_delete_clicked, + 'destroy_passed_object' : utils.destroy_passed_object}) + + textbox = self.xml.get_widget("text") + textbox.set_point(0) + textbox.set_word_wrap(1) + + if len(pevent) > 0: + textbox.insert_defaults(_("People") + "\n") + textbox.insert_defaults("_________________________\n\n") + t = _("%s [%s]: event %s\n") + + for e in pevent: + msg = t % (Config.nameof(e[0]),e[0].getId(),e[1].getName()) + textbox.insert_defaults(msg) + + if len(fevent) > 0: + textbox.insert_defaults("\n%s\n" % _("Families")) + textbox.insert_defaults("_________________________\n\n") + t = _("%s [%s]: event %s\n") + + for e in fevent: + father = e[0].getFather() + mother = e[0].getMother() + if father and mother: + fname = "%s and %s" % (Config.nameof(father),Config.nameof(mother)) + elif father: + fname = "%s" % Config.nameof(father) + else: + fname = "%s" % Config.nameof(mother) + + msg = t % (fname,e[0].getId(),e[1].getName()) + textbox.insert_defaults(msg) + + def on_force_delete_clicked(self,obj): + for event in self.pevent + self.fevent: + event[1].setPlace(None) + map = self.db.getPlaceMap() + del map[self.place.getId()] + utils.modified() + utils.destroy_passed_object(obj) + self.update(0) + diff --git a/gramps/src/SelectChild.py b/gramps/src/SelectChild.py new file mode 100644 index 000000000..1ec5822e3 --- /dev/null +++ b/gramps/src/SelectChild.py @@ -0,0 +1,320 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 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 +# + +#------------------------------------------------------------------------- +# +# Standard python modules +# +#------------------------------------------------------------------------- +import string +import os + +#------------------------------------------------------------------------- +# +# internationalization +# +#------------------------------------------------------------------------- +import intl +_ = intl.gettext + +#------------------------------------------------------------------------- +# +# GTK/Gnome modules +# +#------------------------------------------------------------------------- +from gtk import * +from gnome.ui import * +import libglade + +#------------------------------------------------------------------------- +# +# gramps modules +# +#------------------------------------------------------------------------- +from RelLib import * + +import const +import sort +import utils +import Config + +class SelectChild: + + def __init__(self,db,family,person,redraw): + self.db = db + self.person = person + self.family = family + self.redraw = redraw + self.xml = libglade.GladeXML(const.gladeFile,"selectChild") + + self.xml.signal_autoconnect({ + "on_save_child_clicked" : self.on_save_child_clicked, + "on_show_toggled" : self.on_show_toggled, + "destroy_passed_object" : utils.destroy_passed_object + }) + + self.select_child_list = {} + self.top = self.xml.get_widget("selectChild") + self.add_child = self.xml.get_widget("addChild") + self.add_child.set_column_visibility(1,Config.id_visible) + + father = self.family.getFather() + if father != None: + fname = father.getPrimaryName().getName() + ftitle = _("Relationship to %s") % fname + self.xml.get_widget("flabel").set_text(ftitle) + + mother = self.family.getMother() + if mother != None: + mname = mother.getPrimaryName().getName() + mtitle = _("Relationship to %s") % mname + self.xml.get_widget("mlabel").set_text(mtitle) + + self.xml.get_widget("mrel").set_text(_("Birth")) + self.xml.get_widget("frel").set_text(_("Birth")) + + self.redraw_child_list(2) + self.top.show() + + def redraw_child_list(self,filter): + person_list = self.db.getPersonMap().values() + person_list.sort(sort.by_last_name) + self.add_child.freeze() + self.add_child.clear() + index = 0 + + bday = self.person.getBirth().getDateObj() + dday = self.person.getDeath().getDateObj() + + bday_valid = (bday.getYear() != -1) + dday_valid = (dday.getYear() != -1) + + slist = [] + for f in [self.person.getMainFamily()] + self.person.getFamilyList(): + if f: + if f.getFather(): + slist.append(f.getFather()) + elif f.getMother(): + slist.append(f.getMother()) + for c in f.getChildList(): + slist.append(c) + + personmap = {} + for person in person_list: + if filter: + if person in slist: + continue + if person.getMainFamily() != None: + continue + + pdday = person.getDeath().getDateObj() + pbday = person.getBirth().getDateObj() + + if bday_valid: + if pbday.getYear() != -1: + + # reject if child birthdate < parents birthdate + 10 + if pbday.getLowYear() < bday.getHighYear()+10: + continue + + # reject if child birthdate > parents birthdate + 90 + if pbday.getLowYear() > bday.getHighYear()+90: + continue + + if pdday.getYear() != -1: + # reject if child deathdate < parents birthdate+ 10 + if pdday.getLowYear() < bday.getHighYear()+10: + continue + + if dday_valid: + if pbday.getYear() != -1: + + # reject if childs birth date > parents deathday + 3 + if pdday.getLowYear() > dday.getHighYear()+3: + continue + + if pdday.getYear() != -1: + + # reject if childs death date > parents deathday + 150 + if pbday.getLowYear() > dday.getHighYear() + 150: + continue + + personmap[utils.phonebook_name(person)] = person + + keynames = personmap.keys() + keynames.sort() + for key in keynames: + person = personmap[key] + self.add_child.append([utils.phonebook_name(person),utils.birthday(person),\ + person.getId()]) + self.add_child.set_row_data(index,person) + index = index + 1 + self.add_child.thaw() + + def on_save_child_clicked(self,obj): + for row in self.add_child.selection: + + select_child = self.add_child.get_row_data(row) + if self.family == None: + self.family = database.newFamily() + self.person.addFamily(self.family) + if self.person.getGender() == Person.male: + self.family.setFather(self.person) + else: + self.family.setMother(self.person) + + self.family.addChild(select_child) + + mrel = const.childRelations[self.xml.get_widget("mrel").get_text()] + mother = self.family.getMother() + if mother and mother.getGender() != Person.female: + if mrel == "Birth": + mrel = "Unknown" + + frel = const.childRelations[self.xml.get_widget("frel").get_text()] + father = self.family.getFather() + if father and father.getGender() != Person.male: + if frel == "Birth": + frel = "Unknown" + + if mrel == "Birth" and frel == "Birth": + family = select_child.getMainFamily() + if family != None and family != self.family: + family.removeChild(select_child) + + select_child.setMainFamily(self.family) + else: + select_child.addAltFamily(self.family,mrel,frel) + + utils.modified() + + utils.destroy_passed_object(obj) + self.redraw(self.family) + + def on_show_toggled(self,obj): + self.redraw_child_list(obj.get_active()) + +class NewChild: + + def __init__(self,db,family,person,update): + self.db = db + self.person = person + self.family = family + self.update = update + + self.xml = libglade.GladeXML(const.gladeFile,"addChild") + self.xml.signal_autoconnect({ + "on_addchild_ok_clicked" : self.on_addchild_ok_clicked, + "destroy_passed_object" : utils.destroy_passed_object + }) + + self.mrel = self.xml.get_widget("mrel") + self.frel = self.xml.get_widget("frel") + self.top = self.xml.get_widget("addChild") + self.surname = self.xml.get_widget("childSurname") + self.given = self.xml.get_widget("childGiven") + + surname = "" + if self.person.getGender() == Person.male: + surname = self.person.getPrimaryName().getSurname() + elif self.family: + f = self.family.getFather() + if f: + surname = f.getPrimaryName().getSurname() + + if self.family: + father = self.family.getFather() + mother = self.family.getMother() + + if father != None: + fname = father.getPrimaryName().getName() + label = _("Relationship to %s") % fname + self.xml.get_widget("flabel").set_text(label) + + if mother != None: + mname = mother.getPrimaryName().getName() + label = _("Relationship to %s") % mname + self.xml.get_widget("mlabel").set_text(label) + else: + fname = self.person.getPrimaryName().getName() + label = _("Relationship to %s") % fname + + if self.person.getGender() == Person.male: + self.xml.get_widget("flabel").set_text(label) + self.xml.get_widget("mcombo").set_sensitive(0) + else: + self.xml.get_widget("mlabel").set_text(label) + self.xml.get_widget("fcombo").set_sensitive(0) + + self.surname.set_text(surname) + self.mrel.set_text(_("Birth")) + self.frel.set_text(_("Birth")) + + # Typing CR selects OK button + self.top.editable_enters(self.given) + self.top.editable_enters(self.surname) + self.top.editable_enters(self.mrel) + self.top.editable_enters(self.frel) + self.top.show() + + def on_addchild_ok_clicked(self,obj): + + surname = self.surname.get_text() + given = self.given.get_text() + + person = Person() + self.db.addPerson(person) + + name = Name() + name.setSurname(surname) + name.setFirstName(given) + person.setPrimaryName(name) + + if self.xml.get_widget("childMale").get_active(): + person.setGender(Person.male) + elif self.xml.get_widget("childFemale").get_active(): + person.setGender(Person.female) + else: + person.setGender(Person.unknown) + + if not self.family: + self.family = self.db.newFamily() + if self.person.getGender() == Person.male: + self.family.setFather(self.person) + else: + self.family.setMother(self.person) + self.person.addFamily(active_family) + + mrel = const.childRelations[self.mrel.get_text()] + frel = const.childRelations[self.frel.get_text()] + + if mrel == "Birth" and frel == "Birth": + person.setMainFamily(self.family) + else: + person.addAltFamily(self.family,mrel,frel) + + self.family.addChild(person) + + # must do an apply filter here to make sure the main window gets updated + + self.update(self.family,person) + utils.modified() + utils.destroy_passed_object(obj) + diff --git a/gramps/src/gramps_main.py b/gramps/src/gramps_main.py index 65be6c744..5c30c0fab 100755 --- a/gramps/src/gramps_main.py +++ b/gramps/src/gramps_main.py @@ -92,10 +92,6 @@ active_spouse = None select_father = None select_spouse = None select_mother = None -select_child_list = {} -childWindow = None -new_child_win = None -add_child_win = None bookmarks = None id2col = {} @@ -137,28 +133,12 @@ c_sort_direct = SORT_ASCENDING NOTEBOOK = "notebook1" FILESEL = "fileselection" FILTERNAME = "filter_list" -ODDFGCOLOR = "oddForeground" -ODDBGCOLOR = "oddBackground" -EVENFGCOLOR = "evenForeground" -EVENBGCOLOR = "evenBackground" GIVEN = "g" SURNAME = "s" RELTYPE = "d" PAD = 3 CANVASPAD = 20 -#------------------------------------------------------------------------- -# -# Short hand function to return either the person's birthday, or an empty -# string if the person is None -# -#------------------------------------------------------------------------- -def birthday(person): - if person: - return person.getBirth().getQuoteDate() - else: - return "" - #------------------------------------------------------------------------- # # Short hand function to return either the person's birthday, or an empty @@ -364,290 +344,25 @@ def on_delete_sp_clicked(obj): load_family() utils.modified() - + + #------------------------------------------------------------------------- # # # #------------------------------------------------------------------------- def on_add_child_clicked(obj): - global add_child_win - global childWindow - global select_child_list - - childWindow = libglade.GladeXML(const.gladeFile,"selectChild") - - childWindow.signal_autoconnect({ - "on_save_child_clicked" : on_save_child_clicked, - "on_addChild_select_row" : on_add_child_select_row, - "on_addChild_unselect_row" : on_add_child_unselect_row, - "on_show_toggled" : on_show_toggled, - "destroy_passed_object" : utils.destroy_passed_object - }) + import SelectChild + SelectChild.SelectChild(database,active_family,active_person,load_family) - select_child_list = {} - selectChild = childWindow.get_widget("selectChild") - add_child_win = childWindow.get_widget("addChild") - add_child_win.set_column_visibility(1,Config.id_visible) - - father = active_family.getFather() - if father != None: - fname = father.getPrimaryName().getName() - ftitle = _("Relationship to %s") % fname - childWindow.get_widget("flabel").set_text(ftitle) - - mother = active_family.getMother() - if mother != None: - mname = mother.getPrimaryName().getName() - mtitle = _("Relationship to %s") % mname - childWindow.get_widget("mlabel").set_text(mtitle) - - childWindow.get_widget("mrel").set_text(_("Birth")) - childWindow.get_widget("frel").set_text(_("Birth")) - - redraw_child_list(2) - selectChild.show() - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def redraw_child_list(filter): - person_list = database.getPersonMap().values() - person_list.sort(sort.by_last_name) - add_child_win.freeze() - add_child_win.clear() - index = 0 - - bday = active_person.getBirth().getDateObj() - dday = active_person.getDeath().getDateObj() - - bday_valid = (bday.getYear() != -1) - dday_valid = (dday.getYear() != -1) - - slist = [] - for f in [active_person.getMainFamily()] + active_person.getFamilyList(): - if f: - if f.getFather(): - slist.append(f.getFather()) - elif f.getMother(): - slist.append(f.getMother()) - for c in f.getChildList(): - slist.append(c) - - personmap = {} - for person in person_list: - if filter: - if person in slist: - continue - if person.getMainFamily() != None: - continue - - pdday = person.getDeath().getDateObj() - pbday = person.getBirth().getDateObj() - - if bday_valid: - if pbday.getYear() != -1: - - # reject if child birthdate < parents birthdate + 10 - if pbday.getLowYear() < bday.getHighYear()+10: - continue - - # reject if child birthdate > parents birthdate + 90 - if pbday.getLowYear() > bday.getHighYear()+90: - continue - - if pdday.getYear() != -1: - # reject if child deathdate < parents birthdate+ 10 - if pdday.getLowYear() < bday.getHighYear()+10: - continue - - if dday_valid: - - if pbday.getYear() != -1: - - # reject if childs birth date > parents deathday + 3 - if pdday.getLowYear() > dday.getHighYear()+3: - continue - - if pdday.getYear() != -1: - - # reject if childs death date > parents deathday + 150 - if pbday.getLowYear() > dday.getHighYear() + 150: - continue - - personmap[utils.phonebook_name(person)] = person - - keynames = personmap.keys() - keynames.sort() - for key in keynames: - person = personmap[key] - add_child_win.append([utils.phonebook_name(person),birthday(person),\ - person.getId()]) - add_child_win.set_row_data(index,person) - index = index + 1 - add_child_win.thaw() - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_show_toggled(obj): - redraw_child_list(obj.get_active()) - #------------------------------------------------------------------------- # # # #------------------------------------------------------------------------- def on_add_new_child_clicked(obj): - global new_child_win - - new_child_win = libglade.GladeXML(const.gladeFile,"addChild") - new_child_win.signal_autoconnect({ - "on_addchild_ok_clicked" : on_addchild_ok_clicked, - "destroy_passed_object" : utils.destroy_passed_object - }) - - if active_person.getGender() == Person.male: - surname = active_person.getPrimaryName().getSurname() - elif active_spouse: - surname = active_spouse.getPrimaryName().getSurname() - else: - surname = "" - - if active_family: - father = active_family.getFather() - if father != None: - fname = father.getPrimaryName().getName() - label = _("Relationship to %s") % fname - new_child_win.get_widget("flabel").set_text(label) - - mother = active_family.getMother() - if mother != None: - mname = mother.getPrimaryName().getName() - label = _("Relationship to %s") % mname - new_child_win.get_widget("mlabel").set_text(label) - else: - fname = active_person.getPrimaryName().getName() - label = _("Relationship to %s") % fname - if active_person.getGender() == Person.male: - new_child_win.get_widget("flabel").set_text(label) - new_child_win.get_widget("mcombo").set_sensitive(0) - else: - new_child_win.get_widget("mlabel").set_text(label) - new_child_win.get_widget("fcombo").set_sensitive(0) - - new_child_win.get_widget("childSurname").set_text(surname) - new_child_win.get_widget("addChild").show() - new_child_win.get_widget("mrel").set_text(_("Birth")) - new_child_win.get_widget("frel").set_text(_("Birth")) - - # Typing CR selects OK button - window = new_child_win.get_widget("addChild") - window.editable_enters(new_child_win.get_widget("childGiven")) - window.editable_enters(new_child_win.get_widget("childSurname")) - window.editable_enters(new_child_win.get_widget("mrel")) - window.editable_enters(new_child_win.get_widget("frel")) - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_addchild_ok_clicked(obj): - global active_family - - surname = new_child_win.get_widget("childSurname").get_text() - given = new_child_win.get_widget("childGiven").get_text() - - person = Person() - database.addPerson(person) - - name = Name() - name.setSurname(surname) - name.setFirstName(given) - person.setPrimaryName(name) - - if new_child_win.get_widget("childMale").get_active(): - person.setGender(Person.male) - elif new_child_win.get_widget("childFemale").get_active(): - person.setGender(Person.female) - else: - person.setGender(Person.unknown) - - if not active_family: - active_family = database.newFamily() - if active_person.getGender() == Person.male: - active_family.setFather(active_person) - else: - active_family.setMother(active_person) - active_person.addFamily(active_family) - - mrel = const.childRelations[new_child_win.get_widget("mrel").get_text()] - frel = const.childRelations[new_child_win.get_widget("frel").get_text()] - - if mrel == "Birth" and frel == "Birth": - person.setMainFamily(active_family) - else: - person.addAltFamily(active_family,mrel,frel) - - active_family.addChild(person) - - # must do an apply filter here to make sure the main window gets updated - - redisplay_person_list(person) - load_family() - utils.modified() - utils.destroy_passed_object(obj) - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_save_child_clicked(obj): - global active_family - - for select_child in select_child_list.keys(): - - if active_family == None: - active_family = database.newFamily() - active_person.addFamily(active_family) - if active_person.getGender() == Person.male: - active_family.setFather(active_person) - else: - active_family.setMother(active_person) - - active_family.addChild(select_child) - - mrel = const.childRelations[childWindow.get_widget("mrel").get_text()] - mother = active_family.getMother() - if mother and mother.getGender() != Person.female: - if mrel == "Birth": - mrel = "Unknown" - - frel = const.childRelations[childWindow.get_widget("frel").get_text()] - father = active_family.getFather() - if father and father.getGender() != Person.male: - if frel == "Birth": - frel = "Unknown" - - if mrel == "Birth" and frel == "Birth": - family = select_child.getMainFamily() - if family != None and family != active_family: - family.removeChild(select_child) - - select_child.setMainFamily(active_family) - else: - select_child.addAltFamily(active_family,mrel,frel) - - utils.modified() - - utils.destroy_passed_object(obj) - load_family() + import SelectChild + SelectChild.NewChild(database,active_family,active_person,update_after_newchild) #------------------------------------------------------------------------- # @@ -745,18 +460,18 @@ def on_prel_changed(obj): if person == active_person or person.getGender() == Person.unknown: continue elif type == "Partners": - father_list.append([utils.phonebook_name(person),birthday(person)]) + father_list.append([utils.phonebook_name(person),utils.birthday(person)]) father_list.set_row_data(father_index,person) father_index = father_index + 1 - mother_list.append([utils.phonebook_name(person),birthday(person)]) + mother_list.append([utils.phonebook_name(person),utils.birthday(person)]) mother_list.set_row_data(mother_index,person) mother_index = mother_index + 1 elif person.getGender() == Person.male: - father_list.append([utils.phonebook_name(person),birthday(person)]) + father_list.append([utils.phonebook_name(person),utils.birthday(person)]) father_list.set_row_data(father_index,person) father_index = father_index + 1 else: - mother_list.append([utils.phonebook_name(person),birthday(person)]) + mother_list.append([utils.phonebook_name(person),utils.birthday(person)]) mother_list.set_row_data(mother_index,person) mother_index = mother_index + 1 @@ -973,71 +688,14 @@ def on_delete_place_clicked(obj): fevent.append((f,event)) if len(pevent) > 0 or len(fevent) > 0: - msg = [] - ptop = libglade.GladeXML(const.gladeFile,"place_query") - ptop.signal_autoconnect({ - 'on_force_delete_clicked': on_force_delete_clicked, - 'destroy_passed_object' : utils.destroy_passed_object}) - - fd = ptop.get_widget("place_query") - fd.set_data("p",pevent) - fd.set_data("f",fevent) - fd.set_data("place",place) - - textbox = ptop.get_widget("text") - textbox.set_point(0) - textbox.set_word_wrap(1) - - if len(pevent) > 0: - textbox.insert_defaults(_("People") + "\n") - textbox.insert_defaults("_________________________\n\n") - t = _("%s [%s]: event %s\n") - - for e in pevent: - msg = t % (Config.nameof(e[0]),e[0].getId(),e[1].getName()) - textbox.insert_defaults(msg) - - if len(fevent) > 0: - textbox.insert_defaults("\n%s\n" % _("Families")) - textbox.insert_defaults("_________________________\n\n") - t = _("%s [%s]: event %s\n") - - for e in fevent: - father = e[0].getFather() - mother = e[0].getMother() - if father and mother: - fname = "%s and %s" % (Config.nameof(father),Config.nameof(mother)) - elif father: - fname = "%s" % Config.nameof(father) - else: - fname = "%s" % Config.nameof(mother) - - msg = t % (fname,e[0].getId(),e[1].getName()) - textbox.insert_defaults(msg) + import EditPlace + EditPlace.DeletePlaceQuery(database,place,update_display,pevent,fevent) else: map = database.getPlaceMap() del map[place.getId()] utils.modified() update_display(0) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_force_delete_clicked(obj): - place = obj.get_data('place') - plist = obj.get_data('p') - flist = obj.get_data('f') - - for event in plist + flist: - event[1].setPlace(None) - map = database.getPlaceMap() - del map[place.getId()] - utils.modified() - utils.destroy_passed_object(obj) - update_display(0) - #------------------------------------------------------------------------- # # @@ -1679,7 +1337,7 @@ def on_rel_type_changed(obj): for person in nameList: if person.getGender() == gender: continue - spouse_list.append([person.getPrimaryName().getName(),birthday(person)]) + spouse_list.append([person.getPrimaryName().getName(),utils.birthday(person)]) spouse_list.set_row_data(index,person) index = index + 1 spouse_list.thaw() @@ -1799,22 +1457,6 @@ def on_father_list_select_row(obj,a,b,c): select_father = obj.get_row_data(a) obj.get_data("father_text").set_text(Config.nameof(select_father)) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_add_child_select_row(obj,row,b,c): - select_child_list[obj.get_row_data(row)] = 1 - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_add_child_unselect_row(obj,row,b,c): - del select_child_list[obj.get_row_data(row)] - #------------------------------------------------------------------------- # # @@ -2399,6 +2041,16 @@ def new_after_edit(epo): change_active_person(epo.person) redisplay_person_list(epo.person) + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def update_after_newchild(family,person): + load_family(family) + redisplay_person_list(person) + #------------------------------------------------------------------------- # # @@ -2467,10 +2119,14 @@ def load_person(person): # # #------------------------------------------------------------------------- -def load_family(): +def load_family(family=None): global active_mother global active_parents global active_spouse + global active_family + + if family != None: + active_family = family family_types = [] main_family = None @@ -2977,10 +2633,12 @@ def display_marriage(family): attr = "" for child in child_list: status = _("Unknown") - if child.getGender(): + if child.getGender() == Person.male: gender = const.male - else: + elif child.getGender() == Person.female: gender = const.female + else: + gender = const.unknown if child.getMainFamily() == family: status = _("Birth") else: @@ -3008,7 +2666,7 @@ def display_marriage(family): attr = attr + "P" clist.append([Config.nameof(child),child.getId(),\ - gender,birthday(child),status,attr,"%2d"%i]) + gender,utils.birthday(child),status,attr,"%2d"%i]) clist.set_row_data(i,child) i=i+1 if i != 0: @@ -3350,6 +3008,34 @@ def on_media_list_drag_data_get(w, context, selection_data, info, time): id = d.getId() selection_data.set(selection_data.target, 8, id) +def create_add_dialog(obj): + import AddMedia + AddMedia.AddMediaObject(database,load_media) + +def on_edit_media_clicked(obj): + if len(media_list.selection) <= 0: + return + object = media_list.get_row_data(media_list.selection[0]) + ImageSelect.GlobalMediaProperties(object,database.getSavePath()) + +def on_media_list_drag_data_received(w, context, x, y, data, info, time): + if data and data.format == 8: + d = string.strip(string.replace(data.data,'\0',' ')) + if d[0:5] == "file:": + name = d[5:] + mime = utils.get_mime_type(name) + photo = Photo() + photo.setPath(name) + photo.setMimeType(mime) + description = os.path.basename(name) + photo.setDescription(description) + database.addObject(photo) + utils.modified() + w.drag_finish(context, TRUE, FALSE, time) + load_media() + else: + w.drag_finish(context, FALSE, FALSE, time) + #------------------------------------------------------------------------- # # Main program @@ -3537,85 +3223,6 @@ def on_canvas1_event(obj,event): load_canvas() return 0 -def create_add_dialog(obj): - glade = libglade.GladeXML(const.imageselFile,"imageSelect") - window = glade.get_widget("imageSelect") - fname = glade.get_widget("fname") - image = glade.get_widget("image") - description = glade.get_widget("photoDescription") - external = glade.get_widget("private") - - glade.signal_autoconnect({ - "on_savephoto_clicked" : on_savephoto_clicked, - "on_name_changed" : on_name_changed, - "destroy_passed_object" : utils.destroy_passed_object - }) - - window.editable_enters(description) - window.set_data("t",glade) - window.show() - -def on_savephoto_clicked(obj): - glade = obj.get_data("t") - filename = glade.get_widget("photosel").get_full_path(0) - description = glade.get_widget("photoDescription").get_text() - external = glade.get_widget("private") - - if os.path.exists(filename) == 0: - GnomeErrorDialog(_("That is not a valid file name.")); - return - - type = utils.get_mime_type(filename) - mobj = Photo() - if description == "": - description = os.path.basename(filename) - mobj.setDescription(description) - mobj.setMimeType(type) - database.addObject(mobj) - - if external.get_active() == 0: - path = database.getSavePath() - name = RelImage.import_media_object(filename,path,mobj.getId()) - mobj.setPath(name) - - utils.modified() - load_media() - utils.destroy_passed_object(obj) - -def on_name_changed(obj): - glade = obj.get_data('t') - filename = glade.get_widget("fname").get_text() - if os.path.isfile(filename): - type = utils.get_mime_type(filename) - if type[0:5] == "image": - image = RelImage.scale_image(filename,const.thumbScale) - glade.get_widget("image").load_imlib(image) - else: - glade.get_widget("image").load_file(utils.find_icon(type)) - -def on_edit_media_clicked(obj): - if len(media_list.selection) <= 0: - return - object = media_list.get_row_data(media_list.selection[0]) - ImageSelect.GlobalMediaProperties(object,database.getSavePath()) - -def on_media_list_drag_data_received(w, context, x, y, data, info, time): - if data and data.format == 8: - d = string.strip(string.replace(data.data,'\0',' ')) - if d[0:5] == "file:": - name = d[5:] - mime = utils.get_mime_type(name) - photo = Photo() - photo.setPath(name) - photo.setMimeType(mime) - description = os.path.basename(name) - photo.setDescription(description) - database.addObject(photo) - utils.modified() - w.drag_finish(context, TRUE, FALSE, time) - load_media() - else: - w.drag_finish(context, FALSE, FALSE, time) #------------------------------------------------------------------------- # diff --git a/gramps/src/utils.py b/gramps/src/utils.py index 564919e1a..7127ba93b 100644 --- a/gramps/src/utils.py +++ b/gramps/src/utils.py @@ -367,3 +367,14 @@ def get_mime_description(type): return type +#------------------------------------------------------------------------- +# +# Short hand function to return either the person's birthday, or an empty +# string if the person is None +# +#------------------------------------------------------------------------- +def birthday(person): + if person: + return person.getBirth().getQuoteDate() + else: + return ""