* src/GrampsDbBase.py: keep track of open files

* src/MediaView.py: convert MediaView to handle pluggable views
* src/PersonView.py: update filter on page change
* src/ViewManager.py: change_database handling
* src/gramps.glade: remove unused blocks
* src/gramps_main.py: Add in MediaView


svn: r5075
This commit is contained in:
Don Allingham 2005-08-14 04:31:29 +00:00
parent 2fe3e67f7c
commit 56dea05049
7 changed files with 231 additions and 10912 deletions

View File

@ -1,3 +1,11 @@
2005-08-13 Don Allingham <don@gramps-project.org>
* src/GrampsDbBase.py: keep track of open files
* src/MediaView.py: convert MediaView to handle pluggable views
* src/PersonView.py: update filter on page change
* src/ViewManager.py: change_database handling
* src/gramps.glade: remove unused blocks
* src/gramps_main.py: Add in MediaView
2005-08-12 Don Allingham <don@gramps-project.org> 2005-08-12 Don Allingham <don@gramps-project.org>
* src/ViewManager.py: set up about box and other HELP menu items * src/ViewManager.py: set up about box and other HELP menu items
* src/const.py.in: strings for about box * src/const.py.in: strings for about box

View File

@ -1508,6 +1508,7 @@ class DbState(GrampsDBCallback.GrampsDBCallback):
def __init__(self): def __init__(self):
GrampsDBCallback.GrampsDBCallback.__init__(self) GrampsDBCallback.GrampsDBCallback.__init__(self)
self.db = GrampsDbBase() self.db = GrampsDbBase()
self.open = False
self.active = None self.active = None
def change_active_person(self,person): def change_active_person(self,person):
@ -1526,8 +1527,10 @@ class DbState(GrampsDBCallback.GrampsDBCallback):
def change_database(self,db): def change_database(self,db):
self.db = db self.db = db
self.open = True
self.emit('database-changed',(self.db,)) self.emit('database-changed',(self.db,))
def no_database(self): def no_database(self):
self.db = GrampsDbBase() self.db = GrampsDbBase()
self.open = False
self.emit('no-database') self.emit('no-database')

View File

@ -1,4 +1,3 @@
#
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2001-2005 Donald N. Allingham # Copyright (C) 2001-2005 Donald N. Allingham
@ -20,15 +19,6 @@
# $Id$ # $Id$
#-------------------------------------------------------------------------
#
# standard python modules
#
#-------------------------------------------------------------------------
import os
import gc
from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GTK/Gnome modules # GTK/Gnome modules
@ -43,15 +33,20 @@ import gtk.gdk
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import RelLib import RelLib
import Utils import PageView
import GrampsKeys import DisplayModels
import const
import ImageSelect import ImageSelect
import ImgManip import ImgManip
import RelImage import const
import DisplayModels import Utils
import GrampsMime from QuestionDialog import QuestionDialog, ErrorDialog
from QuestionDialog import QuestionDialog, ErrorDialog, WarningDialog
#-------------------------------------------------------------------------
#
# internationalization
#
#-------------------------------------------------------------------------
from gettext import gettext as _
column_names = [ column_names = [
_('Title'), _('Title'),
@ -62,297 +57,99 @@ column_names = [
_('Date'), _('Date'),
] ]
_HANDLE_COL = len(column_names)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# MediaView # MediaView
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MediaView: class MediaView(PageView.ListView):
def __init__(self,parent,db,glade,update): def __init__(self,dbstate,uistate):
self.parent = parent
self.parent.connect('database-changed',self.change_db)
self.db = db
self.list = glade.get_widget("media_list")
self.mid = glade.get_widget("mid")
self.mtype = glade.get_widget("mtype")
self.mdesc = glade.get_widget("mdesc")
self.mpath = glade.get_widget("mpath")
self.mdetails = glade.get_widget("mdetails")
self.preview = glade.get_widget("preview")
self.topWindow = glade.get_widget("gramps")
self.renderer = gtk.CellRendererText()
self.model = DisplayModels.MediaModel(self.db)
self.sort_col = 0
self.selection = self.list.get_selection() signal_map = {
self.list.set_model(self.model) 'media-add' : self.row_add,
'media-update' : self.row_update,
'media-delete' : self.row_delete,
'media-rebuild' : self.build_tree,
}
DND_TARGETS = [ PageView.ListView.__init__(self,'Media View',dbstate,uistate,
('STRING', 0, 0), column_names,len(column_names),
('text/plain',0,0), DisplayModels.MediaModel,
('text/uri-list',0,2), signal_map)
('application/x-rootwin-drop',0,1)]
self.list.enable_model_drag_source( def column_order(self):
gtk.gdk.BUTTON1_MASK, return self.dbstate.db.get_media_column_order()
DND_TARGETS,
gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_COPY
)
self.list.drag_source_set( def get_stock(self):
gtk.gdk.BUTTON1_MASK|gtk.gdk.BUTTON3_MASK, return 'gramps-media'
DND_TARGETS,
gtk.gdk.ACTION_COPY
)
self.list.enable_model_drag_dest( def build_widget(self):
DND_TARGETS, base = PageView.ListView.build_widget(self)
gtk.gdk.ACTION_DEFAULT vbox = gtk.VBox()
) vbox.set_border_width(4)
self.list.drag_dest_set( vbox.set_spacing(4)
gtk.DEST_DEFAULT_ALL,
DND_TARGETS,
gtk.gdk.ACTION_COPY|gtk.gdk.ACTION_MOVE
)
self.list.connect("drag-data-received", self.on_drag_data_received) self.image = gtk.Image()
self.list.connect("drag-data-get", self.on_drag_data_get) self.image.set_size_request(int(const.thumbScale),
self.list.connect("drag-begin", self.on_drag_begin) int(const.thumbScale))
self.list.connect("drag-drop", self.on_drag_drop) # label = gtk.Label('<b>%s</b>' % _('Preview'))
# label.set_use_markup(True)
# frame = gtk.Frame()
# frame.set_label_widget(label)
# frame.add(self.image)
vbox.pack_start(self.image,False)
vbox.pack_start(base,True)
self.list.connect('button-press-event',self.on_button_press_event) self.selection.connect('changed',self.row_change)
self.list.connect('key-press-event',self.key_press) return vbox
self.selection.connect('changed',self.on_select_row) def row_change(self,obj):
self.update = update
self.columns = []
self.build_columns()
self.build_tree()
def column_clicked(self,obj,data):
if self.sort_col != data:
order = gtk.SORT_ASCENDING
else:
if (self.columns[data].get_sort_order() == gtk.SORT_DESCENDING
or self.columns[data].get_sort_indicator() == False):
order = gtk.SORT_ASCENDING
else:
order = gtk.SORT_DESCENDING
self.sort_col = data
handle = self.first_selected() handle = self.first_selected()
self.model = DisplayModels.MediaModel(self.parent.db, obj = self.dbstate.db.get_object_from_handle(handle)
self.sort_col,order) pix = ImgManip.get_thumbnail_image(obj.get_path())
self.list.set_model(self.model) self.image.set_from_pixbuf(pix)
colmap = self.parent.db.get_place_column_order()
if handle:
path = self.model.on_get_path(handle)
self.selection.select_path(path)
self.list.scroll_to_cell(path,None,1,0.5,0)
for i in range(0,len(self.columns)):
self.columns[i].set_sort_indicator(i==colmap[data][1]-1)
self.columns[self.sort_col].set_sort_order(order)
def first_selected(self):
mlist = []
self.selection.selected_foreach(self.blist,mlist)
if mlist:
return mlist[0]
else:
return None
def blist(self,store,path,iter,list):
handle = store.get_value(iter,_HANDLE_COL)
list.append(handle)
def build_columns(self):
for column in self.columns:
self.list.remove_column(column)
column = gtk.TreeViewColumn(_('Title'), self.renderer,text=0)
column.set_resizable(True)
column.connect('clicked',self.column_clicked,0)
column.set_clickable(True)
column.set_min_width(225)
self.list.append_column(column)
self.columns = [column]
index = 1
for pair in self.parent.db.get_media_column_order():
if not pair[0]:
continue
name = column_names[pair[1]]
column = gtk.TreeViewColumn(name, self.renderer, text=pair[1])
column.set_resizable(True)
column.set_min_width(75)
column.set_clickable(True)
column.connect('clicked',self.column_clicked,index)
self.columns.append(column)
self.list.append_column(column)
index += 1
def media_add(self,handle_list):
for handle in handle_list:
self.model.add_row_by_handle(handle)
def media_update(self,handle_list):
for handle in handle_list:
self.model.update_row_by_handle(handle)
def media_delete(self,handle_list):
for handle in handle_list:
self.model.delete_row_by_handle(handle)
def change_db(self,db):
db.connect('media-add', self.media_add)
db.connect('media-update', self.media_update)
db.connect('media-delete', self.media_delete)
db.connect('media-rebuild',self.build_tree)
self.db = db
self.build_columns()
self.build_tree()
def build_tree(self):
self.model = DisplayModels.MediaModel(self.parent.db)
self.list.set_model(self.model)
self.selection = self.list.get_selection()
def on_select_row(self,obj):
fexists = 1
store,node = self.selection.get_selected()
if not node:
return
handle = store.get_value(node,_HANDLE_COL)
mobj = self.db.get_object_from_handle(handle)
mtype = mobj.get_mime_type()
path = mobj.get_path()
if mtype:
type_name = Utils.get_mime_description(mtype)
if mtype[0:5] == "image":
image = ImgManip.get_thumbnail_image(path)
else:
image = Utils.find_mime_type_pixbuf(mtype)
else:
image = Utils.find_mime_type_pixbuf('text/plain')
type_name = _('Note')
self.preview.set_from_pixbuf(image)
del image
gc.collect()
self.mid.set_text(mobj.get_gramps_id())
self.mtype.set_text(type_name)
self.mdesc.set_text(mobj.get_description())
if len(path) == 0 or fexists == 0:
self.mpath.set_text(_("The file no longer exists"))
else:
self.mpath.set_text(path)
self.mdetails.set_text(Utils.get_detail_text(mobj,0))
def on_button_press_event(self,obj,event):
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
self.on_edit_clicked(obj)
return 1
elif event.button == 3:
self.build_context_menu(event)
return 1
return 0
def key_press(self,obj,event):
if event.keyval == gtk.gdk.keyval_from_name("Return") \
and not event.state:
self.on_edit_clicked(obj)
return 1
return 0
def build_context_menu(self,event):
menu = gtk.Menu()
menu.set_title(_("Media Object"))
store,node = self.selection.get_selected()
if node:
handle = store.get_value(node,_HANDLE_COL)
obj = self.db.get_object_from_handle(handle)
self.obj = obj
mime_type = obj.get_mime_type()
Utils.add_menuitem(menu,_("View in the default viewer"),None,
self.popup_view_photo)
if mime_type and mime_type[0:5] == "image":
Utils.add_menuitem(menu,_("Edit with the GIMP"),
None,self.popup_edit_photo)
item = gtk.MenuItem()
item.show()
menu.append(item)
sel_sensitivity = 1
else:
sel_sensitivity = 0
entries = [
(gtk.STOCK_ADD, self.on_add_clicked,1),
(gtk.STOCK_REMOVE, self.on_delete_clicked,sel_sensitivity),
(_("Edit properties"), self.on_edit_clicked,sel_sensitivity),
]
for stock_id,callback,sensitivity in entries:
item = gtk.ImageMenuItem(stock_id)
if callback:
item.connect("activate",callback)
item.set_sensitive(sensitivity)
item.show()
menu.append(item)
menu.popup(None,None,None,event.button,event.time)
def popup_view_photo(self, obj):
Utils.view_photo(self.obj)
def popup_edit_photo(self, obj): def ui_definition(self):
if os.fork() == 0: return '''<ui>
os.execvp(const.editor,[const.editor, self.obj.get_path()]) <menubar name="MenuBar">
<menu action="EditMenu">
def popup_change_description(self, obj): <placeholder name="CommonEdit">
ImageSelect.GlobalMediaProperties(self.db,self.obj,self,self.topWindow) <menuitem action="Add"/>
<menuitem action="Edit"/>
<menuitem action="Remove"/>
</placeholder>
</menu>
</menubar>
<toolbar name="ToolBar">
<placeholder name="CommonEdit">
<toolitem action="Add"/>
<toolitem action="Edit"/>
<toolitem action="Remove"/>
</placeholder>
</toolbar>
<popup name="Popup">
<menuitem action="Add"/>
<menuitem action="Edit"/>
<menuitem action="Remove"/>
</popup>
</ui>'''
def on_add_clicked(self,obj): def on_double_click(self,obj,event):
handle = self.first_selected()
place = self.dbstate.db.get_place_from_handle(handle)
#EditPlace.EditPlace(place,self.dbstate, self.uistate)
def add(self,obj):
"""Add a new media object to the media list""" """Add a new media object to the media list"""
import AddMedia import AddMedia
am = AddMedia.AddMediaObject(self.db) am = AddMedia.AddMediaObject(self.dbstate.db)
am.run() am.run()
def on_edit_clicked(self,obj): def remove(self,obj):
"""Edit the properties of an existing media object in the media list""" handle = self.first_selected()
the_lists = Utils.get_media_referents(handle,self.dbstate.db)
list_store, node = self.selection.get_selected() ans = ImageSelect.DeleteMediaQuery(handle,self.dbstate.db,the_lists)
if node:
handle = list_store.get_value(node,_HANDLE_COL)
obj = self.db.get_object_from_handle(handle)
if obj.get_mime_type():
ImageSelect.GlobalMediaProperties(self.db,obj,self,self.topWindow)
else:
import NoteEdit
NoteEdit.NoteEditor(obj,self.parent,self.topWindow,
self.note_callback)
def note_callback(self,data):
trans = self.db.transaction_begin()
self.db.commit_media_object(data,trans)
self.db.transaction_commit(trans,_("Edit Media Object"))
def on_delete_clicked(self,obj):
store,node = self.selection.get_selected()
if not node:
return
handle = store.get_value(node,_HANDLE_COL)
the_lists = Utils.get_media_referents(handle,self.db)
ans = ImageSelect.DeleteMediaQuery(handle,self.db,the_lists)
if filter(None,the_lists): # quick test for non-emptiness if filter(None,the_lists): # quick test for non-emptiness
msg = _('This media object is currently being used. ' msg = _('This media object is currently being used. '
'If you delete this object, it will be removed from ' 'If you delete this object, it will be removed from '
@ -364,75 +161,15 @@ class MediaView:
QuestionDialog(_('Delete Media Object?'),msg, QuestionDialog(_('Delete Media Object?'),msg,
_('_Delete Media Object'),ans.query_response) _('_Delete Media Object'),ans.query_response)
def on_drag_drop(self, tree, context, x, y, time): def edit(self,obj):
self.list.emit_stop_by_name('drag-drop') handle = self.first_selected()
return 1
obj = self.dbstate.db.get_object_from_handle(handle)
if obj.get_mime_type():
ImageSelect.GlobalMediaProperties(self.dbstate.db,
obj,self,self.topWindow)
else:
import NoteEdit
NoteEdit.NoteEditor(obj,self.parent,self.topWindow,
self.note_callback)
def on_drag_begin(self,obj,context):
store,node = self.selection.get_selected()
if not node:
return
if (const.dnd_images):
handle = store.get_value(node,_HANDLE_COL)
obj = self.db.get_object_from_handle(handle)
if obj.get_path():
image = ImgManip.get_thumbnail_image(obj.get_path())
context.set_icon_pixbuf(image,0,0)
def on_drag_data_get(self, w, context, selection_data, info, time):
if info == 1:
return
store,node = self.selection.get_selected()
if not node:
return
handle = store.get_value(node,_HANDLE_COL)
selection_data.set(selection_data.target, 8, handle)
def on_drag_data_received(self,w, context, x, y, data, info, time):
import urlparse
self.list.emit_stop_by_name('drag-data-received')
if data and data.format == 8:
d = data.data.replace('\0',' ').strip()
protocol,site,name, j,k,l = urlparse.urlparse(d)
if protocol == "file":
mime = GrampsMime.get_type(name)
photo = RelLib.MediaObject()
photo.set_path(name)
photo.set_mime_type(mime)
description = os.path.basename(name)
photo.set_description(description)
trans = self.db.transaction_begin()
self.db.add_object(photo,trans)
self.db.commit_media_object(photo,trans)
self.db.transaction_commit(trans,_("Add Media Object"))
self.build_tree()
if GrampsKeys.get_media_global():
ImageSelect.GlobalMediaProperties(self.db,photo,
self,self.topWindow)
elif protocol != "":
import urllib
u = urllib.URLopener()
try:
tfile,headers = u.retrieve(d)
except IOError, msg:
ErrorDialog(_('Image import failed'),str(msg))
return
mime = GrampsMime.get_type(tfile)
photo = RelLib.MediaObject()
photo.set_mime_type(mime)
photo.set_description(d)
photo.set_path(tfile)
trans = self.db.transaction_begin()
self.db.add_object(photo,trans)
oref = RelLib.MediaRef()
oref.set_reference_handle(photo.get_handle())
self.db.commit_media_object(photo,trans)
self.db.transaction_commit(trans,_("Add Media Object"))
if GrampsKeys.get_media_global():
ImageSelect.GlobalMediaProperties(self.db,photo,
self,self.topWindow)

View File

@ -75,6 +75,9 @@ class PersonView(PageView.PersonNavView):
dbstate.connect('database-changed',self.change_db) dbstate.connect('database-changed',self.change_db)
dbstate.connect('active-changed',self.goto_active_person) dbstate.connect('active-changed',self.goto_active_person)
def change_page(self):
self.on_filter_name_changed(None)
def define_actions(self): def define_actions(self):
""" """
Required define_actions function for PageView. Builds the action Required define_actions function for PageView. Builds the action
@ -91,12 +94,17 @@ class PersonView(PageView.PersonNavView):
PageView.PersonNavView.define_actions(self) PageView.PersonNavView.define_actions(self)
self.add_action('Add', gtk.STOCK_ADD, "_Add", callback=self.add) self.add_action('Add', gtk.STOCK_ADD, "_Add",
self.add_action('Edit', gtk.STOCK_EDIT, "_Edit", callback=self.edit) callback=self.add)
self.add_action('Remove', gtk.STOCK_REMOVE,"_Remove",callback=self.remove) self.add_action('Edit', gtk.STOCK_EDIT, "_Edit",
self.add_action('HomePerson',gtk.STOCK_HOME, "_Home", callback=self.home) callback=self.edit)
self.add_action('Remove', gtk.STOCK_REMOVE, "_Remove",
callback=self.remove)
self.add_action('HomePerson', gtk.STOCK_HOME, "_Home",
callback=self.home)
self.add_toggle_action('Filter', None, '_Filter', callback=self.filter_toggle) self.add_toggle_action('Filter', None, '_Filter',
callback=self.filter_toggle)
def get_stock(self): def get_stock(self):
""" """
@ -129,9 +137,7 @@ class PersonView(PageView.PersonNavView):
self.filterbar.pack_start(self.filter_invert,False) self.filterbar.pack_start(self.filter_invert,False)
self.filterbar.pack_end(self.filter_button,False) self.filterbar.pack_end(self.filter_button,False)
self.filter_text.hide() self.filter_text.set_sensitive(False)
self.filter_text.set_sensitive(0)
self.filter_label.hide()
self.person_tree = gtk.TreeView() self.person_tree = gtk.TreeView()
self.person_tree.set_rules_hint(True) self.person_tree.set_rules_hint(True)
@ -159,8 +165,9 @@ class PersonView(PageView.PersonNavView):
self.person_selection.set_mode(gtk.SELECTION_MULTIPLE) self.person_selection.set_mode(gtk.SELECTION_MULTIPLE)
self.person_selection.connect('changed',self.row_changed) self.person_selection.connect('changed',self.row_changed)
self.vbox.set_focus_chain([self.person_tree,self.filter_list, self.filter_text, self.vbox.set_focus_chain([self.person_tree, self.filter_list,
self.filter_invert, self.filter_button]) self.filter_text, self.filter_invert,
self.filter_button])
self.setup_filter() self.setup_filter()
return self.vbox return self.vbox
@ -686,12 +693,12 @@ class PersonView(PageView.PersonNavView):
qual = mime_filter.need_param qual = mime_filter.need_param
if qual: if qual:
self.filter_text.show() self.filter_text.show()
self.filter_text.set_sensitive(1) self.filter_text.set_sensitive(True)
self.filter_label.show() self.filter_label.show()
self.filter_label.set_text(mime_filter.get_rules()[0].labels[0]) self.filter_label.set_text(mime_filter.get_rules()[0].labels[0])
else: else:
self.filter_text.hide() self.filter_text.hide()
self.filter_text.set_sensitive(0) self.filter_text.set_sensitive(False)
self.filter_label.hide() self.filter_label.hide()
def apply_filter(self,current_model=None): def apply_filter(self,current_model=None):

View File

@ -185,7 +185,7 @@ class ViewManager:
self.notebook.connect('switch-page',self.change_page) self.notebook.connect('switch-page',self.change_page)
self.uistate = DisplayState.DisplayState(self.window, self.statusbar, self.uistate = DisplayState.DisplayState(self.window, self.statusbar,
self.uimanager, self.state) self.uimanager, self.state)
person_nav = Navigation.PersonNavigation(self.uistate) person_nav = Navigation.PersonNavigation(self.uistate)
self.navigation_type[PageView.NAVIGATION_PERSON] = (person_nav,None) self.navigation_type[PageView.NAVIGATION_PERSON] = (person_nav,None)
@ -193,8 +193,7 @@ class ViewManager:
def init_interface(self): def init_interface(self):
self.create_pages() self.create_pages()
self.change_page(None,None,0) self.change_page(None,None)
#self.state.no_database()
self.actiongroup.set_visible(False) self.actiongroup.set_visible(False)
def set_color(self,obj): def set_color(self,obj):
@ -217,21 +216,21 @@ class ViewManager:
self.actiongroup = gtk.ActionGroup('MainWindow') self.actiongroup = gtk.ActionGroup('MainWindow')
self.fileactions = gtk.ActionGroup('FileWindow') self.fileactions = gtk.ActionGroup('FileWindow')
self.fileactions.add_actions([ self.fileactions.add_actions([
('FileMenu', None, '_File'), ('FileMenu', None, '_File'),
('New', gtk.STOCK_NEW, '_New', "<control>n", None, self.on_new_activate), ('New', gtk.STOCK_NEW, '_New', "<control>n", None, self.new_activate),
('Open', gtk.STOCK_OPEN, '_Open', "<control>o", None, self.on_open_activate), ('Open', gtk.STOCK_OPEN, '_Open', "<control>o", None, self.open_activate),
('OpenRecent', gtk.STOCK_OPEN, 'Open _Recent'), ('OpenRecent', gtk.STOCK_OPEN, 'Open _Recent'),
('Quit', gtk.STOCK_QUIT, '_Quit', "<control>q", None, gtk.main_quit), ('Quit', gtk.STOCK_QUIT, '_Quit', "<control>q", None, gtk.main_quit),
('ViewMenu', None, '_View'), ('ViewMenu', None, '_View'),
('Preferences',gtk.STOCK_PREFERENCES,'_Preferences'), ('Preferences', gtk.STOCK_PREFERENCES, '_Preferences'),
('ColumnEdit', gtk.STOCK_PROPERTIES, '_Column Editor'), ('ColumnEdit', gtk.STOCK_PROPERTIES, '_Column Editor'),
('HelpMenu', None, '_Help'), ('HelpMenu', None, '_Help'),
('HomePage', None, _('GRAMPS _home page'), None, None, self.home_page_activate), ('HomePage', None, _('GRAMPS _home page'), None, None, self.home_page_activate),
('MailingLists',None, _('GRAMPS _mailing lists'), None, None, self.mailing_lists_activate), ('MailingLists', None, _('GRAMPS _mailing lists'), None, None, self.mailing_lists_activate),
('ReportBug', None, _('_Report a bug'), None, None, self.report_bug_activate), ('ReportBug', None, _('_Report a bug'), None, None, self.report_bug_activate),
('About', gtk.STOCK_ABOUT, '_About', None, None, self.about), ('About', gtk.STOCK_ABOUT, '_About', None, None, self.about),
('FAQ', None, '_FAQ', None, None, self.faq_activate), ('FAQ', None, '_FAQ', None, None, self.faq_activate),
('UserManual', gtk.STOCK_HELP, '_User Manual', 'F1', None, self.manual_activate), ('UserManual', gtk.STOCK_HELP, '_User Manual', 'F1', None, self.manual_activate),
]) ])
self.actiongroup.add_actions([ self.actiongroup.add_actions([
@ -242,8 +241,8 @@ class ViewManager:
('Undo', gtk.STOCK_UNDO, '_Undo', '<control>z' ), ('Undo', gtk.STOCK_UNDO, '_Undo', '<control>z' ),
('CmpMerge', None, '_Compare and merge'), ('CmpMerge', None, '_Compare and merge'),
('FastMerge', None, '_Fast merge'), ('FastMerge', None, '_Fast merge'),
('ScratchPad', gtk.STOCK_PASTE, '_ScratchPad', None, None, self.on_scratchpad), ('ScratchPad', gtk.STOCK_PASTE, '_ScratchPad', None, None, self.scratchpad),
('Import', gtk.STOCK_CONVERT, '_Import', None, None, self.on_import), ('Import', gtk.STOCK_CONVERT, '_Import', None, None, self.import_data),
('Reports', gtk.STOCK_DND_MULTIPLE, '_Reports'), ('Reports', gtk.STOCK_DND_MULTIPLE, '_Reports'),
('Tools', gtk.STOCK_EXECUTE, '_Tools'), ('Tools', gtk.STOCK_EXECUTE, '_Tools'),
('EditMenu', None, '_Edit'), ('EditMenu', None, '_Edit'),
@ -356,44 +355,52 @@ class ViewManager:
button.set_border_width(4) button.set_border_width(4)
button.set_relief(gtk.RELIEF_NONE) button.set_relief(gtk.RELIEF_NONE)
button.set_alignment(0,0.5) button.set_alignment(0,0.5)
button.connect('clicked',lambda x,y : self.notebook.set_current_page(y), button.connect('clicked',
index) lambda x,y : self.notebook.set_current_page(y), index)
self.set_color(button) self.set_color(button)
button.show() button.show()
index += 1 index += 1
self.bbox.pack_start(button,False) self.bbox.pack_start(button,False)
def change_page(self,obj,page,num): def change_page(self,obj,page,num=-1):
for mergeid in self.merge_ids: if num == -1:
self.uimanager.remove_ui(mergeid) num = self.notebook.get_current_page()
if self.active_page: if self.state.open == True:
groups = self.active_page.get_actions()
for grp in groups:
self.uimanager.remove_action_group(grp)
if len(self.pages) > 0: for mergeid in self.merge_ids:
self.active_page = self.pages[num] self.uimanager.remove_ui(mergeid)
if self.active_page:
groups = self.active_page.get_actions()
for grp in groups:
self.uimanager.remove_action_group(grp)
old_nav = self.navigation_type[self.prev_nav] if len(self.pages) > 0:
if old_nav[0] != None: self.active_page = self.pages[num]
old_nav[0].disable
nav_type = self.navigation_type[self.active_page.navigation_type()] old_nav = self.navigation_type[self.prev_nav]
if nav_type[0] != None: if old_nav[0] != None:
nav_type[0].enable() old_nav[0].disable()
groups = self.active_page.get_actions()
for grp in groups: nav_type = self.navigation_type[self.active_page.navigation_type()]
self.uimanager.insert_action_group(grp,1) if nav_type[0] != None:
self.merge_ids = [self.uimanager.add_ui_from_string(self.active_page.ui_definition())] nav_type[0].enable()
for ui in self.active_page.additional_ui_definitions():
mergeid = self.uimanager.add_ui_from_string(ui)
self.merge_ids.append(mergeid)
self.active_page.change_page() groups = self.active_page.get_actions()
def on_open_activate(self,obj): for grp in groups:
self.uimanager.insert_action_group(grp,1)
ui = self.active_page.ui_definition()
self.merge_ids = [self.uimanager.add_ui_from_string(ui)]
for ui in self.active_page.additional_ui_definitions():
mergeid = self.uimanager.add_ui_from_string(ui)
self.merge_ids.append(mergeid)
self.pages[num].change_page()
def open_activate(self,obj):
choose = gtk.FileChooserDialog(_('GRAMPS: Open database'), choose = gtk.FileChooserDialog(_('GRAMPS: Open database'),
self.uistate.window, self.uistate.window,
@ -410,8 +417,14 @@ class ViewManager:
add_gedcom_filter(choose) add_gedcom_filter(choose)
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom] format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
# Add more data type selections if opening existing db # Add more data type selections if opening existing db
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list: for data in PluginMgr.import_list:
mime_filter = data[1]
mime_type = data[2]
native_format = data[2]
format_name = data[3]
if not native_format: if not native_format:
choose.add_filter(mime_filter) choose.add_filter(mime_filter)
format_list.append(mime_type) format_list.append(mime_type)
@ -480,7 +493,7 @@ class ViewManager:
choose.destroy() choose.destroy()
return False return False
def on_new_activate(self,obj): def new_activate(self,obj):
choose = gtk.FileChooserDialog(_('GRAMPS: Create GRAMPS database'), choose = gtk.FileChooserDialog(_('GRAMPS: Create GRAMPS database'),
self.uistate.window, self.uistate.window,
@ -522,8 +535,10 @@ class ViewManager:
self.state.db.close() self.state.db.close()
except: except:
pass pass
self.state.db = GrampsBSDDB.GrampsBSDDB() self.state.change_database(GrampsBSDDB.GrampsBSDDB())
self.read_file(filename) self.read_file(filename)
self.state.db.request_rebuild()
self.change_page(None,None)
# Add the file to the recent items # Add the file to the recent items
#RecentFiles.recent_files(filename,const.app_gramps) #RecentFiles.recent_files(filename,const.app_gramps)
#self.parent.build_recent_menu() #self.parent.build_recent_menu()
@ -544,7 +559,7 @@ class ViewManager:
success = False success = False
if filetype == const.app_gramps: if filetype == const.app_gramps:
self.state.db = GrampsBSDDB.GrampsBSDDB() self.state.change_database(GrampsBSDDB.GrampsBSDDB())
msgxml = gtk.glade.XML(const.gladeFile, "load_message","gramps") msgxml = gtk.glade.XML(const.gladeFile, "load_message","gramps")
msg_top = msgxml.get_widget('load_message') msg_top = msgxml.get_widget('load_message')
msg_label = msgxml.get_widget('message') msg_label = msgxml.get_widget('message')
@ -556,13 +571,19 @@ class ViewManager:
gtk.main_iteration() gtk.main_iteration()
success = self.read_file(filename,update_msg) success = self.read_file(filename,update_msg)
self.state.db.request_rebuild()
self.change_page(None,None)
msg_top.destroy() msg_top.destroy()
elif filetype == const.app_gramps_xml: elif filetype == const.app_gramps_xml:
self.state.db = GrampsXMLDB.GrampsXMLDB() self.state.change_database(GrampsXMLDB.GrampsXMLDB())
success = self.read_file(filename) success = self.read_file(filename)
self.state.db.request_rebuild()
self.change_page(None,None)
elif filetype == const.app_gedcom: elif filetype == const.app_gedcom:
self.state.db = GrampsGEDDB.GrampsGEDDB() self.state.change_database(GrampsGEDDB.GrampsGEDDB())
success = self.read_file(filename) success = self.read_file(filename)
self.state.db.request_rebuild()
self.change_page(None,None)
#if success: #if success:
# Add the file to the recent items # Add the file to the recent items
@ -579,13 +600,13 @@ class ViewManager:
ErrorDialog(_('Cannot open database'), ErrorDialog(_('Cannot open database'),
_('The selected file is a directory, not ' _('The selected file is a directory, not '
'a file.\nA GRAMPS database must be a file.')) 'a file.\nA GRAMPS database must be a file.'))
return 0 return False
elif os.path.exists(filename): elif os.path.exists(filename):
if not os.access(filename,os.R_OK): if not os.access(filename,os.R_OK):
ErrorDialog(_('Cannot open database'), ErrorDialog(_('Cannot open database'),
_('You do not have read access to the selected ' _('You do not have read access to the selected '
'file.')) 'file.'))
return 0 return False
elif not os.access(filename,os.W_OK): elif not os.access(filename,os.W_OK):
mode = "r" mode = "r"
QuestionDialog.WarningDialog(_('Read only database'), QuestionDialog.WarningDialog(_('Read only database'),
@ -598,24 +619,26 @@ class ViewManager:
filename = filename[:-1] filename = filename[:-1]
name = os.path.basename(filename) name = os.path.basename(filename)
if self.state.db.readonly: if self.state.db.readonly:
self.uistate.window.set_title("%s (%s) - GRAMPS" % (name,_('Read Only'))) msg = "%s (%s) - GRAMPS" % (name,_('Read Only'))
self.uistate.window.set_title(msg)
else: else:
self.uistate.window.set_title("%s - GRAMPS" % name) msg = "%s - GRAMPS" % name
self.uistate.window.set_title(msg)
else: else:
GrampsKeys.save_last_file("") GrampsKeys.save_last_file("")
QuestionDialog.ErrorDialog(_('Cannot open database'), QuestionDialog.ErrorDialog(_('Cannot open database'),
_('The database file specified could not be opened.')) _('The database file specified could not be opened.'))
return 0 return False
except ( IOError, OSError, Errors.FileVersionError), msg: except ( IOError, OSError, Errors.FileVersionError), msg:
QuestionDialog.ErrorDialog(_('Cannot open database'),str(msg)) QuestionDialog.ErrorDialog(_('Cannot open database'),str(msg))
return 0 return False
except (db.DBAccessError,db.DBError), msg: except (db.DBAccessError,db.DBError), msg:
QuestionDialog.ErrorDialog(_('Cannot open database'), QuestionDialog.ErrorDialog(_('Cannot open database'),
_('%s could not be opened.' % filename) + '\n' + msg[1]) _('%s could not be opened.' % filename) + '\n' + msg[1])
return 0 return False
except Exception: except Exception:
DisplayTrace.DisplayTrace() DisplayTrace.DisplayTrace()
return 0 return False
# Undo/Redo always start with standard labels and insensitive state # Undo/Redo always start with standard labels and insensitive state
#self.undo_callback(None) #self.undo_callback(None)
@ -625,19 +648,16 @@ class ViewManager:
return True return True
def load_database(self,name,callback=None,mode="w"): def load_database(self,name,callback=None,mode="w"):
if not self.state.db.load(name,callback,mode):
filename = name return False
return self.post_load(name,callback)
if self.state.db.load(filename,callback,mode) == 0:
return 0
val = self.post_load(name,callback)
return val
def post_load(self,name,callback=None): def post_load(self,name,callback=None):
if not self.state.db.version_supported(): if not self.state.db.version_supported():
raise Errors.FileVersionError( raise Errors.FileVersionError(
"The database version is not supported by this version of GRAMPS.\n" "The database version is not supported by this "
"Please upgrade to the corresponding version or use XML for porting" "version of GRAMPS.\nPlease upgrade to the "
"corresponding version or use XML for porting"
"data between different database versions.") "data between different database versions.")
self.state.db.set_save_path(name) self.state.db.set_save_path(name)
@ -660,14 +680,9 @@ class ViewManager:
GrampsKeys.save_last_file(name) GrampsKeys.save_last_file(name)
self.relationship = self.RelClass(self.state.db) self.relationship = self.RelClass(self.state.db)
self.state.emit("database-changed", (self.state.db,))
self.state.change_active_person(self.find_initial_person()) self.state.change_active_person(self.find_initial_person())
#self.goto_active_person() self.change_page(None,None)
self.actiongroup.set_visible(True)
#if callback:
# callback(_('Setup complete'))
#self.enable_buttons(True)
return True return True
def find_initial_person(self): def find_initial_person(self):
@ -679,11 +694,11 @@ class ViewManager:
person = self.state.db.get_person_from_handle(the_ids[0]) person = self.state.db.get_person_from_handle(the_ids[0])
return person return person
def on_scratchpad(self,obj): def scratchpad(self,obj):
import ScratchPad import ScratchPad
ScratchPad.ScratchPadWindow(self.state, self) ScratchPad.ScratchPadWindow(self.state, self)
def on_import(self,obj): def import_data(self,obj):
choose = gtk.FileChooserDialog(_('GRAMPS: Import database'), choose = gtk.FileChooserDialog(_('GRAMPS: Import database'),
self.uistate.window, self.uistate.window,
gtk.FILE_CHOOSER_ACTION_OPEN, gtk.FILE_CHOOSER_ACTION_OPEN,
@ -701,7 +716,12 @@ class ViewManager:
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom] format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
# Add more data type selections if opening existing db # Add more data type selections if opening existing db
for (importData,mime_filter,mime_type,native_format,format_name) in PluginMgr.import_list: for data in PluginMgr.import_list:
mime_filter = data[1]
mime_type = data[2]
native_format = data[3]
format_name = data[4]
if not native_format: if not native_format:
choose.add_filter(mime_filter) choose.add_filter(mime_filter)
format_list.append(mime_type) format_list.append(mime_type)
@ -714,7 +734,8 @@ class ViewManager:
# then home. # then home.
default_dir = GrampsKeys.get_last_import_dir() default_dir = GrampsKeys.get_last_import_dir()
if len(default_dir)<=1: if len(default_dir)<=1:
default_dir = os.path.split(GrampsKeys.get_lastfile())[0] + os.path.sep base_path = os.path.split(GrampsKeys.get_lastfile())[0]
default_dir = base_path + os.path.sep
if len(default_dir)<=1: if len(default_dir)<=1:
default_dir = GrampsKeys.get_last_export_dir() default_dir = GrampsKeys.get_last_export_dir()
if len(default_dir)<=1: if len(default_dir)<=1:
@ -831,7 +852,7 @@ class GrampsFormatWidget(gtk.ComboBox):
for format,label in format_list: for format,label in format_list:
self.store.append(row=[label]) self.store.append(row=[label])
self.set_active(0) self.set_active(False)
def get_value(self): def get_value(self):
active = self.get_active() active = self.get_active()

File diff suppressed because it is too large Load Diff

View File

@ -41,6 +41,7 @@ import MapView
import PlaceView import PlaceView
import EventView import EventView
import SourceView import SourceView
import MediaView
import ArgHandler import ArgHandler
import DisplayTrace import DisplayTrace
import GrampsKeys import GrampsKeys
@ -62,6 +63,7 @@ def register_stock_icons ():
items = [ items = [
('people48.png',('gramps-person','Person',gtk.gdk.CONTROL_MASK,0,'')), ('people48.png',('gramps-person','Person',gtk.gdk.CONTROL_MASK,0,'')),
('family48.png',('gramps-family','Family',gtk.gdk.CONTROL_MASK,0,'')), ('family48.png',('gramps-family','Family',gtk.gdk.CONTROL_MASK,0,'')),
('media.png',('gramps-media','Media',gtk.gdk.CONTROL_MASK,0,'')),
('ped24.png',('gramps-pedigree','Pedigree',gtk.gdk.CONTROL_MASK,0,'')), ('ped24.png',('gramps-pedigree','Pedigree',gtk.gdk.CONTROL_MASK,0,'')),
('repos.png',('gramps-repository','Repositories', ('repos.png',('gramps-repository','Repositories',
gtk.gdk.CONTROL_MASK,0,'')), gtk.gdk.CONTROL_MASK,0,'')),
@ -155,13 +157,14 @@ class Gramps:
vm.register_view(EventView.EventView) vm.register_view(EventView.EventView)
vm.register_view(SourceView.SourceView) vm.register_view(SourceView.SourceView)
vm.register_view(PlaceView.PlaceView) vm.register_view(PlaceView.PlaceView)
vm.register_view(MediaView.MediaView)
vm.register_view(MapView.MapView) vm.register_view(MapView.MapView)
vm.register_view(RepositoryView.RepositoryView) vm.register_view(RepositoryView.RepositoryView)
ArgHandler.ArgHandler(state,vm,args) ArgHandler.ArgHandler(state,vm,args)
vm.init_interface() vm.init_interface()
state.emit("database-changed", (state.db,)) state.db.request_rebuild()
state.change_active_person(state.db.get_default_person()) state.change_active_person(state.db.get_default_person())
# Don't show main window until ArgHandler is done. # Don't show main window until ArgHandler is done.