* src/DisplayTabs.py: SourceRef tab

* src/EditSource.py: New source ref dialog
* src/grampsl.glade: New source ref dialog
* src/GrampsDb/_GedTokens.py: repository tokens
* src/GrampsDb/_ReadGedcom.py: repository support


svn: r5828
This commit is contained in:
Don Allingham 2006-01-25 05:07:10 +00:00
parent f723ec0630
commit 07c23e5ff2
6 changed files with 439 additions and 1451 deletions

View File

@ -1,3 +1,10 @@
2006-01-24 Don Allingham <don@gramps-project.org>
* src/DisplayTabs.py: SourceRef tab
* src/EditSource.py: New source ref dialog
* src/grampsl.glade: New source ref dialog
* src/GrampsDb/_GedTokens.py: repository tokens
* src/GrampsDb/_ReadGedcom.py: repository support
2006-01-24 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_GrampsBSDDB.py (load): Set max locks and objects
to 25000; Add DB_RECOVER flag to the environment.

View File

@ -34,7 +34,7 @@ _GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ]
#-------------------------------------------------------------------------
#
# EmbeddedList
# GrampsTab
#
#-------------------------------------------------------------------------
class GrampsTab(gtk.HBox):
@ -207,7 +207,6 @@ class EventEmbedList(EmbeddedList):
def __init__(self,dbstate,uistate,track,obj):
self.obj = obj
EmbeddedList.__init__(self, dbstate, uistate, track,
_('Events'), EventRefModel)
@ -235,6 +234,111 @@ class EventEmbedList(EmbeddedList):
if ref:
print ref
#-------------------------------------------------------------------------
#
# SourceBackRefList
#
#-------------------------------------------------------------------------
class SourceBackRefList(EmbeddedList):
_HANDLE_COL = 3
column_names = [
(_('Type'),0),
(_('ID'),1),
(_('Name'),2),
]
def __init__(self,dbstate,uistate,track,obj):
self.obj = obj
EmbeddedList.__init__(self, dbstate, uistate, track,
_('References'), SourceBackRefModel)
def set_label(self):
self.tab_image.show()
self.label.set_text("<b>%s</b>" % self.tab_name)
self.label.set_use_markup(True)
def create_buttons(self):
self.edit_btn = SimpleButton(gtk.STOCK_EDIT, self.edit_button_clicked)
vbox = gtk.VBox()
vbox.set_spacing(6)
vbox.pack_start(self.edit_btn,False)
vbox.show_all()
self.pack_start(vbox,False)
def selection_changed(self,obj=None):
if self.get_selected():
self.edit_btn.set_sensitive(True)
else:
self.edit_btn.set_sensitive(False)
def get_icon_name(self):
return 'gramps-source'
def get_data(self):
return self.obj
def column_order(self):
return ((1,0),(1,1),(1,2))
def add_button_clicked(self,obj):
pass
def del_button_clicked(self,obj):
ref = self.get_selected()
if ref:
ref_list = self.obj.get_event_ref_list()
ref_list.remove(ref)
self.rebuild()
def edit_button_clicked(self,obj):
ref = self.get_selected()
if ref:
print ref
#-------------------------------------------------------------------------
#
# DataEmbedList
#
#-------------------------------------------------------------------------
class DataEmbedList(EmbeddedList):
column_names = [
(_('Key'),0),
(_('Value'),1),
]
def __init__(self,dbstate,uistate,track,obj):
self.obj = obj
EmbeddedList.__init__(self, dbstate, uistate, track,
_('Data'), DataModel)
def get_data(self):
return self.obj.get_data_map()
def column_order(self):
return ((1,0),(1,1))
def add_button_clicked(self,obj):
pass
def del_button_clicked(self,obj):
ref = self.get_selected()
if ref:
ref_list = self.obj.get_data_map()
ref_list.remove(ref)
self.rebuild()
def edit_button_clicked(self,obj):
ref = self.get_selected()
if ref:
print ref
#-------------------------------------------------------------------------
#
# NoteTab
@ -555,22 +659,69 @@ class AttrModel(gtk.ListStore):
else:
return Utils.personal_attributes[t[0]]
#-------------------------------------------------------------------------
#
# DataModel
#
#-------------------------------------------------------------------------
class DataModel(gtk.ListStore):
def __init__(self,attr_list,db):
gtk.ListStore.__init__(self,str,str)
self.db = db
for attr in attr_list.keys():
self.append(row=[
attr,
attr_list[attr],
])
#-------------------------------------------------------------------------
#
# SourceRefModel
#
#-------------------------------------------------------------------------
class SourceRefModel(gtk.ListStore):
class SourceBackRefModel(gtk.ListStore):
def __init__(self,sref_list,db):
gtk.ListStore.__init__(self,str,str)
gtk.ListStore.__init__(self,str,str,str,str)
self.db = db
for sref in sref_list:
src = db.get_source_from_handle(sref.ref)
self.append(row=[
src.gramps_id,
src.title,
])
for ref in sref_list:
dtype = ref[0]
if dtype == 'Person':
p = self.db.get_person_from_handle(ref[1])
gid = p.gramps_id
handle = p.handle
name = NameDisplay.displayer.display(p)
elif dtype == 'Family':
p = self.db.get_family_from_handle(ref[1])
gid = p.gramps_id
handle = p.handle
name = Utils.family_name(p,self.db)
elif dtype == 'Event':
p = self.db.get_event_from_handle(ref[1])
gid = p.gramps_id
name = event.get_description()
handle = p.handle
if not name:
etype = event.get_type()
if etype[0] == RelLib.Event.CUSTOM:
name = etype[1]
elif Utils.personal_events.has_key(etype[0]):
name = Utils.personal_events[etype[0]]
else:
name = Utils.family_events[etype[0]]
elif dtype == 'Place':
p = self.db.get_place_from_handle(ref[1])
name = p.get_title()
gid = p.gramps_id
handle = p.handle
else:
p = self.db.get_object_from_handle(ref[1])
name = p.get_description()
gid = p.gramps_id
handle = p.handle
self.append(row=[dtype,gid,name,handle])
#-------------------------------------------------------------------------
#

View File

@ -56,6 +56,8 @@ import Spell
import GrampsDisplay
import DisplayState
from DisplayTabs import NoteTab, GalleryTab, DataEmbedList, SourceBackRefList
from WindowUtils import GladeIf
#-------------------------------------------------------------------------
@ -179,7 +181,6 @@ class EditSource(DisplayState.ManagedWindow):
self.uistate = uistate
self.db = dbstate.db
self.idle = None
self.name_display = NameDisplay.displayer.display
DisplayState.ManagedWindow.__init__(self, uistate, self.track, source)
@ -194,7 +195,6 @@ class EditSource(DisplayState.ManagedWindow):
self.path = self.db.get_save_path()
self.not_loaded = 1
self.lists_changed = 0
self.gallery_ok = 0
mode = not self.db.readonly
self.top_window = gtk.glade.XML(const.gladeFile,"sourceEditor","gramps")
@ -204,27 +204,12 @@ class EditSource(DisplayState.ManagedWindow):
Utils.set_titles(self.window,self.top_window.get_widget('title'),
_('Source Editor'))
plwidget = self.top_window.get_widget("iconlist")
self.gallery = ImageSelect.Gallery(source, self.db.commit_place,
self.path,
plwidget,
self.db, self, self.window)
self.author = self.top_window.get_widget("author")
self.pubinfo = self.top_window.get_widget("pubinfo")
self.abbrev = self.top_window.get_widget("abbrev")
self.note = self.top_window.get_widget("source_note")
self.note.set_editable(mode)
self.spell = Spell.Spell(self.note)
self.notes_buffer = self.note.get_buffer()
self.gallery_label = self.top_window.get_widget("source_edit_gallery")
self.refs_label = self.top_window.get_widget("source_edit_refs")
self.notes_label = self.top_window.get_widget("source_edit_notes")
self.data_label = self.top_window.get_widget("source_edit_data")
self.flowed = self.top_window.get_widget("source_flowed")
self.flowed.set_sensitive(mode)
self.preform = self.top_window.get_widget("source_preform")
self.preform.set_sensitive(mode)
self.vbox = self.top_window.get_widget('vbox')
self.refinfo = self.top_window.get_widget("refinfo")
self.title = self.top_window.get_widget("source_title")
@ -237,99 +222,44 @@ class EditSource(DisplayState.ManagedWindow):
self.abbrev.set_text(source.get_abbreviation())
self.abbrev.set_editable(mode)
self.top_window.get_widget('del_data').set_sensitive(mode)
self.top_window.get_widget('add_data').set_sensitive(mode)
self.top_window.get_widget('add_photo').set_sensitive(mode)
self.top_window.get_widget('sel_photo').set_sensitive(mode)
self.top_window.get_widget('delete_photo').set_sensitive(mode)
self.repos_ref_view = ReposRefListView(self.dbstate,
self.top_window.get_widget('repository_ref_list'))
self.repos_ref_model = ReposRefListModel(self.source)
self.repos_ref_view.set_model(self.repos_ref_model)
self.top_window.get_widget('add_repos_ref').set_sensitive(mode)
self.top_window.get_widget('edit_repos_ref').set_sensitive(mode)
self.top_window.get_widget('del_repos_ref').set_sensitive(mode)
if source.get_note():
self.notes_buffer.set_text(source.get_note())
Utils.bold_label(self.notes_label)
if source.get_note_format() == 1:
self.preform.set_active(1)
else:
self.flowed.set_active(1)
else:
Utils.unbold_label(self.notes_label)
if self.source.get_media_list():
Utils.bold_label(self.gallery_label)
else:
Utils.unbold_label(self.gallery_label)
self.gladeif.connect('sourceEditor','delete_event',self.on_delete_event)
self.gladeif.connect('button90','clicked',self.close)
self.gladeif.connect('ok','clicked',self.on_source_apply_clicked)
self.gladeif.connect('button166','clicked',self.on_help_clicked)
self.gladeif.connect('notebook2','switch_page',self.on_switch_page)
self.gladeif.connect('add_data','clicked',self.on_add_data_clicked)
self.gladeif.connect('del_data','clicked',self.on_delete_data_clicked)
self.gladeif.connect('add_photo','clicked',self.gallery.on_add_media_clicked)
self.gladeif.connect('sel_photo','clicked',self.gallery.on_select_media_clicked)
self.gladeif.connect('edit_photo','clicked',self.gallery.on_edit_media_clicked)
self.gladeif.connect('delete_photo','clicked',self.gallery.on_delete_media_clicked)
self.gladeif.connect('add_repos_ref','clicked',self.on_add_repos_ref_clicked)
self.gladeif.connect('del_repos_ref','clicked',self.on_delete_repos_ref_clicked)
self.gladeif.connect('edit_repos_ref','clicked',self.on_edit_repos_ref_clicked)
self.gladeif.connect('repository_ref_list','row_activated',self.on_edit_repos_ref_clicked)
if self.source.get_handle() == None or self.db.readonly:
self.top_window.get_widget("edit_photo").set_sensitive(False)
self.top_window.get_widget("delete_photo").set_sensitive(False)
self.datalist = self.top_window.get_widget('datalist')
colno = 0
first = True
for title in [ (_('Key'),0,175), (_('Value'),1,150)]:
renderer = gtk.CellRendererText()
renderer.set_property('editable',True)
renderer.connect('edited',self.edit_cb, colno)
column = gtk.TreeViewColumn(title[0], renderer, text=colno)
colno += 1
column.set_clickable(True)
column.set_resizable(True)
column.set_min_width(title[2])
column.set_sort_column_id(title[1])
self.datalist.append_column(column)
if first:
first = False
self.key_cell = renderer
self.key_col = column
self.data_model = gtk.ListStore(str,str)
self.datalist.set_model(self.data_model)
dmap = self.source.get_data_map()
for item in dmap.keys():
self.data_model.append(row=[item,dmap[item]])
if dmap:
Utils.bold_label(self.data_label)
else:
Utils.unbold_label(self.data_label)
self.top_window.get_widget('ok').set_sensitive(not self.db.readonly)
self.top_window.get_widget('cancel').connect('clicked', self.close_window)
self.notebook = gtk.Notebook()
self.notebook.show()
self.vbox.pack_start(self.notebook,True)
self.load_data()
self.show()
self.model = None # This will hold the model for backreferences once it is complete.
if self.ref_not_loaded:
self.ref_not_loaded = 0
Utils.temp_label(self.refs_label,self.window)
self.cursor_type = None
self.idle = gobject.idle_add(self.display_references)
self.data_sel = self.datalist.get_selection()
def load_data(self):
self.note_tab = NoteTab(self.dbstate, self.uistate, self.track,
self.source.get_note_object())
self.gallery_tab = GalleryTab(self.dbstate, self.uistate, self.track,
self.source.get_media_list())
self.data_tab = DataEmbedList(self.dbstate, self.uistate, self.track,
self.source)
self.backref_tab = SourceBackRefList(self.dbstate, self.uistate, self.track,
self.db.find_backlink_handles(self.source.handle))
self.notebook.insert_page(self.note_tab)
self.notebook.set_tab_label(self.note_tab,self.note_tab.get_tab_widget())
self.notebook.insert_page(self.data_tab)
self.notebook.set_tab_label(self.data_tab,self.data_tab.get_tab_widget())
self.notebook.insert_page(self.gallery_tab)
self.notebook.set_tab_label(self.gallery_tab,self.gallery_tab.get_tab_widget())
self.notebook.insert_page(self.backref_tab)
self.notebook.set_tab_label(self.backref_tab,self.backref_tab.get_tab_widget())
self.notebook.show_all()
def build_window_key(self,source):
if source:
@ -344,193 +274,16 @@ class EditSource(DisplayState.ManagedWindow):
label = "New Source"
return (label, _('Source Editor'))
def on_add_data_clicked(self,widget):
node = self.data_model.append(row=['',''])
self.data_sel.select_iter(node)
path = self.data_model.get_path(node)
self.datalist.set_cursor_on_cell(path,
focus_column=self.key_col,
focus_cell=None,
start_editing=True)
def on_delete_data_clicked(self,widget):
(model,node) = self.data_sel.get_selected()
if node:
model.remove(node)
def on_add_repos_ref_clicked(self,widget):
RepositoryRefEdit.RepositoryRefEdit(RelLib.RepoRef(),self.dbstate,
self.repos_ref_model.update,self)
def on_delete_repos_ref_clicked(self,widget):
selection = self.repos_ref_view.get_selection()
model, iter = selection.get_selected()
if iter:
model.remove(iter)
return
def on_edit_repos_ref_clicked(self,widget,path=None,colm=None,userp=None):
selection = self.repos_ref_view.get_selection()
model, iter = selection.get_selected()
if iter:
repos_ref = model.get_value(iter,0)
RepositoryRefEdit.RepositoryRefEdit(repos_ref,self.dbstate,
self.repos_ref_model.update,self)
def edit_cb(self, cell, path, new_text, data):
node = self.data_model.get_iter(path)
self.data_model.set_value(node,data,new_text)
def on_delete_event(self,obj,b):
self.close_child_windows()
self.remove_itself_from_menu()
self.gladeif.close()
gc.collect()
def on_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
GrampsDisplay.help('adv-src')
def close(self,obj):
self.gallery.close()
def close_window(self,obj):
self.gladeif.close()
self.window.destroy()
if self.idle != None:
gobject.source_remove(self.idle)
gc.collect()
def button_press(self,obj):
data = self.model.get_selected_objects()
if not data:
return
(data_type,handle) = data[0]
if data_type == 0:
import EditPerson
person = self.db.get_person_from_handle(handle)
EditPerson.EditPerson(self.state, self.uistate, self.track, person)
elif data_type == 1:
import Marriage
family = self.db.get_family_from_handle(handle)
Marriage.Marriage(self.parent,family,self.db)
elif data_type == 2:
import EventEdit
event = self.db.get_event_from_handle(handle)
event_name = event.get_name()
if Utils.family_events.has_key(event_name):
EventEdit.EventEditor(
self,", ", const.marriageEvents, Utils.family_events,
event, None, 0, None, None, self.db.readonly)
elif Utils.personal_events.has_key(event_name):
EventEdit.EventEditor(
self,", ", const.personalEvents, Utils.personal_events,
event, None, 0, None, None, self.db.readonly)
elif event_name in ["Birth","Death"]:
EventEdit.EventEditor(
self,", ", const.personalEvents, Utils.personal_events,
event, None, 1, None, None, self.db.readonly)
elif data_type == 3:
import EditPlace
place = self.db.get_place_from_handle(handle)
EditPlace.EditPlace(self.parent,place)
elif data_type == 4:
source = self.db.get_source_from_handle(handle)
EditSource(source,self.db,self.parent,None,self.db.readonly)
elif data_type == 5:
media = self.db.get_object_from_handle(handle)
ImageSelect.GlobalMediaProperties(self.db,media,self)
def display_references(self):
if not self.model:
self.any_refs = False
source_handle = self.source.get_handle()
slist = self.top_window.get_widget('slist')
titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)]
self.model = ListModel.ListModel(slist,
titles,
event_func=self.button_press)
self.backlink_generator = self.db.find_backlink_handles(source_handle)
while True: # The loop is broken when the backlink_generator finishes
try:
reference = self.backlink_generator.next()
except StopIteration:
# Last reference reached.
break
# If we make it here then there is at least one reference
self.any_refs = True
cls_name,handle = reference
if cls_name == 'Person':
person = self.db.get_person_from_handle(handle)
name = self.name_display(person)
gramps_id = person.get_gramps_id()
self.model.add([_("Person"),gramps_id,name],(0,handle))
elif cls_name == 'Event':
event = self.db.get_event_from_handle(handle)
name = event.get_name()
gramps_id = event.get_gramps_id()
self.model.add([_("Event"),gramps_id,name],(2,handle))
elif cls_name == 'Family':
family = self.db.get_family_from_handle(handle)
name = Utils.family_name(family,self.db)
gramps_id = family.get_gramps_id()
self.model.add([_("Family"),gramps_id,name],(1,handle))
elif cls_name == 'Place':
place = self.db.get_place_from_handle(handle)
name = place.get_title()
gramps_id = place.get_gramps_id()
self.model.add([_("Place"),gramps_id,name],(3,handle))
elif cls_name == 'Source':
source = self.db.get_source_from_handle(handle)
name = source.get_title()
gramps_id = source.get_gramps_id()
self.model.add([_("Source"),gramps_id,name],(4,handle))
self.any_refs = True
elif cls_name == 'Media':
obj = self.db.get_object_from_handle(handle)
name = obj.get_description()
gramps_id = obj.get_gramps_id()
self.model.add([_("Media"),gramps_id,name],(5,handle))
elif cls_name == 'Repository':
pass # handled by seperate Repositories tab in UI
else:
# If we get here it means there is a new Primary object type
# that has been added to the database. Print a warning
# to remind us that this code need updating.
log.warning("Unhandled Primary object type returned from "
"find_backlink_handles()\n")
if gtk.events_pending():
return True
if self.any_refs:
Utils.bold_label(self.refs_label,self.window)
else:
Utils.unbold_label(self.refs_label,self.window)
self.ref_not_loaded = 0
self.backlink_generator = None
return False
self.close()
def on_source_apply_clicked(self,obj):
@ -580,8 +333,6 @@ class EditSource(DisplayState.ManagedWindow):
self.source.set_reporef_list(repos_ref_list)
self.gallery_ok = 1
trans = self.db.transaction_begin()
if self.source.get_handle() == None:
self.db.add_source(self.source,trans)
@ -590,28 +341,6 @@ class EditSource(DisplayState.ManagedWindow):
self.db.transaction_commit(trans,_("Edit Source (%s)") % title)
self.close(obj)
def on_switch_page(self,obj,a,page):
if page == 2 and self.not_loaded:
self.not_loaded = 0
self.gallery.load_images()
elif page == 3 and self.ref_not_loaded:
self.ref_not_loaded = 0
Utils.temp_label(self.refs_label,self.window)
self.idle = gobject.idle_add(self.display_references)
text = unicode(
self.notes_buffer.get_text(self.notes_buffer.get_start_iter(),
self.notes_buffer.get_end_iter(),
False)
)
if text:
Utils.bold_label(self.notes_label,self.window)
else:
Utils.unbold_label(self.notes_label,self.window)
def update_repositories(self, repos_ref):
"""Make the repository list reflect the change or addition of repos_ref"""
pass
class DelSrcQuery:
def __init__(self,source,db,the_lists):

View File

@ -126,9 +126,13 @@ TOKEN__WITN = 102
TOKEN__WTN = 103
TOKEN__CHUR = 104
TOKEN_HEAD = 105
TOKEN_CALN = 106
TOKEN_MEDI = 107
tokens = {
"HEAD" : TOKEN_HEAD,
"MEDI" : TOKEN_MEDI,
"CALN" : TOKEN_CALN,
"ABBR" : TOKEN_ABBR,
"ADDR" : TOKEN_ADDR,
"ADOP" : TOKEN_ADOP,

View File

@ -42,6 +42,7 @@ try:
except NameError:
from sets import Set as set
#-------------------------------------------------------------------------
#
# GTK/GNOME Modules
@ -64,7 +65,6 @@ import DisplayTrace
from ansel_utf8 import ansel_to_utf8
import Utils
import GrampsMime
import logging
from bsddb import db
from _GedcomInfo import *
from _GedTokens import *
@ -84,11 +84,13 @@ def utf8_to_latin(s):
return s.encode('iso-8859-1','replace')
def latin_to_utf8(s):
if type(s) == type(u''):
if type(s) == unicode:
return s
else:
return unicode(s,'iso-8859-1')
def nocnv(s):
return unicode(s)
log = logging.getLogger('.GEDCOM_import')
@ -101,9 +103,6 @@ ANSEL = 1
UNICODE = 2
UPDATE = 25
def nocnv(s):
return unicode(s)
file_systems = {
'VFAT' : _('Windows 9x file system'),
'FAT' : _('Windows 9x file system'),
@ -705,6 +704,11 @@ class GedcomParser:
self.source.set_note(note.strip())
elif matches[1] == TOKEN_ABBR:
self.source.set_abbreviation(matches[2])
elif matches[1] == TOKEN_REPO:
repo_ref = RelLib.RepoRef()
repo_ref = self.find_or_create_repository(matches[2][1:-1])
self.parse_repo_ref(matches,repo_ref,level+1)
self.source.add_repo_reference(repo_ref)
elif matches[1] in (TOKEN_OBJE,TOKEN_CHAN,TOKEN__CAT):
self.ignore_sub_junk(2)
else:
@ -913,6 +917,31 @@ class GedcomParser:
else:
self.barf(1)
def parse_repo_caln(self, matches, repo, level):
while True:
matches = self.get_next()
if int(matches[0]) < level:
self.backup()
return
elif matches[1] == TOKEN_CALN:
repo.set_call_number(matches[2])
self.parse_repo_caln(matches, repo. level+1)
elif matches[1] == TOKEN_NOTE:
repo.set_note(matches[2])
else:
self.barf(1)
def parse_repo_ref(self, matches, repo, level):
while True:
matches = self.get_next()
if int(matches[0]) < level:
self.backup()
return
elif matches[1] == TOKEN_MEDI:
repo.set_media_type(matches[2])
else:
self.barf(1)
def parse_note_data(self,level):
while True:
matches = self.get_next()

File diff suppressed because it is too large Load Diff