diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 8f256fed8..d1cd8c31f 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,7 @@ +2005-07-14 Don Allingham + * src/plugins/NavWebPage.py: gallery/media object enhancements, div/span fixes + in HTML. + 2005-07-14 Martin Hawlisch * src/plugins/NavWebPage.py: Added display_note_object and display_first_image_as_thumbnail to BasePage; PlacePage and diff --git a/gramps2/src/plugins/NavWebPage.py b/gramps2/src/plugins/NavWebPage.py index a253d105f..5be6cc90b 100644 --- a/gramps2/src/plugins/NavWebPage.py +++ b/gramps2/src/plugins/NavWebPage.py @@ -97,8 +97,9 @@ _character_sets = [ ['koi8_r', 'koi8_r', ], ] + class BasePage: - def __init__(self, title, options, archive): + def __init__(self, title, options, archive, photo_list): self.title_str = title self.inc_download = options.handler.options_dict['NWEBdownload'] self.html_dir = options.handler.options_dict['NWEBod'] @@ -111,18 +112,14 @@ class BasePage: self.noid = options.handler.options_dict['NWEBnoid'] self.use_intro = options.handler.options_dict['NWEBintronote'] != u"" self.use_contact = options.handler.options_dict['NWEBcontact'] != u"" + self.photo_list = photo_list def copy_media(self,photo): + if photo.get_handle() != self.photo_list: + self.photo_list.append(photo.get_handle()) newpath = photo.gramps_id + os.path.splitext(photo.get_path())[1] if self.image_dir: newpath = os.path.join(self.image_dir,newpath) - if self.archive: - imagefile = open(photo.get_path(),"r") - self.archive.add_file(newpath,time.time(),imagefile) - imagefile.close() - else: - shutil.copyfile(photo.get_path(), - os.path.join(self.html_dir,newpath)) return newpath def create_file(self,name): @@ -192,6 +189,7 @@ class BasePage: of.write(' %s  \n' % (self.ext,_('Individuals'))) of.write(' %s  \n' % (self.ext,_('Sources'))) of.write(' %s  \n' % (self.ext,_('Places'))) + of.write(' %s  \n' % (self.ext,_('Gallery'))) if self.inc_download: of.write(' %s  \n' % (self.ext,_('Download'))) if self.use_contact: @@ -255,8 +253,8 @@ class BasePage: #------------------------------------------------------------------------ class IndividualListPage(BasePage): - def __init__(self, db, title, person_handle_list, options, archive): - BasePage.__init__(self, title, options, archive) + def __init__(self, db, title, person_handle_list, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) of = self.create_file("individuals") self.display_header(of,_('Individuals'), @@ -293,7 +291,7 @@ class IndividualListPage(BasePage): of.write(' ' % (person.handle,self.ext)) of.write(person.get_primary_name().get_first_name()) if not self.noid: - of.write(u" [%s]" % person.gramps_id) + of.write(u' [%s]' % person.gramps_id) of.write('\n') first = False @@ -308,8 +306,8 @@ class IndividualListPage(BasePage): #------------------------------------------------------------------------ class PlaceListPage(BasePage): - def __init__(self, db, title, place_handles, src_list, options, archive): - BasePage.__init__(self, title, options, archive) + def __init__(self, db, title, place_handles, src_list, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) of = self.create_file("places") self.display_header(of,_('Places'), db.get_researcher().get_name()) @@ -351,7 +349,7 @@ class PlaceListPage(BasePage): of.write('' % (place.handle,self.ext)) of.write(n) if not self.noid: - of.write(' [%s]' % place.gramps_id) + of.write(' [%s]' % place.gramps_id) of.write('') last_surname = n elif n != last_surname: @@ -360,7 +358,7 @@ class PlaceListPage(BasePage): of.write('' % (place.handle,self.ext)) of.write(n) if not self.noid: - of.write(' [%s]' % place.gramps_id) + of.write(' [%s]' % place.gramps_id) of.write('') last_surname = n @@ -375,9 +373,9 @@ class PlaceListPage(BasePage): #------------------------------------------------------------------------ class PlacePage(BasePage): - def __init__(self, db, title, place_handle, src_list, options, archive): + def __init__(self, db, title, place_handle, src_list, options, archive, media_list): place = db.get_place_from_handle( place_handle) - BasePage.__init__(self,title,options,archive) + BasePage.__init__(self, title, options, archive, media_list) of = self.create_file(place.get_handle()) place_name = ReportUtils.place_name(db,place_handle) self.display_header(of,place_name, @@ -425,6 +423,73 @@ class PlacePage(BasePage): self.display_footer(of) self.close_file(of) +#------------------------------------------------------------------------ +# +# +# +#------------------------------------------------------------------------ +class MediaPage(BasePage): + + def __init__(self, db, title, handle, src_list, options, archive, media_list): + photo = db.get_object_from_handle(handle) + BasePage.__init__(self, title, options, archive, media_list) + of = self.create_file(handle) + + newpath = photo.gramps_id + os.path.splitext(photo.get_path())[1] + if self.image_dir: + newpath = os.path.join(self.image_dir,newpath) + if self.archive: + imagefile = open(photo.get_path(),"r") + self.archive.add_file(newpath,time.time(),imagefile) + imagefile.close() + else: + shutil.copyfile(photo.get_path(), + os.path.join(self.html_dir,newpath)) + + title = photo.get_description() + self.display_header(of, title, db.get_researcher().get_name()) + + of.write('
\n') + of.write('

%s

\n' % title) + + mime_type = photo.get_mime_type() + if mime_type and mime_type.startswith("image"): + try: + of.write('
\n') + of.write('' % newpath) + of.write('
\n') + except (IOError,OSError),msg: + ErrorDialog(str(msg)) + + of.write('\n') + + of.write('\n' % _('GRAMPS ID')) + of.write('\n' % photo.gramps_id) + of.write('\n') + of.write('\n' % _('MIME type')) + of.write('\n' % photo.mime) + of.write('\n') + of.write('
%s%s
%s%s
\n') + + noteobj = photo.get_note_object() + if noteobj: + of.write('

%s

\n' % _('Narrative')) + of.write('
\n') + format = noteobj.get_format() + text = noteobj.get() + + if format: + text = u"
" + u"
".join(text.split("\n")) + else: + text = u"

".join(text.split("\n")) + of.write('

%s

\n' % text) + of.write('
\n') + + self.display_footer(of) + self.close_file(of) + #------------------------------------------------------------------------ # # @@ -432,8 +497,8 @@ class PlacePage(BasePage): #------------------------------------------------------------------------ class SurnameListPage(BasePage): - def __init__(self, db, title, person_handle_list, options, archive): - BasePage.__init__(self, title, options, archive) + def __init__(self, db, title, person_handle_list, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) of = self.create_file("surnames") self.display_header(of,_('Surnames'), db.get_researcher().get_name()) @@ -467,13 +532,13 @@ class SurnameListPage(BasePage): of.write('%s' % last_letter) of.write('') of.write('' % (self.ext,self.lnkfmt(surname))) - of.write(surname) + of.write("%s (%d)" % (surname,len(data_list))) of.write('') elif surname != last_surname: of.write(' ') of.write('') of.write('' % (self.ext,self.lnkfmt(surname))) - of.write(surname) + of.write("%s (%d)" % (surname,len(data_list))) of.write('') last_surname = surname @@ -489,8 +554,8 @@ class SurnameListPage(BasePage): #------------------------------------------------------------------------ class IntroductionPage(BasePage): - def __init__(self, db, title, options, archive): - BasePage.__init__(self, title, options, archive) + def __init__(self, db, title, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) note_id = options.handler.options_dict['NWEBintronote'] of = self.create_file("introduction") @@ -534,8 +599,8 @@ class IntroductionPage(BasePage): #------------------------------------------------------------------------ class HomePage(BasePage): - def __init__(self, db, title, options, archive): - BasePage.__init__(self, title, options, archive) + def __init__(self, db, title, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) note_id = options.handler.options_dict['NWEBhomenote'] of = self.create_file("index") @@ -579,8 +644,8 @@ class HomePage(BasePage): #------------------------------------------------------------------------ class SourcesPage(BasePage): - def __init__(self, db, title, handle_set, options, archive): - BasePage.__init__(self, title, options, archive) + def __init__(self, db, title, handle_set, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) of = self.create_file("sources") self.display_header(of,_('Sources'), @@ -606,6 +671,41 @@ class SourcesPage(BasePage): self.display_footer(of) self.close_file(of) +#------------------------------------------------------------------------ +# +# +# +#------------------------------------------------------------------------ +class GalleryPage(BasePage): + + def __init__(self, db, title, handle_set, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) + + of = self.create_file("gallery") + self.display_header(of, _('Gallery'), db.get_researcher().get_name()) + + handle_list = list(handle_set) + + of.write('

%s

\n

' % _('Gallery')) + of.write(_('All media images cited in the project.')) + of.write('

\n
\n\n') + + index = 1 + for handle in media_list: + media = db.get_object_from_handle(handle) + of.write('\n' % index) + of.write('\n') + index += 1 + + of.write('
%d.') + of.write('' % (handle,self.ext)) + of.write(media.get_description()) + of.write('\n') + of.write('
\n
\n') + + self.display_footer(of) + self.close_file(of) + #------------------------------------------------------------------------ # # @@ -613,8 +713,8 @@ class SourcesPage(BasePage): #------------------------------------------------------------------------ class DownloadPage(BasePage): - def __init__(self, db, title, options, archive): - BasePage.__init__(self, title, options, archive) + def __init__(self, db, title, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) of = self.create_file("download") self.display_header(of,_('Download'), @@ -632,8 +732,8 @@ class DownloadPage(BasePage): #------------------------------------------------------------------------ class ContactPage(BasePage): - def __init__(self, db, title, options, archive): - BasePage.__init__(self, title, options, archive) + def __init__(self, db, title, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) of = self.create_file("contact") self.display_header(of,_('Contact'), @@ -644,8 +744,6 @@ class ContactPage(BasePage): note_id = options.handler.options_dict['NWEBcontact'] - print "NOTEID",note_id - obj = db.get_object_from_handle(note_id) mime_type = obj.get_mime_type() @@ -656,7 +754,7 @@ class ContactPage(BasePage): of.write('') of.write('
') of.write('' % newpath) + of.write('src="%s.%s" />' % (note_id,self.ext)) of.write('
\n') of.write('\n') except (IOError,OSError),msg: @@ -702,8 +800,8 @@ class IndividualPage(BasePage): } def __init__(self, db, person, title, ind_list, - place_list, src_list, options, archive): - BasePage.__init__(self, title, options, archive) + place_list, src_list, options, archive, media_list): + BasePage.__init__(self, title, options, archive, media_list) self.person = person self.db = db self.ind_list = ind_list @@ -866,7 +964,7 @@ class IndividualPage(BasePage): of.write('' % (person.handle,self.ext)) of.write(_nd.display(person)) if not self.noid: - of.write(' [%s]' % (val)) + of.write(' [%s]' % (val)) if use_link: of.write('') of.write('\n') @@ -920,7 +1018,7 @@ class IndividualPage(BasePage): of.write('' % (child.handle,self.ext)) of.write(_nd.display(child)) if not self.noid: - of.write(' [%s]' % gid) + of.write(' [%s]' % gid) if use_link: of.write('\n') of.write(u"
\n") @@ -959,7 +1057,7 @@ class IndividualPage(BasePage): of.write('' % (spouse.handle,self.ext)) of.write(name) if not self.noid: - of.write(' [%s]' % (gid)) + of.write(' [%s]' % (gid)) if use_link: of.write('') @@ -1095,7 +1193,7 @@ class WebReport(Report.Report): self.separate_alpha = options_class.handler.options_dict['NWEBsplita'] self.depth = options_class.handler.options_dict['NWEBtreed'] self.sort = Sort.Sort(self.database) - self.inc_contact = options_class.handler.options_dict['NWEBcontact'] + self.inc_contact = options_class.handler.options_dict['NWEBcontact'] != u"" self.inc_download = options_class.handler.options_dict['NWEBdownload'] self.use_archive = options_class.handler.options_dict['NWEBarchive'] self.use_intro = options_class.handler.options_dict['NWEBintronote'] != u"" @@ -1160,14 +1258,16 @@ class WebReport(Report.Report): self.write_css(archive,self.target_path,self.css) - HomePage(self.database, self.title, self.options_class, archive) + photo_list = [] + + HomePage(self.database, self.title, self.options_class, archive, photo_list) if self.inc_contact: - ContactPage(self.database, self.title, self.options_class, archive) + ContactPage(self.database, self.title, self.options_class, archive, photo_list) if self.inc_download: - DownloadPage(self.database, self.title, self.options_class, archive) + DownloadPage(self.database, self.title, self.options_class, archive, photo_list) if self.use_intro: - IntroductionPage(self.database, self.title, self.options_class, archive) + IntroductionPage(self.database, self.title, self.options_class, archive, photo_list) place_list = sets.Set() source_list = sets.Set() @@ -1179,29 +1279,37 @@ class WebReport(Report.Report): idoc = IndividualPage(self.database, person, self.title, ind_list, place_list, source_list, - self.options_class, archive) + self.options_class, archive, photo_list) self.progress_bar_step() while gtk.events_pending(): gtk.main_iteration() if len(ind_list) > 1: IndividualListPage(self.database, self.title, ind_list, - self.options_class, archive) + self.options_class, archive, photo_list) SurnameListPage(self.database, self.title, ind_list, - self.options_class, archive) + self.options_class, archive, photo_list) self.progress_bar_step() while gtk.events_pending(): gtk.main_iteration() PlaceListPage(self.database, self.title, place_list, - source_list,self.options_class, archive) + source_list,self.options_class, archive, photo_list) for place in place_list: PlacePage(self.database, self.title, place, source_list, - self.options_class, archive) + self.options_class, archive, photo_list) SourcesPage(self.database,self.title, source_list, self.options_class, - archive) + archive, photo_list) + + GalleryPage(self.database,self.title, source_list, self.options_class, + archive, photo_list) + + for photo_handle in photo_list: + MediaPage(self.database, self.title, photo_handle, source_list, + self.options_class, archive, photo_list) + if archive: archive.close() self.progress_bar_done() @@ -1406,38 +1514,9 @@ class WebReportOptions(ReportOptions.ReportOptions): cursor.close() media_list.sort() - home_node = None - home_note = self.options_dict['NWEBhomenote'] - - store = gtk.ListStore(str,str) - for data in media_list: - if data[1] == home_note: - home_node = store.append(row=data) - else: - store.append(row=data) - self.home_note = GrampsNoteComboBox(store,home_node) - - intro_node = None - intro_note = self.options_dict['NWEBintronote'] - - store = gtk.ListStore(str,str) - for data in media_list: - if data[1] == intro_note: - intro_node = store.append(row=data) - else: - store.append(row=data) - self.intro_note = GrampsNoteComboBox(store,intro_node) - - contact_node = None - self.inc_contact = self.options_dict['NWEBcontact'] - - store = gtk.ListStore(str,str) - for data in media_list: - if data[1] == self.inc_contact: - contact_node = store.append(row=data) - else: - store.append(row=data) - self.contact = GrampsNoteComboBox(store,contact_node) + self.home_note = build_combo_box(media_list,self.options_dict['NWEBhomenote']) + self.intro_note = build_combo_box(media_list,self.options_dict['NWEBintronote']) + self.contact = build_combo_box(media_list,self.options_dict['NWEBcontact']) dialog.add_frame_option(title,_('Home Media/Note ID'), self.home_note) @@ -1732,6 +1811,21 @@ class GrampsNoteComboBox(gtk.ComboBox): handle = self.local_store.get_value(active,1) return handle +def build_combo_box(media_list,select_value): + store = gtk.ListStore(str,str) + node = None + + for data in media_list: + if data[1] == select_value: + node = store.append(row=data) + else: + store.append(row=data) + widget = GrampsNoteComboBox(store,node) + if len(media_list) == 0: + widget.set_sensitive(False) + return widget + + #------------------------------------------------------------------------- # #