WriteCD merges
svn: r1531
This commit is contained in:
parent
77f359bfe3
commit
8a15c6ee03
@ -46,8 +46,9 @@ import gnome.vfs
|
|||||||
import WriteXML
|
import WriteXML
|
||||||
import Utils
|
import Utils
|
||||||
import const
|
import const
|
||||||
from QuestionDialog import MissingMediaDialog
|
import QuestionDialog
|
||||||
import RelImage
|
import RelImage
|
||||||
|
import ImgManip
|
||||||
|
|
||||||
from intl import gettext as _
|
from intl import gettext as _
|
||||||
|
|
||||||
@ -91,35 +92,50 @@ class PackageWriter:
|
|||||||
self.top.signal_autoconnect(dic)
|
self.top.signal_autoconnect(dic)
|
||||||
self.top.get_widget("packageExport").show()
|
self.top.get_widget("packageExport").show()
|
||||||
|
|
||||||
def vfs_copy(self,dir_name,filename,newfilename=""):
|
def copy_file(self,src,dest):
|
||||||
# Everything has to be ascii for the CD
|
original = open(src,"r")
|
||||||
dir_name = dir_name.encode('ascii')
|
destobj = gnome.vfs.URI(dest)
|
||||||
filename = filename.encode('ascii')
|
target = gnome.vfs.create(destobj,gnome.vfs.OPEN_WRITE)
|
||||||
newfilename = newfilename.encode('ascii')
|
done = 0
|
||||||
|
while 1:
|
||||||
orig_file = open(filename,"r")
|
buf = original.read(2048)
|
||||||
if not newfilename:
|
if buf == '':
|
||||||
newfilename = filename
|
break
|
||||||
new_vfsname = 'burn:///%s/%s' % (dir_name,newfilename)
|
else:
|
||||||
new_file = gnome.vfs.create(new_vfsname,gnome.vfs.OPEN_WRITE)
|
target.write(buf)
|
||||||
buf = orig_file.read()
|
target.close()
|
||||||
new_file.write(buf)
|
original.close()
|
||||||
orig_file.close()
|
|
||||||
new_file.close()
|
|
||||||
|
|
||||||
|
def make_thumbnail(self,dbname,root,path):
|
||||||
|
img = ImgManip.ImgManip(path)
|
||||||
|
data = img.jpg_scale_data(const.thumbScale,const.thumbScale)
|
||||||
|
|
||||||
|
uri = gnome.vfs.URI('burn:///%s/.thumb/%s.jpg' % (dbname,root))
|
||||||
|
th = gnome.vfs.create(uri,gnome.vfs.OPEN_WRITE)
|
||||||
|
th.write(data)
|
||||||
|
th.close()
|
||||||
|
|
||||||
def on_ok_clicked(self,obj):
|
def on_ok_clicked(self,obj):
|
||||||
Utils.destroy_passed_object(obj)
|
Utils.destroy_passed_object(obj)
|
||||||
|
|
||||||
base = os.path.basename(self.db.getSavePath())
|
base = os.path.basename(self.db.getSavePath())
|
||||||
thumb_base = os.path.join(base,'.thumb')
|
|
||||||
|
|
||||||
gnome.vfs.make_directory('burn:///%s' % base,gnome.vfs.OPEN_WRITE)
|
try:
|
||||||
gnome.vfs.make_directory('burn:///%s' % thumb_base,gnome.vfs.OPEN_WRITE)
|
uri = gnome.vfs.URI('burn:///%s' % base)
|
||||||
|
gnome.vfs.make_directory(uri,gnome.vfs.OPEN_WRITE)
|
||||||
|
except gnome.vfs.error, msg:
|
||||||
|
print msg
|
||||||
|
|
||||||
|
try:
|
||||||
|
uri = gnome.vfs.URI('burn:///%s/.thumb' % base)
|
||||||
|
gnome.vfs.make_directory(uri,gnome.vfs.OPEN_WRITE)
|
||||||
|
except gnome.vfs.error, msg:
|
||||||
|
print msg
|
||||||
|
|
||||||
#--------------------------------------------------------
|
#--------------------------------------------------------
|
||||||
def remove_clicked():
|
def remove_clicked():
|
||||||
# File is lost => remove all references and the object itself
|
# File is lost => remove all references and the object itself
|
||||||
mobj = ObjectMap[ObjectId]
|
mobj = self.db.getObject(self.object_id)
|
||||||
for p in self.db.getFamilyMap().values():
|
for p in self.db.getFamilyMap().values():
|
||||||
nl = p.getPhotoList()
|
nl = p.getPhotoList()
|
||||||
for o in nl:
|
for o in nl:
|
||||||
@ -147,7 +163,7 @@ class PackageWriter:
|
|||||||
if o.getReference() == mobj:
|
if o.getReference() == mobj:
|
||||||
nl.remove(o)
|
nl.remove(o)
|
||||||
p.setPhotoList(nl)
|
p.setPhotoList(nl)
|
||||||
self.db.removeObject(ObjectId)
|
self.db.removeObject(self.object_id)
|
||||||
Utils.modified()
|
Utils.modified()
|
||||||
|
|
||||||
def leave_clicked():
|
def leave_clicked():
|
||||||
@ -163,15 +179,10 @@ class PackageWriter:
|
|||||||
newfile = fs_top.get_filename()
|
newfile = fs_top.get_filename()
|
||||||
fs_top.destroy()
|
fs_top.destroy()
|
||||||
if os.path.isfile(newfile):
|
if os.path.isfile(newfile):
|
||||||
nbase = os.path.basename(newfile)
|
self.copy_file(newfile,'burn:///%s/%s' % (base,obase))
|
||||||
self.vfs_copy(base,newfile,obase)
|
|
||||||
ntype = Utils.get_mime_type(newfile)
|
ntype = Utils.get_mime_type(newfile)
|
||||||
if ntype[0:5] == "image":
|
if ntype[0:5] == "image":
|
||||||
(oname,oext) = os.path.splitext(obase)
|
self.make_thumbnail(base,obase,newfile)
|
||||||
thumb_name = "%s.jpg" % oname
|
|
||||||
thumb_dest = "%s/.thumb/%s" % (opath,thumb_name)
|
|
||||||
RelImage.check_thumb(newfile,thumb_dest,const.thumbScale)
|
|
||||||
self.vfs_copy(thumb_base,thumb_dest,thumb_name)
|
|
||||||
|
|
||||||
fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file"))
|
fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file"))
|
||||||
fs_top.hide_fileop_buttons()
|
fs_top.hide_fileop_buttons()
|
||||||
@ -184,23 +195,18 @@ class PackageWriter:
|
|||||||
|
|
||||||
# Write media files first, since the database may be modified
|
# Write media files first, since the database may be modified
|
||||||
# during the process (i.e. when removing object)
|
# during the process (i.e. when removing object)
|
||||||
ObjectMap = self.db.getObjectMap()
|
|
||||||
for ObjectId in ObjectMap.keys():
|
for obj in self.db.getObjectMap().values():
|
||||||
oldfile = ObjectMap[ObjectId].getPath()
|
oldfile = obj.getPath()
|
||||||
opath = os.path.dirname(oldfile)
|
root = os.path.basename(oldfile)
|
||||||
obase = os.path.basename(oldfile)
|
|
||||||
if os.path.isfile(oldfile):
|
if os.path.isfile(oldfile):
|
||||||
self.vfs_copy(base,oldfile,obase)
|
self.copy_file(oldfile,'burn:///%s/%s' % (base,root))
|
||||||
otype = Utils.get_mime_type(oldfile)
|
if obj.getMimeType()[0:5] == "image":
|
||||||
if otype[0:5] == "image":
|
self.make_thumbnail(base,root,obj.getPath())
|
||||||
(oname,oext) = os.path.splitext(obase)
|
|
||||||
thumb_name = "%s.jpg" % oname
|
|
||||||
thumb_dest = "%s/.thumb/%s" % (opath,thumb_name)
|
|
||||||
RelImage.check_thumb(oldfile,thumb_dest,const.thumbScale)
|
|
||||||
self.vfs_copy(thumb_base,thumb_dest,thumb_name)
|
|
||||||
else:
|
else:
|
||||||
# File is lost => ask what to do
|
# File is lost => ask what to do
|
||||||
MissingMediaDialog(_("Media object could not be found"),
|
self.object_id = obj.getId()
|
||||||
|
QuestionDialog.MissingMediaDialog(_("Media object could not be found"),
|
||||||
_("%(file_name)s is referenced in the database, but no longer exists. "
|
_("%(file_name)s is referenced in the database, but no longer exists. "
|
||||||
"The file may have been deleted or moved to a different location. "
|
"The file may have been deleted or moved to a different location. "
|
||||||
"You may choose to either remove the reference from the database, "
|
"You may choose to either remove the reference from the database, "
|
||||||
@ -214,7 +220,6 @@ class PackageWriter:
|
|||||||
gfile = WriteXML.XmlWriter(self.db,None,1)
|
gfile = WriteXML.XmlWriter(self.db,None,1)
|
||||||
gfile.write_handle(g)
|
gfile.write_handle(g)
|
||||||
g.close()
|
g.close()
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user