* src/GrampsBSDDB.py: first pass of readonly support
* src/GrampsInMem.py: first pass of readonly support * src/GrampsGEDDB.py: first pass of readonly support * src/GrampsXMLDB.py: first pass of readonly support * src/gramps.py: first pass of readonly support * src/FamilyView.py: first pass of readonly support * src/EditPerson.py: first pass of readonly support * src/EditPlace.py: first pass of readonly support * src/EditSource.py: first pass of readonly support * src/gramps.glade: assign names to buttons svn: r4041
This commit is contained in:
parent
c193912063
commit
5ce24ad90a
10
ChangeLog
10
ChangeLog
@ -3,6 +3,16 @@
|
||||
field, not 'hpages'
|
||||
|
||||
2005-02-16 Don Allingham <dallingham@users.sourceforge.net>
|
||||
* src/GrampsBSDDB.py: first pass of readonly support
|
||||
* src/GrampsInMem.py: first pass of readonly support
|
||||
* src/GrampsGEDDB.py: first pass of readonly support
|
||||
* src/GrampsXMLDB.py: first pass of readonly support
|
||||
* src/gramps.py: first pass of readonly support
|
||||
* src/FamilyView.py: first pass of readonly support
|
||||
* src/EditPerson.py: first pass of readonly support
|
||||
* src/EditPlace.py: first pass of readonly support
|
||||
* src/EditSource.py: first pass of readonly support
|
||||
* src/gramps.glade: assign names to buttons
|
||||
* src/DisplayModels.py: don't override on_row_deleted
|
||||
|
||||
2005-02-16 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||
|
@ -279,8 +279,9 @@ class EditPerson:
|
||||
'Place' : (_('Place'),-1,100)
|
||||
}
|
||||
|
||||
values = self.db.metadata.get('event_order')
|
||||
if not values:
|
||||
if not self.db.readonly:
|
||||
values = self.db.metadata.get('event_order',event_default)
|
||||
else:
|
||||
values = event_default
|
||||
|
||||
etitles = []
|
||||
@ -469,6 +470,9 @@ class EditPerson:
|
||||
self.get_widget("notebook").set_current_page(0)
|
||||
self.given.grab_focus()
|
||||
self.add_itself_to_winsmenu()
|
||||
|
||||
self.get_widget('ok').set_sensitive(not self.db.readonly)
|
||||
|
||||
self.window.show()
|
||||
|
||||
def image_button_press(self,obj,event):
|
||||
@ -543,7 +547,8 @@ class EditPerson:
|
||||
event_list = []
|
||||
for col in self.event_list.get_columns():
|
||||
event_list.append(self.event_trans.find_key(col.get_title()))
|
||||
self.db.metadata['event_order'] = event_list
|
||||
if not self.db.readonly:
|
||||
self.db.metadata['event_order'] = event_list
|
||||
|
||||
self.gallery.close()
|
||||
self.close_child_windows()
|
||||
|
@ -222,6 +222,7 @@ class EditPlace:
|
||||
if parent_window:
|
||||
self.top.set_transient_for(parent_window)
|
||||
self.add_itself_to_menu()
|
||||
self.top_window.get_widget('ok').set_sensitive(not self.db.readonly)
|
||||
self.top.show()
|
||||
|
||||
def on_delete_event(self,obj,b):
|
||||
|
@ -181,6 +181,8 @@ class EditSource:
|
||||
focus_cell=None,
|
||||
start_editing=True)
|
||||
|
||||
self.top_window.get_widget('ok').set_sensitive(not self.db.readonly)
|
||||
|
||||
def on_delete_data_clicked(self,widget):
|
||||
(model,node) = self.data_sel.get_selected()
|
||||
if node:
|
||||
|
@ -178,6 +178,7 @@ class FamilyView:
|
||||
self.ap_parents_clicked)
|
||||
self.top.get_widget('sp_parents_btn').connect('clicked',
|
||||
self.sp_parents_clicked)
|
||||
|
||||
self.parent.views.get_nth_page(1).show_all()
|
||||
if self.parent.views.get_current_page() == 2:
|
||||
self.parent.views.set_current_page(1)
|
||||
@ -921,9 +922,31 @@ class FamilyView:
|
||||
self.ap_model.clear()
|
||||
self.child_model = DisplayModels.ChildModel([],self.parent.db)
|
||||
self.child_list.set_model(self.child_model)
|
||||
|
||||
def set_buttons(self):
|
||||
mode = not self.parent.db.readonly
|
||||
|
||||
self.top.get_widget('add_child_btn').set_sensitive(mode)
|
||||
self.top.get_widget('add_child_btn2').set_sensitive(mode)
|
||||
self.top.get_widget('add_parents').set_sensitive(mode)
|
||||
self.top.get_widget('add_parents2').set_sensitive(mode)
|
||||
self.top.get_widget('add_spparents').set_sensitive(mode)
|
||||
self.top.get_widget('add_spparents2').set_sensitive(mode)
|
||||
self.top.get_widget('del_child_btn').set_sensitive(mode)
|
||||
self.top.get_widget('del_child_btn2').set_sensitive(mode)
|
||||
self.top.get_widget('del_parents').set_sensitive(mode)
|
||||
self.top.get_widget('del_parents2').set_sensitive(mode)
|
||||
self.top.get_widget('del_spparents').set_sensitive(mode)
|
||||
self.top.get_widget('del_spparents2').set_sensitive(mode)
|
||||
self.top.get_widget('select_child2').set_sensitive(mode)
|
||||
self.top.get_widget('select_child').set_sensitive(mode)
|
||||
self.add_spouse_btn.set_sensitive(mode)
|
||||
self.remove_spouse_btn.set_sensitive(mode)
|
||||
self.select_spouse_btn.set_sensitive(mode)
|
||||
|
||||
def load_family(self,family=None):
|
||||
|
||||
self.set_buttons()
|
||||
if self.parent.active_person:
|
||||
handle = self.parent.active_person.get_handle()
|
||||
self.person = self.parent.db.get_person_from_handle(handle)
|
||||
|
@ -75,7 +75,10 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
def dbopen(self,name,dbname):
|
||||
dbmap = dbshelve.DBShelf(self.env)
|
||||
dbmap.db.set_pagesize(16384)
|
||||
dbmap.open(name, dbname, db.DB_HASH, db.DB_CREATE, 0666)
|
||||
if self.readonly:
|
||||
dbmap.open(name, dbname, db.DB_HASH, db.DB_RDONLY)
|
||||
else:
|
||||
dbmap.open(name, dbname, db.DB_HASH, db.DB_CREATE, 0666)
|
||||
return dbmap
|
||||
|
||||
def get_person_cursor(self):
|
||||
@ -93,10 +96,12 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
def get_media_cursor(self):
|
||||
return GrampsBSDDBCursor(self.media_map)
|
||||
|
||||
def load(self,name,callback):
|
||||
def load(self,name,callback,mode="w"):
|
||||
if self.person_map:
|
||||
self.close()
|
||||
|
||||
self.readonly = mode == "r"
|
||||
|
||||
self.env = db.DBEnv()
|
||||
self.env.set_cachesize(0,0x2000000) # 2MB
|
||||
flags = db.DB_CREATE|db.DB_INIT_MPOOL|db.DB_PRIVATE
|
||||
@ -114,46 +119,53 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
self.metadata = self.dbopen(name, "meta")
|
||||
self.person_map = self.dbopen(name, "person")
|
||||
|
||||
if self.readonly:
|
||||
openflags = db.DB_RDONLY
|
||||
else:
|
||||
openflags = db.DB_CREATE
|
||||
|
||||
self.surnames = db.DB(self.env)
|
||||
self.surnames.set_flags(db.DB_DUP)
|
||||
self.surnames.open(name, "surnames", db.DB_HASH, flags=db.DB_CREATE)
|
||||
self.surnames.open(name, "surnames", db.DB_HASH, flags=openflags)
|
||||
|
||||
self.name_group = db.DB(self.env)
|
||||
self.name_group.set_flags(db.DB_DUP)
|
||||
self.name_group.open(name, "name_group", db.DB_HASH, flags=db.DB_CREATE)
|
||||
self.name_group.open(name, "name_group", db.DB_HASH, flags=openflags)
|
||||
|
||||
self.id_trans = db.DB(self.env)
|
||||
self.id_trans.set_flags(db.DB_DUP)
|
||||
self.id_trans.open(name, "idtrans", db.DB_HASH, flags=db.DB_CREATE)
|
||||
self.id_trans.open(name, "idtrans", db.DB_HASH, flags=openflags)
|
||||
|
||||
self.fid_trans = db.DB(self.env)
|
||||
self.fid_trans.set_flags(db.DB_DUP)
|
||||
self.fid_trans.open(name, "fidtrans", db.DB_HASH, flags=db.DB_CREATE)
|
||||
self.fid_trans.open(name, "fidtrans", db.DB_HASH, flags=openflags)
|
||||
|
||||
self.pid_trans = db.DB(self.env)
|
||||
self.pid_trans.set_flags(db.DB_DUP)
|
||||
self.pid_trans.open(name, "pidtrans", db.DB_HASH, flags=db.DB_CREATE)
|
||||
self.pid_trans.open(name, "pidtrans", db.DB_HASH, flags=openflags)
|
||||
|
||||
self.sid_trans = db.DB(self.env)
|
||||
self.sid_trans.set_flags(db.DB_DUP)
|
||||
self.sid_trans.open(name, "sidtrans", db.DB_HASH, flags=db.DB_CREATE)
|
||||
self.sid_trans.open(name, "sidtrans", db.DB_HASH, flags=openflags)
|
||||
|
||||
self.oid_trans = db.DB(self.env)
|
||||
self.oid_trans.set_flags(db.DB_DUP)
|
||||
self.oid_trans.open(name, "oidtrans", db.DB_HASH, flags=db.DB_CREATE)
|
||||
self.oid_trans.open(name, "oidtrans", db.DB_HASH, flags=openflags)
|
||||
|
||||
self.eventnames = db.DB(self.env)
|
||||
self.eventnames.set_flags(db.DB_DUP)
|
||||
self.eventnames.open(name, "eventnames", db.DB_HASH, flags=db.DB_CREATE)
|
||||
self.person_map.associate(self.surnames, find_surname, db.DB_CREATE)
|
||||
self.person_map.associate(self.id_trans, find_idmap, db.DB_CREATE)
|
||||
self.family_map.associate(self.fid_trans, find_idmap, db.DB_CREATE)
|
||||
self.place_map.associate(self.pid_trans, find_idmap, db.DB_CREATE)
|
||||
self.media_map.associate(self.oid_trans, find_idmap, db.DB_CREATE)
|
||||
self.source_map.associate(self.sid_trans, find_idmap, db.DB_CREATE)
|
||||
self.event_map.associate(self.eventnames, find_eventname, db.DB_CREATE)
|
||||
self.eventnames.open(name, "eventnames", db.DB_HASH, flags=openflags)
|
||||
|
||||
self.undodb = db.DB()
|
||||
self.undodb.open(self.undolog, db.DB_RECNO, db.DB_CREATE)
|
||||
if not self.readonly:
|
||||
self.person_map.associate(self.surnames, find_surname, openflags)
|
||||
self.person_map.associate(self.id_trans, find_idmap, openflags)
|
||||
self.family_map.associate(self.fid_trans, find_idmap, openflags)
|
||||
self.place_map.associate(self.pid_trans, find_idmap, openflags)
|
||||
self.media_map.associate(self.oid_trans, find_idmap, openflags)
|
||||
self.source_map.associate(self.sid_trans, find_idmap, openflags)
|
||||
self.event_map.associate(self.eventnames, find_eventname, openflags)
|
||||
self.undodb = db.DB()
|
||||
self.undodb.open(self.undolog, db.DB_RECNO, db.DB_CREATE)
|
||||
|
||||
self.bookmarks = self.metadata.get('bookmarks')
|
||||
if self.bookmarks == None:
|
||||
@ -175,8 +187,9 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
self.source_map.close()
|
||||
self.media_map.close()
|
||||
self.event_map.close()
|
||||
self.metadata['bookmarks'] = self.bookmarks
|
||||
self.metadata['gender_stats'] = self.genderStats.save_stats()
|
||||
if not self.readonly:
|
||||
self.metadata['bookmarks'] = self.bookmarks
|
||||
self.metadata['gender_stats'] = self.genderStats.save_stats()
|
||||
self.metadata.close()
|
||||
self.surnames.close()
|
||||
self.eventnames.close()
|
||||
@ -186,12 +199,13 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
self.sid_trans.close()
|
||||
self.pid_trans.close()
|
||||
self.env.close()
|
||||
self.undodb.close()
|
||||
|
||||
try:
|
||||
os.remove(self.undolog)
|
||||
except:
|
||||
pass
|
||||
if not self.readonly:
|
||||
self.undodb.close()
|
||||
try:
|
||||
os.remove(self.undolog)
|
||||
except:
|
||||
pass
|
||||
|
||||
self.person_map = None
|
||||
self.family_map = None
|
||||
@ -204,11 +218,12 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
self.metadata = None
|
||||
|
||||
def set_name_group_mapping(self,name,group):
|
||||
name = str(name)
|
||||
if not group and self.name_group.has_key(name):
|
||||
self.name_group.delete(name)
|
||||
else:
|
||||
self.name_group[name] = group
|
||||
if not self.readonly:
|
||||
name = str(name)
|
||||
if not group and self.name_group.has_key(name):
|
||||
self.name_group.delete(name)
|
||||
else:
|
||||
self.name_group[name] = group
|
||||
|
||||
def get_surname_list(self):
|
||||
names = self.surnames.keys()
|
||||
@ -229,41 +244,47 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
return vals
|
||||
|
||||
def remove_person(self,handle,transaction):
|
||||
person = self.get_person_from_handle(handle)
|
||||
self.genderStats.uncount_person (person)
|
||||
if transaction != None:
|
||||
transaction.add(PERSON_KEY,handle,person.serialize())
|
||||
self.person_map.delete(str(handle))
|
||||
if not self.readonly:
|
||||
person = self.get_person_from_handle(handle)
|
||||
self.genderStats.uncount_person (person)
|
||||
if transaction != None:
|
||||
transaction.add(PERSON_KEY,handle,person.serialize())
|
||||
self.person_map.delete(str(handle))
|
||||
|
||||
def remove_source(self,handle,transaction):
|
||||
if transaction != None:
|
||||
old_data = self.source_map.get(str(handle))
|
||||
transaction.add(SOURCE_KEY,handle,old_data)
|
||||
self.source_map.delete(str(handle))
|
||||
if not self.readonly:
|
||||
if transaction != None:
|
||||
old_data = self.source_map.get(str(handle))
|
||||
transaction.add(SOURCE_KEY,handle,old_data)
|
||||
self.source_map.delete(str(handle))
|
||||
|
||||
def remove_family(self,handle,transaction):
|
||||
if transaction != None:
|
||||
old_data = self.family_map.get(str(handle))
|
||||
transaction.add(FAMILY_KEY,handle,old_data)
|
||||
self.family_map.delete(str(handle))
|
||||
if not self.readonly:
|
||||
if transaction != None:
|
||||
old_data = self.family_map.get(str(handle))
|
||||
transaction.add(FAMILY_KEY,handle,old_data)
|
||||
self.family_map.delete(str(handle))
|
||||
|
||||
def remove_event(self,handle,transaction):
|
||||
if transaction != None:
|
||||
old_data = self.event_map.get(str(handle))
|
||||
transaction.add(EVENT_KEY,handle,old_data)
|
||||
self.event_map.delete(str(handle))
|
||||
if not self.readonly:
|
||||
if transaction != None:
|
||||
old_data = self.event_map.get(str(handle))
|
||||
transaction.add(EVENT_KEY,handle,old_data)
|
||||
self.event_map.delete(str(handle))
|
||||
|
||||
def remove_place(self,handle,transaction):
|
||||
if transaction != None:
|
||||
old_data = self.place_map.get(handle)
|
||||
transaction.add(PLACE_KEY,handle,old_data)
|
||||
self.place_map.delete(str(handle))
|
||||
if not self.readonly:
|
||||
if transaction != None:
|
||||
old_data = self.place_map.get(handle)
|
||||
transaction.add(PLACE_KEY,handle,old_data)
|
||||
self.place_map.delete(str(handle))
|
||||
|
||||
def remove_object(self,handle,transaction):
|
||||
if transaction != None:
|
||||
old_data = self.media_map.get(handle)
|
||||
transaction.add(PLACE_KEY,handle,old_data)
|
||||
self.media_map.delete(str(handle))
|
||||
if not self.readonly:
|
||||
if transaction != None:
|
||||
old_data = self.media_map.get(handle)
|
||||
transaction.add(PLACE_KEY,handle,old_data)
|
||||
self.media_map.delete(str(handle))
|
||||
|
||||
def get_person_from_gramps_id(self,val):
|
||||
"""finds a Person in the database from the passed gramps' ID.
|
||||
|
@ -117,6 +117,7 @@ class GrampsDbBase:
|
||||
be created.
|
||||
"""
|
||||
|
||||
self.readonly = False
|
||||
self.rand = random.Random(time.time())
|
||||
self.smap_index = 0
|
||||
self.emap_index = 0
|
||||
@ -221,6 +222,8 @@ class GrampsDbBase:
|
||||
Commits the specified Person to the database, storing the changes
|
||||
as part of the transaction.
|
||||
"""
|
||||
if self.readonly:
|
||||
return
|
||||
if change_time:
|
||||
person.change = int(change_time)
|
||||
else:
|
||||
@ -237,6 +240,8 @@ class GrampsDbBase:
|
||||
Commits the specified MediaObject to the database, storing the changes
|
||||
as part of the transaction.
|
||||
"""
|
||||
if self.readonly:
|
||||
return
|
||||
if change_time:
|
||||
obj.change = int(change_time)
|
||||
else:
|
||||
@ -252,6 +257,8 @@ class GrampsDbBase:
|
||||
Commits the specified Source to the database, storing the changes
|
||||
as part of the transaction.
|
||||
"""
|
||||
if self.readonly:
|
||||
return
|
||||
if change_time:
|
||||
source.change = int(change_time)
|
||||
else:
|
||||
@ -267,6 +274,8 @@ class GrampsDbBase:
|
||||
Commits the specified Place to the database, storing the changes
|
||||
as part of the transaction.
|
||||
"""
|
||||
if self.readonly:
|
||||
return
|
||||
if change_time:
|
||||
place.change = int(change_time)
|
||||
else:
|
||||
@ -282,6 +291,8 @@ class GrampsDbBase:
|
||||
Commits the specified Event to the database, storing the changes
|
||||
as part of the transaction.
|
||||
"""
|
||||
if self.readonly:
|
||||
return
|
||||
if change_time:
|
||||
event.change = int(change_time)
|
||||
else:
|
||||
@ -297,6 +308,8 @@ class GrampsDbBase:
|
||||
Commits the specified Family to the database, storing the changes
|
||||
as part of the transaction.
|
||||
"""
|
||||
if self.readonly:
|
||||
return
|
||||
if change_time:
|
||||
family.change = int(change_time)
|
||||
else:
|
||||
@ -451,9 +464,10 @@ class GrampsDbBase:
|
||||
person.unserialize(data)
|
||||
else:
|
||||
person.set_handle(val)
|
||||
if transaction != None:
|
||||
transaction.add(PERSON_KEY, val, None)
|
||||
self.person_map[str(val)] = person.serialize()
|
||||
if not self.readonly:
|
||||
if transaction != None:
|
||||
transaction.add(PERSON_KEY, val, None)
|
||||
self.person_map[str(val)] = person.serialize()
|
||||
self.genderStats.count_person (person, self)
|
||||
return person
|
||||
|
||||
@ -677,7 +691,7 @@ class GrampsDbBase:
|
||||
Allows the retreiving people display data into the database metadata.
|
||||
This allows faster display of the treeview.
|
||||
"""
|
||||
if self.metadata:
|
||||
if self.metadata and not self.readonly:
|
||||
self.metadata['tp_path'] = maps[0]
|
||||
self.metadata['p_iter'] = maps[1]
|
||||
self.metadata['p_path'] = maps[2]
|
||||
@ -870,7 +884,7 @@ class GrampsDbBase:
|
||||
"""
|
||||
Commits the transaction to the assocated UNDO database.
|
||||
"""
|
||||
if not len(transaction):
|
||||
if not len(transaction) or self.readonly:
|
||||
return
|
||||
transaction.set_description(msg)
|
||||
self.undoindex += 1
|
||||
@ -887,7 +901,7 @@ class GrampsDbBase:
|
||||
Accesses the last committed transaction, and reverts the data to
|
||||
the state before the transaction was committed.
|
||||
"""
|
||||
if self.undoindex == -1:
|
||||
if self.undoindex == -1 or self.readonly:
|
||||
return False
|
||||
transaction = self.translist[self.undoindex]
|
||||
|
||||
@ -982,11 +996,12 @@ class GrampsDbBase:
|
||||
|
||||
def set_default_person_handle(self,handle):
|
||||
"""sets the default Person to the passed instance"""
|
||||
self.metadata['default'] = handle
|
||||
if not self.readonly:
|
||||
self.metadata['default'] = handle
|
||||
|
||||
def get_default_person(self):
|
||||
"""returns the default Person of the database"""
|
||||
if self.metadata and self.metadata.has_key('default'):
|
||||
if self.metadata and self.metadata.has_key('default') and not self.readonly:
|
||||
person = Person()
|
||||
handle = self.metadata['default']
|
||||
data = self.person_map.get(str(handle),None)
|
||||
@ -1126,7 +1141,7 @@ class GrampsDbBase:
|
||||
Stores the Person display common information in the
|
||||
database's metadata.
|
||||
"""
|
||||
if self.metadata != None:
|
||||
if self.metadata != None and not self.readonly:
|
||||
self.metadata['columns'] = list
|
||||
|
||||
def set_child_column_order(self,list):
|
||||
@ -1134,7 +1149,7 @@ class GrampsDbBase:
|
||||
Stores the Person display common information in the
|
||||
database's metadata.
|
||||
"""
|
||||
if self.metadata != None:
|
||||
if self.metadata != None and not self.readonly:
|
||||
self.metadata['child_columns'] = list
|
||||
|
||||
def set_place_column_order(self,list):
|
||||
@ -1142,7 +1157,7 @@ class GrampsDbBase:
|
||||
Stores the Place display common information in the
|
||||
database's metadata.
|
||||
"""
|
||||
if self.metadata != None:
|
||||
if self.metadata != None and not self.readonly:
|
||||
self.metadata['place_columns'] = list
|
||||
|
||||
def set_source_column_order(self,list):
|
||||
@ -1150,7 +1165,7 @@ class GrampsDbBase:
|
||||
Stores the Source display common information in the
|
||||
database's metadata.
|
||||
"""
|
||||
if self.metadata != None:
|
||||
if self.metadata != None and not self.readonly:
|
||||
self.metadata['source_columns'] = list
|
||||
|
||||
def set_media_column_order(self,list):
|
||||
@ -1158,7 +1173,7 @@ class GrampsDbBase:
|
||||
Stores the Media display common information in the
|
||||
database's metadata.
|
||||
"""
|
||||
if self.metadata != None:
|
||||
if self.metadata != None and not self.readonly:
|
||||
self.metadata['media_columns'] = list
|
||||
|
||||
def get_person_column_order(self):
|
||||
|
@ -44,17 +44,19 @@ class GrampsGEDDB(GrampsInMemDB):
|
||||
"""creates a new GrampsDB"""
|
||||
GrampsInMemDB.__init__(self)
|
||||
|
||||
def load(self,name,callback):
|
||||
def load(self,name,callback, mode="w"):
|
||||
self.filename = name
|
||||
ReadGedcom.importData(self,name,use_trans=False)
|
||||
|
||||
self.readonly = mode == "r"
|
||||
|
||||
self.bookmarks = self.metadata.get('bookmarks')
|
||||
if self.bookmarks == None:
|
||||
self.bookmarks = []
|
||||
return 1
|
||||
|
||||
def close(self):
|
||||
if len(self.undodb) > 0:
|
||||
if not self.readonly and len(self.undodb) > 0:
|
||||
writer = WriteGedcom.GedcomWriter(self,self.get_default_person())
|
||||
writer.export_data(self.filename)
|
||||
|
||||
|
@ -130,6 +130,8 @@ class GrampsInMemDB(GrampsDbBase):
|
||||
return vals
|
||||
|
||||
def remove_person(self,handle,transaction):
|
||||
if self.readonly:
|
||||
return
|
||||
person = self.get_person_from_handle(handle)
|
||||
self.genderStats.uncount_person (person)
|
||||
if transaction != None:
|
||||
@ -139,6 +141,8 @@ class GrampsInMemDB(GrampsDbBase):
|
||||
del self.person_map[handle]
|
||||
|
||||
def remove_source(self,handle,transaction):
|
||||
if self.readonly:
|
||||
return
|
||||
source = self.get_source_from_handle(handle)
|
||||
if transaction != None:
|
||||
old_data = self.source_map.get(str(handle))
|
||||
@ -147,6 +151,8 @@ class GrampsInMemDB(GrampsDbBase):
|
||||
del self.source_map[str(handle)]
|
||||
|
||||
def remove_place(self,handle,transaction):
|
||||
if self.readonly:
|
||||
return
|
||||
place = self.get_place_from_handle(handle)
|
||||
if transaction != None:
|
||||
old_data = self.place_map.get(str(handle))
|
||||
@ -155,6 +161,8 @@ class GrampsInMemDB(GrampsDbBase):
|
||||
del self.place_map[str(handle)]
|
||||
|
||||
def remove_object(self,handle,transaction):
|
||||
if self.readonly:
|
||||
return
|
||||
obj = self.get_object_from_handle(handle)
|
||||
if transaction != None:
|
||||
old_data = self.media_map.get(str(handle))
|
||||
@ -163,6 +171,8 @@ class GrampsInMemDB(GrampsDbBase):
|
||||
del self.media_map[str(handle)]
|
||||
|
||||
def remove_family(self,handle,transaction):
|
||||
if self.readonly:
|
||||
return
|
||||
family = self.get_family_from_handle(handle)
|
||||
if transaction != None:
|
||||
old_data = self.family_map.get(str(handle))
|
||||
@ -171,32 +181,44 @@ class GrampsInMemDB(GrampsDbBase):
|
||||
del self.family_map[str(handle)]
|
||||
|
||||
def remove_event(self,handle,transaction):
|
||||
if self.readonly:
|
||||
return
|
||||
if transaction != None:
|
||||
old_data = self.event_map.get(str(handle))
|
||||
transaction.add(EVENT_KEY,handle,old_data)
|
||||
del self.event_map[str(handle)]
|
||||
|
||||
def commit_person(self,person,transaction,change_time=None):
|
||||
if self.readonly:
|
||||
return
|
||||
gid = person.get_gramps_id()
|
||||
self.id_trans[gid] = person.get_handle()
|
||||
GrampsDbBase.commit_person(self,person,transaction,change_time)
|
||||
|
||||
def commit_place(self,place,transaction,change_time=None):
|
||||
if self.readonly:
|
||||
return
|
||||
gid = place.get_gramps_id()
|
||||
self.pid_trans[gid] = place.get_handle()
|
||||
GrampsDbBase.commit_place(self,place,transaction,change_time)
|
||||
|
||||
def commit_family(self,family,transaction,change_time=None):
|
||||
if self.readonly:
|
||||
return
|
||||
gid = family.get_gramps_id()
|
||||
self.fid_trans[gid] = family.get_handle()
|
||||
GrampsDbBase.commit_family(self,family,transaction,change_time)
|
||||
|
||||
def commit_media_object(self,obj,transaction,change_time=None):
|
||||
if self.readonly:
|
||||
return
|
||||
gid = obj.get_gramps_id()
|
||||
self.oid_trans[gid] = obj.get_handle()
|
||||
GrampsDbBase.commit_media_object(self,obj,transaction,change_time)
|
||||
|
||||
def commit_source(self,source,transaction,change_time=None):
|
||||
if self.readonly:
|
||||
return
|
||||
gid = source.get_gramps_id()
|
||||
self.sid_trans[gid] = source.get_handle()
|
||||
GrampsDbBase.commit_source(self,source,transaction,change_time)
|
||||
|
@ -44,10 +44,12 @@ class GrampsXMLDB(GrampsInMemDB):
|
||||
"""creates a new GrampsDB"""
|
||||
GrampsInMemDB.__init__(self)
|
||||
|
||||
def load(self,name,callback):
|
||||
def load(self,name,callback,mode="w"):
|
||||
self.filename = name
|
||||
self.id_trans = {}
|
||||
|
||||
self.readonly = mode == "r"
|
||||
|
||||
ReadXML.importData(self,name,use_trans=False)
|
||||
|
||||
self.bookmarks = self.metadata.get('bookmarks')
|
||||
@ -56,6 +58,6 @@ class GrampsXMLDB(GrampsInMemDB):
|
||||
return 1
|
||||
|
||||
def close(self):
|
||||
if len(self.undodb) > 0:
|
||||
if not self.readonly and len(self.undodb) > 0:
|
||||
WriteXML.quick_write(self,self.filename)
|
||||
|
||||
|
1846
src/gramps.glade
1846
src/gramps.glade
File diff suppressed because it is too large
Load Diff
@ -787,11 +787,16 @@ class Gramps:
|
||||
self.media_view.on_delete_clicked(obj)
|
||||
|
||||
def enable_buttons(self,val):
|
||||
self.add_button.set_sensitive(val)
|
||||
self.remove_button.set_sensitive(val)
|
||||
if self.db.readonly:
|
||||
mode = False
|
||||
else:
|
||||
mode = val
|
||||
self.add_button.set_sensitive(mode)
|
||||
self.remove_button.set_sensitive(mode)
|
||||
self.add_item.set_sensitive(mode)
|
||||
self.remove_item.set_sensitive(mode)
|
||||
|
||||
self.edit_button.set_sensitive(val)
|
||||
self.add_item.set_sensitive(val)
|
||||
self.remove_item.set_sensitive(val)
|
||||
self.edit_item.set_sensitive(val)
|
||||
|
||||
def on_show_plugin_status(self,obj):
|
||||
@ -1071,6 +1076,7 @@ class Gramps:
|
||||
|
||||
def read_file(self,filename,callback=None):
|
||||
self.topWindow.set_resizable(gtk.FALSE)
|
||||
mode = "w"
|
||||
filename = os.path.normpath(os.path.abspath(filename))
|
||||
|
||||
if os.path.isdir(filename):
|
||||
@ -1085,25 +1091,37 @@ class Gramps:
|
||||
'file.'))
|
||||
return 0
|
||||
elif not os.access(filename,os.W_OK):
|
||||
ErrorDialog(_('Cannot open database'),
|
||||
_('You do not have write access to the selected '
|
||||
'file.'))
|
||||
return 0
|
||||
mode = "r"
|
||||
WarningDialog(_('Read only database'),
|
||||
_('You do not have write access to the selected '
|
||||
'file.'))
|
||||
|
||||
try:
|
||||
if self.load_database(filename,callback) == 1:
|
||||
if filename[-1] == '/':
|
||||
filename = filename[:-1]
|
||||
name = os.path.basename(filename)
|
||||
self.topWindow.set_title("%s - GRAMPS" % name)
|
||||
else:
|
||||
GrampsKeys.save_last_file("")
|
||||
ErrorDialog(_('Cannot open database'),
|
||||
_('The database file specified could not be opened file.'))
|
||||
return 0
|
||||
except db.DBAccessError, msg:
|
||||
# try:
|
||||
# if self.load_database(filename,callback,mode=mode) == 1:
|
||||
# if filename[-1] == '/':
|
||||
# filename = filename[:-1]
|
||||
# name = os.path.basename(filename)
|
||||
# self.topWindow.set_title("%s - GRAMPS" % name)
|
||||
# else:
|
||||
# GrampsKeys.save_last_file("")
|
||||
# ErrorDialog(_('Cannot open database'),
|
||||
# _('The database file specified could not be opened.'))
|
||||
# return 0
|
||||
# except db.DBAccessError, msg:
|
||||
# ErrorDialog(_('Cannot open database'),
|
||||
# _('%s could not be opened.' % filename) + '\n' + msg[1])
|
||||
# return 0
|
||||
|
||||
|
||||
if self.load_database(filename,callback,mode=mode) == 1:
|
||||
if filename[-1] == '/':
|
||||
filename = filename[:-1]
|
||||
name = os.path.basename(filename)
|
||||
self.topWindow.set_title("%s - GRAMPS" % name)
|
||||
else:
|
||||
GrampsKeys.save_last_file("")
|
||||
ErrorDialog(_('Cannot open database'),
|
||||
_('%s could not be opened.' % filename) + '\n' + msg[1])
|
||||
_('The database file specified could not be opened.'))
|
||||
return 0
|
||||
|
||||
self.topWindow.set_resizable(gtk.TRUE)
|
||||
@ -1583,6 +1601,7 @@ class Gramps:
|
||||
self.goto_active_person()
|
||||
if callback:
|
||||
callback(_('Setup complete'))
|
||||
self.enable_buttons(True)
|
||||
return 1
|
||||
|
||||
def find_initial_person(self):
|
||||
@ -1594,7 +1613,7 @@ class Gramps:
|
||||
person = self.db.get_person_from_handle(the_ids[0])
|
||||
return person
|
||||
|
||||
def load_database(self,name,callback=None):
|
||||
def load_database(self,name,callback=None,mode="w"):
|
||||
|
||||
filename = name
|
||||
|
||||
@ -1603,7 +1622,7 @@ class Gramps:
|
||||
if callback:
|
||||
callback(_('Opening database...'))
|
||||
|
||||
if self.db.load(filename,callback) == 0:
|
||||
if self.db.load(filename,callback,mode) == 0:
|
||||
self.status_text('')
|
||||
return 0
|
||||
self.status_text('')
|
||||
|
Loading…
Reference in New Issue
Block a user