Don't reimport a file that has already been imported

svn: r556
This commit is contained in:
Don Allingham 2001-11-08 14:49:58 +00:00
parent 3111d7e463
commit e2df6299c2
6 changed files with 152 additions and 86 deletions

View File

@ -130,25 +130,37 @@ class ImageSelect:
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)
self.savephoto(mobj)
already_imported = None
for o in self.db.getObjectMap().values():
if o.getPath() == filename:
already_imported = o
break
if type[0:5] == "image":
if self.external.get_active() == 0:
name = RelImage.import_media_object(filename,self.path,mobj.getId())
if (already_imported):
oref = ObjectRef()
oref.setReference(already_imported)
self.dataobj.addPhoto(oref)
self.add_thumbnail(oref)
else:
if self.external.get_active() == 1:
name = filename
RelImage.mk_thumb(filename,self.path,mobj.getId())
else:
name = RelImage.import_media_object(filename,self.path,mobj.getId())
type = utils.get_mime_type(filename)
mobj = Photo()
if description == "":
description = os.path.basename(filename)
mobj.setDescription(description)
mobj.setMimeType(type)
self.savephoto(mobj)
mobj.setPath(name)
if type[0:5] == "image":
if self.external.get_active() == 0:
name = RelImage.import_media_object(filename,self.path,mobj.getId())
else:
if self.external.get_active() == 1:
name = filename
RelImage.mk_thumb(filename,self.path,mobj.getId())
else:
name = RelImage.import_media_object(filename,self.path,mobj.getId())
mobj.setPath(name)
utils.modified()
utils.destroy_passed_object(obj)
@ -211,8 +223,6 @@ class Gallery(ImageSelect):
oref = ObjectRef()
oref.setReference(photo)
self.dataobj.addPhoto(oref)
dest = "%s/.thumb/%s.jpg" % (self.db.getSavePath(),photo.getId())
RelImage.mk_thumb(photo.getPath(),dest,const.thumbScale)
self.add_thumbnail(oref)
#-------------------------------------------------------------------------

View File

@ -55,17 +55,17 @@ class PlaceView:
self.place_list.set_column_visibility(10,0)
self.place_list.set_column_visibility(11,0)
self.place_list.set_column_visibility(12,0)
self.place_list.set_column_visibility(13,0)
self.place_list.connect('button-press-event',self.on_button_press_event)
self.place_list.connect('select-row',self.select_row)
self.active = None
self.sort_map = [7,1,8,9,10,11,12]
# Restore the previous sort column
self.sort_col,self.sort_dir = Config.get_sort_cols("place",0,GTK.SORT_ASCENDING)
self.place_list.set_sort_column(self.sort_col+7)
self.place_list.set_sort_type(self.sort_dir)
self.set_arrow(self.sort_col)
self.place_list.set_sort_column(self.sort_map[self.sort_col])
self.place_list.set_sort_type(self.sort_dir)
def load_places(self):
if len(self.place_list.selection) == 0:
@ -92,7 +92,7 @@ class PlaceView:
parish = mloc.get_parish()
country = mloc.get_country()
self.place_list.append([title,id,parish,city,county,state,country,
u(title), u(id), u(parish), u(city),
u(title), u(parish), u(city),
u(county),u(state), u(country)])
self.place_list.set_row_data(index,src)
index = index + 1
@ -159,7 +159,7 @@ class PlaceView:
self.sort_col = column
self.set_arrow(column)
self.place_list.set_sort_type(self.sort_direct)
self.place_list.set_sort_column(self.sort_col + 7)
self.place_list.set_sort_column(self.sort_map[self.sort_col])
Config.save_sort_cols("place",self.sort_col,self.sort_direct)
self.place_list.sort()

View File

@ -80,6 +80,7 @@ def import_media_object(filename,path,base):
try:
path = "%s/%s" % (thumb,base)
print filename,path,const.thumbScale
mk_thumb(filename,path,const.thumbScale)
shutil.copy(filename,name)
except:

View File

@ -69,16 +69,20 @@ class SourceView:
self.sort_arrow = [self.title_arrow, self.id_arrow, self.author_arrow]
self.source_list.connect('click-column',self.click_column)
self.sort_col,self.sort_dir = Config.get_sort_cols("source",3,GTK.SORT_ASCENDING)
if self.sort_col >= len(self.sort_arrow):
self.sort_col = 0
self.source_list.set_sort_type(self.sort_dir)
self.source_list.set_sort_column(self.sort_map[self.sort_col])
self.set_arrow(self.sort_col)
def set_arrow(self,column):
for a in self.sort_arrow:
a.hide()
print column
a = self.sort_arrow[column]
a.show()
if self.sort_dir == GTK.SORT_ASCENDING:

View File

@ -1275,6 +1275,45 @@
<ypad>0</ypad>
</widget>
<widget>
<class>GtkScrolledWindow</class>
<name>scrolledwindow28</name>
<hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy>
<hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
<vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
<widget>
<class>GnomeCanvas</class>
<name>canvas1</name>
<can_focus>True</can_focus>
<signal>
<name>event</name>
<handler>on_canvas1_event</handler>
<last_modification_time>Sun, 02 Sep 2001 21:58:31 GMT</last_modification_time>
</signal>
<anti_aliased>False</anti_aliased>
<scroll_x1>0</scroll_x1>
<scroll_y1>0</scroll_y1>
<scroll_x2>100</scroll_x2>
<scroll_y2>100</scroll_y2>
<pixels_per_unit>1</pixels_per_unit>
</widget>
</widget>
<widget>
<class>GtkLabel</class>
<child_name>Notebook:tab</child_name>
<name>label237</name>
<label>Pedigree</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
<widget>
<class>GtkVBox</class>
<name>vbox2</name>
@ -2306,45 +2345,6 @@
<ypad>0</ypad>
</widget>
<widget>
<class>GtkScrolledWindow</class>
<name>scrolledwindow28</name>
<hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy>
<hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
<vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
<widget>
<class>GnomeCanvas</class>
<name>canvas1</name>
<can_focus>True</can_focus>
<signal>
<name>event</name>
<handler>on_canvas1_event</handler>
<last_modification_time>Sun, 02 Sep 2001 21:58:31 GMT</last_modification_time>
</signal>
<anti_aliased>False</anti_aliased>
<scroll_x1>0</scroll_x1>
<scroll_y1>0</scroll_y1>
<scroll_x2>100</scroll_x2>
<scroll_y2>100</scroll_y2>
<pixels_per_unit>1</pixels_per_unit>
</widget>
</widget>
<widget>
<class>GtkLabel</class>
<child_name>Notebook:tab</child_name>
<name>label237</name>
<label>Pedigree</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
<widget>
<class>GtkVBox</class>
<name>vbox33</name>
@ -2379,7 +2379,7 @@
<last_modification_time>Thu, 31 May 2001 17:22:45 GMT</last_modification_time>
</signal>
<columns>5</columns>
<column_widths>293,60,344,5,5</column_widths>
<column_widths>293,61,306,5,5</column_widths>
<selection_mode>GTK_SELECTION_SINGLE</selection_mode>
<show_titles>True</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type>
@ -2683,8 +2683,8 @@
<handler>on_place_list_click_column</handler>
<last_modification_time>Tue, 30 Oct 2001 18:18:53 GMT</last_modification_time>
</signal>
<columns>14</columns>
<column_widths>222,47,102,88,77,80,5,5,5,5,5,5,5,5</column_widths>
<columns>13</columns>
<column_widths>213,47,107,88,77,80,29,1,1,1,1,1,1</column_widths>
<selection_mode>GTK_SELECTION_EXTENDED</selection_mode>
<show_titles>True</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type>
@ -3087,19 +3087,6 @@
</widget>
</widget>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
<name>label276</name>
<label></label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
</widget>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
@ -3628,7 +3615,7 @@
<widget>
<class>GtkLabel</class>
<name>label266</name>
<label>Description</label>
<label>Title</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>1</xalign>

View File

@ -184,6 +184,12 @@ class GedcomParser:
self.error_count = 0
self.error_text_obj.set_point(0)
self.error_text_obj.set_word_wrap(0)
map = const.personalConstantAttributes
self.attrs = map.values()
self.gedattr = {}
for val in map.keys():
self.gedattr[map[val]] = val
self.update(self.file_obj,file)
self.code = 0
@ -563,23 +569,33 @@ class GedcomParser:
elif matches[1] == "EVEN":
event = Event()
self.parse_person_event(event,2)
if string.strip(event.getName()) == "SSN":
n = string.strip(event.getName())
if n in self.attrs:
attr = Attribute()
attr.setType("Social Security Number")
attr.setType(self.gedattr[n])
attr.setValue(event.getDescription())
self.person.addAttribute(attr)
else:
self.person.addEvent(event)
else:
event = Event()
try:
event.setName(ged2gramps[matches[1]])
except:
n = string.strip(matches[1])
if ged2gramps.has_key(n):
event.setName(ged2gramps[n])
elif self.gedattr.has_key(n):
attr = Attribute()
attr.setType(self.gedattr[n])
attr.setValue(event.getDescription())
self.person.addAttribute(attr)
self.parse_person_attr(attr,2)
continue
else:
event.setName(matches[1])
self.parse_person_event(event,2)
if matches[2] != None:
event.setDescription(matches[2])
self.person.addEvent(event)
self.parse_person_event(event,2)
def parse_optional_note(self,level):
note = ""
@ -882,6 +898,54 @@ class GedcomParser:
else:
self.barf(level+1)
def parse_person_attr(self,attr,level):
note = ""
while 1:
matches = self.get_next()
if int(matches[0]) < level:
self.backup()
break
elif matches[1] == "TYPE":
if attr.getType() == "":
if ged2gramps.has_key(matches[2]):
name = ged2gramps[matches[2]]
else:
name = matches[2]
attr.setName(name)
elif matches[1] == ["CAUS", "DATE","TIME","ADDR","AGE","AGNC","STAT","TEMP","OBJE"]:
self.ignore_sub_junk(level+1)
elif matches[1] == "SOUR":
source_ref = SourceRef()
if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(1))
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
self.parse_source_reference(source_ref,level+1)
attr.addSourceRef(source_ref)
elif matches[1] == "PLAC":
val = matches[2]
if attr.getValue() == "":
attr.setValue(val)
self.ignore_sub_junk(level+1)
elif matches[1] == "NOTE":
info = matches[2] + self.parse_continue_data(level+1)
if note == "":
note = info
else:
note = "\n%s" % info
elif matches[1] == "CONC":
attr.setValue( "%s %s" % (attr.getValue(), matches[2]))
elif matches[1] == "CONT":
attr.setValue("%s\n%s" % (attr.getValue(),matches[2]))
else:
self.barf(level+1)
def parse_family_event(self,event,level):
global ged2fam
global ged2gramps