* src/Bookmarks.py: pylint fixes
* src/ColumnOrder.py: pylint fixes * src/DateEdit.py: pylint fixes * src/DbLoader.py: pylint fixes * src/ManagedWindow.py: pylint fixes 2007-05-19 Don Allingham <don@gramps-project.org> svn: r8498
This commit is contained in:
parent
659814e22d
commit
a598df4f6d
@ -1,3 +1,10 @@
|
|||||||
|
2007-05-19 Don Allingham <don@gramps-project.org>
|
||||||
|
* src/Bookmarks.py: pylint fixes
|
||||||
|
* src/ColumnOrder.py: pylint fixes
|
||||||
|
* src/DateEdit.py: pylint fixes
|
||||||
|
* src/DbLoader.py: pylint fixes
|
||||||
|
* src/ManagedWindow.py: pylint fixes
|
||||||
|
|
||||||
2007-05-19 Don Allingham <don@gramps-project.org>
|
2007-05-19 Don Allingham <don@gramps-project.org>
|
||||||
* src/AutoComp.py: removal of unused functions
|
* src/AutoComp.py: removal of unused functions
|
||||||
* src/BaseDoc.py: clean up and add documentation
|
* src/BaseDoc.py: clean up and add documentation
|
||||||
|
123
src/Bookmarks.py
123
src/Bookmarks.py
@ -89,18 +89,34 @@ class Bookmarks :
|
|||||||
self.dbstate.connect('database-changed', self.db_changed)
|
self.dbstate.connect('database-changed', self.db_changed)
|
||||||
|
|
||||||
def db_changed(self, data):
|
def db_changed(self, data):
|
||||||
|
"""
|
||||||
|
Reconnect the signals on a database changed.
|
||||||
|
"""
|
||||||
self.connect_signals()
|
self.connect_signals()
|
||||||
|
|
||||||
def connect_signals(self):
|
def connect_signals(self):
|
||||||
|
"""
|
||||||
|
Connect the person-delete signal
|
||||||
|
"""
|
||||||
self.dbstate.db.connect('person-delete', self.remove_handles)
|
self.dbstate.db.connect('person-delete', self.remove_handles)
|
||||||
|
|
||||||
def update_bookmarks(self, bookmarks):
|
def update_bookmarks(self, bookmarks):
|
||||||
|
"""
|
||||||
|
Assign bookmarks
|
||||||
|
"""
|
||||||
self.bookmarks = bookmarks
|
self.bookmarks = bookmarks
|
||||||
|
|
||||||
def display(self):
|
def display(self):
|
||||||
|
"""
|
||||||
|
|
||||||
|
Redraw teh display
|
||||||
|
"""
|
||||||
self.redraw()
|
self.redraw()
|
||||||
|
|
||||||
def undisplay(self):
|
def undisplay(self):
|
||||||
|
"""
|
||||||
|
Update the uimanager
|
||||||
|
"""
|
||||||
if self.active != DISABLED:
|
if self.active != DISABLED:
|
||||||
self.uistate.uimanager.remove_ui(self.active)
|
self.uistate.uimanager.remove_ui(self.active)
|
||||||
self.uistate.uimanager.remove_action_group(self.action_group)
|
self.uistate.uimanager.remove_action_group(self.action_group)
|
||||||
@ -108,8 +124,8 @@ class Bookmarks :
|
|||||||
|
|
||||||
def redraw(self):
|
def redraw(self):
|
||||||
"""Create the pulldown menu"""
|
"""Create the pulldown menu"""
|
||||||
f = StringIO()
|
text = StringIO()
|
||||||
f.write(_top)
|
text.write(_top)
|
||||||
|
|
||||||
self.undisplay()
|
self.undisplay()
|
||||||
|
|
||||||
@ -117,7 +133,7 @@ class Bookmarks :
|
|||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
if len(self.bookmarks.get()) > 0:
|
if len(self.bookmarks.get()) > 0:
|
||||||
f.write('<placeholder name="GoToBook">')
|
text.write('<placeholder name="GoToBook">')
|
||||||
|
|
||||||
new_list = []
|
new_list = []
|
||||||
for item in self.bookmarks.get():
|
for item in self.bookmarks.get():
|
||||||
@ -125,26 +141,26 @@ class Bookmarks :
|
|||||||
label, obj = self.make_label(item)
|
label, obj = self.make_label(item)
|
||||||
func = self.callback(item)
|
func = self.callback(item)
|
||||||
action_id = "BM:%s" % item
|
action_id = "BM:%s" % item
|
||||||
actions.append((action_id,None,label,None,None,func))
|
actions.append((action_id, None, label, None, None, func))
|
||||||
f.write('<menuitem action="%s"/>' % action_id)
|
text.write('<menuitem action="%s"/>' % action_id)
|
||||||
count +=1
|
count += 1
|
||||||
new_list.append(item)
|
new_list.append(item)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
f.write('</placeholder>')
|
text.write('</placeholder>')
|
||||||
self.bookmarks.set(new_list)
|
self.bookmarks.set(new_list)
|
||||||
|
|
||||||
f.write(_btm)
|
text.write(_btm)
|
||||||
self.action_group.add_actions(actions)
|
self.action_group.add_actions(actions)
|
||||||
self.uistate.uimanager.insert_action_group(self.action_group,1)
|
self.uistate.uimanager.insert_action_group(self.action_group, 1)
|
||||||
self.active = self.uistate.uimanager.add_ui_from_string(f.getvalue())
|
self.active = self.uistate.uimanager.add_ui_from_string(text.getvalue())
|
||||||
self.uistate.uimanager.ensure_update()
|
self.uistate.uimanager.ensure_update()
|
||||||
f.close()
|
text.close()
|
||||||
|
|
||||||
def make_label(self,handle):
|
def make_label(self, handle):
|
||||||
person = self.dbstate.db.get_person_from_handle(handle)
|
person = self.dbstate.db.get_person_from_handle(handle)
|
||||||
name = NameDisplay.displayer.display(person)
|
name = NameDisplay.displayer.display(person)
|
||||||
return ("%s [%s]" % (name,person.gramps_id), person)
|
return ("%s [%s]" % (name, person.gramps_id), person)
|
||||||
|
|
||||||
def callback(self, handle):
|
def callback(self, handle):
|
||||||
return make_callback(handle, self.dbstate.change_active_handle)
|
return make_callback(handle, self.dbstate.change_active_handle)
|
||||||
@ -175,25 +191,25 @@ class Bookmarks :
|
|||||||
"""Draws the bookmark dialog box"""
|
"""Draws the bookmark dialog box"""
|
||||||
title = "%s - GRAMPS" % _("Edit Bookmarks")
|
title = "%s - GRAMPS" % _("Edit Bookmarks")
|
||||||
self.top = gtk.Dialog(title)
|
self.top = gtk.Dialog(title)
|
||||||
self.top.set_default_size(400,350)
|
self.top.set_default_size(400, 350)
|
||||||
self.top.set_has_separator(False)
|
self.top.set_has_separator(False)
|
||||||
self.top.vbox.set_spacing(5)
|
self.top.vbox.set_spacing(5)
|
||||||
label = gtk.Label('<span size="larger" weight="bold">%s</span>'
|
label = gtk.Label('<span size="larger" weight="bold">%s</span>'
|
||||||
% _("Edit Bookmarks"))
|
% _("Edit Bookmarks"))
|
||||||
label.set_use_markup(True)
|
label.set_use_markup(True)
|
||||||
self.top.vbox.pack_start(label,0,0,5)
|
self.top.vbox.pack_start(label, 0, 0, 5)
|
||||||
box = gtk.HBox()
|
box = gtk.HBox()
|
||||||
self.top.vbox.pack_start(box,1,1,5)
|
self.top.vbox.pack_start(box, 1, 1, 5)
|
||||||
|
|
||||||
name_titles = [(_('Name'),-1,200),(_('ID'),-1,50),('',-1,0)]
|
name_titles = [(_('Name'), -1, 200), (_('ID'), -1, 50), ('', -1, 0)]
|
||||||
self.namelist = gtk.TreeView()
|
self.namelist = gtk.TreeView()
|
||||||
self.namemodel = ListModel.ListModel(self.namelist,name_titles)
|
self.namemodel = ListModel.ListModel(self.namelist, name_titles)
|
||||||
self.namemodel_cols = len(name_titles)
|
self.namemodel_cols = len(name_titles)
|
||||||
|
|
||||||
slist = gtk.ScrolledWindow()
|
slist = gtk.ScrolledWindow()
|
||||||
slist.add_with_viewport(self.namelist)
|
slist.add_with_viewport(self.namelist)
|
||||||
slist.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
slist.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||||
box.pack_start(slist,1,1,5)
|
box.pack_start(slist, 1, 1, 5)
|
||||||
bbox = gtk.VButtonBox()
|
bbox = gtk.VButtonBox()
|
||||||
bbox.set_layout(gtk.BUTTONBOX_START)
|
bbox.set_layout(gtk.BUTTONBOX_START)
|
||||||
bbox.set_spacing(6)
|
bbox.set_spacing(6)
|
||||||
@ -201,14 +217,14 @@ class Bookmarks :
|
|||||||
down = gtk.Button(stock=gtk.STOCK_GO_DOWN)
|
down = gtk.Button(stock=gtk.STOCK_GO_DOWN)
|
||||||
delete = gtk.Button(stock=gtk.STOCK_REMOVE)
|
delete = gtk.Button(stock=gtk.STOCK_REMOVE)
|
||||||
up.connect('clicked', self.up_clicked)
|
up.connect('clicked', self.up_clicked)
|
||||||
down.connect('clicked',self.down_clicked)
|
down.connect('clicked', self.down_clicked)
|
||||||
delete.connect('clicked',self.delete_clicked)
|
delete.connect('clicked', self.delete_clicked)
|
||||||
self.top.add_button(gtk.STOCK_CLOSE,gtk.RESPONSE_CLOSE)
|
self.top.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
|
||||||
self.top.add_button(gtk.STOCK_HELP,gtk.RESPONSE_HELP)
|
self.top.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
|
||||||
bbox.add(up)
|
bbox.add(up)
|
||||||
bbox.add(down)
|
bbox.add(down)
|
||||||
bbox.add(delete)
|
bbox.add(delete)
|
||||||
box.pack_start(bbox,0,0,5)
|
box.pack_start(bbox, 0, 0, 5)
|
||||||
self.top.show_all()
|
self.top.show_all()
|
||||||
|
|
||||||
def edit(self):
|
def edit(self):
|
||||||
@ -225,7 +241,7 @@ class Bookmarks :
|
|||||||
name, obj = self.make_label(handle)
|
name, obj = self.make_label(handle)
|
||||||
if obj:
|
if obj:
|
||||||
gramps_id = obj.get_gramps_id()
|
gramps_id = obj.get_gramps_id()
|
||||||
self.namemodel.add([name,gramps_id,handle])
|
self.namemodel.add([name, gramps_id, handle])
|
||||||
self.namemodel.connect_model()
|
self.namemodel.connect_model()
|
||||||
|
|
||||||
self.modified = False
|
self.modified = False
|
||||||
@ -236,9 +252,9 @@ class Bookmarks :
|
|||||||
self.redraw()
|
self.redraw()
|
||||||
self.top.destroy()
|
self.top.destroy()
|
||||||
|
|
||||||
def delete_clicked(self,obj):
|
def delete_clicked(self, obj):
|
||||||
"""Removes the current selection from the list"""
|
"""Removes the current selection from the list"""
|
||||||
store,the_iter = self.namemodel.get_selected()
|
store, the_iter = self.namemodel.get_selected()
|
||||||
if not the_iter:
|
if not the_iter:
|
||||||
return
|
return
|
||||||
row = self.namemodel.get_selected_row()
|
row = self.namemodel.get_selected_row()
|
||||||
@ -246,30 +262,30 @@ class Bookmarks :
|
|||||||
self.namemodel.remove(the_iter)
|
self.namemodel.remove(the_iter)
|
||||||
self.modified = True
|
self.modified = True
|
||||||
|
|
||||||
def up_clicked(self,obj):
|
def up_clicked(self, obj):
|
||||||
"""Moves the current selection up one row"""
|
"""Moves the current selection up one row"""
|
||||||
row = self.namemodel.get_selected_row()
|
row = self.namemodel.get_selected_row()
|
||||||
if not row or row == -1:
|
if not row or row == -1:
|
||||||
return
|
return
|
||||||
store,the_iter = self.namemodel.get_selected()
|
store, the_iter = self.namemodel.get_selected()
|
||||||
data = self.namemodel.get_data(the_iter,range(self.namemodel_cols))
|
data = self.namemodel.get_data(the_iter, range(self.namemodel_cols))
|
||||||
self.namemodel.remove(the_iter)
|
self.namemodel.remove(the_iter)
|
||||||
self.namemodel.insert(row-1,data,None,1)
|
self.namemodel.insert(row-1, data, None, 1)
|
||||||
handle = self.bookmarks.pop(row)
|
handle = self.bookmarks.pop(row)
|
||||||
self.bookmarks.insert(row-1,handle)
|
self.bookmarks.insert(row-1, handle)
|
||||||
self.modified = True
|
self.modified = True
|
||||||
|
|
||||||
def down_clicked(self,obj):
|
def down_clicked(self, obj):
|
||||||
"""Moves the current selection down one row"""
|
"""Moves the current selection down one row"""
|
||||||
row = self.namemodel.get_selected_row()
|
row = self.namemodel.get_selected_row()
|
||||||
if row + 1 >= self.namemodel.count or row == -1:
|
if row + 1 >= self.namemodel.count or row == -1:
|
||||||
return
|
return
|
||||||
store,the_iter = self.namemodel.get_selected()
|
store, the_iter = self.namemodel.get_selected()
|
||||||
data = self.namemodel.get_data(the_iter,range(self.namemodel_cols))
|
data = self.namemodel.get_data(the_iter, range(self.namemodel_cols))
|
||||||
self.namemodel.remove(the_iter)
|
self.namemodel.remove(the_iter)
|
||||||
self.namemodel.insert(row+1,data,None,1)
|
self.namemodel.insert(row+1, data, None, 1)
|
||||||
handle = self.bookmarks.pop(row)
|
handle = self.bookmarks.pop(row)
|
||||||
self.bookmarks.insert(row+1,handle)
|
self.bookmarks.insert(row+1, handle)
|
||||||
self.modified = True
|
self.modified = True
|
||||||
|
|
||||||
def help_clicked(self):
|
def help_clicked(self):
|
||||||
@ -279,7 +295,7 @@ class Bookmarks :
|
|||||||
|
|
||||||
class ListBookmarks(Bookmarks):
|
class ListBookmarks(Bookmarks):
|
||||||
|
|
||||||
def __init__(self,dbstate,uistate,bookmarks, goto_handle):
|
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
|
||||||
self.goto_handle = goto_handle
|
self.goto_handle = goto_handle
|
||||||
Bookmarks.__init__(self, dbstate, uistate, bookmarks)
|
Bookmarks.__init__(self, dbstate, uistate, bookmarks)
|
||||||
|
|
||||||
@ -289,15 +305,14 @@ class ListBookmarks(Bookmarks):
|
|||||||
def do_callback(self, handle):
|
def do_callback(self, handle):
|
||||||
self.goto_handle(handle)
|
self.goto_handle(handle)
|
||||||
|
|
||||||
|
|
||||||
class FamilyBookmarks(ListBookmarks) :
|
class FamilyBookmarks(ListBookmarks) :
|
||||||
"Handle the bookmarks interface for Gramps"
|
"Handle the bookmarks interface for Gramps"
|
||||||
|
|
||||||
def __init__(self,dbstate,uistate,bookmarks, goto_handle):
|
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
|
||||||
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
||||||
goto_handle)
|
goto_handle)
|
||||||
|
|
||||||
def make_label(self,handle):
|
def make_label(self, handle):
|
||||||
obj = self.dbstate.db.get_family_from_handle(handle)
|
obj = self.dbstate.db.get_family_from_handle(handle)
|
||||||
name = Utils.family_name(obj, self.dbstate.db)
|
name = Utils.family_name(obj, self.dbstate.db)
|
||||||
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
||||||
@ -308,11 +323,11 @@ class FamilyBookmarks(ListBookmarks) :
|
|||||||
class EventBookmarks(ListBookmarks) :
|
class EventBookmarks(ListBookmarks) :
|
||||||
"Handle the bookmarks interface for Gramps"
|
"Handle the bookmarks interface for Gramps"
|
||||||
|
|
||||||
def __init__(self,dbstate,uistate,bookmarks, goto_handle):
|
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
|
||||||
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
||||||
goto_handle)
|
goto_handle)
|
||||||
|
|
||||||
def make_label(self,handle):
|
def make_label(self, handle):
|
||||||
obj = self.dbstate.db.get_event_from_handle(handle)
|
obj = self.dbstate.db.get_event_from_handle(handle)
|
||||||
if obj.get_description() == "":
|
if obj.get_description() == "":
|
||||||
name = str(obj.get_type())
|
name = str(obj.get_type())
|
||||||
@ -325,11 +340,11 @@ class EventBookmarks(ListBookmarks) :
|
|||||||
|
|
||||||
class SourceBookmarks(ListBookmarks) :
|
class SourceBookmarks(ListBookmarks) :
|
||||||
"Handle the bookmarks interface for Gramps"
|
"Handle the bookmarks interface for Gramps"
|
||||||
def __init__(self,dbstate,uistate,bookmarks, goto_handle):
|
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
|
||||||
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
||||||
goto_handle)
|
goto_handle)
|
||||||
|
|
||||||
def make_label(self,handle):
|
def make_label(self, handle):
|
||||||
obj = self.dbstate.db.get_source_from_handle(handle)
|
obj = self.dbstate.db.get_source_from_handle(handle)
|
||||||
name = obj.get_title()
|
name = obj.get_title()
|
||||||
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
||||||
@ -340,11 +355,11 @@ class SourceBookmarks(ListBookmarks) :
|
|||||||
class MediaBookmarks(ListBookmarks) :
|
class MediaBookmarks(ListBookmarks) :
|
||||||
"Handle the bookmarks interface for Gramps"
|
"Handle the bookmarks interface for Gramps"
|
||||||
|
|
||||||
def __init__(self,dbstate,uistate,bookmarks, goto_handle):
|
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
|
||||||
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
||||||
goto_handle)
|
goto_handle)
|
||||||
|
|
||||||
def make_label(self,handle):
|
def make_label(self, handle):
|
||||||
obj = self.dbstate.db.get_object_from_handle(handle)
|
obj = self.dbstate.db.get_object_from_handle(handle)
|
||||||
name = obj.get_description()
|
name = obj.get_description()
|
||||||
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
||||||
@ -355,11 +370,11 @@ class MediaBookmarks(ListBookmarks) :
|
|||||||
class RepoBookmarks(ListBookmarks) :
|
class RepoBookmarks(ListBookmarks) :
|
||||||
"Handle the bookmarks interface for Gramps"
|
"Handle the bookmarks interface for Gramps"
|
||||||
|
|
||||||
def __init__(self,dbstate,uistate,bookmarks, goto_handle):
|
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
|
||||||
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
||||||
goto_handle)
|
goto_handle)
|
||||||
|
|
||||||
def make_label(self,handle):
|
def make_label(self, handle):
|
||||||
obj = self.dbstate.db.get_repository_from_handle(handle)
|
obj = self.dbstate.db.get_repository_from_handle(handle)
|
||||||
name = obj.get_name()
|
name = obj.get_name()
|
||||||
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
||||||
@ -370,11 +385,11 @@ class RepoBookmarks(ListBookmarks) :
|
|||||||
class PlaceBookmarks(ListBookmarks) :
|
class PlaceBookmarks(ListBookmarks) :
|
||||||
"Handle the bookmarks interface for Gramps"
|
"Handle the bookmarks interface for Gramps"
|
||||||
|
|
||||||
def __init__(self,dbstate,uistate,bookmarks, goto_handle):
|
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
|
||||||
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
||||||
goto_handle)
|
goto_handle)
|
||||||
|
|
||||||
def make_label(self,handle):
|
def make_label(self, handle):
|
||||||
obj = self.dbstate.db.get_place_from_handle(handle)
|
obj = self.dbstate.db.get_place_from_handle(handle)
|
||||||
name = obj.get_title()
|
name = obj.get_title()
|
||||||
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
return ("%s [%s]" % (name, obj.gramps_id), obj)
|
||||||
@ -385,11 +400,11 @@ class PlaceBookmarks(ListBookmarks) :
|
|||||||
class NoteBookmarks(ListBookmarks) :
|
class NoteBookmarks(ListBookmarks) :
|
||||||
"Handle the bookmarks interface for Gramps"
|
"Handle the bookmarks interface for Gramps"
|
||||||
|
|
||||||
def __init__(self,dbstate,uistate,bookmarks, goto_handle):
|
def __init__(self, dbstate, uistate, bookmarks, goto_handle):
|
||||||
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
ListBookmarks.__init__(self, dbstate, uistate, bookmarks,
|
||||||
goto_handle)
|
goto_handle)
|
||||||
|
|
||||||
def make_label(self,handle):
|
def make_label(self, handle):
|
||||||
obj = self.dbstate.db.get_note_from_handle(handle)
|
obj = self.dbstate.db.get_note_from_handle(handle)
|
||||||
name = obj.get().replace('\n', ' ')
|
name = obj.get().replace('\n', ' ')
|
||||||
if len(name) > 40:
|
if len(name) > 40:
|
||||||
@ -399,5 +414,5 @@ class NoteBookmarks(ListBookmarks) :
|
|||||||
def connect_signals(self):
|
def connect_signals(self):
|
||||||
self.dbstate.db.connect('note-delete', self.remove_handles)
|
self.dbstate.db.connect('note-delete', self.remove_handles)
|
||||||
|
|
||||||
def make_callback(n,f):
|
def make_callback(n, f):
|
||||||
return lambda x: f(n)
|
return lambda x: f(n)
|
||||||
|
@ -18,16 +18,31 @@
|
|||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
#
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Handle the column ordering
|
||||||
|
"""
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# GTK/Gnome modules
|
# python modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
from gettext import gettext as _
|
||||||
|
import logging
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# GTK modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import gtk.glade
|
import gtk.glade
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# GRAMPS modules
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
import const
|
import const
|
||||||
from gettext import gettext as _
|
|
||||||
|
|
||||||
import ManagedWindow
|
import ManagedWindow
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -35,16 +50,21 @@ import ManagedWindow
|
|||||||
# set up logging
|
# set up logging
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import logging
|
__LOG = logging.getLogger(".ColumnOrder")
|
||||||
log = logging.getLogger(".ColumnOrder")
|
|
||||||
|
|
||||||
class ColumnOrder(ManagedWindow.ManagedWindow):
|
class ColumnOrder(ManagedWindow.ManagedWindow):
|
||||||
|
"""
|
||||||
|
Column ordering selection dialog
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, win_name, uistate, arglist, column_names, callback):
|
def __init__(self, win_name, uistate, arglist, column_names, callback):
|
||||||
|
"""
|
||||||
|
Create the Column Ordering dialog
|
||||||
|
"""
|
||||||
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
|
||||||
|
|
||||||
self.glade = gtk.glade.XML(const.gladeFile,"columns","gramps")
|
self.glade = gtk.glade.XML(const.gladeFile, "columns", "gramps")
|
||||||
|
|
||||||
self.set_window(self.glade.get_widget('columns'), None, win_name)
|
self.set_window(self.glade.get_widget('columns'), None, win_name)
|
||||||
|
|
||||||
@ -57,7 +77,7 @@ class ColumnOrder(ManagedWindow.ManagedWindow):
|
|||||||
self.tree.set_model(self.model)
|
self.tree.set_model(self.model)
|
||||||
|
|
||||||
checkbox = gtk.CellRendererToggle()
|
checkbox = gtk.CellRendererToggle()
|
||||||
checkbox.connect('toggled', self.toggled, self.model)
|
checkbox.connect('toggled', __toggled, self.model)
|
||||||
renderer = gtk.CellRendererText()
|
renderer = gtk.CellRendererText()
|
||||||
|
|
||||||
column_n = gtk.TreeViewColumn(_('Display'), checkbox, active=0)
|
column_n = gtk.TreeViewColumn(_('Display'), checkbox, active=0)
|
||||||
@ -81,25 +101,38 @@ class ColumnOrder(ManagedWindow.ManagedWindow):
|
|||||||
2, item[1],
|
2, item[1],
|
||||||
3, item)
|
3, item)
|
||||||
|
|
||||||
def build_menu_names(self,obj):
|
def build_menu_names(self, obj):
|
||||||
|
"""
|
||||||
|
Build the information for the Managed Window menu entries
|
||||||
|
"""
|
||||||
return (_('Column Editor'), _('Column Editor'))
|
return (_('Column Editor'), _('Column Editor'))
|
||||||
|
|
||||||
def ok_clicked(self,obj):
|
def ok_clicked(self, obj):
|
||||||
|
"""
|
||||||
|
called with the OK button is pressed
|
||||||
|
"""
|
||||||
newlist = []
|
newlist = []
|
||||||
for i in range(0,len(self.arglist)):
|
for i in range(0, len(self.arglist)):
|
||||||
node = self.model.get_iter((int(i),))
|
node = self.model.get_iter((int(i), ))
|
||||||
enable = self.model.get_value(node, 0)
|
enable = self.model.get_value(node, 0)
|
||||||
index = self.model.get_value(node, 2)
|
index = self.model.get_value(node, 2)
|
||||||
value = self.model.get_value(node,3)
|
value = self.model.get_value(node, 3)
|
||||||
newlist.append((enable, index, value[2]))
|
newlist.append((enable, index, value[2]))
|
||||||
|
|
||||||
self.callback(newlist)
|
self.callback(newlist)
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def cancel_clicked(self,obj):
|
def cancel_clicked(self, obj):
|
||||||
|
"""
|
||||||
|
Called with the Cancel button is pressed.
|
||||||
|
"""
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def toggled(self, cell, path, model):
|
def __toggled(cell, path, model):
|
||||||
node = model.get_iter((int(path),))
|
"""
|
||||||
value = not model.get_value(node,0)
|
Called when the cell information is changed, updating the
|
||||||
model.set(node,0,value)
|
data model so the that change occurs.
|
||||||
|
"""
|
||||||
|
node = model.get_iter((int(path), ))
|
||||||
|
value = not model.get_value(node, 0)
|
||||||
|
model.set(node, 0, value)
|
||||||
|
@ -49,7 +49,7 @@ from gettext import gettext as _
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(".DateEdit")
|
__LOG = logging.getLogger(".DateEdit")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -125,9 +125,9 @@ class DateEdit:
|
|||||||
self.button_obj.set_relief(gtk.RELIEF_NORMAL)
|
self.button_obj.set_relief(gtk.RELIEF_NORMAL)
|
||||||
self.pixmap_obj = button_obj.get_child()
|
self.pixmap_obj = button_obj.get_child()
|
||||||
|
|
||||||
self.text_obj.connect('validate',self.validate)
|
self.text_obj.connect('validate', self.validate)
|
||||||
self.text_obj.connect('content-changed',self.set_date)
|
self.text_obj.connect('content-changed', self.set_date)
|
||||||
self.button_obj.connect('clicked',self.invoke_date_editor)
|
self.button_obj.connect('clicked', self.invoke_date_editor)
|
||||||
|
|
||||||
self.text_obj.set_text(DateHandler.displayer.display(self.date_obj))
|
self.text_obj.set_text(DateHandler.displayer.display(self.date_obj))
|
||||||
self.text_obj.validate()
|
self.text_obj.validate()
|
||||||
@ -147,7 +147,7 @@ class DateEdit:
|
|||||||
if self.date_obj.get_modifier() == Date.MOD_TEXTONLY:
|
if self.date_obj.get_modifier() == Date.MOD_TEXTONLY:
|
||||||
return ValidationError(_('Bad Date'))
|
return ValidationError(_('Bad Date'))
|
||||||
|
|
||||||
def invoke_date_editor(self,obj):
|
def invoke_date_editor(self, obj):
|
||||||
"""
|
"""
|
||||||
Invokes Date Editor dialog when the user clicks the Calendar button.
|
Invokes Date Editor dialog when the user clicks the Calendar button.
|
||||||
If date was in fact built, sets the date_obj to the newly built
|
If date was in fact built, sets the date_obj to the newly built
|
||||||
@ -157,7 +157,7 @@ class DateEdit:
|
|||||||
the_date = date_dialog.return_date
|
the_date = date_dialog.return_date
|
||||||
self.update_after_editor(the_date)
|
self.update_after_editor(the_date)
|
||||||
|
|
||||||
def update_after_editor(self,date_obj):
|
def update_after_editor(self, date_obj):
|
||||||
"""
|
"""
|
||||||
Update text entry and validate it
|
Update text entry and validate it
|
||||||
"""
|
"""
|
||||||
@ -200,7 +200,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
self.calendar_box.append_text(name)
|
self.calendar_box.append_text(name)
|
||||||
|
|
||||||
self.calendar_box.set_active(self.date.get_calendar())
|
self.calendar_box.set_active(self.date.get_calendar())
|
||||||
self.calendar_box.connect('changed',self.switch_calendar)
|
self.calendar_box.connect('changed', self.switch_calendar)
|
||||||
|
|
||||||
self.quality_box = self.top.get_widget('quality_box')
|
self.quality_box = self.top.get_widget('quality_box')
|
||||||
for item_number in range(len(QUAL_TEXT)):
|
for item_number in range(len(QUAL_TEXT)):
|
||||||
@ -213,7 +213,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
self.type_box.append_text(MOD_TEXT[item_number][1])
|
self.type_box.append_text(MOD_TEXT[item_number][1])
|
||||||
if self.date.get_modifier() == MOD_TEXT[item_number][0]:
|
if self.date.get_modifier() == MOD_TEXT[item_number][0]:
|
||||||
self.type_box.set_active(item_number)
|
self.type_box.set_active(item_number)
|
||||||
self.type_box.connect('changed',self.switch_type)
|
self.type_box.connect('changed', self.switch_type)
|
||||||
|
|
||||||
self.start_month_box = self.top.get_widget('start_month_box')
|
self.start_month_box = self.top.get_widget('start_month_box')
|
||||||
self.stop_month_box = self.top.get_widget('stop_month_box')
|
self.stop_month_box = self.top.get_widget('stop_month_box')
|
||||||
@ -267,8 +267,8 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
(the_quality,the_modifier,the_calendar,
|
(the_quality, the_modifier, the_calendar,
|
||||||
the_value,the_text) = self.build_date_from_ui()
|
the_value, the_text) = self.build_date_from_ui()
|
||||||
self.return_date = Date(self.date)
|
self.return_date = Date(self.date)
|
||||||
self.return_date.set(
|
self.return_date.set(
|
||||||
quality=the_quality,
|
quality=the_quality,
|
||||||
@ -298,12 +298,12 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
text = self.text_entry.get_text()
|
text = self.text_entry.get_text()
|
||||||
|
|
||||||
if modifier == Date.MOD_TEXTONLY:
|
if modifier == Date.MOD_TEXTONLY:
|
||||||
return (Date.QUAL_NONE,Date.MOD_TEXTONLY,Date.CAL_GREGORIAN,
|
return (Date.QUAL_NONE, Date.MOD_TEXTONLY, Date.CAL_GREGORIAN,
|
||||||
Date.EMPTY,text)
|
Date.EMPTY,text)
|
||||||
|
|
||||||
quality = QUAL_TEXT[self.quality_box.get_active()][0]
|
quality = QUAL_TEXT[self.quality_box.get_active()][0]
|
||||||
|
|
||||||
if modifier in (Date.MOD_RANGE,Date.MOD_SPAN):
|
if modifier in (Date.MOD_RANGE, Date.MOD_SPAN):
|
||||||
value = (
|
value = (
|
||||||
self.start_day.get_value_as_int(),
|
self.start_day.get_value_as_int(),
|
||||||
self.start_month_box.get_active(),
|
self.start_month_box.get_active(),
|
||||||
@ -320,9 +320,9 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
self.start_year.get_value_as_int(),
|
self.start_year.get_value_as_int(),
|
||||||
False)
|
False)
|
||||||
calendar = self.calendar_box.get_active()
|
calendar = self.calendar_box.get_active()
|
||||||
return (quality,modifier,calendar,value,text)
|
return (quality, modifier, calendar, value, text)
|
||||||
|
|
||||||
def switch_type(self,obj):
|
def switch_type(self, obj):
|
||||||
"""
|
"""
|
||||||
Disable/enable various date controls depending on the date
|
Disable/enable various date controls depending on the date
|
||||||
type selected via the menu.
|
type selected via the menu.
|
||||||
@ -332,7 +332,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
|
|
||||||
# Disable/enable second date controls based on whether
|
# Disable/enable second date controls based on whether
|
||||||
# the type allows compound dates
|
# the type allows compound dates
|
||||||
if the_modifier in (Date.MOD_RANGE,Date.MOD_SPAN):
|
if the_modifier in (Date.MOD_RANGE, Date.MOD_SPAN):
|
||||||
stop_date_sensitivity = 1
|
stop_date_sensitivity = 1
|
||||||
else:
|
else:
|
||||||
stop_date_sensitivity = 0
|
stop_date_sensitivity = 0
|
||||||
@ -348,7 +348,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
self.calendar_box.set_sensitive(date_sensitivity)
|
self.calendar_box.set_sensitive(date_sensitivity)
|
||||||
self.quality_box.set_sensitive(date_sensitivity)
|
self.quality_box.set_sensitive(date_sensitivity)
|
||||||
|
|
||||||
def switch_calendar(self,obj):
|
def switch_calendar(self, obj):
|
||||||
"""
|
"""
|
||||||
Change month names and convert the date based on the calendar
|
Change month names and convert the date based on the calendar
|
||||||
selected via the menu.
|
selected via the menu.
|
||||||
@ -357,7 +357,7 @@ class DateEditorDialog(ManagedWindow.ManagedWindow):
|
|||||||
old_cal = self.date.get_calendar()
|
old_cal = self.date.get_calendar()
|
||||||
new_cal = self.calendar_box.get_active()
|
new_cal = self.calendar_box.get_active()
|
||||||
|
|
||||||
(the_quality,the_modifier,the_calendar,the_value,the_text) = \
|
(the_quality, the_modifier, the_calendar, the_value, the_text) = \
|
||||||
self.build_date_from_ui()
|
self.build_date_from_ui()
|
||||||
self.date.set(
|
self.date.set(
|
||||||
quality=the_quality,
|
quality=the_quality,
|
||||||
|
119
src/DbLoader.py
119
src/DbLoader.py
@ -31,10 +31,17 @@ Handling of loading new/existing databases.
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from bsddb.db import DBAccessError, DBRunRecoveryError, DBPageNotFoundError, DBInvalidArgError
|
from bsddb.db import DBAccessError, DBRunRecoveryError, \
|
||||||
|
DBPageNotFoundError, DBInvalidArgError
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(".")
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Set up logging
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
__LOG = logging.getLogger(".")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -68,13 +75,15 @@ _KNOWN_FORMATS = {
|
|||||||
const.app_gedcom : _('GEDCOM'),
|
const.app_gedcom : _('GEDCOM'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__OPEN_FORMATS = [const.app_gramps, const.app_gramps_xml, const.app_gedcom]
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# DbLoader class
|
# DbLoader class
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class DbLoader:
|
class DbLoader:
|
||||||
def __init__(self,dbstate,uistate):
|
def __init__(self, dbstate, uistate):
|
||||||
self.dbstate = dbstate
|
self.dbstate = dbstate
|
||||||
self.uistate = uistate
|
self.uistate = uistate
|
||||||
|
|
||||||
@ -92,9 +101,7 @@ class DbLoader:
|
|||||||
add_xml_filter(choose)
|
add_xml_filter(choose)
|
||||||
add_gedcom_filter(choose)
|
add_gedcom_filter(choose)
|
||||||
|
|
||||||
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
|
(box, type_selector) = format_maker(__OPEN_FORMATS)
|
||||||
|
|
||||||
(box, type_selector) = format_maker(format_list)
|
|
||||||
choose.set_extra_widget(box)
|
choose.set_extra_widget(box)
|
||||||
|
|
||||||
choose.set_current_folder(get_default_dir())
|
choose.set_current_folder(get_default_dir())
|
||||||
@ -110,31 +117,29 @@ class DbLoader:
|
|||||||
filetype = Mime.get_type(filename)
|
filetype = Mime.get_type(filename)
|
||||||
(the_path, the_file) = os.path.split(filename)
|
(the_path, the_file) = os.path.split(filename)
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
if filetype in [const.app_gramps,const.app_gramps_xml,
|
if filetype in __OPEN_FORMATS:
|
||||||
const.app_gedcom]:
|
self.read_file(filename, filetype)
|
||||||
|
|
||||||
self.read_file(filename,filetype)
|
|
||||||
try:
|
try:
|
||||||
os.chdir(os.path.dirname(filename))
|
os.chdir(os.path.dirname(filename))
|
||||||
except:
|
except:
|
||||||
return ('','')
|
return ('', '')
|
||||||
return (filename,filetype)
|
return (filename, filetype)
|
||||||
elif filetype in [const.app_gramps_package,const.app_geneweb]:
|
elif filetype in [const.app_gramps_package, const.app_geneweb]:
|
||||||
QuestionDialog.ErrorDialog(
|
QuestionDialog.ErrorDialog(
|
||||||
_("Could not open file: %s") % filename,
|
_("Could not open file: %s") % filename,
|
||||||
_('Files of type "%s" cannot be opened directly.\n\n'
|
_('Files of type "%s" cannot be opened directly.\n\n'
|
||||||
'Please create a new GRAMPS database and import '
|
'Please create a new GRAMPS database and import '
|
||||||
'the file.') % filetype)
|
'the file.') % filetype)
|
||||||
return ('','')
|
return ('', '')
|
||||||
else:
|
else:
|
||||||
QuestionDialog.ErrorDialog(
|
QuestionDialog.ErrorDialog(
|
||||||
_("Could not open file: %s") % filename,
|
_("Could not open file: %s") % filename,
|
||||||
_('File type "%s" is unknown to GRAMPS.\n\n'
|
_('File type "%s" is unknown to GRAMPS.\n\n'
|
||||||
'Valid types are: GRAMPS database, GRAMPS XML, '
|
'Valid types are: GRAMPS database, GRAMPS XML, '
|
||||||
'GRAMPS package, and GEDCOM.') % filetype)
|
'GRAMPS package, and GEDCOM.') % filetype)
|
||||||
return ('','')
|
return ('', '')
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
return ('','')
|
return ('', '')
|
||||||
|
|
||||||
def new_file(self):
|
def new_file(self):
|
||||||
choose = gtk.FileChooserDialog(
|
choose = gtk.FileChooserDialog(
|
||||||
@ -179,19 +184,19 @@ class DbLoader:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.read_file(filename,filetype)
|
self.read_file(filename, filetype)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.chdir(os.path.dirname(filename))
|
os.chdir(os.path.dirname(filename))
|
||||||
except:
|
except:
|
||||||
return ('','')
|
return ('', '')
|
||||||
self.dbstate.db.db_is_open = True
|
self.dbstate.db.db_is_open = True
|
||||||
return (filename,filetype)
|
return (filename, filetype)
|
||||||
else:
|
else:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
return ('','')
|
return ('', '')
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
return ('','')
|
return ('', '')
|
||||||
|
|
||||||
def save_as(self):
|
def save_as(self):
|
||||||
choose = gtk.FileChooserDialog(
|
choose = gtk.FileChooserDialog(
|
||||||
@ -208,8 +213,7 @@ class DbLoader:
|
|||||||
add_xml_filter(choose)
|
add_xml_filter(choose)
|
||||||
add_gedcom_filter(choose)
|
add_gedcom_filter(choose)
|
||||||
|
|
||||||
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
|
(box, type_selector) = format_maker(__OPEN_FORMATS)
|
||||||
(box, type_selector) = format_maker(format_list)
|
|
||||||
choose.set_extra_widget(box)
|
choose.set_extra_widget(box)
|
||||||
|
|
||||||
default_dir = get_default_dir()
|
default_dir = get_default_dir()
|
||||||
@ -242,17 +246,15 @@ class DbLoader:
|
|||||||
str(msg))
|
str(msg))
|
||||||
return ('','')
|
return ('','')
|
||||||
# First we try our best formats
|
# First we try our best formats
|
||||||
if filetype not in (const.app_gramps,
|
if filetype not in _OPEN_FORMATS:
|
||||||
const.app_gramps_xml,
|
|
||||||
const.app_gedcom):
|
|
||||||
QuestionDialog.ErrorDialog(
|
QuestionDialog.ErrorDialog(
|
||||||
_("Could not open file: %s") % filename,
|
_("Could not open file: %s") % filename,
|
||||||
_("Unknown type: %s") % filetype
|
_("Unknown type: %s") % filetype
|
||||||
)
|
)
|
||||||
return ('','')
|
return ('','')
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
self.open_saved_as(filename,filetype)
|
self.open_saved_as(filename, filetype)
|
||||||
return (filename,filetype)
|
return (filename, filetype)
|
||||||
else:
|
else:
|
||||||
choose.destroy()
|
choose.destroy()
|
||||||
return ('','')
|
return ('','')
|
||||||
@ -288,7 +290,7 @@ class DbLoader:
|
|||||||
add_xml_filter(choose)
|
add_xml_filter(choose)
|
||||||
add_gedcom_filter(choose)
|
add_gedcom_filter(choose)
|
||||||
|
|
||||||
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
|
format_list = _OPEN_FORMATS
|
||||||
|
|
||||||
# Add more data type selections if opening existing db
|
# Add more data type selections if opening existing db
|
||||||
for data in import_list:
|
for data in import_list:
|
||||||
@ -334,17 +336,15 @@ class DbLoader:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# First we try our best formats
|
# First we try our best formats
|
||||||
if filetype in (const.app_gramps,
|
if filetype in _OPEN_FORMATS:
|
||||||
const.app_gramps_xml,
|
|
||||||
const.app_gedcom):
|
|
||||||
importer = GrampsDbUtils.gramps_db_reader_factory(filetype)
|
importer = GrampsDbUtils.gramps_db_reader_factory(filetype)
|
||||||
self.do_import(choose, importer, filename)
|
self.do_import(choose, importer, filename)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Then we try all the known plugins
|
# Then we try all the known plugins
|
||||||
(the_path, the_file) = os.path.split(filename)
|
(the_path, the_file) = os.path.split(filename)
|
||||||
Config.set(Config.RECENT_IMPORT_DIR,the_path)
|
Config.set(Config.RECENT_IMPORT_DIR, the_path)
|
||||||
for (importData,mime_filter,mime_type,native_format,format_name) \
|
for (importData, mime_filter, mime_type, native_format, format_name) \
|
||||||
in import_list:
|
in import_list:
|
||||||
if filetype == mime_type or the_file == mime_type:
|
if filetype == mime_type or the_file == mime_type:
|
||||||
self.do_import(choose, importData, filename)
|
self.do_import(choose, importData, filename)
|
||||||
@ -360,13 +360,13 @@ class DbLoader:
|
|||||||
choose.destroy()
|
choose.destroy()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_errors(self,filename):
|
def check_errors(self, filename):
|
||||||
"""
|
"""
|
||||||
This methods runs common error checks and returns True if any found.
|
This methods runs common error checks and returns True if any found.
|
||||||
In this process, warning dialog can pop up.
|
In this process, warning dialog can pop up.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if type(filename) not in (str,unicode):
|
if type(filename) not in (str, unicode):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
filename = os.path.normpath(os.path.abspath(filename))
|
filename = os.path.normpath(os.path.abspath(filename))
|
||||||
@ -447,31 +447,31 @@ class DbLoader:
|
|||||||
self.uistate.progress.show()
|
self.uistate.progress.show()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.dbstate.db.load(filename,self.uistate.pulse_progressbar,mode)
|
self.dbstate.db.load(filename, self.uistate.pulse_progressbar, mode)
|
||||||
self.dbstate.db.set_save_path(filename)
|
self.dbstate.db.set_save_path(filename)
|
||||||
try:
|
try:
|
||||||
os.chdir(os.path.dirname(filename))
|
os.chdir(os.path.dirname(filename))
|
||||||
except:
|
except:
|
||||||
print "could not change directory"
|
print "could not change directory"
|
||||||
except OSError, msg:
|
except OSError, msg:
|
||||||
QuestionDialog.ErrorDialog(
|
QuestionDialog.ErrorDialog(
|
||||||
_("Could not open file: %s") % filename, str(msg))
|
_("Could not open file: %s") % filename, str(msg))
|
||||||
except DBRunRecoveryError, msg:
|
except DBRunRecoveryError, msg:
|
||||||
QuestionDialog.ErrorDialog(
|
QuestionDialog.ErrorDialog(
|
||||||
_("Low level database corruption detected"),
|
_("Low level database corruption detected"),
|
||||||
_("GRAMPS has detected a problem in the underlying "
|
_("GRAMPS has detected a problem in the underlying "
|
||||||
"Berkeley database. Please exit the program, and GRAMPS "
|
"Berkeley database. Please exit the program, and GRAMPS "
|
||||||
"will attempt to run the recovery repair operation "
|
"will attempt to run the recovery repair operation "
|
||||||
"the next time you open this database. If this "
|
"the next time you open this database. If this "
|
||||||
"problem persists, create a new database, import "
|
"problem persists, create a new database, import "
|
||||||
"from a backup database, and report the problem to "
|
"from a backup database, and report the problem to "
|
||||||
"gramps-bugs@lists.sourceforge.net."))
|
"gramps-bugs@lists.sourceforge.net."))
|
||||||
except (DBAccessError, DBPageNotFoundError,DBInvalidArgError), msg:
|
except (DBAccessError, DBPageNotFoundError, DBInvalidArgError), msg:
|
||||||
QuestionDialog.ErrorDialog(
|
QuestionDialog.ErrorDialog(
|
||||||
_("Could not open file: %s") % filename,
|
_("Could not open file: %s") % filename,
|
||||||
str(msg[1]))
|
str(msg[1]))
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("Failed to open database.", exc_info=True)
|
__LOG.error("Failed to open database.", exc_info=True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -489,11 +489,11 @@ class DbLoader:
|
|||||||
self.uistate.progress.show()
|
self.uistate.progress.show()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
new_database.load_from(old_database,filename,
|
new_database.load_from(old_database, filename,
|
||||||
self.uistate.pulse_progressbar)
|
self.uistate.pulse_progressbar)
|
||||||
old_database.close()
|
old_database.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("Failed to open database.", exc_info=True)
|
__LOG.error("Failed to open database.", exc_info=True)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def do_import(self, dialog, importer, filename):
|
def do_import(self, dialog, importer, filename):
|
||||||
@ -504,9 +504,9 @@ class DbLoader:
|
|||||||
try:
|
try:
|
||||||
importer(self.dbstate.db, filename, self.uistate.pulse_progressbar)
|
importer(self.dbstate.db, filename, self.uistate.pulse_progressbar)
|
||||||
dirname = os.path.dirname(filename) + os.path.sep
|
dirname = os.path.dirname(filename) + os.path.sep
|
||||||
Config.set(Config.RECENT_IMPORT_DIR,dirname)
|
Config.set(Config.RECENT_IMPORT_DIR, dirname)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("Failed to import database.", exc_info=True)
|
__LOG.error("Failed to import database.", exc_info=True)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -549,9 +549,8 @@ def add_gramps_files_filter(chooser):
|
|||||||
"""
|
"""
|
||||||
mime_filter = gtk.FileFilter()
|
mime_filter = gtk.FileFilter()
|
||||||
mime_filter.set_name(_('All GRAMPS files'))
|
mime_filter.set_name(_('All GRAMPS files'))
|
||||||
mime_filter.add_mime_type(const.app_gramps)
|
for fmt in __OPEN_FORMATS:
|
||||||
mime_filter.add_mime_type(const.app_gramps_xml)
|
mime_filter.add_mime_type(fmt)
|
||||||
mime_filter.add_mime_type(const.app_gedcom)
|
|
||||||
chooser.add_filter(mime_filter)
|
chooser.add_filter(mime_filter)
|
||||||
|
|
||||||
def add_grdb_filter(chooser):
|
def add_grdb_filter(chooser):
|
||||||
|
@ -20,6 +20,11 @@
|
|||||||
|
|
||||||
# $Id: DisplayState.py 6085 2006-03-05 23:39:20Z dallingham $
|
# $Id: DisplayState.py 6085 2006-03-05 23:39:20Z dallingham $
|
||||||
|
|
||||||
|
"""
|
||||||
|
Provides the managed window interface, which allows GRAMPS to track
|
||||||
|
the create/deletion of dialog windows.
|
||||||
|
"""
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Standard python modules
|
# Standard python modules
|
||||||
@ -77,7 +82,7 @@ class GrampsWindowManager:
|
|||||||
Lookup can be also done by ID for windows that are identifiable.
|
Lookup can be also done by ID for windows that are identifiable.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,uimanager):
|
def __init__(self, uimanager):
|
||||||
# initialize empty tree and lookup dictionary
|
# initialize empty tree and lookup dictionary
|
||||||
self.uimanager = uimanager
|
self.uimanager = uimanager
|
||||||
self.window_tree = []
|
self.window_tree = []
|
||||||
@ -103,31 +108,31 @@ class GrampsWindowManager:
|
|||||||
self.active = self.uimanager.add_ui_from_string(self.ui)
|
self.active = self.uimanager.add_ui_from_string(self.ui)
|
||||||
self.uimanager.ensure_update()
|
self.uimanager.ensure_update()
|
||||||
|
|
||||||
def get_item_from_track(self,track):
|
def get_item_from_track(self, track):
|
||||||
# Recursively find an item given track sequence
|
# Recursively find an item given track sequence
|
||||||
item = self.window_tree
|
item = self.window_tree
|
||||||
for index in track:
|
for index in track:
|
||||||
item = item[index]
|
item = item[index]
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def get_item_from_id(self,item_id):
|
def get_item_from_id(self, item_id):
|
||||||
# Find an item given its ID
|
# Find an item given its ID
|
||||||
# Return None if the ID is not found
|
# Return None if the ID is not found
|
||||||
return self.id2item.get(item_id,None)
|
return self.id2item.get(item_id, None)
|
||||||
|
|
||||||
def close_track(self,track):
|
def close_track(self, track):
|
||||||
# This is called when item needs to be closed
|
# This is called when item needs to be closed
|
||||||
# Closes all its children and then removes the item from the tree.
|
# Closes all its children and then removes the item from the tree.
|
||||||
try:
|
try:
|
||||||
item = self.get_item_from_track(track)
|
item = self.get_item_from_track(track)
|
||||||
self.recursive_action(item,self.close_item)
|
self.recursive_action(item, self.close_item)
|
||||||
# This only needs to be run once for the highest level point
|
# This only needs to be run once for the highest level point
|
||||||
# to remove.
|
# to remove.
|
||||||
self.remove_item(track)
|
self.remove_item(track)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print "Missing item from window manager", track, self.close_item
|
print "Missing item from window manager", track, self.close_item
|
||||||
|
|
||||||
def recursive_action(self,item,func,*args):
|
def recursive_action(self, item, func, *args):
|
||||||
# This function recursively calls itself over the child items
|
# This function recursively calls itself over the child items
|
||||||
# starting with the given item.
|
# starting with the given item.
|
||||||
# Eventualy, every non-list item (leaf) will be reached
|
# Eventualy, every non-list item (leaf) will be reached
|
||||||
@ -136,23 +141,23 @@ class GrampsWindowManager:
|
|||||||
# If this item is a branch
|
# If this item is a branch
|
||||||
# close the children except for the first one
|
# close the children except for the first one
|
||||||
for sub_item in item[1:]:
|
for sub_item in item[1:]:
|
||||||
self.recursive_action(sub_item,func,*args)
|
self.recursive_action(sub_item, func, *args)
|
||||||
# return the first child
|
# return the first child
|
||||||
last_item = item[0]
|
last_item = item[0]
|
||||||
else:
|
else:
|
||||||
# This item is a leaf -- no children to close
|
# This item is a leaf -- no children to close
|
||||||
# return itself
|
# return itself
|
||||||
last_item = item
|
last_item = item
|
||||||
func(last_item,*args)
|
func(last_item, *args)
|
||||||
|
|
||||||
def close_item(self,item,*args):
|
def close_item(self, item, *args):
|
||||||
# Given an item, close its window and remove it's ID from the dict
|
# Given an item, close its window and remove it's ID from the dict
|
||||||
if item.window_id:
|
if item.window_id:
|
||||||
del self.id2item[item.window_id]
|
del self.id2item[item.window_id]
|
||||||
if item.window:
|
if item.window:
|
||||||
item.window.destroy()
|
item.window.destroy()
|
||||||
|
|
||||||
def remove_item(self,track):
|
def remove_item(self, track):
|
||||||
# We need the whole gymnastics below because our item
|
# We need the whole gymnastics below because our item
|
||||||
# may actually be a list consisting of a single real
|
# may actually be a list consisting of a single real
|
||||||
# item and empty lists.
|
# item and empty lists.
|
||||||
@ -166,19 +171,19 @@ class GrampsWindowManager:
|
|||||||
parent_item.pop(child_in_parent)
|
parent_item.pop(child_in_parent)
|
||||||
# Adjust each item following the removed one
|
# Adjust each item following the removed one
|
||||||
# so that it's track is down by one on this level
|
# so that it's track is down by one on this level
|
||||||
for ix in range(child_in_parent,len(parent_item)):
|
for ix in range(child_in_parent, len(parent_item)):
|
||||||
item = parent_item[ix]
|
item = parent_item[ix]
|
||||||
self.recursive_action(item,self.move_item_down,len(track)-1)
|
self.recursive_action(item, self.move_item_down, len(track)-1)
|
||||||
# Rebuild menu
|
# Rebuild menu
|
||||||
self.build_windows_menu()
|
self.build_windows_menu()
|
||||||
|
|
||||||
def move_item_down(self,item,*args):
|
def move_item_down(self, item, *args):
|
||||||
# Given an item and an index, adjust the item's track
|
# Given an item and an index, adjust the item's track
|
||||||
# by subtracting 1 from that index's level
|
# by subtracting 1 from that index's level
|
||||||
index = args[0]
|
index = args[0]
|
||||||
item.track[index] -= 1
|
item.track[index] -= 1
|
||||||
|
|
||||||
def add_item(self,track,item):
|
def add_item(self, track, item):
|
||||||
# if the item is identifiable then we need to remember
|
# if the item is identifiable then we need to remember
|
||||||
# its id so that in the future we recall this window
|
# its id so that in the future we recall this window
|
||||||
# instead of spawning a new one
|
# instead of spawning a new one
|
||||||
@ -208,45 +213,45 @@ class GrampsWindowManager:
|
|||||||
new_track = track + [len(parent_item)-1]
|
new_track = track + [len(parent_item)-1]
|
||||||
return new_track
|
return new_track
|
||||||
|
|
||||||
def call_back_factory(self,item):
|
def call_back_factory(self, item):
|
||||||
if type(item) != list:
|
if type(item) != list:
|
||||||
def f(obj):
|
def func(obj):
|
||||||
if item.window_id and self.id2item.get(item.window_id):
|
if item.window_id and self.id2item.get(item.window_id):
|
||||||
self.id2item[item.window_id].present()
|
self.id2item[item.window_id].present()
|
||||||
else:
|
else:
|
||||||
def f(obj):
|
def func(obj):
|
||||||
pass
|
pass
|
||||||
return f
|
return func
|
||||||
|
|
||||||
def generate_id(self,item):
|
def generate_id(self, item):
|
||||||
return str(item.window_id)
|
return str(item.window_id)
|
||||||
|
|
||||||
def display_menu_list(self,data,action_data,mlist):
|
def display_menu_list(self, data, action_data, mlist):
|
||||||
if type(mlist) in (list,tuple):
|
if type(mlist) in (list, tuple):
|
||||||
i = mlist[0]
|
i = mlist[0]
|
||||||
idval = self.generate_id(i)
|
idval = self.generate_id(i)
|
||||||
data.write('<menu action="M:%s">' % idval)
|
data.write('<menu action="M:%s">' % idval)
|
||||||
action_data.append(("M:"+idval,None,i.submenu_label,
|
action_data.append(("M:"+idval, None, i.submenu_label,
|
||||||
None,None,None))
|
None, None, None))
|
||||||
else:
|
else:
|
||||||
i = mlist
|
i = mlist
|
||||||
idval = self.generate_id(i)
|
idval = self.generate_id(i)
|
||||||
|
|
||||||
data.write('<menuitem action="%s"/>' % idval)
|
data.write('<menuitem action="%s"/>' % idval)
|
||||||
action_data.append((idval,None,i.menu_label,None,None,
|
action_data.append((idval, None, i.menu_label, None, None,
|
||||||
self.call_back_factory(i)))
|
self.call_back_factory(i)))
|
||||||
|
|
||||||
if (type(mlist) in (list,tuple)) and (len(mlist) > 1):
|
if (type(mlist) in (list, tuple)) and (len(mlist) > 1):
|
||||||
for i in mlist[1:]:
|
for i in mlist[1:]:
|
||||||
if type(i) == list:
|
if type(i) == list:
|
||||||
self.display_menu_list(data,action_data,i)
|
self.display_menu_list(data, action_data, i)
|
||||||
else:
|
else:
|
||||||
idval = self.generate_id(i)
|
idval = self.generate_id(i)
|
||||||
data.write('<menuitem action="%s"/>'
|
data.write('<menuitem action="%s"/>'
|
||||||
% self.generate_id(i))
|
% self.generate_id(i))
|
||||||
action_data.append((idval,None,i.menu_label,None,None,
|
action_data.append((idval, None, i.menu_label, None, None,
|
||||||
self.call_back_factory(i)))
|
self.call_back_factory(i)))
|
||||||
if type(mlist) in (list,tuple):
|
if type(mlist) in (list, tuple):
|
||||||
data.write('</menu>')
|
data.write('</menu>')
|
||||||
|
|
||||||
def build_windows_menu(self):
|
def build_windows_menu(self):
|
||||||
@ -260,7 +265,7 @@ class GrampsWindowManager:
|
|||||||
data = StringIO()
|
data = StringIO()
|
||||||
data.write(_win_top)
|
data.write(_win_top)
|
||||||
for i in self.window_tree:
|
for i in self.window_tree:
|
||||||
self.display_menu_list(data,action_data,i)
|
self.display_menu_list(data, action_data, i)
|
||||||
data.write(_win_btm)
|
data.write(_win_btm)
|
||||||
self.ui = data.getvalue()
|
self.ui = data.getvalue()
|
||||||
data.close()
|
data.close()
|
||||||
@ -307,7 +312,7 @@ class ManagedWindow:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
window_key = self.build_window_key(obj)
|
window_key = self.build_window_key(obj)
|
||||||
menu_label,submenu_label = self.build_menu_names(obj)
|
menu_label, submenu_label = self.build_menu_names(obj)
|
||||||
self._gladeobj = None
|
self._gladeobj = None
|
||||||
|
|
||||||
if uistate.gwm.get_item_from_id(window_key):
|
if uistate.gwm.get_item_from_id(window_key):
|
||||||
@ -318,7 +323,7 @@ class ManagedWindow:
|
|||||||
self.submenu_label = submenu_label
|
self.submenu_label = submenu_label
|
||||||
self.menu_label = menu_label
|
self.menu_label = menu_label
|
||||||
self.uistate = uistate
|
self.uistate = uistate
|
||||||
self.track = self.uistate.gwm.add_item(track,self)
|
self.track = self.uistate.gwm.add_item(track, self)
|
||||||
# Work out parent_window
|
# Work out parent_window
|
||||||
if len(self.track) > 1:
|
if len(self.track) > 1:
|
||||||
# We don't belong to the lop level
|
# We don't belong to the lop level
|
||||||
@ -340,15 +345,15 @@ class ManagedWindow:
|
|||||||
# On the top level: we use gramps top window
|
# On the top level: we use gramps top window
|
||||||
self.parent_window = self.uistate.window
|
self.parent_window = self.uistate.window
|
||||||
|
|
||||||
def set_window(self,window,title,text,msg=None):
|
def set_window(self, window, title, text, msg=None):
|
||||||
set_titles(window, title, text, msg)
|
set_titles(window, title, text, msg)
|
||||||
self.window = window
|
self.window = window
|
||||||
self.window.connect('delete-event', self.close)
|
self.window.connect('delete-event', self.close)
|
||||||
|
|
||||||
def build_menu_names(self,obj):
|
def build_menu_names(self, obj):
|
||||||
return ('Undefined Menu','Undefined Submenu')
|
return ('Undefined Menu','Undefined Submenu')
|
||||||
|
|
||||||
def build_window_key(self,obj):
|
def build_window_key(self, obj):
|
||||||
return id(obj)
|
return id(obj)
|
||||||
|
|
||||||
def define_glade(self, top_module, glade_file=None):
|
def define_glade(self, top_module, glade_file=None):
|
||||||
@ -363,7 +368,7 @@ class ManagedWindow:
|
|||||||
|
|
||||||
def connect_button(self, button_name, function):
|
def connect_button(self, button_name, function):
|
||||||
assert(self._gladeobj)
|
assert(self._gladeobj)
|
||||||
self.get_widget(button_name).connect('clicked',function)
|
self.get_widget(button_name).connect('clicked', function)
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
assert self.window, "ManagedWindow: self.window does not exist!"
|
assert self.window, "ManagedWindow: self.window does not exist!"
|
||||||
@ -371,7 +376,7 @@ class ManagedWindow:
|
|||||||
self.opened = True
|
self.opened = True
|
||||||
self.window.show_all()
|
self.window.show_all()
|
||||||
|
|
||||||
def close(self,*obj):
|
def close(self, *obj):
|
||||||
"""
|
"""
|
||||||
Close itself.
|
Close itself.
|
||||||
|
|
||||||
@ -393,12 +398,12 @@ class ManagedWindow:
|
|||||||
# Helper functions
|
# Helper functions
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def set_titles(window,title,t,msg=None):
|
def set_titles(window, title, text, msg=None):
|
||||||
if title:
|
if title:
|
||||||
title.set_text('<span weight="bold" size="larger">%s</span>' % t)
|
title.set_text('<span weight="bold" size="larger">%s</span>' % text)
|
||||||
title.set_use_markup(True)
|
title.set_use_markup(True)
|
||||||
if msg:
|
if msg:
|
||||||
window.set_title('%s - GRAMPS' % msg)
|
window.set_title('%s - GRAMPS' % msg)
|
||||||
else:
|
else:
|
||||||
window.set_title('%s - GRAMPS' % t)
|
window.set_title('%s - GRAMPS' % text)
|
||||||
window.set_icon_from_file(const.icon)
|
window.set_icon_from_file(const.icon)
|
||||||
|
Loading…
Reference in New Issue
Block a user