Web page enhancements

svn: r796
This commit is contained in:
Don Allingham 2002-02-23 23:51:29 +00:00
parent 80313f3ec5
commit e78176cb80
6 changed files with 223 additions and 144 deletions

125
gramps/src/DbPrompter.py Normal file
View File

@ -0,0 +1,125 @@
#! /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
#
#-------------------------------------------------------------------------
#
# libraries
#
#-------------------------------------------------------------------------
import libglade
import Utils
import gtk
import const
import GrampsCfg
#-------------------------------------------------------------------------
#
# Make sure a database is opened
#
#-------------------------------------------------------------------------
class DbPrompter:
def __init__(self,db,want_new):
self.db = db
self.want_new = want_new
self.show()
def show(self):
opendb = libglade.GladeXML(const.gladeFile, "opendb")
opendb.signal_autoconnect({
"on_open_ok_clicked" : self.open_ok_clicked,
"on_open_cancel_clicked" : self.open_cancel_clicked,
"on_opendb_delete_event": self.open_delete_event,
})
self.new = opendb.get_widget("new")
if self.want_new:
self.new.set_active(1)
def open_ok_clicked(self,obj):
if self.new.get_active():
self.save_as_activate()
else:
self.open_activate()
Utils.destroy_passed_object(obj)
def save_as_activate(self):
wFs = libglade.GladeXML (const.gladeFile, "fileselection")
wFs.signal_autoconnect({
"on_ok_button1_clicked": self.save_ok_button_clicked,
"destroy_passed_object": self.cancel_button_clicked,
})
def save_ok_button_clicked(self,obj):
filename = obj.get_filename()
if filename:
Utils.destroy_passed_object(obj)
if GrampsCfg.usevc and GrampsCfg.vc_comment:
self.db.display_comment_box(filename)
else:
self.db.save_file(filename,_("No Comment Provided"))
def open_activate(self):
wFs = libglade.GladeXML(const.revisionFile, "dbopen")
wFs.signal_autoconnect({
"on_ok_button1_clicked": self.ok_button_clicked,
"destroy_passed_object": self.cancel_button_clicked,
})
self.fileSelector = wFs.get_widget("dbopen")
self.dbname = wFs.get_widget("dbname")
self.getoldrev = wFs.get_widget("getoldrev")
self.dbname.set_default_path(GrampsCfg.db_dir)
self.getoldrev.set_sensitive(GrampsCfg.usevc)
def cancel_button_clicked(self,obj):
Utils.destroy_passed_object(obj)
self.show()
def ok_button_clicked(self,obj):
filename = self.dbname.get_full_path(0)
if not filename:
return
Utils.destroy_passed_object(obj)
self.db.clear_database()
if self.getoldrev.get_active():
vc = VersionControl.RcsVersionControl(filename)
VersionControl.RevisionSelect(self.db.database,filename,vc,
self.db.load_revision,self.show)
else:
self.db.read_file(filename)
def open_delete_event(self,obj,event):
gtk.mainquit()
def open_cancel_clicked(self,obj):
gtk.mainquit()
#-------------------------------------------------------------------------
#
# Start it all
#
#-------------------------------------------------------------------------
if __name__ == '__main__':
Gramps(None)
gtk.mainloop()

View File

@ -105,6 +105,13 @@ class LdsOrd(SourceNote):
self.status = 0
self.place = None
def getPlaceName(self):
"""returns the title of the Place associated with the Ordinance"""
if self.place:
return self.place.get_title()
else:
return ""
def setPlace(self,place):
"""sets the Place instance of the Event"""
self.place = place

View File

@ -673,7 +673,6 @@ class ReportDialog:
table.attach(self.extra_textbox_label,0,1,row,row+1,FILL,FILL,pad,pad)
table.attach(self.extra_textbox,1,2,row,row+1,xpadding=pad,ypadding=pad)
row = row + 1
# self.topDialog.get_widget("extra_scrolledwindow").show()
# Setup requested widgets
for (text,widget) in self.widgets:

View File

@ -76,6 +76,7 @@ class HtmlDoc(TextDoc):
self.load_template()
self.build_header()
self.build_style_declaration()
self.image_dir = "images"
else:
self.f = None
@ -88,6 +89,10 @@ class HtmlDoc(TextDoc):
self.style_declaration = source.style_declaration
self.table_styles = source.table_styles;
self.cell_styles = source.cell_styles;
self.image_dir = source.image_dir
def set_image_dir(self,dirname):
self.image_dir = dirname
def load_template(self):
start = re.compile(r"<!--\s*START\s*-->")
@ -232,7 +237,11 @@ class HtmlDoc(TextDoc):
size = int(max(x,y) * float(150.0/2.54))
refname = "is%s" % os.path.basename(name)
imdir = self.base + os.sep + "images"
if self.image_dir:
imdir = "%s/%s" % (self.base,self.image_dir)
else:
imdir = self.base
if not os.path.isdir(imdir):
try:
@ -242,7 +251,7 @@ class HtmlDoc(TextDoc):
try:
img = ImgManip.ImgManip(name)
img.jpg_thumbnail(imdir + os.sep + refname,size,size)
img.jpg_thumbnail("%s/%s" % (imdir,refname),size,size)
except:
return
@ -253,8 +262,11 @@ class HtmlDoc(TextDoc):
else:
xtra = ''
self.f.write('<img src="images/%s" border="0""%s>\n' % \
(refname,xtra))
if self.image_dir:
self.f.write('<img src="%s/%s" border="0""%s>\n' % \
(self.image_dir,refname,xtra))
else:
self.f.write('<img src="%s" border="0""%s>\n' % (refname,xtra))
def start_table(self,name,style):
self.tbl = self.table_styles[style]

View File

@ -70,6 +70,7 @@ import EditPerson
import Marriage
import Find
import VersionControl
import WriteXML
#-------------------------------------------------------------------------
#
@ -95,10 +96,10 @@ class Gramps:
self.c_gender = 3
self.c_id = 2
self.c_name = 1
self.c_sort_column = self.c_birth_order
self.c_sort_direct = GTK.SORT_ASCENDING
self.sort_column = 0
self.sort_direct = GTK.SORT_ASCENDING
self.c_sort_col = self.c_birth_order
self.c_sort_dir = GTK.SORT_ASCENDING
self.sort_col = 0
self.sort_dir = GTK.SORT_ASCENDING
self.id2col = {}
self.alt2col = {}
@ -110,7 +111,7 @@ class Gramps:
self.database = GrampsDB()
(self.sort_column,self.sort_direct) = GrampsCfg.get_sort_cols("person",self.sort_column,self.sort_direct)
(self.sort_col,self.sort_dir) = GrampsCfg.get_sort_cols("person",self.sort_col,self.sort_dir)
GrampsCfg.loadConfig(self.full_update)
self.init_interface()
@ -119,8 +120,8 @@ class Gramps:
self.col_arr = [ self.nameArrow, self.idArrow, self.genderArrow,
self.dateArrow, self.deathArrow]
self.change_sort(self.sort_column,self.sort_direct==GTK.SORT_DESCENDING)
self.set_sort_arrow(self.sort_column,self.sort_direct)
self.change_sort(self.sort_col,self.sort_dir==GTK.SORT_DESCENDING)
self.set_sort_arrow(self.sort_col,self.sort_dir)
self.database.set_iprefix(GrampsCfg.iprefix)
self.database.set_oprefix(GrampsCfg.oprefix)
@ -133,7 +134,8 @@ class Gramps:
elif GrampsCfg.lastfile != None and GrampsCfg.lastfile != "" and GrampsCfg.autoload:
self.auto_save_load(GrampsCfg.lastfile)
else:
DbPrompter(self,0)
import DbPrompter
DbPrompter.DbPrompter(self,0)
if GrampsCfg.autosave_int != 0:
Utils.enable_autosave(self.autosave_database,GrampsCfg.autosave_int)
@ -141,6 +143,9 @@ class Gramps:
self.database.setResearcher(GrampsCfg.get_researcher())
def init_interface(self):
"""Initializes the GLADE interface, and gets references to the
widgets that it will need.
"""
self.gtop = libglade.GladeXML(const.gladeFile, "gramps")
self.statusbar = self.gtop.get_widget("statusbar")
@ -507,10 +512,11 @@ class Gramps:
gnome.ui.GnomeQuestionDialog(msg,self.new_database_response)
def new_database_response(self,val):
import DbPrompter
if val == 1:
return
self.clear_database()
DbPrompter(self.database,1)
DbPrompter.DbPrompter(self.database,1)
def clear_database(self):
"""Clear out the database if permission was granted"""
@ -641,6 +647,7 @@ class Gramps:
self.displayError(_("%s is not a directory") % filename)
return
self.statusbar.set_status(_("Loading %s ...") % filename)
if self.load_database(filename) == 1:
@ -662,7 +669,6 @@ class Gramps:
self.save_file(filename,_("No Comment Provided"))
def save_file(self,filename,comment):
import WriteXML
path = filename
filename = os.path.normpath(filename)
@ -680,14 +686,10 @@ class Gramps:
else:
try:
os.mkdir(filename)
except IOError, msg:
except (OSError,IOError), msg:
gnome.ui.GnomeErrorDialog(_("Could not create %s") % filename +\
"\n" + str(msg))
return
except OSError, msg:
gnome.ui.GnomeErrorDialog(_("Could not create %s") % filename + \
"\n" + str(msg))
return
except:
gnome.ui.GnomeErrorDialog(_("Could not create %s") % filename)
return
@ -726,7 +728,6 @@ class Gramps:
pass
def autosave_database(self):
import WriteXML
path = self.database.getSavePath()
filename = os.path.normpath(path)
@ -738,8 +739,8 @@ class Gramps:
try:
WriteXML.quick_write(self.database,filename,self.quick_progress)
self.statusbar.set_status(_("autosave complete"));
except (IOError,OSError):
self.statusbar.set_status(_("autosave failed"));
except (IOError,OSError),msg:
self.statusbar.set_status(_("autosave failed") + (" - %s" % msg));
except:
import traceback
traceback.print_exc()
@ -855,9 +856,7 @@ class Gramps:
def on_person_list_click_column(self,obj,column):
self.change_sort(column)
def set_sort_arrow(self,column,direct):
arrow = self.col_arr[column]
for a in self.col_arr:
if arrow != a:
@ -869,7 +868,6 @@ class Gramps:
arrow.set(GTK.ARROW_UP,2)
def change_sort(self,column,change=1):
arrow = self.col_arr[column]
for a in self.col_arr:
if arrow != a:
@ -877,28 +875,28 @@ class Gramps:
arrow.show()
self.person_list.set_sort_column(self.col_map[column])
self.person_list.set_sort_type(self.sort_direct)
self.person_list.set_sort_type(self.sort_dir)
self.sort_person_list()
if change:
if self.sort_column == column:
if self.sort_direct == GTK.SORT_DESCENDING:
self.sort_direct = GTK.SORT_ASCENDING
if self.sort_col == column:
if self.sort_dir == GTK.SORT_DESCENDING:
self.sort_dir = GTK.SORT_ASCENDING
arrow.set(GTK.ARROW_DOWN,2)
else:
self.sort_direct = GTK.SORT_DESCENDING
self.sort_dir = GTK.SORT_DESCENDING
arrow.set(GTK.ARROW_UP,2)
else:
self.sort_direct = GTK.SORT_ASCENDING
self.sort_dir = GTK.SORT_ASCENDING
arrow.set(GTK.ARROW_DOWN,2)
self.sort_column = column
self.sort_col = column
if self.id2col.has_key(self.active_person):
data = self.id2col[self.active_person]
row = self.person_list.find_row_from_data(data)
self.person_list.moveto(row)
GrampsCfg.save_sort_cols("person",self.sort_column,self.sort_direct)
GrampsCfg.save_sort_cols("person",self.sort_col,self.sort_dir)
def sort_person_list(self):
self.person_list.freeze()
@ -1004,19 +1002,19 @@ class Gramps:
self.cGenderArrow.hide()
arrow.show()
if self.c_sort_column == column:
if self.c_sort_direct == GTK.SORT_DESCENDING:
self.c_sort_direct = GTK.SORT_ASCENDING
if self.c_sort_col == column:
if self.c_sort_dir == GTK.SORT_DESCENDING:
self.c_sort_dir = GTK.SORT_ASCENDING
arrow.set(GTK.ARROW_DOWN,2)
else:
self.c_sort_direct = GTK.SORT_DESCENDING
self.c_sort_dir = GTK.SORT_DESCENDING
arrow.set(GTK.ARROW_UP,2)
else:
self.c_sort_direct = GTK.SORT_ASCENDING
self.c_sort_column = column
clist.set_sort_type(self.c_sort_direct)
clist.set_sort_column(self.c_sort_column)
clist.set_reorderable(self.c_sort_column == self.c_birth_order)
self.c_sort_dir = GTK.SORT_ASCENDING
self.c_sort_col = column
clist.set_sort_type(self.c_sort_dir)
clist.set_sort_column(self.c_sort_col)
clist.set_reorderable(self.c_sort_col == self.c_birth_order)
def sort_child_list(self,clist):
clist.freeze()
@ -1069,7 +1067,7 @@ class Gramps:
# This function deals with ascending order lists. Convert if
# necessary.
if (self.c_sort_direct == GTK.SORT_DESCENDING):
if (self.c_sort_dir == GTK.SORT_DESCENDING):
clist_order.reverse()
max_index = len(clist_order) - 1
fm = max_index - fm
@ -1098,7 +1096,7 @@ class Gramps:
# Convert the original list back to whatever ordering is being
# used by the clist itself.
if (self.c_sort_direct == GTK.SORT_DESCENDING):
if (self.c_sort_dir == GTK.SORT_DESCENDING):
clist_order.reverse()
# Update the clist indices so any change of sorting works
@ -1494,9 +1492,9 @@ class Gramps:
self.active_child = None
i = 0
self.child_list.set_sort_type(self.c_sort_direct)
self.child_list.set_sort_column(self.c_sort_column)
self.child_list.set_reorderable(self.c_sort_column == self.c_birth_order)
self.child_list.set_sort_type(self.c_sort_dir)
self.child_list.set_sort_column(self.c_sort_col)
self.child_list.set_reorderable(self.c_sort_col == self.c_birth_order)
if family != None:
if self.active_person.getGender() == Person.male:
@ -1783,92 +1781,6 @@ class Gramps:
elif event.keyval == GDK.Insert:
self.load_new_person(obj)
#-------------------------------------------------------------------------
#
# Make sure a database is opened
#
#-------------------------------------------------------------------------
class DbPrompter:
def __init__(self,db,want_new):
self.db = db
self.want_new = want_new
self.show()
def show(self):
opendb = libglade.GladeXML(const.gladeFile, "opendb")
opendb.signal_autoconnect({
"on_open_ok_clicked" : self.open_ok_clicked,
"on_open_cancel_clicked" : self.open_cancel_clicked,
"on_opendb_delete_event": self.open_delete_event,
})
self.new = opendb.get_widget("new")
if self.want_new:
self.new.set_active(1)
def open_ok_clicked(self,obj):
if self.new.get_active():
self.save_as_activate()
else:
self.open_activate()
Utils.destroy_passed_object(obj)
def save_as_activate(self):
wFs = libglade.GladeXML (const.gladeFile, "fileselection")
wFs.signal_autoconnect({
"on_ok_button1_clicked": self.save_ok_button_clicked,
"destroy_passed_object": self.cancel_button_clicked,
})
def save_ok_button_clicked(self,obj):
filename = obj.get_filename()
if filename:
Utils.destroy_passed_object(obj)
if GrampsCfg.usevc and GrampsCfg.vc_comment:
self.db.display_comment_box(filename)
else:
self.db.save_file(filename,_("No Comment Provided"))
def open_activate(self):
wFs = libglade.GladeXML(const.revisionFile, "dbopen")
wFs.signal_autoconnect({
"on_ok_button1_clicked": self.ok_button_clicked,
"destroy_passed_object": self.cancel_button_clicked,
})
self.fileSelector = wFs.get_widget("dbopen")
self.dbname = wFs.get_widget("dbname")
self.getoldrev = wFs.get_widget("getoldrev")
self.dbname.set_default_path(GrampsCfg.db_dir)
self.getoldrev.set_sensitive(GrampsCfg.usevc)
def cancel_button_clicked(self,obj):
Utils.destroy_passed_object(obj)
self.show()
def ok_button_clicked(self,obj):
filename = self.dbname.get_full_path(0)
if not filename:
return
Utils.destroy_passed_object(obj)
self.db.clear_database()
if self.getoldrev.get_active():
vc = VersionControl.RcsVersionControl(filename)
VersionControl.RevisionSelect(self.db.database,filename,vc,
self.db.load_revision,self.show)
else:
self.db.read_file(filename)
def open_delete_event(self,obj,event):
gtk.mainquit()
def open_cancel_clicked(self,obj):
gtk.mainquit()
#-------------------------------------------------------------------------
#
# Start it all

View File

@ -71,7 +71,7 @@ class HtmlLinkDoc(HtmlDoc):
#------------------------------------------------------------------------
class IndividualPage:
def __init__(self,person,photos,restrict,private,uc,link,map,dir_name,doc):
def __init__(self,person,photos,restrict,private,uc,link,map,dir_name,imgdir,doc):
self.person = person
self.doc = doc
self.list = map
@ -83,6 +83,7 @@ class IndividualPage:
self.link = link
self.slist = []
self.scnt = 1
self.image_dir = imgdir
name = person.getPrimaryName().getRegularName()
self.doc.set_title(_("Summary of %s") % name)
@ -199,7 +200,7 @@ class IndividualPage:
"""Generate the HTML page for the specific person"""
filebase = "%s.html" % self.person.getId()
self.doc.open("%s%s%s" % (self.dir,os.sep,filebase))
self.doc.open("%s/%s" % (self.dir,filebase))
photo_list = self.person.getPhotoList()
name_obj = self.person.getPrimaryName()
@ -311,11 +312,19 @@ class IndividualPage:
try:
src = obj.getReference().getPath()
base = os.path.basename(src)
shutil.copy(src,"%s/images/%s" % (self.dir,base))
if self.image_dir:
shutil.copy(src,"%s/%s/%s" % (self.dir,self.image_dir,base))
else:
shutil.copy(src,"%s/%s" % (self.dir,base))
self.doc.start_row()
self.doc.start_cell("ImageCell")
self.doc.start_paragraph("Data")
self.doc.start_link("images/%s" % base)
if self.image_dir:
self.doc.start_link("%s/%s" % (self.image_dir,base))
else:
self.doc.start_link("%s" % base)
self.doc.add_photo(src,"row",1.5,1.5)
self.doc.end_link()
@ -646,7 +655,8 @@ filter_map = {
#------------------------------------------------------------------------
class WebReport(Report):
def __init__(self,db,person,target_path,max_gen,photos,filter,restrict,
private, srccomments, include_link, style, template_name):
private, srccomments, include_link, style, image_dir,
template_name):
self.db = db
self.person = person
self.target_path = target_path
@ -658,6 +668,7 @@ class WebReport(Report):
self.srccomments = srccomments
self.include_link = include_link
self.selected_style = style
self.image_dir = image_dir
self.template_name = template_name
def get_progressbar_data(self):
@ -673,7 +684,7 @@ class WebReport(Report):
doc = HtmlLinkDoc(self.selected_style,None,template,None)
doc.set_title(_("Family Tree Index"))
doc.open(html_dir + os.sep + "index.html")
doc.open("%s/index.html" % html_dir)
doc.start_paragraph("Title")
doc.write_text(_("Family Tree Index"))
doc.end_paragraph()
@ -709,7 +720,10 @@ class WebReport(Report):
dir_name)
return
image_dir_name = os.path.join(dir_name, "images")
if self.image_dir:
image_dir_name = os.path.join(dir_name, self.image_dir)
else:
image_dir_name = dir_name
if not os.path.isdir(image_dir_name) and self.photos != 0:
try:
os.mkdir(image_dir_name)
@ -728,6 +742,8 @@ class WebReport(Report):
self.progress_bar_setup(float(len(ind_list)))
doc = HtmlLinkDoc(self.selected_style,None,self.template_name,None)
doc.set_image_dir(self.image_dir)
self.add_styles(doc)
doc.build_style_declaration()
@ -738,7 +754,8 @@ class WebReport(Report):
tdoc = HtmlLinkDoc(self.selected_style,None,None,None,doc)
idoc = IndividualPage(person, self.photos, self.restrict,
self.private, self.srccomments,
self.include_link, my_map, dir_name, tdoc)
self.include_link, my_map, dir_name,
self.image_dir, tdoc)
idoc.create_page()
idoc.close()
self.progress_bar_step()
@ -784,6 +801,7 @@ class WebReportDialog(ReportDialog):
no_img_msg = _("Do not use images")
no_limg_msg = _("Do not use images for living people")
no_com_msg = _("Do not include comments and text in source information")
imgdir_msg = _("Image subdirectory")
self.use_link = GtkCheckButton(lnk_msg)
self.use_link.set_active(1)
@ -793,8 +811,12 @@ class WebReportDialog(ReportDialog):
self.no_images = GtkCheckButton(no_img_msg)
self.no_living_images = GtkCheckButton(no_limg_msg)
self.no_comments = GtkCheckButton(no_com_msg)
self.imgdir = GtkEntry()
self.imgdir.set_text("images")
self.add_option(imgdir_msg,self.imgdir)
self.add_option('',self.use_link)
title = _("Privacy Options")
self.add_frame_option(title,None,self.no_private)
self.add_frame_option(title,None,self.restrict_living)
@ -987,6 +1009,8 @@ class WebReportDialog(ReportDialog):
user selected choices for later use."""
self.restrict = self.restrict_living.get_active()
self.private = self.no_private.get_active()
self.img_dir_text = self.imgdir.get_text()
self.srccomments = self.no_comments.get_active()
if self.no_images.get_active() == 1:
self.photos = 0
@ -1021,7 +1045,7 @@ class WebReportDialog(ReportDialog):
self.max_gen, self.photos, self.filter,
self.restrict, self.private, self.srccomments,
self.include_link, self.selected_style,
self.template_name)
self.img_dir_text,self.template_name)
MyReport.write_report()
#------------------------------------------------------------------------