* 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:
parent
4424259671
commit
afa0df1e54
@ -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>
|
||||
* src/ViewManager.py: set up about box and other HELP menu items
|
||||
* src/const.py.in: strings for about box
|
||||
|
@ -1508,6 +1508,7 @@ class DbState(GrampsDBCallback.GrampsDBCallback):
|
||||
def __init__(self):
|
||||
GrampsDBCallback.GrampsDBCallback.__init__(self)
|
||||
self.db = GrampsDbBase()
|
||||
self.open = False
|
||||
self.active = None
|
||||
|
||||
def change_active_person(self,person):
|
||||
@ -1526,8 +1527,10 @@ class DbState(GrampsDBCallback.GrampsDBCallback):
|
||||
|
||||
def change_database(self,db):
|
||||
self.db = db
|
||||
self.open = True
|
||||
self.emit('database-changed',(self.db,))
|
||||
|
||||
def no_database(self):
|
||||
self.db = GrampsDbBase()
|
||||
self.open = False
|
||||
self.emit('no-database')
|
||||
|
@ -1,4 +1,3 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2001-2005 Donald N. Allingham
|
||||
@ -20,15 +19,6 @@
|
||||
|
||||
# $Id$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# standard python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import os
|
||||
import gc
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GTK/Gnome modules
|
||||
@ -43,15 +33,20 @@ import gtk.gdk
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import RelLib
|
||||
import Utils
|
||||
import GrampsKeys
|
||||
import const
|
||||
import PageView
|
||||
import DisplayModels
|
||||
import ImageSelect
|
||||
import ImgManip
|
||||
import RelImage
|
||||
import DisplayModels
|
||||
import GrampsMime
|
||||
from QuestionDialog import QuestionDialog, ErrorDialog, WarningDialog
|
||||
import const
|
||||
import Utils
|
||||
from QuestionDialog import QuestionDialog, ErrorDialog
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# internationalization
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
column_names = [
|
||||
_('Title'),
|
||||
@ -62,297 +57,99 @@ column_names = [
|
||||
_('Date'),
|
||||
]
|
||||
|
||||
_HANDLE_COL = len(column_names)
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# MediaView
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class MediaView:
|
||||
def __init__(self,parent,db,glade,update):
|
||||
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
|
||||
class MediaView(PageView.ListView):
|
||||
def __init__(self,dbstate,uistate):
|
||||
|
||||
self.selection = self.list.get_selection()
|
||||
self.list.set_model(self.model)
|
||||
signal_map = {
|
||||
'media-add' : self.row_add,
|
||||
'media-update' : self.row_update,
|
||||
'media-delete' : self.row_delete,
|
||||
'media-rebuild' : self.build_tree,
|
||||
}
|
||||
|
||||
DND_TARGETS = [
|
||||
('STRING', 0, 0),
|
||||
('text/plain',0,0),
|
||||
('text/uri-list',0,2),
|
||||
('application/x-rootwin-drop',0,1)]
|
||||
PageView.ListView.__init__(self,'Media View',dbstate,uistate,
|
||||
column_names,len(column_names),
|
||||
DisplayModels.MediaModel,
|
||||
signal_map)
|
||||
|
||||
self.list.enable_model_drag_source(
|
||||
gtk.gdk.BUTTON1_MASK,
|
||||
DND_TARGETS,
|
||||
gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_COPY
|
||||
)
|
||||
def column_order(self):
|
||||
return self.dbstate.db.get_media_column_order()
|
||||
|
||||
self.list.drag_source_set(
|
||||
gtk.gdk.BUTTON1_MASK|gtk.gdk.BUTTON3_MASK,
|
||||
DND_TARGETS,
|
||||
gtk.gdk.ACTION_COPY
|
||||
)
|
||||
def get_stock(self):
|
||||
return 'gramps-media'
|
||||
|
||||
self.list.enable_model_drag_dest(
|
||||
DND_TARGETS,
|
||||
gtk.gdk.ACTION_DEFAULT
|
||||
)
|
||||
self.list.drag_dest_set(
|
||||
gtk.DEST_DEFAULT_ALL,
|
||||
DND_TARGETS,
|
||||
gtk.gdk.ACTION_COPY|gtk.gdk.ACTION_MOVE
|
||||
)
|
||||
def build_widget(self):
|
||||
base = PageView.ListView.build_widget(self)
|
||||
vbox = gtk.VBox()
|
||||
vbox.set_border_width(4)
|
||||
vbox.set_spacing(4)
|
||||
|
||||
self.list.connect("drag-data-received", self.on_drag_data_received)
|
||||
self.list.connect("drag-data-get", self.on_drag_data_get)
|
||||
self.list.connect("drag-begin", self.on_drag_begin)
|
||||
self.list.connect("drag-drop", self.on_drag_drop)
|
||||
self.image = gtk.Image()
|
||||
self.image.set_size_request(int(const.thumbScale),
|
||||
int(const.thumbScale))
|
||||
# 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.list.connect('key-press-event',self.key_press)
|
||||
self.selection.connect('changed',self.row_change)
|
||||
return vbox
|
||||
|
||||
self.selection.connect('changed',self.on_select_row)
|
||||
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
|
||||
def row_change(self,obj):
|
||||
handle = self.first_selected()
|
||||
self.model = DisplayModels.MediaModel(self.parent.db,
|
||||
self.sort_col,order)
|
||||
self.list.set_model(self.model)
|
||||
|
||||
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)
|
||||
obj = self.dbstate.db.get_object_from_handle(handle)
|
||||
pix = ImgManip.get_thumbnail_image(obj.get_path())
|
||||
self.image.set_from_pixbuf(pix)
|
||||
|
||||
def popup_edit_photo(self, obj):
|
||||
if os.fork() == 0:
|
||||
os.execvp(const.editor,[const.editor, self.obj.get_path()])
|
||||
|
||||
def popup_change_description(self, obj):
|
||||
ImageSelect.GlobalMediaProperties(self.db,self.obj,self,self.topWindow)
|
||||
def ui_definition(self):
|
||||
return '''<ui>
|
||||
<menubar name="MenuBar">
|
||||
<menu action="EditMenu">
|
||||
<placeholder name="CommonEdit">
|
||||
<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"""
|
||||
import AddMedia
|
||||
am = AddMedia.AddMediaObject(self.db)
|
||||
am = AddMedia.AddMediaObject(self.dbstate.db)
|
||||
am.run()
|
||||
|
||||
def on_edit_clicked(self,obj):
|
||||
"""Edit the properties of an existing media object in the media list"""
|
||||
def remove(self,obj):
|
||||
handle = self.first_selected()
|
||||
the_lists = Utils.get_media_referents(handle,self.dbstate.db)
|
||||
|
||||
list_store, node = self.selection.get_selected()
|
||||
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)
|
||||
ans = ImageSelect.DeleteMediaQuery(handle,self.dbstate.db,the_lists)
|
||||
if filter(None,the_lists): # quick test for non-emptiness
|
||||
msg = _('This media object is currently being used. '
|
||||
'If you delete this object, it will be removed from '
|
||||
@ -364,75 +161,15 @@ class MediaView:
|
||||
QuestionDialog(_('Delete Media Object?'),msg,
|
||||
_('_Delete Media Object'),ans.query_response)
|
||||
|
||||
def on_drag_drop(self, tree, context, x, y, time):
|
||||
self.list.emit_stop_by_name('drag-drop')
|
||||
return 1
|
||||
def edit(self,obj):
|
||||
handle = self.first_selected()
|
||||
|
||||
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)
|
||||
|
@ -75,6 +75,9 @@ class PersonView(PageView.PersonNavView):
|
||||
dbstate.connect('database-changed',self.change_db)
|
||||
dbstate.connect('active-changed',self.goto_active_person)
|
||||
|
||||
def change_page(self):
|
||||
self.on_filter_name_changed(None)
|
||||
|
||||
def define_actions(self):
|
||||
"""
|
||||
Required define_actions function for PageView. Builds the action
|
||||
@ -91,12 +94,17 @@ class PersonView(PageView.PersonNavView):
|
||||
|
||||
PageView.PersonNavView.define_actions(self)
|
||||
|
||||
self.add_action('Add', gtk.STOCK_ADD, "_Add", callback=self.add)
|
||||
self.add_action('Edit', gtk.STOCK_EDIT, "_Edit", 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_action('Add', gtk.STOCK_ADD, "_Add",
|
||||
callback=self.add)
|
||||
self.add_action('Edit', gtk.STOCK_EDIT, "_Edit",
|
||||
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):
|
||||
"""
|
||||
@ -129,9 +137,7 @@ class PersonView(PageView.PersonNavView):
|
||||
self.filterbar.pack_start(self.filter_invert,False)
|
||||
self.filterbar.pack_end(self.filter_button,False)
|
||||
|
||||
self.filter_text.hide()
|
||||
self.filter_text.set_sensitive(0)
|
||||
self.filter_label.hide()
|
||||
self.filter_text.set_sensitive(False)
|
||||
|
||||
self.person_tree = gtk.TreeView()
|
||||
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.connect('changed',self.row_changed)
|
||||
|
||||
self.vbox.set_focus_chain([self.person_tree,self.filter_list, self.filter_text,
|
||||
self.filter_invert, self.filter_button])
|
||||
self.vbox.set_focus_chain([self.person_tree, self.filter_list,
|
||||
self.filter_text, self.filter_invert,
|
||||
self.filter_button])
|
||||
|
||||
self.setup_filter()
|
||||
return self.vbox
|
||||
@ -686,12 +693,12 @@ class PersonView(PageView.PersonNavView):
|
||||
qual = mime_filter.need_param
|
||||
if qual:
|
||||
self.filter_text.show()
|
||||
self.filter_text.set_sensitive(1)
|
||||
self.filter_text.set_sensitive(True)
|
||||
self.filter_label.show()
|
||||
self.filter_label.set_text(mime_filter.get_rules()[0].labels[0])
|
||||
else:
|
||||
self.filter_text.hide()
|
||||
self.filter_text.set_sensitive(0)
|
||||
self.filter_text.set_sensitive(False)
|
||||
self.filter_label.hide()
|
||||
|
||||
def apply_filter(self,current_model=None):
|
||||
|
@ -185,7 +185,7 @@ class ViewManager:
|
||||
|
||||
self.notebook.connect('switch-page',self.change_page)
|
||||
self.uistate = DisplayState.DisplayState(self.window, self.statusbar,
|
||||
self.uimanager, self.state)
|
||||
self.uimanager, self.state)
|
||||
|
||||
person_nav = Navigation.PersonNavigation(self.uistate)
|
||||
self.navigation_type[PageView.NAVIGATION_PERSON] = (person_nav,None)
|
||||
@ -193,8 +193,7 @@ class ViewManager:
|
||||
|
||||
def init_interface(self):
|
||||
self.create_pages()
|
||||
self.change_page(None,None,0)
|
||||
#self.state.no_database()
|
||||
self.change_page(None,None)
|
||||
self.actiongroup.set_visible(False)
|
||||
|
||||
def set_color(self,obj):
|
||||
@ -217,21 +216,21 @@ class ViewManager:
|
||||
self.actiongroup = gtk.ActionGroup('MainWindow')
|
||||
self.fileactions = gtk.ActionGroup('FileWindow')
|
||||
self.fileactions.add_actions([
|
||||
('FileMenu', None, '_File'),
|
||||
('New', gtk.STOCK_NEW, '_New', "<control>n", None, self.on_new_activate),
|
||||
('Open', gtk.STOCK_OPEN, '_Open', "<control>o", None, self.on_open_activate),
|
||||
('OpenRecent', gtk.STOCK_OPEN, 'Open _Recent'),
|
||||
('Quit', gtk.STOCK_QUIT, '_Quit', "<control>q", None, gtk.main_quit),
|
||||
('ViewMenu', None, '_View'),
|
||||
('Preferences',gtk.STOCK_PREFERENCES,'_Preferences'),
|
||||
('FileMenu', None, '_File'),
|
||||
('New', gtk.STOCK_NEW, '_New', "<control>n", None, self.new_activate),
|
||||
('Open', gtk.STOCK_OPEN, '_Open', "<control>o", None, self.open_activate),
|
||||
('OpenRecent', gtk.STOCK_OPEN, 'Open _Recent'),
|
||||
('Quit', gtk.STOCK_QUIT, '_Quit', "<control>q", None, gtk.main_quit),
|
||||
('ViewMenu', None, '_View'),
|
||||
('Preferences', gtk.STOCK_PREFERENCES, '_Preferences'),
|
||||
('ColumnEdit', gtk.STOCK_PROPERTIES, '_Column Editor'),
|
||||
('HelpMenu', None, '_Help'),
|
||||
('HomePage', None, _('GRAMPS _home page'), None, None, self.home_page_activate),
|
||||
('MailingLists',None, _('GRAMPS _mailing lists'), None, None, self.mailing_lists_activate),
|
||||
('ReportBug', None, _('_Report a bug'), None, None, self.report_bug_activate),
|
||||
('About', gtk.STOCK_ABOUT, '_About', None, None, self.about),
|
||||
('FAQ', None, '_FAQ', None, None, self.faq_activate),
|
||||
('UserManual', gtk.STOCK_HELP, '_User Manual', 'F1', None, self.manual_activate),
|
||||
('HelpMenu', None, '_Help'),
|
||||
('HomePage', None, _('GRAMPS _home page'), None, None, self.home_page_activate),
|
||||
('MailingLists', None, _('GRAMPS _mailing lists'), None, None, self.mailing_lists_activate),
|
||||
('ReportBug', None, _('_Report a bug'), None, None, self.report_bug_activate),
|
||||
('About', gtk.STOCK_ABOUT, '_About', None, None, self.about),
|
||||
('FAQ', None, '_FAQ', None, None, self.faq_activate),
|
||||
('UserManual', gtk.STOCK_HELP, '_User Manual', 'F1', None, self.manual_activate),
|
||||
])
|
||||
|
||||
self.actiongroup.add_actions([
|
||||
@ -242,8 +241,8 @@ class ViewManager:
|
||||
('Undo', gtk.STOCK_UNDO, '_Undo', '<control>z' ),
|
||||
('CmpMerge', None, '_Compare and merge'),
|
||||
('FastMerge', None, '_Fast merge'),
|
||||
('ScratchPad', gtk.STOCK_PASTE, '_ScratchPad', None, None, self.on_scratchpad),
|
||||
('Import', gtk.STOCK_CONVERT, '_Import', None, None, self.on_import),
|
||||
('ScratchPad', gtk.STOCK_PASTE, '_ScratchPad', None, None, self.scratchpad),
|
||||
('Import', gtk.STOCK_CONVERT, '_Import', None, None, self.import_data),
|
||||
('Reports', gtk.STOCK_DND_MULTIPLE, '_Reports'),
|
||||
('Tools', gtk.STOCK_EXECUTE, '_Tools'),
|
||||
('EditMenu', None, '_Edit'),
|
||||
@ -356,44 +355,52 @@ class ViewManager:
|
||||
button.set_border_width(4)
|
||||
button.set_relief(gtk.RELIEF_NONE)
|
||||
button.set_alignment(0,0.5)
|
||||
button.connect('clicked',lambda x,y : self.notebook.set_current_page(y),
|
||||
index)
|
||||
button.connect('clicked',
|
||||
lambda x,y : self.notebook.set_current_page(y), index)
|
||||
self.set_color(button)
|
||||
button.show()
|
||||
index += 1
|
||||
self.bbox.pack_start(button,False)
|
||||
|
||||
def change_page(self,obj,page,num):
|
||||
for mergeid in self.merge_ids:
|
||||
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)
|
||||
def change_page(self,obj,page,num=-1):
|
||||
if num == -1:
|
||||
num = self.notebook.get_current_page()
|
||||
if self.state.open == True:
|
||||
|
||||
if len(self.pages) > 0:
|
||||
self.active_page = self.pages[num]
|
||||
for mergeid in self.merge_ids:
|
||||
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 old_nav[0] != None:
|
||||
old_nav[0].disable
|
||||
if len(self.pages) > 0:
|
||||
self.active_page = self.pages[num]
|
||||
|
||||
nav_type = self.navigation_type[self.active_page.navigation_type()]
|
||||
if nav_type[0] != None:
|
||||
nav_type[0].enable()
|
||||
|
||||
groups = self.active_page.get_actions()
|
||||
old_nav = self.navigation_type[self.prev_nav]
|
||||
if old_nav[0] != None:
|
||||
old_nav[0].disable()
|
||||
|
||||
for grp in groups:
|
||||
self.uimanager.insert_action_group(grp,1)
|
||||
self.merge_ids = [self.uimanager.add_ui_from_string(self.active_page.ui_definition())]
|
||||
for ui in self.active_page.additional_ui_definitions():
|
||||
mergeid = self.uimanager.add_ui_from_string(ui)
|
||||
self.merge_ids.append(mergeid)
|
||||
nav_type = self.navigation_type[self.active_page.navigation_type()]
|
||||
if nav_type[0] != None:
|
||||
nav_type[0].enable()
|
||||
|
||||
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'),
|
||||
self.uistate.window,
|
||||
@ -410,8 +417,14 @@ class ViewManager:
|
||||
add_gedcom_filter(choose)
|
||||
|
||||
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
|
||||
|
||||
# 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:
|
||||
choose.add_filter(mime_filter)
|
||||
format_list.append(mime_type)
|
||||
@ -480,7 +493,7 @@ class ViewManager:
|
||||
choose.destroy()
|
||||
return False
|
||||
|
||||
def on_new_activate(self,obj):
|
||||
def new_activate(self,obj):
|
||||
|
||||
choose = gtk.FileChooserDialog(_('GRAMPS: Create GRAMPS database'),
|
||||
self.uistate.window,
|
||||
@ -522,8 +535,10 @@ class ViewManager:
|
||||
self.state.db.close()
|
||||
except:
|
||||
pass
|
||||
self.state.db = GrampsBSDDB.GrampsBSDDB()
|
||||
self.state.change_database(GrampsBSDDB.GrampsBSDDB())
|
||||
self.read_file(filename)
|
||||
self.state.db.request_rebuild()
|
||||
self.change_page(None,None)
|
||||
# Add the file to the recent items
|
||||
#RecentFiles.recent_files(filename,const.app_gramps)
|
||||
#self.parent.build_recent_menu()
|
||||
@ -544,7 +559,7 @@ class ViewManager:
|
||||
|
||||
success = False
|
||||
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")
|
||||
msg_top = msgxml.get_widget('load_message')
|
||||
msg_label = msgxml.get_widget('message')
|
||||
@ -556,13 +571,19 @@ class ViewManager:
|
||||
gtk.main_iteration()
|
||||
|
||||
success = self.read_file(filename,update_msg)
|
||||
self.state.db.request_rebuild()
|
||||
self.change_page(None,None)
|
||||
msg_top.destroy()
|
||||
elif filetype == const.app_gramps_xml:
|
||||
self.state.db = GrampsXMLDB.GrampsXMLDB()
|
||||
self.state.change_database(GrampsXMLDB.GrampsXMLDB())
|
||||
success = self.read_file(filename)
|
||||
self.state.db.request_rebuild()
|
||||
self.change_page(None,None)
|
||||
elif filetype == const.app_gedcom:
|
||||
self.state.db = GrampsGEDDB.GrampsGEDDB()
|
||||
self.state.change_database(GrampsGEDDB.GrampsGEDDB())
|
||||
success = self.read_file(filename)
|
||||
self.state.db.request_rebuild()
|
||||
self.change_page(None,None)
|
||||
|
||||
#if success:
|
||||
# Add the file to the recent items
|
||||
@ -579,13 +600,13 @@ class ViewManager:
|
||||
ErrorDialog(_('Cannot open database'),
|
||||
_('The selected file is a directory, not '
|
||||
'a file.\nA GRAMPS database must be a file.'))
|
||||
return 0
|
||||
return False
|
||||
elif os.path.exists(filename):
|
||||
if not os.access(filename,os.R_OK):
|
||||
ErrorDialog(_('Cannot open database'),
|
||||
_('You do not have read access to the selected '
|
||||
'file.'))
|
||||
return 0
|
||||
return False
|
||||
elif not os.access(filename,os.W_OK):
|
||||
mode = "r"
|
||||
QuestionDialog.WarningDialog(_('Read only database'),
|
||||
@ -598,24 +619,26 @@ class ViewManager:
|
||||
filename = filename[:-1]
|
||||
name = os.path.basename(filename)
|
||||
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:
|
||||
self.uistate.window.set_title("%s - GRAMPS" % name)
|
||||
msg = "%s - GRAMPS" % name
|
||||
self.uistate.window.set_title(msg)
|
||||
else:
|
||||
GrampsKeys.save_last_file("")
|
||||
QuestionDialog.ErrorDialog(_('Cannot open database'),
|
||||
_('The database file specified could not be opened.'))
|
||||
return 0
|
||||
return False
|
||||
except ( IOError, OSError, Errors.FileVersionError), msg:
|
||||
QuestionDialog.ErrorDialog(_('Cannot open database'),str(msg))
|
||||
return 0
|
||||
return False
|
||||
except (db.DBAccessError,db.DBError), msg:
|
||||
QuestionDialog.ErrorDialog(_('Cannot open database'),
|
||||
_('%s could not be opened.' % filename) + '\n' + msg[1])
|
||||
return 0
|
||||
return False
|
||||
except Exception:
|
||||
DisplayTrace.DisplayTrace()
|
||||
return 0
|
||||
return False
|
||||
|
||||
# Undo/Redo always start with standard labels and insensitive state
|
||||
#self.undo_callback(None)
|
||||
@ -625,19 +648,16 @@ class ViewManager:
|
||||
return True
|
||||
|
||||
def load_database(self,name,callback=None,mode="w"):
|
||||
|
||||
filename = name
|
||||
|
||||
if self.state.db.load(filename,callback,mode) == 0:
|
||||
return 0
|
||||
val = self.post_load(name,callback)
|
||||
return val
|
||||
if not self.state.db.load(name,callback,mode):
|
||||
return False
|
||||
return self.post_load(name,callback)
|
||||
|
||||
def post_load(self,name,callback=None):
|
||||
if not self.state.db.version_supported():
|
||||
raise Errors.FileVersionError(
|
||||
"The database version is not supported by this version of GRAMPS.\n"
|
||||
"Please upgrade to the corresponding version or use XML for porting"
|
||||
"The database version is not supported by this "
|
||||
"version of GRAMPS.\nPlease upgrade to the "
|
||||
"corresponding version or use XML for porting"
|
||||
"data between different database versions.")
|
||||
|
||||
self.state.db.set_save_path(name)
|
||||
@ -660,14 +680,9 @@ class ViewManager:
|
||||
GrampsKeys.save_last_file(name)
|
||||
|
||||
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.goto_active_person()
|
||||
|
||||
#if callback:
|
||||
# callback(_('Setup complete'))
|
||||
#self.enable_buttons(True)
|
||||
self.change_page(None,None)
|
||||
self.actiongroup.set_visible(True)
|
||||
return True
|
||||
|
||||
def find_initial_person(self):
|
||||
@ -679,11 +694,11 @@ class ViewManager:
|
||||
person = self.state.db.get_person_from_handle(the_ids[0])
|
||||
return person
|
||||
|
||||
def on_scratchpad(self,obj):
|
||||
def scratchpad(self,obj):
|
||||
import ScratchPad
|
||||
ScratchPad.ScratchPadWindow(self.state, self)
|
||||
|
||||
def on_import(self,obj):
|
||||
def import_data(self,obj):
|
||||
choose = gtk.FileChooserDialog(_('GRAMPS: Import database'),
|
||||
self.uistate.window,
|
||||
gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
@ -701,7 +716,12 @@ class ViewManager:
|
||||
format_list = [const.app_gramps,const.app_gramps_xml,const.app_gedcom]
|
||||
|
||||
# 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:
|
||||
choose.add_filter(mime_filter)
|
||||
format_list.append(mime_type)
|
||||
@ -714,7 +734,8 @@ class ViewManager:
|
||||
# then home.
|
||||
default_dir = GrampsKeys.get_last_import_dir()
|
||||
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:
|
||||
default_dir = GrampsKeys.get_last_export_dir()
|
||||
if len(default_dir)<=1:
|
||||
@ -831,7 +852,7 @@ class GrampsFormatWidget(gtk.ComboBox):
|
||||
|
||||
for format,label in format_list:
|
||||
self.store.append(row=[label])
|
||||
self.set_active(0)
|
||||
self.set_active(False)
|
||||
|
||||
def get_value(self):
|
||||
active = self.get_active()
|
||||
|
10460
gramps2/src/gramps.glade
10460
gramps2/src/gramps.glade
File diff suppressed because it is too large
Load Diff
@ -41,6 +41,7 @@ import MapView
|
||||
import PlaceView
|
||||
import EventView
|
||||
import SourceView
|
||||
import MediaView
|
||||
import ArgHandler
|
||||
import DisplayTrace
|
||||
import GrampsKeys
|
||||
@ -62,6 +63,7 @@ def register_stock_icons ():
|
||||
items = [
|
||||
('people48.png',('gramps-person','Person',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,'')),
|
||||
('repos.png',('gramps-repository','Repositories',
|
||||
gtk.gdk.CONTROL_MASK,0,'')),
|
||||
@ -155,13 +157,14 @@ class Gramps:
|
||||
vm.register_view(EventView.EventView)
|
||||
vm.register_view(SourceView.SourceView)
|
||||
vm.register_view(PlaceView.PlaceView)
|
||||
vm.register_view(MediaView.MediaView)
|
||||
vm.register_view(MapView.MapView)
|
||||
vm.register_view(RepositoryView.RepositoryView)
|
||||
|
||||
ArgHandler.ArgHandler(state,vm,args)
|
||||
|
||||
vm.init_interface()
|
||||
state.emit("database-changed", (state.db,))
|
||||
state.db.request_rebuild()
|
||||
state.change_active_person(state.db.get_default_person())
|
||||
|
||||
# Don't show main window until ArgHandler is done.
|
||||
|
Loading…
Reference in New Issue
Block a user