* 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>
|
2004-11-25 Don Allingham <dallingham@users.sourceforge.net>
|
||||||
* src/FamilyView.py: Add check for empty family in
|
* src/FamilyView.py: Add check for empty family in
|
||||||
display_marriage
|
display_marriage
|
||||||
|
@ -180,7 +180,7 @@ class ExistingDbPrompter:
|
|||||||
(the_path,the_file) = os.path.split(filename)
|
(the_path,the_file) = os.path.split(filename)
|
||||||
GrampsGconfKeys.save_last_import_dir(the_path)
|
GrampsGconfKeys.save_last_import_dir(the_path)
|
||||||
|
|
||||||
ret = False
|
success = False
|
||||||
if filetype == const.app_gramps:
|
if filetype == const.app_gramps:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
self.parent.db = GrampsBSDDB.GrampsBSDDB()
|
self.parent.db = GrampsBSDDB.GrampsBSDDB()
|
||||||
@ -188,19 +188,20 @@ class ExistingDbPrompter:
|
|||||||
msg_top = msgxml.get_widget('load_message')
|
msg_top = msgxml.get_widget('load_message')
|
||||||
self.parent.read_file(filename)
|
self.parent.read_file(filename)
|
||||||
msg_top.destroy()
|
msg_top.destroy()
|
||||||
ret = True
|
success = True
|
||||||
elif filetype == const.app_gramps_xml:
|
elif filetype == const.app_gramps_xml:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
self.parent.db = GrampsXMLDB.GrampsXMLDB()
|
self.parent.db = GrampsXMLDB.GrampsXMLDB()
|
||||||
self.parent.read_file(filename)
|
self.parent.read_file(filename)
|
||||||
ret = True
|
success = True
|
||||||
elif filetype == const.app_gedcom:
|
elif filetype == const.app_gedcom:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
self.parent.db = GrampsGEDDB.GrampsGEDDB()
|
self.parent.db = GrampsGEDDB.GrampsGEDDB()
|
||||||
self.parent.read_file(filename)
|
self.parent.read_file(filename)
|
||||||
ret = True
|
success = True
|
||||||
|
|
||||||
if ret:
|
if success:
|
||||||
|
# Add the file to the recent items
|
||||||
rf = RecentFiles.RecentFiles()
|
rf = RecentFiles.RecentFiles()
|
||||||
item = RecentFiles.RecentItem(
|
item = RecentFiles.RecentItem(
|
||||||
u='file://%s' % filename,
|
u='file://%s' % filename,
|
||||||
@ -388,6 +389,16 @@ class NewNativeDbPrompter:
|
|||||||
filename = filename + ".grdb"
|
filename = filename + ".grdb"
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
self.parent.read_file(filename)
|
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
|
return True
|
||||||
else:
|
else:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
|
@ -87,6 +87,10 @@ class RecentItem:
|
|||||||
def get_groups(self):
|
def get_groups(self):
|
||||||
return self.groups[:]
|
return self.groups[:]
|
||||||
|
|
||||||
|
def add_group(self,group):
|
||||||
|
if group not in self.groups:
|
||||||
|
self.groups.append(group)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# RecentFiles
|
# RecentFiles
|
||||||
@ -102,13 +106,31 @@ class RecentFiles:
|
|||||||
self.recent_files = parser.get()
|
self.recent_files = parser.get()
|
||||||
|
|
||||||
def add(self,item2add):
|
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:
|
for item in self.recent_files:
|
||||||
if item.get_uri() == item2add.get_uri():
|
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())
|
item.set_time(item2add.get_time())
|
||||||
|
for group in item2add.get_groups():
|
||||||
|
item.add_group(group)
|
||||||
return
|
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)
|
self.recent_files.insert(0,item2add)
|
||||||
|
|
||||||
def save(self):
|
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.
|
Saves the current RecentFiles collection to the associated file.
|
||||||
"""
|
"""
|
||||||
@ -146,33 +168,29 @@ class RecentParser:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
xml_file = file(os.path.expanduser(FILENAME))
|
self.recent_files = []
|
||||||
fcntl.lockf(xml_file,fcntl.LOCK_SH)
|
|
||||||
|
|
||||||
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 = xml.parsers.expat.ParserCreate()
|
||||||
p.StartElementHandler = self.startElement
|
p.StartElementHandler = self.startElement
|
||||||
p.EndElementHandler = self.endElement
|
p.EndElementHandler = self.endElement
|
||||||
p.CharacterDataHandler = self.characters
|
p.CharacterDataHandler = self.characters
|
||||||
p.ParseFile(xml_file)
|
p.ParseFile(xml_file)
|
||||||
|
|
||||||
fcntl.lockf(xml_file,fcntl.LOCK_UN)
|
fcntl.lockf(xml_file,fcntl.LOCK_UN)
|
||||||
xml_file.close()
|
xml_file.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
return self.recent_files
|
return self.recent_files
|
||||||
|
|
||||||
def startElement(self,tag,attrs):
|
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 = []
|
self.tlist = []
|
||||||
if tag == "RecentFiles":
|
if tag == "RecentItem":
|
||||||
self.recent_files = []
|
|
||||||
elif tag == "RecentItem":
|
|
||||||
self.item = RecentItem()
|
self.item = RecentItem()
|
||||||
elif tag == "Groups":
|
elif tag == "Groups":
|
||||||
self.groups = []
|
self.groups = []
|
||||||
|
Loading…
Reference in New Issue
Block a user