2007-05-06 Don Allingham <don@gramps-project.org>
* src/DataViews/_PersonView.py: add quick report * src/GrampsDb/_GrampsDbBase.py: use NotImplementedError instead of assertion * src/ReportBase/_SimpleAccess.py: added functionality * src/RelLib/_MediaObject.py: comments * src/RelLib/_Person.py: remove @sort comment * src/RelLib/_BasicPrimaryObject.py: * src/plugins/all_events.py: comments * src/glade/gramps.glade: clean up width * src/gramps_main.py: added docgen to the search path * src/docgen/TextBufDoc.py: Added interface svn: r8439
This commit is contained in:
parent
be7b8d6c94
commit
6e065c407f
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
||||
2007-05-06 Don Allingham <don@gramps-project.org>
|
||||
* src/DataViews/_PersonView.py: add quick report
|
||||
* src/GrampsDb/_GrampsDbBase.py: use NotImplementedError instead of assertion
|
||||
* src/ReportBase/_SimpleAccess.py: added functionality
|
||||
* src/RelLib/_MediaObject.py: comments
|
||||
* src/RelLib/_Person.py: remove @sort comment
|
||||
* src/RelLib/_BasicPrimaryObject.py:
|
||||
* src/plugins/all_events.py: comments
|
||||
* src/glade/gramps.glade: clean up width
|
||||
* src/gramps_main.py: added docgen to the search path
|
||||
* src/docgen/TextBufDoc.py: Added interface
|
||||
|
||||
2007-05-06 Brian Matherly <brian@gramps-project.org>
|
||||
* src/data/main5.css: Fix generation chart alignment for Narrative Web.
|
||||
|
||||
|
@ -152,6 +152,8 @@ class PersonView(PageView.PersonNavView):
|
||||
_("Edit the selected person"), self.edit),
|
||||
('CloseAllNodes', None, _("Collapse all nodes"), None, None,
|
||||
self.close_all_nodes),
|
||||
('QuickReport', None, _("Quick Report"), None, None,
|
||||
self.quick_report),
|
||||
])
|
||||
|
||||
self.edit_action.add_actions(
|
||||
@ -408,6 +410,8 @@ class PersonView(PageView.PersonNavView):
|
||||
<menuitem action="Add"/>
|
||||
<menuitem action="Edit"/>
|
||||
<menuitem action="Remove"/>
|
||||
<separator/>
|
||||
<menuitem action="QuickReport"/>
|
||||
</popup>
|
||||
</ui>'''
|
||||
|
||||
@ -951,3 +955,15 @@ class PersonView(PageView.PersonNavView):
|
||||
ofile.end_page()
|
||||
ofile.close()
|
||||
|
||||
def quick_report(self, obj):
|
||||
from TextBufDoc import TextBufDoc
|
||||
from ReportBase._SimpleDoc import make_basic_stylesheet
|
||||
import all_events
|
||||
|
||||
if self.dbstate.active:
|
||||
d = TextBufDoc(make_basic_stylesheet(), None, None)
|
||||
handle = self.dbstate.active.handle
|
||||
person = self.dbstate.db.get_person_from_handle(handle)
|
||||
d.open("")
|
||||
all_events.run(self.db, d, person)
|
||||
d.close()
|
||||
|
@ -369,49 +369,49 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
self.rand.randint(0, maxint))
|
||||
|
||||
def get_person_cursor(self):
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_person_cursor_iter(self, msg=_("Processing Person records")):
|
||||
return CursorIterator(self, self.get_person_cursor(), msg)
|
||||
|
||||
def get_family_cursor(self):
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_family_cursor_iter(self, msg=_("Processing Family records")):
|
||||
return CursorIterator(self, self.get_family_cursor(), msg)
|
||||
|
||||
def get_event_cursor(self):
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_event_cursor_iter(self, msg=_("Processing Event records")):
|
||||
return CursorIterator(self, self.get_event_cursor(), msg)
|
||||
|
||||
def get_place_cursor(self):
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_place_cursor_iter(self, msg=_("Processing Place records")):
|
||||
return CursorIterator(self, self.get_place_cursor(), msg)
|
||||
|
||||
def get_source_cursor(self):
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_source_cursor_iter(self, msg=_("Processing Source records")):
|
||||
return CursorIterator(self, self.get_source_cursor(), msg)
|
||||
|
||||
def get_media_cursor(self):
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_media_cursor_iter(self, msg=_("Processing Media records")):
|
||||
return CursorIterator(self, self.get_media_cursor(), msg)
|
||||
|
||||
def get_repository_cursor(self):
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_repository_cursor_iter(self, msg=_("Processing Repository records")):
|
||||
return CursorIterator(self, self.get_repository_cursor(), msg)
|
||||
|
||||
def get_note_cursor(self):
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_note_cursor_iter(self, msg=_("Processing Note records")):
|
||||
return CursorIterator(self, self.get_note_cursor(), msg)
|
||||
@ -435,7 +435,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
Opens the specified database. The method needs to be overridden
|
||||
in the derived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def load_from(self, other_database, filename, callback):
|
||||
"""
|
||||
@ -443,7 +443,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
The filename is the name of the file for the newly created database.
|
||||
The method needs to be overridden in the derived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
@ -1023,7 +1023,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
|
||||
Needs to be overridden by the derrived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_family_from_gramps_id(self, val):
|
||||
"""
|
||||
@ -1032,7 +1032,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
|
||||
Needs to be overridden by the derrived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_event_from_gramps_id(self, val):
|
||||
"""
|
||||
@ -1041,7 +1041,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
|
||||
Needs to be overridden by the derrived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_place_from_gramps_id(self, val):
|
||||
"""
|
||||
@ -1050,7 +1050,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
|
||||
Needs to be overridden by the derrived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_source_from_gramps_id(self, val):
|
||||
"""
|
||||
@ -1059,7 +1059,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
|
||||
Needs to be overridden by the derrived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_object_from_gramps_id(self, val):
|
||||
"""
|
||||
@ -1068,7 +1068,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
|
||||
Needs to be overridden by the derrived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_repository_from_gramps_id(self, val):
|
||||
"""
|
||||
@ -1077,7 +1077,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
|
||||
Needs to be overridden by the derrived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_note_from_gramps_id(self, val):
|
||||
"""
|
||||
@ -1086,7 +1086,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
|
||||
Needs to be overridden by the derrived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def _add_object(self, obj, transaction, find_next_func, commit_func):
|
||||
if not obj.gramps_id:
|
||||
@ -1205,7 +1205,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
Sets the default grouping name for a surname. Needs to be overridden
|
||||
in the derived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_number_of_people(self):
|
||||
"""
|
||||
@ -1753,7 +1753,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
Builds the list of locale-sorted surnames contained in the database.
|
||||
The function must be overridden in the derived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def sort_surname_list(self):
|
||||
vals = [(locale.strxfrm(item),item) for item in self.surname_list]
|
||||
@ -1774,7 +1774,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
the database. If not then we need to remove the name from the list.
|
||||
The function must be overridden in the derived class.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
raise NotImplementedError
|
||||
|
||||
def get_bookmarks(self):
|
||||
"""returns the list of Person handles in the bookmarks"""
|
||||
|
@ -203,7 +203,7 @@ class BasicPrimaryObject(BaseObject, PrivacyBase):
|
||||
derived class type.
|
||||
|
||||
@return: Returns the marker for the object.
|
||||
@type marker: MarkerType
|
||||
@rtype: MarkerType
|
||||
"""
|
||||
return self.marker
|
||||
|
||||
|
@ -174,8 +174,8 @@ class MediaObject(SourceBase,NoteBase,DateBase,AttributeBase,PrimaryObject):
|
||||
"""
|
||||
Sets the MIME type associated with the MediaObject
|
||||
|
||||
@param type: MIME type to be assigned to the object
|
||||
@type type: str
|
||||
@param mime_type: MIME type to be assigned to the object
|
||||
@type mime_type: str
|
||||
"""
|
||||
self.mime = mime_type
|
||||
|
||||
|
@ -72,7 +72,6 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase,
|
||||
to the database using the database object's commit_person function,
|
||||
or the changes will be lost.
|
||||
|
||||
@sort: serialize, unserialize, get_*, set_*, add_*, remove_*
|
||||
"""
|
||||
|
||||
UNKNOWN = 2
|
||||
|
@ -528,6 +528,27 @@ class SimpleAccess:
|
||||
else:
|
||||
return []
|
||||
|
||||
def sources(self, obj):
|
||||
"""
|
||||
Returns a list of events associated with the object. This object
|
||||
can be either a L{RelLib.Person} or L{RelLib.Family}.
|
||||
|
||||
@param obj: Person or Family
|
||||
@type obj: L{RelLib.Person} or L{RelLib.Family}
|
||||
@param restrict: Optional list of strings that will limit the types
|
||||
of events to those of the specfied types.
|
||||
@type restrict: list
|
||||
@return: list of events assocated with the object
|
||||
@rtype: list
|
||||
"""
|
||||
assert(isinstance(obj, (RelLib.Person, RelLib.Family, RelLib.Event, NoneType)))
|
||||
|
||||
if obj:
|
||||
handles = [ ref.ref for ref in obj.get_source_references() ]
|
||||
return [ self.dbase.get_source_from_handle(h) for h in handles ]
|
||||
else:
|
||||
return []
|
||||
|
||||
def parent_in(self, person):
|
||||
"""
|
||||
Returns a list of families in which the person is listed as a parent.
|
||||
@ -562,6 +583,25 @@ class SimpleAccess:
|
||||
for handle in person.get_parent_family_handle_list() ]
|
||||
return []
|
||||
|
||||
def __all_objects(self, gen_cursor, get_object):
|
||||
"""
|
||||
Returns a all the objects of a particular type in the database, one
|
||||
at a time as an iterator. The user can treat this just like a list.
|
||||
|
||||
@return: list of objects of a particular type in the database
|
||||
@rtype: list
|
||||
"""
|
||||
slist = []
|
||||
cursor = gen_cursor()
|
||||
data = cursor.first()
|
||||
while data:
|
||||
slist.append(data[0])
|
||||
data = cursor.next()
|
||||
cursor.close()
|
||||
for info in slist:
|
||||
obj = get_object(info)
|
||||
yield obj
|
||||
|
||||
def all_people(self):
|
||||
"""
|
||||
Returns a all the people in the database, one at a time as an iterator.
|
||||
@ -582,51 +622,86 @@ class SimpleAccess:
|
||||
cursor.close()
|
||||
slist.sort()
|
||||
for info in slist:
|
||||
person = self.dbase.get_person_from_handle(info[1])
|
||||
yield person
|
||||
obj = self.dbase.get_person_from_handle(info[1])
|
||||
yield obj
|
||||
|
||||
def all_families(self):
|
||||
"""
|
||||
Returns all the families in the database, one at a time as an iterator.
|
||||
The user can treat this just like a list. For example::
|
||||
|
||||
# if __name__ == "__main__":
|
||||
for person in sa.all_families():
|
||||
sa.print(sa.father(person))
|
||||
|
||||
# from GrampsDb import gramps_db_factory
|
||||
# import sys
|
||||
# import const
|
||||
@return: list of families in the database
|
||||
@rtype: list
|
||||
"""
|
||||
return self.__all_objects(self.dbase.get_family_cursor,
|
||||
self.dbase.get_family_from_handle)
|
||||
|
||||
# db_class = gramps_db_factory(const.app_gramps_xml)
|
||||
# database = db_class()
|
||||
# database.load(sys.argv[1], lambda x: None, mode="w")
|
||||
# person = database.get_default_person()
|
||||
|
||||
# sa = SimpleAccess(database)
|
||||
def all_events(self):
|
||||
"""
|
||||
Returns all the events in the database, one at a time as an iterator.
|
||||
The user can treat this just like a list. For example::
|
||||
|
||||
# print "Person : ", sa.name(person)
|
||||
# print "Gender : ", sa.gender(person)
|
||||
# print "Birth date : ", sa.birth_date(person)
|
||||
# print "Birth place : ", sa.birth_place(person)
|
||||
# print "Death date : ", sa.death_date(person)
|
||||
# print "Death place : ", sa.death_place(person)
|
||||
# print "Father : ", sa.name(sa.father(person))
|
||||
# print "Mother : ", sa.name(sa.mother(person))
|
||||
# print "Spouse : ", sa.name(sa.spouse(person))
|
||||
# print "Marriage Type : ", sa.marriage_type(person)
|
||||
# print "Marriage Date : ", sa.marriage_date(person)
|
||||
# print "Marriage Place: ", sa.marriage_place(person)
|
||||
# for child in sa.children(person):
|
||||
# print "Child : ", sa.name(child)
|
||||
|
||||
# for event in sa.events( person , [ "Burial" ]):
|
||||
# print "Event : ", sa.event_type(event), \
|
||||
# sa.event_date(event), sa.event_place(event)
|
||||
|
||||
# # for person in sa.all_people():
|
||||
# # print sa.name(person)
|
||||
for person in sa.all_events():
|
||||
sa.print(sa.event_place(event))
|
||||
|
||||
# print "************************************************"
|
||||
# for family in sa.parent_in(person):
|
||||
# print "Father : ", sa.name(sa.father(family))
|
||||
# print "Mother : ", sa.name(sa.mother(family))
|
||||
@return: list of events in the database
|
||||
@rtype: list
|
||||
"""
|
||||
return self.__all_objects(self.dbase.get_events_cursor,
|
||||
self.dbase.get_event_from_handle)
|
||||
|
||||
# print "************************************************"
|
||||
# for family in sa.child_in(person):
|
||||
# print "Father : ", sa.name(sa.father(family))
|
||||
# print "Mother : ", sa.name(sa.mother(family))
|
||||
def all_sources(self):
|
||||
"""
|
||||
Returns all the sources in the database, one at a time as an iterator.
|
||||
The user can treat this just like a list. For example::
|
||||
|
||||
@return: list of sources in the database
|
||||
@rtype: list
|
||||
"""
|
||||
return self.__all_objects(self.dbase.get_source_cursor,
|
||||
self.dbase.get_source_from_handle)
|
||||
|
||||
def title(self, source):
|
||||
"""
|
||||
Returns the title of the source.
|
||||
|
||||
@param source: Source object
|
||||
@type source: L{RelLib.Source}
|
||||
@return: title of the source
|
||||
@rtype: unicode
|
||||
"""
|
||||
assert(isinstance(source, (RelLib.Source, NoneType)))
|
||||
if source:
|
||||
return source.get_title()
|
||||
return u''
|
||||
|
||||
def author(self, source):
|
||||
"""
|
||||
Returns the author of the source.
|
||||
|
||||
@param source: Source object
|
||||
@type source: L{RelLib.Source}
|
||||
@return: author of the source
|
||||
@rtype: unicode
|
||||
"""
|
||||
assert(isinstance(source, (RelLib.Source, NoneType)))
|
||||
if source:
|
||||
return source.get_author()
|
||||
return u''
|
||||
|
||||
def by_date(event1, event2):
|
||||
"""
|
||||
Sort function that will compare two events by their dates.
|
||||
|
||||
@param event1: first event
|
||||
@type event1: L{Event}
|
||||
@param event2: second event
|
||||
@type event2: L{Event}
|
||||
@return: Returns -1 if event1 < event2, 0 if they are equal, and
|
||||
1 if they are the same.
|
||||
@rtype: int
|
||||
"""
|
||||
return cmp(event1.get_date_object() , event2.get_date_object())
|
||||
|
@ -1,192 +0,0 @@
|
||||
|
||||
from types import NoneType
|
||||
|
||||
import RelLib
|
||||
import DateHandler
|
||||
|
||||
from BasicUtils import NameDisplay
|
||||
from ReportBase import ReportUtils
|
||||
|
||||
class SimpleReport:
|
||||
|
||||
def __init__(self, db, person):
|
||||
self.db = db
|
||||
self.person = person
|
||||
|
||||
def run(self):
|
||||
pass
|
||||
|
||||
def name(self, person):
|
||||
assert(isinstance(person, (RelLib.Person, NoneType)))
|
||||
if person:
|
||||
return NameDisplay.displayer.display(person)
|
||||
else:
|
||||
return u''
|
||||
|
||||
def __parent(self, person, func):
|
||||
assert(isinstance(person, (RelLib.Person, NoneType)))
|
||||
|
||||
if person:
|
||||
parent_handle_list = person.get_parent_family_handle_list()
|
||||
if parent_handle_list:
|
||||
family_id = parent_handle_list[0]
|
||||
family = self.db.get_family_from_handle(family_id)
|
||||
person_handle = func(family)
|
||||
if person_handle:
|
||||
return self.db.get_person_from_handle(person_handle)
|
||||
return None
|
||||
|
||||
def __event_date(self, person, func):
|
||||
assert(isinstance(person, (RelLib.Person, NoneType)))
|
||||
|
||||
if person:
|
||||
ref = func(person)
|
||||
if ref:
|
||||
event_handle = ref.get_reference_handle()
|
||||
if event_handle:
|
||||
event = self.db.get_event_from_handle(event_handle)
|
||||
date_obj = event.get_date_object()
|
||||
if date_obj:
|
||||
return DateHandler.displayer.display(date_obj)
|
||||
return u''
|
||||
|
||||
def __event_place(self, person, func):
|
||||
assert(isinstance(person, (RelLib.Person, NoneType)))
|
||||
|
||||
if person:
|
||||
ref = func(person)
|
||||
if ref:
|
||||
event_handle = ref.get_reference_handle()
|
||||
if event_handle:
|
||||
event = self.db.get_event_from_handle(event_handle)
|
||||
place_handle = event.get_place_handle()
|
||||
return ReportUtils.place_name(self.db, place_handle)
|
||||
return u''
|
||||
|
||||
def spouse(self, person):
|
||||
assert(isinstance(person, (RelLib.Person, NoneType)))
|
||||
|
||||
if person:
|
||||
family_handle_list = person.get_family_handle_list()
|
||||
if family_handle_list:
|
||||
family_id = family_handle_list[0]
|
||||
family = self.db.get_family_from_handle(family_id)
|
||||
if family.get_father_handle() == person.get_handle():
|
||||
person_handle = family.get_mother_handle()
|
||||
else:
|
||||
person_handle = family.get_father_handle()
|
||||
if person_handle:
|
||||
return self.db.get_person_from_handle(person_handle)
|
||||
return None
|
||||
|
||||
def marriage_type(self, person):
|
||||
assert(isinstance(person, (RelLib.Person, NoneType)))
|
||||
|
||||
if person:
|
||||
family_handle_list = person.get_family_handle_list()
|
||||
if family_handle_list:
|
||||
family_id = family_handle_list[0]
|
||||
family = self.db.get_family_from_handle(family_id)
|
||||
if family:
|
||||
return str(family.get_relationship())
|
||||
return u''
|
||||
|
||||
def marriage_place(self, person):
|
||||
assert(isinstance(person, (RelLib.Person, NoneType)))
|
||||
|
||||
if person:
|
||||
family_handle_list = person.get_family_handle_list()
|
||||
if family_handle_list:
|
||||
family_id = family_handle_list[0]
|
||||
family = self.db.get_family_from_handle(family_id)
|
||||
if family:
|
||||
reflist = family.get_event_ref_list()
|
||||
if reflist:
|
||||
ref = reflist[0].ref
|
||||
event = self.db.get_event_from_handle(ref)
|
||||
place_handle = event.get_place_handle()
|
||||
return ReportUtils.place_name(self.db, place_handle)
|
||||
return u''
|
||||
|
||||
def marriage_date(self, person):
|
||||
assert(isinstance(person, (RelLib.Person, NoneType)))
|
||||
|
||||
if person:
|
||||
family_handle_list = person.get_family_handle_list()
|
||||
if family_handle_list:
|
||||
family_id = family_handle_list[0]
|
||||
family = self.db.get_family_from_handle(family_id)
|
||||
if family:
|
||||
reflist = family.get_event_ref_list()
|
||||
if reflist:
|
||||
ref = reflist[0].ref
|
||||
event = self.db.get_event_from_handle(ref)
|
||||
date_obj = event.get_date_object()
|
||||
if date_obj:
|
||||
return DateHandler.displayer.display(date_obj)
|
||||
return u''
|
||||
|
||||
def children(self, person):
|
||||
assert(isinstance(person, (RelLib.Person, NoneType)))
|
||||
|
||||
if person:
|
||||
family_handle_list = person.get_family_handle_list()
|
||||
if family_handle_list:
|
||||
family_id = family_handle_list[0]
|
||||
family = self.db.get_family_from_handle(family_id)
|
||||
|
||||
return [ self.db.get_person_from_handle(hndl.ref)
|
||||
for hndl in family.get_child_ref_list() ]
|
||||
return []
|
||||
|
||||
def father(self, person):
|
||||
return self.__parent(person, RelLib.Family.get_father_handle)
|
||||
|
||||
def mother(self, person):
|
||||
return self.__parent(person, RelLib.Family.get_mother_handle)
|
||||
|
||||
def birth_date(self, person):
|
||||
return self.__event_date(person, RelLib.Person.get_birth_ref)
|
||||
|
||||
def birth_place(self, person):
|
||||
return self.__event_place(person, RelLib.Person.get_birth_ref)
|
||||
|
||||
def death_date(self, person):
|
||||
return self.__event_date(person, RelLib.Person.get_death_ref)
|
||||
|
||||
def death_place(self, person):
|
||||
return self.__event_place(person, RelLib.Person.get_death_ref)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
from GrampsDb import gramps_db_factory
|
||||
import sys
|
||||
import const
|
||||
|
||||
class MyReport(SimpleReport):
|
||||
|
||||
def run(self):
|
||||
print "Person : ", self.name(self.person)
|
||||
print "Birth date : ", self.birth_date(self.person)
|
||||
print "Birth place : ", self.birth_place(self.person)
|
||||
print "Death date : ", self.death_date(self.person)
|
||||
print "Death place : ", self.death_place(self.person)
|
||||
print "Father : ", self.name(self.father(self.person))
|
||||
print "Mother : ", self.name(self.mother(self.person))
|
||||
print "Spouse : ", self.name(self.spouse(self.person))
|
||||
print "Marriage Type : ", self.marriage_type(self.person)
|
||||
print "Marriage Date : ", self.marriage_date(self.person)
|
||||
print "Marriage Place: ", self.marriage_place(self.person)
|
||||
for child in self.children(self.person):
|
||||
print "Child : ", self.name(child)
|
||||
|
||||
db_class = gramps_db_factory(const.app_gramps_xml)
|
||||
database = db_class()
|
||||
database.load(sys.argv[1], lambda x: None, mode="w")
|
||||
person = database.get_default_person()
|
||||
|
||||
a = MyReport(database, person)
|
||||
|
||||
a.run()
|
||||
|
||||
|
327
src/docgen/TextBufDoc.py
Normal file
327
src/docgen/TextBufDoc.py
Normal file
@ -0,0 +1,327 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
# Copyright (C) 2007 Brian G. Matherly
|
||||
#
|
||||
# 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: TextBufDoc.py 8431 2007-04-30 01:56:34Z pez4brian $
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
import gtk
|
||||
import pango
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Gramps modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import BaseDoc
|
||||
from PluginUtils import register_text_doc
|
||||
import const
|
||||
import Errors
|
||||
import Utils
|
||||
|
||||
try:
|
||||
import pangocairo
|
||||
|
||||
RESOLUTION = pangocairo.cairo_font_map_get_default().get_resolution()
|
||||
except:
|
||||
RESOLUTION = 96
|
||||
|
||||
def pixels(cm):
|
||||
return int (RESOLUTION/2.54 * cm)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
LEFT,RIGHT,CENTER = 'LEFT','RIGHT','CENTER'
|
||||
_WIDTH_IN_CHARS = 72
|
||||
|
||||
|
||||
class DisplayBuf:
|
||||
|
||||
def __init__(self, title, buffer):
|
||||
g = gtk.glade.XML(const.gladeFile,'scrollmsg')
|
||||
self.top = g.get_widget('scrollmsg')
|
||||
msg = g.get_widget('msg')
|
||||
msg.set_buffer(buffer)
|
||||
g.get_widget('close').connect('clicked', self.close)
|
||||
|
||||
def close(self, obj):
|
||||
self.top.destroy()
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# TextBuf
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
class TextBufDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc):
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# Opens the file, resets the text buffer.
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def open(self, filename):
|
||||
self.tag_table = gtk.TextTagTable()
|
||||
|
||||
sheet = self.get_style_sheet()
|
||||
print sheet
|
||||
|
||||
for name in sheet.get_paragraph_style_names():
|
||||
print name
|
||||
tag = gtk.TextTag(name)
|
||||
|
||||
style = sheet.get_paragraph_style(name)
|
||||
font = style.get_font()
|
||||
if font.get_type_face() == BaseDoc.FONT_SERIF:
|
||||
tag.set_property("family", "Serif")
|
||||
elif font.get_type_face() == BaseDoc.FONT_SANS_SERIF:
|
||||
tag.set_property("family", "Sans")
|
||||
elif font.get_type_face() == BaseDoc.FONT_MONOSPACE:
|
||||
tag.set_property("family", "MonoSpace")
|
||||
|
||||
tag.set_property("size-points", float(font.get_size()))
|
||||
if font.get_bold():
|
||||
tag.set_property("weight", pango.WEIGHT_BOLD)
|
||||
if style.get_alignment() == BaseDoc.PARA_ALIGN_RIGHT:
|
||||
tag.set_property("justification", gtk.JUSTIFY_RIGHT)
|
||||
elif style.get_alignment() == BaseDoc.PARA_ALIGN_LEFT:
|
||||
tag.set_property("justification", gtk.JUSTIFY_LEFT)
|
||||
elif style.get_alignment() == BaseDoc.PARA_ALIGN_CENTER:
|
||||
tag.set_property("justification", gtk.JUSTIFY_CENTER)
|
||||
else:
|
||||
tag.set_property("justification", gtk.JUSTIFY_FILL)
|
||||
|
||||
if font.get_italic():
|
||||
tag.set_property("style", pango.STYLE_ITALIC)
|
||||
|
||||
if style.get_first_indent():
|
||||
tag.set_property("indent", pixels(style.get_first_indent()))
|
||||
#tag.set_property("tabs", [pixels(abs(style.get_first_indent()))])
|
||||
|
||||
tag.set_property("left-margin", pixels(style.get_left_margin()))
|
||||
tag.set_property("right-margin", pixels(style.get_right_margin()))
|
||||
tag.set_property("pixels-above-lines", pixels(style.get_top_margin()))
|
||||
tag.set_property("pixels-below-lines", pixels(style.get_bottom_margin()))
|
||||
tag.set_property("wrap-mode", gtk.WRAP_WORD)
|
||||
|
||||
self.tag_table.add(tag)
|
||||
self.buffer = gtk.TextBuffer(self.tag_table)
|
||||
return
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# Close the file. Call the app if required.
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def close(self):
|
||||
DisplayBuf('',self.buffer)
|
||||
|
||||
def get_usable_width(self):
|
||||
return _WIDTH_IN_CHARS
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# Force a section page break
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def end_page(self):
|
||||
return
|
||||
self.f.write('\012')
|
||||
|
||||
def start_bold(self):
|
||||
pass
|
||||
|
||||
def end_bold(self):
|
||||
pass
|
||||
|
||||
def page_break(self):
|
||||
pass
|
||||
|
||||
def start_superscript(self):
|
||||
return
|
||||
|
||||
def end_superscript(self):
|
||||
return
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# Starts a paragraph.
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def start_paragraph(self, style_name, leader=None):
|
||||
self.style_name = style_name
|
||||
if leader:
|
||||
self.text = leader + "\t"
|
||||
else:
|
||||
self.text = ""
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# End a paragraph. First format it to the desired widths.
|
||||
# If not in table cell, write it immediately. If in the cell,
|
||||
# add it to the list for this cell after formatting.
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def end_paragraph(self):
|
||||
self.buffer.insert_with_tags_by_name(
|
||||
self.buffer.get_end_iter(),
|
||||
self.text + "\n",
|
||||
self.style_name)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# Start a table. Grab the table style, and store it.
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def start_table(self,name,style_name):
|
||||
return
|
||||
styles = self.get_style_sheet()
|
||||
self.tbl_style = styles.get_table_style(style_name)
|
||||
self.ncols = self.tbl_style.get_columns()
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# End a table. Turn off the self.in_cell flag
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def end_table(self):
|
||||
return
|
||||
self.in_cell = 0
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# Start a row. Initialize lists for cell contents, number of lines,
|
||||
# and the widths. It is necessary to keep a list of cell contents
|
||||
# that is to be written after all the cells are defined.
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def start_row(self):
|
||||
return
|
||||
|
||||
self.cellpars = [''] * self.ncols
|
||||
self.cell_lines = [0] * self.ncols
|
||||
self.cell_widths = [0] * self.ncols
|
||||
self.cellnum = -1
|
||||
self.maxlines = 0
|
||||
table_width = self.get_usable_width() * self.tbl_style.get_width() / 100.0
|
||||
for cell in range(self.ncols):
|
||||
self.cell_widths[cell] = int( table_width * \
|
||||
self.tbl_style.get_column_width(cell) / 100.0 )
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# End a row. Write the cell contents. Write the line of spaces
|
||||
# if the cell has fewer lines than the maximum number.
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def end_row(self):
|
||||
return
|
||||
|
||||
self.in_cell = 0
|
||||
cell_text = [None]*self.ncols
|
||||
for cell in range(self.ncols):
|
||||
if self.cell_widths[cell]:
|
||||
blanks = ' '*self.cell_widths[cell] + '\n'
|
||||
if self.cell_lines[cell] < self.maxlines:
|
||||
self.cellpars[cell] = self.cellpars[cell] \
|
||||
+ blanks * (self.maxlines-self.cell_lines[cell])
|
||||
cell_text[cell] = self.cellpars[cell].split('\n')
|
||||
for line in range(self.maxlines):
|
||||
for cell in range(self.ncols):
|
||||
if self.cell_widths[cell]:
|
||||
self.f.write(cell_text[cell][line])
|
||||
self.f.write('\n')
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# Start a cell. Set the self.in_cell flag, increment the curren cell number.
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def start_cell(self,style_name,span=1):
|
||||
return
|
||||
|
||||
self.in_cell = 1
|
||||
self.cellnum = self.cellnum + span
|
||||
span = span - 1
|
||||
while span:
|
||||
self.cell_widths[self.cellnum-span] = 0
|
||||
span = span - 1
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# End a cell. Find out the number of lines in this cell, correct
|
||||
# the maximum number of lines if necessary.
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def end_cell(self):
|
||||
return
|
||||
|
||||
self.in_cell = 0
|
||||
self.cell_lines[self.cellnum] = self.cellpars[self.cellnum].count('\n')
|
||||
if self.cell_lines[self.cellnum] > self.maxlines:
|
||||
self.maxlines = self.cell_lines[self.cellnum]
|
||||
|
||||
def add_media_object(self, name, align, w_cm, h_cm):
|
||||
return
|
||||
|
||||
this_text = '(photo)'
|
||||
if self.in_cell:
|
||||
self.cellpars[self.cellnum] = self.cellpars[self.cellnum] + this_text
|
||||
else:
|
||||
self.f.write(this_text)
|
||||
|
||||
def write_note(self,text,format,style_name):
|
||||
return
|
||||
|
||||
if format == 1:
|
||||
for line in text.split('\n'):
|
||||
self.start_paragraph(style_name)
|
||||
self.write_text(line)
|
||||
self.end_paragraph()
|
||||
elif format == 0:
|
||||
for line in text.split('\n\n'):
|
||||
self.start_paragraph(style_name)
|
||||
line = line.replace('\n',' ')
|
||||
line = ' '.join(line.split())
|
||||
self.write_text(line)
|
||||
self.end_paragraph()
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
# Writes text.
|
||||
#--------------------------------------------------------------------
|
||||
def write_text(self,text,mark=None):
|
||||
self.text = self.text + text
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Register the document generator with the GRAMPS plugin system
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
print_label = None
|
||||
register_text_doc(_("TextBuffer"), TextBufDoc, 1, 1, 1, ".xyz", None)
|
||||
|
@ -9830,8 +9830,8 @@
|
||||
<property name="type">GTK_WINDOW_TOPLEVEL</property>
|
||||
<property name="window_position">GTK_WIN_POS_CENTER_ALWAYS</property>
|
||||
<property name="modal">False</property>
|
||||
<property name="default_width">450</property>
|
||||
<property name="default_height">400</property>
|
||||
<property name="default_width">650</property>
|
||||
<property name="default_height">500</property>
|
||||
<property name="resizable">True</property>
|
||||
<property name="destroy_with_parent">False</property>
|
||||
<property name="decorated">True</property>
|
||||
@ -9855,7 +9855,7 @@
|
||||
<property name="layout_style">GTK_BUTTONBOX_END</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkButton" id="closebutton1">
|
||||
<widget class="GtkButton" id="close">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
|
@ -182,6 +182,7 @@ def build_user_paths():
|
||||
user_paths = [const.home_dir,
|
||||
os.path.join(const.home_dir,"filters"),
|
||||
os.path.join(const.home_dir,"plugins"),
|
||||
os.path.join(const.home_dir,"docgen"),
|
||||
os.path.join(const.home_dir,"templates"),
|
||||
os.path.join(const.home_dir,"thumb")]
|
||||
|
||||
|
29
src/plugins/all_events.py
Normal file
29
src/plugins/all_events.py
Normal file
@ -0,0 +1,29 @@
|
||||
from ReportBase._SimpleAccess import SimpleAccess, by_date
|
||||
from ReportBase._SimpleDoc import SimpleDoc
|
||||
|
||||
def run(database, document, person):
|
||||
|
||||
sa = SimpleAccess(database)
|
||||
sd = SimpleDoc(document)
|
||||
|
||||
# get the personal events
|
||||
event_list = sa.events(person)
|
||||
|
||||
# get the events of each family in which the person is
|
||||
# a parent
|
||||
for family in sa.parent_in(person):
|
||||
event_list += sa.events(family)
|
||||
|
||||
# Sort the events by their date
|
||||
event_list.sort(by_date)
|
||||
|
||||
# display the results
|
||||
|
||||
sd.title("Sorted events of %s" % sa.name(person))
|
||||
sd.paragraph("")
|
||||
|
||||
sd.header1("Event Type\tEvent Date\tEvent Place")
|
||||
for event in event_list:
|
||||
sd.paragraph("%-12s\t%-12s\t%s" % (sa.event_type(event),
|
||||
sa.event_date(event),
|
||||
sa.event_place(event)))
|
Loading…
Reference in New Issue
Block a user