From 95ee36dfda156c3f0ae8964ace6e7ecc4f569d9f Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sat, 6 Nov 2004 03:31:34 +0000 Subject: [PATCH] * src/ImageSelect.py: Add date/place property to media objects * src/ReadXML.py: Add date/place property to media objects * src/RelLib.py: Add date/place property to media objects * src/WriteXML.py: Add date/place property to media objects * src/gramps.glade: Add date/place property to media objects * src/SelectObject.py: display gramps id instead of internal handle svn: r3707 --- ChangeLog | 8 +++ src/ImageSelect.py | 74 +++++++++++++++++++- src/ReadXML.py | 8 +++ src/RelLib.py | 47 ++++++++++++- src/SelectObject.py | 4 +- src/WriteXML.py | 9 ++- src/gramps.glade | 162 ++++++++++++++++++++++++++++++++++++++++---- 7 files changed, 294 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index d2ebc2bd9..b5e2c02f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-11-05 Don Allingham + * src/ImageSelect.py: Add date/place property to media objects + * src/ReadXML.py: Add date/place property to media objects + * src/RelLib.py: Add date/place property to media objects + * src/WriteXML.py: Add date/place property to media objects + * src/gramps.glade: Add date/place property to media objects + * src/SelectObject.py: display gramps id instead of internal handle + 2004-11-05 Tim Waugh * src/plugins/Ancestors.py: Include non-marriage relationships. diff --git a/src/ImageSelect.py b/src/ImageSelect.py index 48593da1d..0f4c8d9ef 100644 --- a/src/ImageSelect.py +++ b/src/ImageSelect.py @@ -57,6 +57,9 @@ import ListModel import SelectObject import GrampsMime import Sources +import DateEdit +import DateHandler +import Date from QuestionDialog import ErrorDialog _IMAGEX = 140 @@ -870,6 +873,8 @@ class GlobalMediaProperties: def __init__(self,db,obj,update,parent,parent_window=None): self.parent = parent + self.dp = DateHandler.create_parser() + self.dd = DateHandler.create_display() if obj: if self.parent.parent.child_windows.has_key(obj.get_handle()): self.parent.parent.child_windows[obj.get_handle()].present(None) @@ -885,18 +890,48 @@ class GlobalMediaProperties: self.db = db self.update = update self.refs = 0 - + if obj: + self.date_object = Date.Date(self.obj.get_date_object()) + else: + self.date_object = Date.Date() + self.path = self.db.get_save_path() self.change_dialog = gtk.glade.XML(const.imageselFile,"change_global","gramps") title = _('Media Properties Editor') self.window = self.change_dialog.get_widget('change_global') + self.date_entry = self.change_dialog.get_widget('date') + + self.pdmap = {} + self.add_places = [] + for key in self.db.get_place_handles(): + p = db.get_place_from_handle(key).get_display_info() + self.pdmap[p[0]] = key + + self.place = self.change_dialog.get_widget('place') + self.place_list = self.pdmap.keys() + self.place_list.sort() + build_dropdown(self.place,self.place_list) + + if self.obj: + handle = self.obj.get_place_handle() + pobj = self.db.get_place_from_handle(handle) + if pobj: + self.place.set_text(pobj.get_title()) + + self.date_entry.set_text(self.dd.display(self.date_object)) + Utils.set_titles(self.window, self.change_dialog.get_widget('title'),title) self.descr_window = self.change_dialog.get_widget("description") self.notes = self.change_dialog.get_widget("notes") + self.date_check = DateEdit.DateEdit(self.date_object, + self.date_entry, + self.change_dialog.get_widget("date_edit"), + self.window) + self.pixmap = self.change_dialog.get_widget("pixmap") self.attr_type = self.change_dialog.get_widget("attr_type") self.attr_value = self.change_dialog.get_widget("attr_value") @@ -1089,11 +1124,38 @@ class GlobalMediaProperties: else: Utils.unbold_label(self.notes_label) + def get_place(self,field,makenew=0): + text = unicode(field.get_text().strip()) + if text: + if self.pdmap.has_key(text): + return self.pdmap[text] + elif makenew: + place = RelLib.Place() + place.set_title(text) + trans = self.db.transaction_begin() + self.db.add_place(place,trans) + self.db.transaction_commit(trans,_('Add Place (%s)' % text)) + self.pdmap[text] = place.get_handle() + self.add_places.append(place) + return place.get_handle() + else: + return None + else: + return None + def on_apply_clicked(self, obj): t = self.notes.get_buffer() text = unicode(t.get_text(t.get_start_iter(),t.get_end_iter(),gtk.FALSE)) desc = unicode(self.descr_window.get_text()) note = self.obj.get_note() + + if not self.date_object.is_equal(self.obj.get_date_object()): + self.obj.set_date_object(self.date_object) + + p = self.get_place(self.place) + if p: + self.obj.set_place_handle(p) + format = self.preform.get_active() if text != note or desc != self.obj.get_description(): self.obj.set_note(text) @@ -1219,3 +1281,13 @@ class DeleteMediaQuery: self.db.transaction_commit(trans,_("Remove Media Object")) if self.update: self.update() + +def build_dropdown(entry,strings): + store = gtk.ListStore(str) + for value in strings: + node = store.append() + store.set(node,0,value) + completion = gtk.EntryCompletion() + completion.set_text_column(0) + completion.set_model(store) + entry.set_completion(completion) diff --git a/src/ReadXML.py b/src/ReadXML.py index fe0711fd3..b0630d3d4 100644 --- a/src/ReadXML.py +++ b/src/ReadXML.py @@ -967,6 +967,8 @@ class GrampsParser: dv = self.source_ref.get_date() elif self.ord: dv = self.ord.get_date_object() + elif self.object: + dv = self.object.get_date_object() elif self.address: dv = self.address.get_date_object() else: @@ -1017,6 +1019,8 @@ class GrampsParser: dv = self.source_ref.get_date() elif self.ord: dv = self.ord.get_date_object() + elif self.object: + dv = self.object.get_date_object() elif self.address: dv = self.address.get_date_object() else: @@ -1067,6 +1071,8 @@ class GrampsParser: dv = self.source_ref.get_date() elif self.ord: dv = self.ord.get_date_object() + elif self.object: + dv = self.object.get_date_object() elif self.address: dv = self.address.get_date_object() else: @@ -1171,6 +1177,8 @@ class GrampsParser: self.placeobj.set_title(tag) if self.ord: self.ord.set_place_handle(self.placeobj.get_handle()) + elif self.object: + self.object.set_place_handle(self.placeobj.get_handle()) else: self.event.set_place_handle(self.placeobj.get_handle()) self.db.commit_place(self.placeobj,self.trans,self.change) diff --git a/src/RelLib.py b/src/RelLib.py index a2219bf80..2bef86389 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -1075,12 +1075,16 @@ class MediaObject(PrimaryObject,SourceNote): self.mime = source.mime self.desc = source.desc self.thumb = source.thumb + self.date = Date.Date(source.date) + self.place = source.place for attr in source.attrlist: self.attrlist.append(Attribute(attr)) else: self.path = "" self.mime = "" self.desc = "" + self.date = None + self.place = u"" self.thumb = None def serialize(self): @@ -1097,7 +1101,7 @@ class MediaObject(PrimaryObject,SourceNote): """ return (self.handle, self.gramps_id, self.path, self.mime, self.desc, self.attrlist, self.source_list, self.note, - self.change) + self.change, self.date, self.place) def unserialize(self,data): """ @@ -1105,8 +1109,37 @@ class MediaObject(PrimaryObject,SourceNote): back into the data in an Event structure. """ (self.handle, self.gramps_id, self.path, self.mime, self.desc, - self.attrlist, self.source_list, self.note, self.change) = data + self.attrlist, self.source_list, self.note, self.change, + self.date, self.place) = data + def set_place_handle(self,place): + """sets the Place instance of the Event""" + self.place = place + + def get_place_handle(self): + """returns the Place instance of the Event""" + return self.place + + def get_date(self) : + """returns a string representation of the date of the Event instance""" + if self.date: + return display.display(self.date) + return u"" + + def get_date_object(self): + """returns the Date object associated with the Event""" + if not self.date: + self.date = Date.Date() + return self.date + + def set_date(self, date) : + """attempts to sets the date of the Event instance""" + self.date = parser.parse(date) + + def set_date_object(self,date): + """sets the Date object associated with the Event""" + self.date = date + def set_mime_type(self,type): self.mime = type @@ -1548,10 +1581,12 @@ class MediaRef(SourceNote): self.note = Note(source.note) for attr in source.attrlist: self.attrlist.append(Attribute(attr)) + self.rect = source.rect else: self.private = 0 self.ref = None self.note = None + self.rect = None def set_privacy(self,val): """Sets or clears the privacy flag of the data""" @@ -1561,6 +1596,14 @@ class MediaRef(SourceNote): """Returns the privacy level of the data""" return self.private + def set_rectangle(self,coord): + """Sets subection of an image""" + self.rect = coord + + def get_rectangle(self): + """Returns the subsection of an image""" + return self.rect + def set_reference_handle(self,obj_id): self.ref = obj_id diff --git a/src/SelectObject.py b/src/SelectObject.py index 6684cd1e4..0b30dcb49 100644 --- a/src/SelectObject.py +++ b/src/SelectObject.py @@ -72,7 +72,7 @@ class SelectObject: self.top = self.glade.get_widget('select_object') title_label = self.glade.get_widget('object_title') self.object_tree = self.glade.get_widget('object_tree') - self.object_handle = self.glade.get_widget('object_handle') + self.object_handle = self.glade.get_widget('object_id') self.object_type = self.glade.get_widget('object_type') self.object_desc = self.glade.get_widget('object_desc') self.object_path = self.glade.get_widget('object_path') @@ -126,7 +126,7 @@ class SelectObject: if not pexists: fexists = 0 - self.object_handle.set_text(obj.get_handle()) + self.object_handle.set_text(obj.get_gramps_id()) self.object_type.set_text(the_type) self.object_desc.set_text(obj.get_description()) if len(path) == 0 or fexists == 0: diff --git a/src/WriteXML.py b/src/WriteXML.py index b35e60f1e..59ef96048 100644 --- a/src/WriteXML.py +++ b/src/WriteXML.py @@ -832,14 +832,21 @@ class XmlWriter: self.g.write(' description="%s"' % self.fix(obj.get_description())) alist = obj.get_attribute_list() note = obj.get_note() + phandle = obj.get_place_handle() + dval = obj.get_date_object() slist = obj.get_source_references() - if len(alist) == 0 and len(slist) == 0 and note == "": + if len(alist) == 0 and len(slist) == 0 and note == "" and \ + phandle == "" and not dval.is_empty(): self.g.write('/>\n') else: self.g.write('>\n') self.write_attribute_list(alist) if note != "": self.write_note("note",obj.get_note_object(),3) + if phandle: + self.g.write(' \n' % phandle) + if not dval.is_empty(): + self.write_date(dval,3) for s in slist: self.dump_source_ref(s,3) self.g.write(" \n") diff --git a/src/gramps.glade b/src/gramps.glade index 028626677..997364980 100644 --- a/src/gramps.glade +++ b/src/gramps.glade @@ -23559,11 +23559,14 @@ Other 0 - + 12 True + 3 + 3 False - 0 + 6 + 6 @@ -23571,19 +23574,22 @@ Other _Title: True False - GTK_JUSTIFY_CENTER + GTK_JUSTIFY_LEFT False False - 1 + 0 0.5 - 5 - 5 + 0 + 0 description - 0 - False - False + 1 + 2 + 0 + 1 + fill + @@ -23600,9 +23606,141 @@ Other False - 5 - True - True + 2 + 3 + 0 + 1 + + + + + + + True + _Date: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 1 + 2 + 1 + 2 + fill + + + + + + + True + _Place: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + place + + + 1 + 2 + 2 + 3 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 2 + 3 + 2 + 3 + + + + + + + True + False + 0 + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + + True + Invoke date editor + True + GTK_RELIEF_NONE + True + + + + True + 0.5 + 0.5 + 0 + 0 + + + + + 0 + False + False + + + + + 2 + 3 + 1 + 2 + fill + fill