* src/RecentFiles.py: Make robust to parse/save problems.
* src/DbPrompter.py: Support for recent-files on new db creation. svn: r3754
This commit is contained in:
parent
635f079fcb
commit
662b0a3ab0
@ -1,3 +1,7 @@
|
||||
2004-11-25 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||
* src/RecentFiles.py: Make robust to parse/save problems.
|
||||
* src/DbPrompter.py: Support for recent-files on new db creation.
|
||||
|
||||
2004-11-25 Don Allingham <dallingham@users.sourceforge.net>
|
||||
* src/FamilyView.py: Add check for empty family in
|
||||
display_marriage
|
||||
|
@ -180,7 +180,7 @@ class ExistingDbPrompter:
|
||||
(the_path,the_file) = os.path.split(filename)
|
||||
GrampsGconfKeys.save_last_import_dir(the_path)
|
||||
|
||||
ret = False
|
||||
success = False
|
||||
if filetype == const.app_gramps:
|
||||
choose.destroy()
|
||||
self.parent.db = GrampsBSDDB.GrampsBSDDB()
|
||||
@ -188,19 +188,20 @@ class ExistingDbPrompter:
|
||||
msg_top = msgxml.get_widget('load_message')
|
||||
self.parent.read_file(filename)
|
||||
msg_top.destroy()
|
||||
ret = True
|
||||
success = True
|
||||
elif filetype == const.app_gramps_xml:
|
||||
choose.destroy()
|
||||
self.parent.db = GrampsXMLDB.GrampsXMLDB()
|
||||
self.parent.read_file(filename)
|
||||
ret = True
|
||||
success = True
|
||||
elif filetype == const.app_gedcom:
|
||||
choose.destroy()
|
||||
self.parent.db = GrampsGEDDB.GrampsGEDDB()
|
||||
self.parent.read_file(filename)
|
||||
ret = True
|
||||
success = True
|
||||
|
||||
if ret:
|
||||
if success:
|
||||
# Add the file to the recent items
|
||||
rf = RecentFiles.RecentFiles()
|
||||
item = RecentFiles.RecentItem(
|
||||
u='file://%s' % filename,
|
||||
@ -388,6 +389,16 @@ class NewNativeDbPrompter:
|
||||
filename = filename + ".grdb"
|
||||
choose.destroy()
|
||||
self.parent.read_file(filename)
|
||||
# Add the file to the recent items
|
||||
rf = RecentFiles.RecentFiles()
|
||||
item = RecentFiles.RecentItem(
|
||||
u='file://%s' % filename,
|
||||
m=const.app_gramps,
|
||||
t=int(time.time()),
|
||||
p=False,
|
||||
g=['Gramps'])
|
||||
rf.add(item)
|
||||
rf.save()
|
||||
return True
|
||||
else:
|
||||
choose.destroy()
|
||||
|
@ -87,6 +87,10 @@ class RecentItem:
|
||||
def get_groups(self):
|
||||
return self.groups[:]
|
||||
|
||||
def add_group(self,group):
|
||||
if group not in self.groups:
|
||||
self.groups.append(group)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# RecentFiles
|
||||
@ -102,13 +106,31 @@ class RecentFiles:
|
||||
self.recent_files = parser.get()
|
||||
|
||||
def add(self,item2add):
|
||||
# First we need to walk the existing items to see
|
||||
# if our item is already there
|
||||
for item in self.recent_files:
|
||||
if item.get_uri() == item2add.get_uri():
|
||||
# Found it -- modify timestamp and add all groups
|
||||
# to the item's groups
|
||||
item.set_time(item2add.get_time())
|
||||
for group in item2add.get_groups():
|
||||
item.add_group(group)
|
||||
return
|
||||
# At this point we walked the items and not found one,
|
||||
# so simply inserting a new item in the beginning
|
||||
self.recent_files.insert(0,item2add)
|
||||
|
||||
def save(self):
|
||||
"""
|
||||
Attempt saving into XML.
|
||||
The trick is not to fail under any circumstances.
|
||||
"""
|
||||
try:
|
||||
self.do_save()
|
||||
except:
|
||||
pass
|
||||
|
||||
def do_save(self):
|
||||
"""
|
||||
Saves the current RecentFiles collection to the associated file.
|
||||
"""
|
||||
@ -146,33 +168,29 @@ class RecentParser:
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
xml_file = file(os.path.expanduser(FILENAME))
|
||||
fcntl.lockf(xml_file,fcntl.LOCK_SH)
|
||||
self.recent_files = []
|
||||
|
||||
self.recent_files = None
|
||||
try:
|
||||
xml_file = open(os.path.expanduser(FILENAME))
|
||||
fcntl.lockf(xml_file,fcntl.LOCK_SH)
|
||||
|
||||
p = xml.parsers.expat.ParserCreate()
|
||||
p.StartElementHandler = self.startElement
|
||||
p.EndElementHandler = self.endElement
|
||||
p.CharacterDataHandler = self.characters
|
||||
p.ParseFile(xml_file)
|
||||
p = xml.parsers.expat.ParserCreate()
|
||||
p.StartElementHandler = self.startElement
|
||||
p.EndElementHandler = self.endElement
|
||||
p.CharacterDataHandler = self.characters
|
||||
p.ParseFile(xml_file)
|
||||
|
||||
fcntl.lockf(xml_file,fcntl.LOCK_UN)
|
||||
xml_file.close()
|
||||
fcntl.lockf(xml_file,fcntl.LOCK_UN)
|
||||
xml_file.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
def get(self):
|
||||
return self.recent_files
|
||||
|
||||
def startElement(self,tag,attrs):
|
||||
"""
|
||||
Loads the dictionary when an XML tag of 'template' is found. The format
|
||||
XML tag is <template title=\"name\" file=\"path\">
|
||||
"""
|
||||
|
||||
self.tlist = []
|
||||
if tag == "RecentFiles":
|
||||
self.recent_files = []
|
||||
elif tag == "RecentItem":
|
||||
if tag == "RecentItem":
|
||||
self.item = RecentItem()
|
||||
elif tag == "Groups":
|
||||
self.groups = []
|
||||
|
Loading…
Reference in New Issue
Block a user