Some basic media object editing
svn: r456
This commit is contained in:
parent
5550614368
commit
88aab453f7
@ -22,7 +22,7 @@
|
||||
<last_modification_time>Fri, 03 Aug 2001 01:42:42 GMT</last_modification_time>
|
||||
</signal>
|
||||
<title>Gramps - Edit Person</title>
|
||||
<type>GTK_WINDOW_TOPLEVEL</type>
|
||||
<type>GTK_WINDOW_DIALOG</type>
|
||||
<position>GTK_WIN_POS_NONE</position>
|
||||
<modal>False</modal>
|
||||
<allow_shrink>False</allow_shrink>
|
||||
@ -3567,10 +3567,10 @@
|
||||
<class>GtkHButtonBox</class>
|
||||
<name>hbuttonbox13</name>
|
||||
<layout_style>GTK_BUTTONBOX_SPREAD</layout_style>
|
||||
<spacing>30</spacing>
|
||||
<spacing>15</spacing>
|
||||
<child_min_width>85</child_min_width>
|
||||
<child_min_height>27</child_min_height>
|
||||
<child_ipad_x>7</child_ipad_x>
|
||||
<child_ipad_x>3</child_ipad_x>
|
||||
<child_ipad_y>0</child_ipad_y>
|
||||
<child>
|
||||
<padding>0</padding>
|
||||
@ -3589,7 +3589,7 @@
|
||||
<object>editPerson</object>
|
||||
<last_modification_time>Sat, 09 Dec 2000 22:09:54 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>Add Object</label>
|
||||
<label>Add Media Object</label>
|
||||
<relief>GTK_RELIEF_NORMAL</relief>
|
||||
</widget>
|
||||
|
||||
@ -3604,7 +3604,7 @@
|
||||
<object>editPerson</object>
|
||||
<last_modification_time>Sun, 10 Dec 2000 03:48:08 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>Delete Object</label>
|
||||
<label>Delete Media Object</label>
|
||||
<relief>GTK_RELIEF_NORMAL</relief>
|
||||
</widget>
|
||||
|
||||
@ -3619,7 +3619,22 @@
|
||||
<object>editPerson</object>
|
||||
<last_modification_time>Sun, 10 Dec 2000 15:10:41 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>Make Primary</label>
|
||||
<label>Make Primary Object</label>
|
||||
<relief>GTK_RELIEF_NORMAL</relief>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkButton</class>
|
||||
<name>button127</name>
|
||||
<can_default>True</can_default>
|
||||
<can_focus>True</can_focus>
|
||||
<signal>
|
||||
<name>clicked</name>
|
||||
<handler>on_edit_properties_clicked</handler>
|
||||
<object>editPerson</object>
|
||||
<last_modification_time>Thu, 11 Oct 2001 22:22:08 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>Edit Properties</label>
|
||||
<relief>GTK_RELIEF_NORMAL</relief>
|
||||
</widget>
|
||||
</widget>
|
||||
|
@ -197,6 +197,7 @@ class EditPerson:
|
||||
"on_delete_event" : on_delete_event,
|
||||
"on_delete_url_clicked" : on_delete_url_clicked,
|
||||
"on_deletephoto_clicked" : self.gallery.on_delete_photo_clicked,
|
||||
"on_edit_properties_clicked": self.gallery.popup_change_description,
|
||||
"on_editperson_switch_page" : on_switch_page,
|
||||
"on_event_add_clicked" : on_event_add_clicked,
|
||||
"on_event_delete_clicked" : on_event_delete_clicked,
|
||||
@ -263,7 +264,8 @@ class EditPerson:
|
||||
if len(photo_list) != 0:
|
||||
ph = photo_list[0]
|
||||
object = ph.getReference()
|
||||
self.load_photo(object.getPath())
|
||||
if object.getMimeType()[0:5] == "image":
|
||||
self.load_photo(object.getPath())
|
||||
|
||||
# set notes data
|
||||
self.notes_field.set_point(0)
|
||||
@ -407,11 +409,12 @@ class PersonGallery(ImageSelect.Gallery):
|
||||
for i in range(0,selected_icon):
|
||||
photolist[selected_icon-i] = photolist[selected_icon-i-1]
|
||||
photolist[0] = savePhoto
|
||||
|
||||
self.epo.load_photo(savePhoto.getReference().getPath())
|
||||
|
||||
ref = savePhoto.getReference()
|
||||
if ref.getMimeType() == "image":
|
||||
self.epo.load_photo(savePhoto.getReference().getPath())
|
||||
self.load_images()
|
||||
utils.modified()
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -505,7 +505,7 @@ class GrampsParser(handler.ContentHandler):
|
||||
a.setType(key)
|
||||
a.setValue(u2l(attrs[key]))
|
||||
self.photo.addAttribute(a)
|
||||
self.photo.setMimeType(gnome.mime.type_or_default(self.photo.getPath(),"unknown"))
|
||||
self.photo.setMimeType(utils.get_mime_type(self.photo.getPath()))
|
||||
self.db.addObject(self.photo)
|
||||
if self.family:
|
||||
self.family.addPhoto(self.pref)
|
||||
|
@ -34,7 +34,6 @@ import string
|
||||
from gtk import *
|
||||
from gnome.ui import *
|
||||
import GDK
|
||||
import gnome.mime
|
||||
import libglade
|
||||
import GdkImlib
|
||||
|
||||
@ -103,8 +102,12 @@ class ImageSelect:
|
||||
def on_name_changed(self, obj):
|
||||
filename = self.fname.get_text()
|
||||
if os.path.isfile(filename):
|
||||
image = RelImage.scale_image(filename,const.thumbScale)
|
||||
self.image.load_imlib(image)
|
||||
type = utils.get_mime_type(filename)
|
||||
if type[0:5] == "image":
|
||||
image = RelImage.scale_image(filename,const.thumbScale)
|
||||
self.image.load_imlib(image)
|
||||
else:
|
||||
self.image.load_file(utils.find_icon(type))
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -119,24 +122,31 @@ class ImageSelect:
|
||||
GnomeErrorDialog(_("That is not a valid file name."));
|
||||
return
|
||||
|
||||
if self.external.get_active() == 1:
|
||||
if os.path.isfile(filename):
|
||||
name = filename
|
||||
thumb = "%s%s.thumb%s%s" % (self.path,os.sep,os.sep,os.path.basename(filename))
|
||||
RelImage.mk_thumb(filename,thumb,const.thumbScale)
|
||||
else:
|
||||
return
|
||||
else:
|
||||
name = RelImage.import_photo(filename,self.path,self.prefix)
|
||||
if name == None:
|
||||
return
|
||||
|
||||
photo = Photo()
|
||||
photo.setPath(name)
|
||||
photo.setDescription(description)
|
||||
photo.setMimeType(gnome.mime.type_or_default_of_file(name,"unknown"))
|
||||
type = utils.get_mime_type(filename)
|
||||
mobj = Photo()
|
||||
if description == "":
|
||||
description = os.path.basename(name)
|
||||
mobj.setDescription(description)
|
||||
mobj.setMimeType(type)
|
||||
self.savephoto(mobj)
|
||||
|
||||
self.savephoto(photo)
|
||||
if type[0:5] == "image":
|
||||
if self.external.get_active() == 1:
|
||||
if os.path.isfile(filename):
|
||||
name = filename
|
||||
thumb = "%s/.thumb/%s.jpg" % (self.path,mobj.getId())
|
||||
RelImage.mk_thumb(filename,thumb,const.thumbScale)
|
||||
else:
|
||||
return
|
||||
else:
|
||||
name = RelImage.import_media_object(filename,self.path,mobj.getId())
|
||||
else:
|
||||
if self.external.get_active() == 1:
|
||||
name = filename
|
||||
else:
|
||||
name = RelImage.import_media_object(filename,self.path,mobj.getId())
|
||||
|
||||
mobj.setPath(name)
|
||||
|
||||
utils.modified()
|
||||
utils.destroy_passed_object(obj)
|
||||
@ -166,11 +176,11 @@ class Gallery(ImageSelect):
|
||||
('text/uri-list',0,2),
|
||||
('application/x-rootwin-drop',0,1)]
|
||||
|
||||
icon_list.drag_dest_set(DEST_DEFAULT_ALL, t, GDK.ACTION_COPY)
|
||||
icon_list.drag_dest_set(DEST_DEFAULT_ALL, t, GDK.ACTION_COPY | GDK.ACTION_MOVE)
|
||||
icon_list.connect("drag_data_received", self.on_photolist_drag_data_received)
|
||||
|
||||
icon_list.drag_source_set(GDK.BUTTON1_MASK|GDK.BUTTON3_MASK,t,\
|
||||
GDK.ACTION_COPY)
|
||||
GDK.ACTION_COPY | GDK.ACTION_MOVE)
|
||||
icon_list.connect("drag_data_get", self.on_photolist_drag_data_get)
|
||||
|
||||
|
||||
@ -210,11 +220,11 @@ class Gallery(ImageSelect):
|
||||
object = photo.getReference()
|
||||
path = object.getPath()
|
||||
src = os.path.basename(path)
|
||||
if object.getLocal():
|
||||
thumb = "%s%s.thumb%s%s" % (self.path,os.sep,os.sep,src)
|
||||
if object.getMimeType()[0:5] == "image":
|
||||
thumb = "%s/.thumb/%s.jpg" % (self.path,object.getId())
|
||||
RelImage.check_thumb(path,thumb,const.thumbScale)
|
||||
else:
|
||||
thumb = "%s%s.thumb%s%s.jpg" % (self.path,os.sep,os.sep,os.path.basename(src))
|
||||
RelImage.check_thumb(path,thumb,const.thumbScale)
|
||||
thumb = utils.find_icon(object.getMimeType())
|
||||
self.icon_list.append(thumb,object.getDescription())
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -244,22 +254,25 @@ class Gallery(ImageSelect):
|
||||
d = string.strip(string.replace(data.data,'\0',' '))
|
||||
if d[0:5] == "file:":
|
||||
name = d[5:]
|
||||
mime = gnome.mime.type_or_default_of_file(name,"unknown")
|
||||
if mime[0:5] == "image":
|
||||
photo = Photo()
|
||||
photo.setPath(name)
|
||||
photo.setMimeType(mime)
|
||||
self.savephoto(photo)
|
||||
else:
|
||||
print name,mime
|
||||
mime = utils.get_mime_type(name)
|
||||
photo = Photo()
|
||||
photo.setPath(name)
|
||||
photo.setMimeType(mime)
|
||||
description = os.path.basename(name)
|
||||
photo.setDescription(description)
|
||||
self.savephoto(photo)
|
||||
else:
|
||||
if self.db.getObjectMap().has_key(data.data):
|
||||
w.drag_finish(context, TRUE, FALSE, time)
|
||||
for p in self.dataobj.getPhotoList():
|
||||
if data.data == p.getReference().getId():
|
||||
w.drag_finish(context, TRUE, FALSE, time)
|
||||
return
|
||||
oref = ObjectRef()
|
||||
oref.setReference(self.db.findObjectNoMap(data.data))
|
||||
self.dataobj.addPhoto(oref)
|
||||
self.add_thumbnail(oref)
|
||||
utils.modified()
|
||||
w.drag_finish(context, TRUE, FALSE, time)
|
||||
else:
|
||||
w.drag_finish(context, FALSE, FALSE, time)
|
||||
|
||||
@ -292,6 +305,11 @@ class Gallery(ImageSelect):
|
||||
if icon != -1:
|
||||
self.icon_list.remove(icon)
|
||||
del self.dataobj.getPhotoList()[icon]
|
||||
if len(self.dataobj.getPhotoList()) == 0:
|
||||
self.selectedIcon = -1
|
||||
else:
|
||||
self.selectedIcon = 0
|
||||
self.icon_list.select_icon(0)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -310,9 +328,9 @@ class Gallery(ImageSelect):
|
||||
item = GtkTearoffMenuItem()
|
||||
item.show()
|
||||
menu.append(item)
|
||||
utils.add_menuitem(menu,_("View Object"),None,self.popup_view_photo)
|
||||
utils.add_menuitem(menu,_("Edit Object"),None,self.popup_edit_photo)
|
||||
utils.add_menuitem(menu,_("Edit Description"),None,
|
||||
utils.add_menuitem(menu,_("View in the default viewer"),None,self.popup_view_photo)
|
||||
utils.add_menuitem(menu,_("Edit in the default editor"),None,self.popup_edit_photo)
|
||||
utils.add_menuitem(menu,_("Edit Object Properties"),None,
|
||||
self.popup_change_description)
|
||||
object = photo.getReference()
|
||||
if object.getLocal() == 0:
|
||||
@ -362,17 +380,31 @@ class Gallery(ImageSelect):
|
||||
def popup_change_description(self, obj):
|
||||
photo = self.dataobj.getPhotoList()[self.selectedIcon]
|
||||
object = photo.getReference()
|
||||
path = object.getPath()
|
||||
src = os.path.basename(path)
|
||||
|
||||
self.change_dialog = libglade.GladeXML(const.imageselFile,"change_description")
|
||||
|
||||
window = self.change_dialog.get_widget("change_description")
|
||||
text = self.change_dialog.get_widget("text")
|
||||
text.set_text(object.getDescription())
|
||||
|
||||
image2 = RelImage.scale_image(object.getPath(),200.0)
|
||||
self.change_dialog.get_widget("photo").load_imlib(image2)
|
||||
self.change_dialog.get_widget("description").set_text(object.getDescription())
|
||||
pixmap = self.change_dialog.get_widget("pixmap")
|
||||
mtype = object.getMimeType()
|
||||
if mtype[0:5] == "image":
|
||||
thumb = "%s/.thumb/%s" % (self.path,object.getId())
|
||||
RelImage.check_thumb(path,thumb,const.thumbScale)
|
||||
pixmap.load_file(thumb)
|
||||
else:
|
||||
pixmap.load_file(utils.find_icon(mtype))
|
||||
|
||||
self.change_dialog.get_widget("gid").set_text(object.getId())
|
||||
self.change_dialog.get_widget("description").set_text(object.getDescription())
|
||||
if object.getLocal():
|
||||
self.change_dialog.get_widget("path").set_text("<local>")
|
||||
else:
|
||||
self.change_dialog.get_widget("path").set_text(path)
|
||||
self.change_dialog.get_widget("type").set_text(utils.get_mime_description(mtype))
|
||||
self.change_dialog.get_widget("notes").insert_defaults(photo.getNote())
|
||||
window.set_data("p",photo)
|
||||
window.set_data("t",text)
|
||||
window.editable_enters(text)
|
||||
window.set_data("t",self.change_dialog)
|
||||
self.change_dialog.signal_autoconnect({
|
||||
"on_cancel_clicked" : utils.destroy_passed_object,
|
||||
"on_ok_clicked" : self.new_desc_ok_clicked,
|
||||
@ -386,11 +418,11 @@ class Gallery(ImageSelect):
|
||||
#-------------------------------------------------------------------------
|
||||
def new_desc_apply_clicked(self, obj):
|
||||
photo = obj.get_data("p")
|
||||
object = photo.getReference()
|
||||
text = obj.get_data("t").get_text()
|
||||
if text != object.getDescription():
|
||||
object.setDescription(text)
|
||||
self.load_images()
|
||||
top = obj.get_data('t')
|
||||
text = top.get_widget("notes").get_chars(0,-1)
|
||||
note = photo.getNote()
|
||||
if text != note:
|
||||
photo.setNote(text)
|
||||
utils.modified()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
@ -26,6 +26,8 @@
|
||||
import os
|
||||
import const
|
||||
import intl
|
||||
import string
|
||||
import utils
|
||||
from gnome.ui import *
|
||||
|
||||
_ = intl.gettext
|
||||
@ -38,49 +40,47 @@ except:
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# import_photo
|
||||
# import_media_object
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def import_photo(filename,path,prefix):
|
||||
import gnome.mime
|
||||
def import_media_object(filename,path,base):
|
||||
import shutil
|
||||
|
||||
type = gnome.mime.type_of_file(filename)
|
||||
if type[0:6] != "image/":
|
||||
GnomeErrorDialog(_("Currently only image files are supported"))
|
||||
return None
|
||||
|
||||
for index in range(0,1000):
|
||||
name = "%s%s%s_%d.jpg" % (path,os.sep,prefix,index)
|
||||
base = "%s_%d.jpg" % (prefix,index)
|
||||
if os.path.exists(name) == 0:
|
||||
break
|
||||
type = utils.get_mime_type(filename)
|
||||
if type[0:5] == "image":
|
||||
name = "%s/%s.jpg" % (path,base)
|
||||
base = "%s.jpg" % (base)
|
||||
|
||||
thumb = "%s%s.thumb" % (path,os.sep)
|
||||
thumb = "%s/.thumb" % (path)
|
||||
|
||||
try:
|
||||
if not os.path.exists(thumb):
|
||||
os.mkdir(thumb)
|
||||
except IOError,msg:
|
||||
GnomeErrorDialog(_("Could not create %s") % thumb + "\n" + str(msg))
|
||||
except:
|
||||
GnomeErrorDialog(_("Could not create %s") % thumb)
|
||||
try:
|
||||
if not os.path.exists(thumb):
|
||||
os.mkdir(thumb)
|
||||
except IOError,msg:
|
||||
GnomeErrorDialog(_("Could not create %s") % thumb + "\n" + str(msg))
|
||||
except:
|
||||
GnomeErrorDialog(_("Could not create %s") % thumb)
|
||||
|
||||
try:
|
||||
path = "%s%s%s" % (thumb,os.sep,base)
|
||||
try:
|
||||
path = "%s/%s" % (thumb,base)
|
||||
|
||||
mk_thumb(filename,path,const.thumbScale)
|
||||
mk_thumb(filename,path,const.thumbScale)
|
||||
|
||||
if type == "image/jpeg":
|
||||
shutil.copy(filename,name)
|
||||
else:
|
||||
if no_pil:
|
||||
cmd = "%s '%s' '%s'" % (const.convert,filename,name)
|
||||
os.system(cmd)
|
||||
if type == "image/jpeg":
|
||||
shutil.copy(filename,name)
|
||||
else:
|
||||
PIL.Image.open(filename).save(name)
|
||||
except:
|
||||
return None
|
||||
if no_pil:
|
||||
cmd = "%s '%s' '%s'" % (const.convert,filename,name)
|
||||
os.system(cmd)
|
||||
else:
|
||||
PIL.Image.open(filename).save(name)
|
||||
except:
|
||||
return None
|
||||
else:
|
||||
bname = os.path.basename(filename)
|
||||
l = string.split(bname,'.')
|
||||
name = "%s/%s.%s" % (path,base,l[-1])
|
||||
shutil.copy(filename,name)
|
||||
|
||||
return name
|
||||
|
||||
|
@ -293,8 +293,6 @@ def write_photo_list(g,list,indent=3):
|
||||
g.write(">\n")
|
||||
write_attribute_list(g,proplist,indent+1)
|
||||
write_note(g,"note",photo.getNote(),indent+1)
|
||||
for s in photo.getSourceRefList():
|
||||
dump_source_ref(g,s,indent+1)
|
||||
g.write('%s</objref>\n' % sp)
|
||||
|
||||
def write_url_list(g, list):
|
||||
|
@ -2879,6 +2879,11 @@
|
||||
<handler>on_media_list_drag_data_get</handler>
|
||||
<last_modification_time>Tue, 09 Oct 2001 21:02:46 GMT</last_modification_time>
|
||||
</signal>
|
||||
<signal>
|
||||
<name>drag_data_received</name>
|
||||
<handler>on_media_list_drag_data_received</handler>
|
||||
<last_modification_time>Thu, 11 Oct 2001 22:42:26 GMT</last_modification_time>
|
||||
</signal>
|
||||
<columns>5</columns>
|
||||
<column_widths>33,331,104,168,80</column_widths>
|
||||
<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
|
||||
@ -2972,6 +2977,11 @@
|
||||
<name>button142</name>
|
||||
<can_default>True</can_default>
|
||||
<can_focus>True</can_focus>
|
||||
<signal>
|
||||
<name>clicked</name>
|
||||
<handler>on_add_media_clicked</handler>
|
||||
<last_modification_time>Thu, 11 Oct 2001 22:36:50 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>Add Media Object</label>
|
||||
<relief>GTK_RELIEF_NORMAL</relief>
|
||||
</widget>
|
||||
|
@ -42,7 +42,6 @@ _ = intl.gettext
|
||||
#-------------------------------------------------------------------------
|
||||
from gtk import *
|
||||
from gnome.ui import *
|
||||
|
||||
import GDK
|
||||
import GTK
|
||||
import libglade
|
||||
@ -1681,7 +1680,7 @@ def remove_from_person_list(person):
|
||||
del id2col[person]
|
||||
del alt2col[person]
|
||||
|
||||
if row <= person_list.rows:
|
||||
if row > person_list.rows:
|
||||
(active_person,alt) = person_list.get_row_data(row)
|
||||
person_list.thaw()
|
||||
|
||||
@ -2118,6 +2117,7 @@ def load_places():
|
||||
def on_media_list_select_row(obj,row,b,c):
|
||||
mobj = obj.get_row_data(row)
|
||||
type = mobj.getMimeType()
|
||||
type_name = utils.get_mime_description(type)
|
||||
path = mobj.getPath()
|
||||
if type[0:5] == "image":
|
||||
dir = os.path.dirname(path)
|
||||
@ -2126,9 +2126,10 @@ def on_media_list_select_row(obj,row,b,c):
|
||||
RelImage.check_thumb(path,thumb,const.thumbScale)
|
||||
preview.load_file(thumb)
|
||||
else:
|
||||
pass
|
||||
preview.load_file(utils.find_icon(type))
|
||||
|
||||
mid.set_text(mobj.getId())
|
||||
mtype.set_text(type)
|
||||
mtype.set_text(type_name)
|
||||
mdesc.set_text(mobj.getDescription())
|
||||
if path[0] == "/":
|
||||
mpath.set_text(path)
|
||||
@ -2156,7 +2157,7 @@ def load_media():
|
||||
for src in objects:
|
||||
title = src.getDescription()
|
||||
id = src.getId()
|
||||
type = src.getMimeType()
|
||||
type = utils.get_mime_description(src.getMimeType())
|
||||
if src.getLocal():
|
||||
path = "<local copy>"
|
||||
else:
|
||||
@ -3338,8 +3339,12 @@ def main(arg):
|
||||
dateArrow = gtop.get_widget("dateSort")
|
||||
deathArrow = gtop.get_widget("deathSort")
|
||||
|
||||
t = [('STRING', 0, 0)]
|
||||
t = [ ('STRING', 0, 0),
|
||||
('text/plain',0,0),
|
||||
('text/uri-list',0,2),
|
||||
('application/x-rootwin-drop',0,1)]
|
||||
media_list.drag_source_set(GDK.BUTTON1_MASK|GDK.BUTTON3_MASK,t,GDK.ACTION_COPY)
|
||||
media_list.drag_dest_set(DEST_DEFAULT_ALL,t,GDK.ACTION_COPY|GDK.ACTION_MOVE)
|
||||
person_list.set_column_visibility(5,0)
|
||||
person_list.set_column_visibility(6,0)
|
||||
person_list.set_column_visibility(7,0)
|
||||
@ -3406,9 +3411,11 @@ def main(arg):
|
||||
"on_person_list_select_row" : on_person_list_select_row,
|
||||
"on_place_list_button_press_event" : on_place_list_button_press_event,
|
||||
"on_main_key_release_event" : on_main_key_release_event,
|
||||
"on_add_media_clicked" : create_add_dialog,
|
||||
"on_media_activate" : on_media_activate,
|
||||
"on_media_list_select_row" : on_media_list_select_row,
|
||||
"on_media_list_drag_data_get" : on_media_list_drag_data_get,
|
||||
"on_media_list_drag_data_received" : on_media_list_drag_data_received,
|
||||
"on_places_activate" : on_places_activate,
|
||||
"on_preferences_activate" : on_preferences_activate,
|
||||
"on_remove_child_clicked" : on_remove_child_clicked,
|
||||
@ -3463,6 +3470,80 @@ def on_canvas1_event(obj,event):
|
||||
load_canvas()
|
||||
return 0
|
||||
|
||||
def create_add_dialog(obj):
|
||||
glade = libglade.GladeXML(const.imageselFile,"imageSelect")
|
||||
window = glade.get_widget("imageSelect")
|
||||
fname = glade.get_widget("fname")
|
||||
image = glade.get_widget("image")
|
||||
description = glade.get_widget("photoDescription")
|
||||
external = glade.get_widget("private")
|
||||
|
||||
glade.signal_autoconnect({
|
||||
"on_savephoto_clicked" : on_savephoto_clicked,
|
||||
"on_name_changed" : on_name_changed,
|
||||
"destroy_passed_object" : utils.destroy_passed_object
|
||||
})
|
||||
|
||||
window.editable_enters(description)
|
||||
window.set_data("t",glade)
|
||||
window.show()
|
||||
|
||||
def on_savephoto_clicked(obj):
|
||||
glade = obj.get_data("t")
|
||||
filename = glade.get_widget("photosel").get_full_path(0)
|
||||
description = glade.get_widget("photoDescription").get_text()
|
||||
external = glade.get_widget("private")
|
||||
|
||||
if os.path.exists(filename) == 0:
|
||||
GnomeErrorDialog(_("That is not a valid file name."));
|
||||
return
|
||||
|
||||
type = utils.get_mime_type(filename)
|
||||
mobj = Photo()
|
||||
if description == "":
|
||||
description = os.path.basename(filename)
|
||||
mobj.setDescription(description)
|
||||
mobj.setMimeType(type)
|
||||
database.addObject(mobj)
|
||||
|
||||
if external.get_active() == 0:
|
||||
path = database.getSavePath()
|
||||
name = RelImage.import_media_object(filename,path,mobj.getId())
|
||||
mobj.setPath(name)
|
||||
|
||||
utils.modified()
|
||||
load_media()
|
||||
utils.destroy_passed_object(obj)
|
||||
|
||||
def on_name_changed(obj):
|
||||
glade = obj.get_data('t')
|
||||
filename = glade.get_widget("fname").get_text()
|
||||
if os.path.isfile(filename):
|
||||
type = utils.get_mime_type(filename)
|
||||
if type[0:5] == "image":
|
||||
image = RelImage.scale_image(filename,const.thumbScale)
|
||||
glade.get_widget("image").load_imlib(image)
|
||||
else:
|
||||
glade.get_widget("image").load_file(utils.find_icon(type))
|
||||
|
||||
def on_media_list_drag_data_received(w, context, x, y, data, info, time):
|
||||
if data and data.format == 8:
|
||||
d = string.strip(string.replace(data.data,'\0',' '))
|
||||
if d[0:5] == "file:":
|
||||
name = d[5:]
|
||||
mime = utils.get_mime_type(name)
|
||||
photo = Photo()
|
||||
photo.setPath(name)
|
||||
photo.setMimeType(mime)
|
||||
description = os.path.basename(name)
|
||||
photo.setDescription(description)
|
||||
database.addObject(photo)
|
||||
utils.modified()
|
||||
w.drag_finish(context, TRUE, FALSE, time)
|
||||
load_media()
|
||||
else:
|
||||
w.drag_finish(context, FALSE, FALSE, time)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Start it all
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,6 +20,7 @@
|
||||
|
||||
import gtk
|
||||
import gnome.mime
|
||||
from gnome.ui import *
|
||||
import string
|
||||
import os
|
||||
import const
|
||||
@ -247,8 +248,27 @@ def add_menuitem(menu,msg,obj,func):
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def view_photo(photo):
|
||||
type = gnome.mime.type(photo.getPath())
|
||||
prog = string.split(gnome.mime.get_value(type,'view'))
|
||||
type = photo.getMimeType()
|
||||
prog = ""
|
||||
open = ""
|
||||
edit = ""
|
||||
for key in gnome.mime.get_keys(type):
|
||||
print key,gnome.mime.get_value(type,key)
|
||||
if key == 'view':
|
||||
prog = string.split(gnome.mime.get_value(type,key))
|
||||
if key == 'open':
|
||||
open = string.split(gnome.mime.get_value(type,key))
|
||||
if key == 'edit':
|
||||
edit = string.split(gnome.mime.get_value(type,key))
|
||||
if prog == "" and open == "" and edit == "":
|
||||
GnomeWarningDialog("Sorry, I cannot find a viewer for %s type" % type)
|
||||
return
|
||||
|
||||
if prog == "" and open == "":
|
||||
prog = edit
|
||||
else:
|
||||
prog = open
|
||||
|
||||
args = []
|
||||
for val in prog:
|
||||
if val == "%f":
|
||||
@ -256,6 +276,7 @@ def view_photo(photo):
|
||||
else:
|
||||
args.append(val)
|
||||
|
||||
print args
|
||||
if os.fork() == 0:
|
||||
os.execvp(args[0],args)
|
||||
|
||||
@ -312,3 +333,39 @@ def get_place_from_list(obj):
|
||||
return None
|
||||
else:
|
||||
return select[0].get_data(LISTOBJ)
|
||||
|
||||
def find_icon(mtype):
|
||||
icon = None
|
||||
nicon = None
|
||||
for k in gnome.mime.get_keys(mtype):
|
||||
if k == "icon-filename":
|
||||
icon = gnome.mime.get_value(mtype,k)
|
||||
elif k == "icon_filename":
|
||||
nicon = gnome.mime.get_value(mtype,k)
|
||||
if nicon:
|
||||
p = "%s/%s" % (gnome.util.pixmap_file("nautilus"),nicon)
|
||||
if os.path.isfile(p):
|
||||
print "n",p
|
||||
return p
|
||||
p = "%s.png" % p
|
||||
if os.path.isfile(p):
|
||||
print "n",p
|
||||
return p
|
||||
if icon:
|
||||
return icon
|
||||
return ""
|
||||
|
||||
def get_mime_type(file):
|
||||
if os.path.isfile(file) or os.path.isdir(file):
|
||||
mtype = gnome.mime.type_of_file(file)
|
||||
if len(string.split(mtype,"/")) != 2:
|
||||
mtype = gnome.mime.type(file)
|
||||
else:
|
||||
mtype = gnome.mime.type(file)
|
||||
return mtype
|
||||
|
||||
def get_mime_description(type):
|
||||
for key in gnome.mime.get_keys(type):
|
||||
if key == "description":
|
||||
return gnome.mime.get_value(type,key)
|
||||
return type
|
||||
|
Loading…
x
Reference in New Issue
Block a user