* various: added new views
svn: r5054
This commit is contained in:
parent
6839cb9a85
commit
9d62401d7b
@ -1,4 +1,5 @@
|
||||
2005-08-11 Don Allingham <don@gramps-project.org>
|
||||
* various: added new views
|
||||
* src/DbState.py: handle self.index == -1
|
||||
* src/PageView.py: Provide PersonNavPage to handle page views
|
||||
that to person navigation, add start of a ListView
|
||||
|
@ -51,7 +51,6 @@ import NameDisplay
|
||||
|
||||
from DdTargets import DdTargets
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# EditPlace
|
||||
@ -59,23 +58,25 @@ from DdTargets import DdTargets
|
||||
#-------------------------------------------------------------------------
|
||||
class EditPlace:
|
||||
|
||||
def __init__(self,parent,place,parent_window=None):
|
||||
self.parent = parent
|
||||
if place and place.get_handle():
|
||||
if self.parent.child_windows.has_key(place.get_handle()):
|
||||
self.parent.child_windows[place.get_handle()].present(None)
|
||||
return
|
||||
else:
|
||||
self.win_key = place.get_handle()
|
||||
self.ref_not_loaded = 1
|
||||
else:
|
||||
self.win_key = self
|
||||
self.ref_not_loaded = 0
|
||||
def __init__(self,parent,place,dbstate,uistate):
|
||||
#self.parent = parent
|
||||
self.dbstate = dbstate
|
||||
self.uistate = uistate
|
||||
# if place and place.get_handle():
|
||||
# if self.parent.child_windows.has_key(place.get_handle()):
|
||||
# self.parent.child_windows[place.get_handle()].present(None)
|
||||
# return
|
||||
# else:
|
||||
# self.win_key = place.get_handle()
|
||||
# self.ref_not_loaded = 1
|
||||
# else:
|
||||
# self.win_key = self
|
||||
# self.ref_not_loaded = 0
|
||||
self.name_display = NameDisplay.displayer.display
|
||||
self.place = place
|
||||
self.db = parent.db
|
||||
self.child_windows = {}
|
||||
self.path = parent.db.get_save_path()
|
||||
# self.child_windows = {}
|
||||
# self.path = parent.db.get_save_path()
|
||||
self.not_loaded = 1
|
||||
self.lists_changed = 0
|
||||
if place:
|
||||
@ -93,7 +94,7 @@ class EditPlace:
|
||||
self.glry = ImageSelect.Gallery(place, self.db.commit_place, self.path,
|
||||
self.iconlist, self.db, self,self.top)
|
||||
|
||||
mode = not self.parent.db.readonly
|
||||
mode = not self.dbstate.db.readonly
|
||||
self.title = self.top_window.get_widget("place_title")
|
||||
self.title.set_editable(mode)
|
||||
self.city = self.top_window.get_widget("city")
|
||||
@ -220,9 +221,9 @@ class EditPlace:
|
||||
self.top_window.get_widget('add_src'),
|
||||
self.top_window.get_widget('edit_src'),
|
||||
self.top_window.get_widget('del_src'),
|
||||
self.parent.db.readonly)
|
||||
self.dbstate.db.readonly)
|
||||
|
||||
if self.place.get_handle() == None or self.parent.db.readonly:
|
||||
if self.place.get_handle() == None or self.dbstate.db.readonly:
|
||||
self.top_window.get_widget("add_photo").set_sensitive(0)
|
||||
self.top_window.get_widget("delete_photo").set_sensitive(0)
|
||||
|
||||
@ -283,6 +284,7 @@ class EditPlace:
|
||||
self.child_windows = {}
|
||||
|
||||
def add_itself_to_menu(self):
|
||||
return
|
||||
self.parent.child_windows[self.win_key] = self
|
||||
if not self.place.get_title():
|
||||
label = _("New Place")
|
||||
@ -302,6 +304,7 @@ class EditPlace:
|
||||
self.winsmenu.append(self.menu_item)
|
||||
|
||||
def remove_itself_from_menu(self):
|
||||
return
|
||||
del self.parent.child_windows[self.win_key]
|
||||
self.menu_item.destroy()
|
||||
self.winsmenu.destroy()
|
||||
|
@ -165,7 +165,8 @@ class ReposRefListView:
|
||||
|
||||
class EditSource:
|
||||
|
||||
def __init__(self,source,db,parent,parent_window=None,readonly=False):
|
||||
def __init__(self,source,dbstate,uistate,readonly=False):
|
||||
self.dbstate = dbstate
|
||||
if source:
|
||||
self.source = source
|
||||
else:
|
||||
@ -174,19 +175,18 @@ class EditSource:
|
||||
self.ref_not_loaded = 1
|
||||
else:
|
||||
self.ref_not_loaded = 0
|
||||
self.db = db
|
||||
self.parent = parent
|
||||
self.db = dbstate.db
|
||||
self.name_display = NameDisplay.displayer.display
|
||||
if source:
|
||||
if parent and self.parent.child_windows.has_key(source.get_handle()):
|
||||
self.parent.child_windows[source.get_handle()].present(None)
|
||||
return
|
||||
else:
|
||||
self.win_key = source.get_handle()
|
||||
else:
|
||||
self.win_key = self
|
||||
self.child_windows = {}
|
||||
self.path = db.get_save_path()
|
||||
# if source:
|
||||
# if parent and self.parent.child_windows.has_key(source.get_handle()):
|
||||
# self.parent.child_windows[source.get_handle()].present(None)
|
||||
# return
|
||||
# else:
|
||||
# self.win_key = source.get_handle()
|
||||
# else:
|
||||
# self.win_key = self
|
||||
# self.child_windows = {}
|
||||
self.path = self.db.get_save_path()
|
||||
self.not_loaded = 1
|
||||
self.lists_changed = 0
|
||||
self.gallery_ok = 0
|
||||
@ -199,8 +199,10 @@ class EditSource:
|
||||
_('Source Editor'))
|
||||
|
||||
plwidget = self.top_window.get_widget("iconlist")
|
||||
self.gallery = ImageSelect.Gallery(source, db.commit_place, self.path,
|
||||
plwidget, db, self, self.top)
|
||||
self.gallery = ImageSelect.Gallery(source, self.db.commit_place,
|
||||
self.path,
|
||||
plwidget,
|
||||
self.db, self, self.top)
|
||||
self.author = self.top_window.get_widget("author")
|
||||
self.pubinfo = self.top_window.get_widget("pubinfo")
|
||||
self.abbrev = self.top_window.get_widget("abbrev")
|
||||
@ -234,10 +236,10 @@ class EditSource:
|
||||
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.parent,
|
||||
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.repos_ref_view = ReposRefListView(self.parent,
|
||||
# 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)
|
||||
@ -313,14 +315,14 @@ class EditSource:
|
||||
else:
|
||||
Utils.unbold_label(self.data_label)
|
||||
|
||||
if parent_window:
|
||||
self.top.set_transient_for(parent_window)
|
||||
# if parent_window:
|
||||
# self.top.set_transient_for(parent_window)
|
||||
|
||||
self.top_window.get_widget('ok').set_sensitive(not self.db.readonly)
|
||||
|
||||
if parent_window:
|
||||
self.top.set_transient_for(parent_window)
|
||||
self.add_itself_to_menu()
|
||||
# if parent_window:
|
||||
# self.top.set_transient_for(parent_window)
|
||||
# self.add_itself_to_menu()
|
||||
self.top.show()
|
||||
if self.ref_not_loaded:
|
||||
self.ref_not_loaded = 0
|
||||
@ -386,11 +388,13 @@ class EditSource:
|
||||
self.top.destroy()
|
||||
|
||||
def close_child_windows(self):
|
||||
return
|
||||
for child_window in self.child_windows.values():
|
||||
child_window.close(None)
|
||||
self.child_windows = {}
|
||||
|
||||
def add_itself_to_menu(self):
|
||||
return
|
||||
self.parent.child_windows[self.win_key] = self
|
||||
if not self.source:
|
||||
label = _("New Source")
|
||||
@ -410,12 +414,14 @@ class EditSource:
|
||||
self.winsmenu.append(self.menu_item)
|
||||
|
||||
def remove_itself_from_menu(self):
|
||||
return
|
||||
del self.parent.child_windows[self.win_key]
|
||||
self.menu_item.destroy()
|
||||
self.winsmenu.destroy()
|
||||
self.parent_menu_item.destroy()
|
||||
|
||||
def present(self,obj):
|
||||
return
|
||||
self.top.present()
|
||||
|
||||
def button_press(self,obj):
|
||||
|
@ -77,6 +77,9 @@ class EventView(PageView.ListView):
|
||||
DisplayModels.EventModel,
|
||||
signal_map)
|
||||
|
||||
def column_order(self):
|
||||
return self.dbstate.db.get_event_column_order()
|
||||
|
||||
def get_stock(self):
|
||||
return 'gramps-event'
|
||||
|
||||
@ -98,56 +101,23 @@ class EventView(PageView.ListView):
|
||||
<toolitem action="Remove"/>
|
||||
</placeholder>
|
||||
</toolbar>
|
||||
<popup name="Popup">
|
||||
<menuitem action="Add"/>
|
||||
<menuitem action="Edit"/>
|
||||
<menuitem action="Remove"/>
|
||||
</popup>
|
||||
</ui>'''
|
||||
|
||||
def button_press(self,obj,event):
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
handle = mlist[0]
|
||||
the_event = self.dbstate.db.get_event_from_handle(handle)
|
||||
EventEdit.EventEditor(the_event,self.dbstate, self.uistate)
|
||||
return True
|
||||
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||
self.build_context_menu(event)
|
||||
return True
|
||||
return False
|
||||
|
||||
def build_context_menu(self,event):
|
||||
"""Builds the menu with editing operations on the repository's list"""
|
||||
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
if mlist:
|
||||
sel_sensitivity = 1
|
||||
else:
|
||||
sel_sensitivity = 0
|
||||
|
||||
entries = [
|
||||
(gtk.STOCK_ADD, self.on_add_clicked,1),
|
||||
(gtk.STOCK_REMOVE, self.on_deletze_clicked,sel_sensitivity),
|
||||
(_("Edit"), self.on_edit_clicked,sel_sensitivity),
|
||||
]
|
||||
|
||||
menu = gtk.Menu()
|
||||
menu.set_title(_('Event Menu'))
|
||||
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 on_double_click(self,obj,event):
|
||||
handle = self.first_selected()
|
||||
the_event = self.dbstate.db.get_event_from_handle(handle)
|
||||
EventEdit.EventEditor(the_event,self.dbstate, self.uistate)
|
||||
|
||||
def add(self,obj):
|
||||
EventEdit.EventEditor(RelLib.Event(),self.dbstate, self.uistate)
|
||||
|
||||
def remove(self,obj):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
|
||||
for event_handle in mlist:
|
||||
for event_handle in self.selected_handles():
|
||||
db = self.dbstate.db
|
||||
person_list = [ handle for handle in
|
||||
db.get_person_handles(False)
|
||||
@ -169,9 +139,12 @@ class EventView(PageView.ListView):
|
||||
msg = _('Deleting event will remove it from the database.')
|
||||
|
||||
msg = "%s %s" % (msg,Utils.data_recover_msg)
|
||||
QuestionDialog(_('Delete %s?') % event.get_gramps_id(), msg,
|
||||
_('_Delete Event'),ans.query_response,
|
||||
self.topWindow)
|
||||
descr = event.get_description()
|
||||
if descr == "":
|
||||
descr = event.get_gramps_id()
|
||||
|
||||
QuestionDialog(_('Delete %s?') % descr, msg,
|
||||
_('_Delete Event'),ans.query_response)
|
||||
|
||||
def edit(self,obj):
|
||||
mlist = []
|
||||
|
@ -1383,7 +1383,7 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback):
|
||||
Returns the Event display common information stored in the
|
||||
database's metadata.
|
||||
"""
|
||||
default = [(1,0),(1,1),(1,2),(1,3),(1,4),(1,5),(0,6)]
|
||||
default = [(1,1),(1,2),(1,3),(1,4),(1,5),(0,6)]
|
||||
return self._get_column_order(EVENT_COL_KEY,default)
|
||||
|
||||
def get_repository_column_order(self):
|
||||
|
@ -277,7 +277,7 @@ class MapView(PageView.PageView):
|
||||
This assumes that this icon has already been registered with
|
||||
GNOME as a stock icon.
|
||||
"""
|
||||
return 'gramps-place'
|
||||
return 'gramps-map'
|
||||
|
||||
def build_widget(self):
|
||||
hbox = gtk.HBox( False, 4)
|
||||
|
@ -25,7 +25,11 @@ import gtk
|
||||
NAVIGATION_NONE = -1
|
||||
NAVIGATION_PERSON = 0
|
||||
|
||||
|
||||
#----------------------------------------------------------------
|
||||
#
|
||||
# PageView
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
class PageView:
|
||||
|
||||
def __init__(self,title,dbstate,uistate):
|
||||
@ -86,10 +90,12 @@ class PageView:
|
||||
if len(self.action_toggle_list) > 0:
|
||||
self.action_group.add_toggle_actions(self.action_toggle_list)
|
||||
|
||||
def add_action(self, name, stock_icon, label, accel=None, tip=None, callback=None):
|
||||
def add_action(self, name, stock_icon, label, accel=None, tip=None,
|
||||
callback=None):
|
||||
self.action_list.append((name,stock_icon,label,accel,tip,callback))
|
||||
|
||||
def add_toggle_action(self, name, stock_icon, label, accel=None, tip=None, callback=None):
|
||||
def add_toggle_action(self, name, stock_icon, label, accel=None,
|
||||
tip=None, callback=None):
|
||||
self.action_toggle_list.append((name,stock_icon,label,accel,tip,callback))
|
||||
|
||||
def get_actions(self):
|
||||
@ -110,8 +116,31 @@ class PageView:
|
||||
self.edit(obj)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def blist(self,store,path,iter,sel_list):
|
||||
handle = store.get_value(iter,self.handle_col)
|
||||
sel_list.append(handle)
|
||||
|
||||
def selected_handles(self):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
return mlist
|
||||
|
||||
def first_selected(self):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
if mlist:
|
||||
return mlist[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
#----------------------------------------------------------------
|
||||
#
|
||||
# PersonNavView
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
class PersonNavView(PageView):
|
||||
|
||||
def __init__(self,title,dbstate,uistate):
|
||||
PageView.__init__(self,title,dbstate,uistate)
|
||||
|
||||
@ -226,6 +255,11 @@ class PersonNavView(PageView):
|
||||
self.fwd_action.set_sensitive(not hobj.at_end())
|
||||
self.back_action.set_sensitive(not hobj.at_front())
|
||||
|
||||
#----------------------------------------------------------------
|
||||
#
|
||||
# ListView
|
||||
#
|
||||
#----------------------------------------------------------------
|
||||
class ListView(PageView):
|
||||
|
||||
def __init__(self, title, dbstate, uistate, columns, handle_col,
|
||||
@ -240,6 +274,9 @@ class ListView(PageView):
|
||||
self.signal_map = signal_map
|
||||
dbstate.connect('database-changed',self.change_db)
|
||||
|
||||
def column_order(self):
|
||||
assert False
|
||||
|
||||
def build_widget(self):
|
||||
"""
|
||||
Builds the interface and returns a gtk.Container type that
|
||||
@ -250,7 +287,7 @@ class ListView(PageView):
|
||||
self.list.set_rules_hint(True)
|
||||
self.list.set_headers_visible(True)
|
||||
self.list.set_headers_clickable(True)
|
||||
#self.list.connect('button-press-event',self.button_press)
|
||||
self.list.connect('button-press-event',self.button_press)
|
||||
self.list.connect('key-press-event',self.key_press)
|
||||
|
||||
scrollwindow = gtk.ScrolledWindow()
|
||||
@ -279,10 +316,9 @@ class ListView(PageView):
|
||||
order = gtk.SORT_DESCENDING
|
||||
self.sort_col = data
|
||||
handle = self.first_selected()
|
||||
self.model = DisplayModels.EventModel(self.dbstate.db,
|
||||
self.sort_col,order)
|
||||
self.model = self.make_model(self.dbstate.db, self.sort_col,order)
|
||||
self.list.set_model(self.model)
|
||||
colmap = self.dbstate.db.get_repository_column_order()
|
||||
colmap = self.column_order()
|
||||
|
||||
if handle:
|
||||
path = self.model.on_get_path(handle)
|
||||
@ -298,8 +334,15 @@ class ListView(PageView):
|
||||
|
||||
self.columns = []
|
||||
|
||||
column = gtk.TreeViewColumn(self.colinfo[0], self.renderer,text=0)
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(225)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
self.list.append_column(column)
|
||||
self.columns = [column]
|
||||
|
||||
index = 0
|
||||
for pair in self.dbstate.db.get_event_column_order():
|
||||
for pair in self.column_order():
|
||||
if not pair[0]:
|
||||
continue
|
||||
name = self.colinfo[pair[1]]
|
||||
@ -312,18 +355,6 @@ class ListView(PageView):
|
||||
self.list.append_column(column)
|
||||
index += 1
|
||||
|
||||
def blist(self,store,path,iter,sel_list):
|
||||
handle = store.get_value(iter,self.handle_col)
|
||||
sel_list.append(handle)
|
||||
|
||||
def first_selected(self):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
if mlist:
|
||||
return mlist[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def build_tree(self):
|
||||
self.model = self.make_model(self.dbstate.db,self.sort_col)
|
||||
self.list.set_model(self.model)
|
||||
@ -361,6 +392,16 @@ class ListView(PageView):
|
||||
self.add_action('Edit', gtk.STOCK_EDIT, "_Edit", callback=self.edit)
|
||||
self.add_action('Remove', gtk.STOCK_REMOVE,"_Remove",callback=self.remove)
|
||||
|
||||
def button_press(self,obj,event):
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
||||
self.double_click(obj,event)
|
||||
return True
|
||||
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||
menu = self.uistate.uimanager.get_widget('/Popup')
|
||||
menu.popup(None,None,None,event.button,event.time)
|
||||
return True
|
||||
return False
|
||||
|
||||
def key_press(self,obj,event):
|
||||
ret_key = gtk.gdk.keyval_from_name("Return")
|
||||
if event.keyval == ret_key and not event.state:
|
||||
@ -368,3 +409,5 @@ class ListView(PageView):
|
||||
return True
|
||||
return False
|
||||
|
||||
def double_click(self,obj,event):
|
||||
return False
|
||||
|
@ -151,9 +151,7 @@ class PersonView(PageView.PersonNavView):
|
||||
|
||||
self.columns = []
|
||||
self.build_columns()
|
||||
self.person_tree.connect('row_activated', self.alpha_event)
|
||||
self.person_tree.connect('button-press-event',
|
||||
self.on_plist_button_press)
|
||||
self.person_tree.connect('button-press-event', self.on_button_press)
|
||||
self.person_tree.connect('drag_data_get', self.person_drag_data_get)
|
||||
|
||||
|
||||
@ -206,6 +204,15 @@ class PersonView(PageView.PersonNavView):
|
||||
<toolitem action="Remove"/>
|
||||
</placeholder>
|
||||
</toolbar>
|
||||
<popup name="Popup">
|
||||
<menuitem action="Back"/>
|
||||
<menuitem action="Forward"/>
|
||||
<menuitem action="HomePerson"/>
|
||||
<separator/>
|
||||
<menuitem action="Add"/>
|
||||
<menuitem action="Edit"/>
|
||||
<menuitem action="Remove"/>
|
||||
</popup>
|
||||
</ui>'''
|
||||
|
||||
def change_db(self,db):
|
||||
@ -552,12 +559,12 @@ class PersonView(PageView.PersonNavView):
|
||||
ACTION_COPY)
|
||||
self.uistate.modify_statusbar()
|
||||
|
||||
def alpha_event(self,*obj):
|
||||
EditPerson.EditPerson(self.dbstate, self.dbstate.active)
|
||||
|
||||
def on_plist_button_press(self,obj,event):
|
||||
def on_button_press(self,obj,event):
|
||||
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||
self.build_people_context_menu(event)
|
||||
menu = self.uistate.uimanager.get_widget('/Popup')
|
||||
menu.popup(None,None,None,event.button,event.time)
|
||||
return True
|
||||
return False
|
||||
|
||||
def person_drag_data_get(self, widget, context, sel_data, info, time):
|
||||
selected_ids = self.get_selected_objects()
|
||||
@ -710,65 +717,15 @@ class PersonView(PageView.PersonNavView):
|
||||
elif row == 0 and self.person_model.on_get_iter(path):
|
||||
self.person_selection.select_path(path)
|
||||
|
||||
def build_backhistmenu(self,event):
|
||||
"""Builds and displays the menu with the back portion of the history"""
|
||||
hobj = self.uistate.phistory
|
||||
if hobj.index > 0:
|
||||
backhistmenu = gtk.Menu()
|
||||
backhistmenu.set_title(_('Back Menu'))
|
||||
pids = hobj.history[:hobj.index]
|
||||
pids.reverse()
|
||||
num = 1
|
||||
for pid in pids:
|
||||
if num <= 10:
|
||||
f,r = divmod(num,10)
|
||||
hotkey = "_%d" % r
|
||||
elif num <= 20:
|
||||
hotkey = "_%s" % chr(ord('a')+num-11)
|
||||
elif num >= 21:
|
||||
break
|
||||
person = self.dbstate.db.get_person_from_handle(pid)
|
||||
item = gtk.MenuItem("%s. %s [%s]" %
|
||||
(hotkey,
|
||||
NameDisplay.displayer.display(person),
|
||||
person.get_gramps_id()))
|
||||
item.connect("activate",self.back_clicked,num)
|
||||
item.show()
|
||||
backhistmenu.append(item)
|
||||
num = num + 1
|
||||
backhistmenu.popup(None,None,None,event.button,event.time)
|
||||
|
||||
def back_pressed(self,obj,event):
|
||||
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||
self.build_backhistmenu(event)
|
||||
|
||||
def build_fwdhistmenu(self,event):
|
||||
"""Builds and displays the menu with the forward portion of the history"""
|
||||
if self.hindex < len(self.history)-1:
|
||||
fwdhistmenu = gtk.Menu()
|
||||
fwdhistmenu.set_title(_('Forward Menu'))
|
||||
pids = self.history[self.hindex+1:]
|
||||
num = 1
|
||||
for pid in pids:
|
||||
if num <= 10:
|
||||
f,r = divmod(num,10)
|
||||
hotkey = "_%d" % r
|
||||
elif num <= 20:
|
||||
hotkey = "_%s" % chr(ord('a')+num-11)
|
||||
elif num >= 21:
|
||||
break
|
||||
person = self.db.get_person_from_handle(pid)
|
||||
item = gtk.MenuItem("%s. %s [%s]" %
|
||||
(hotkey,
|
||||
NameDisplay.displayer.display(person),
|
||||
person.get_gramps_id()))
|
||||
item.connect("activate",self.fwd_clicked,num)
|
||||
item.show()
|
||||
fwdhistmenu.append(item)
|
||||
num = num + 1
|
||||
fwdhistmenu.popup(None,None,None,event.button,event.time)
|
||||
|
||||
def fwd_pressed(self,obj,event):
|
||||
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||
self.build_fwdhistmenu(event)
|
||||
def button_press(self,obj,event):
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
||||
handle = self.first_selected()
|
||||
person = self.dbstate.db.get_person_from_handle(handle)
|
||||
EditPerson.EditPerson(self.dbstate, self.uistate,person)
|
||||
return True
|
||||
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||
menu = self.uistate.uimanager.get_widget('/Popup')
|
||||
menu.popup(None,None,None,event.button,event.time)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
317
src/PlaceView.py
317
src/PlaceView.py
@ -1,7 +1,6 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2001-2004 Donald N. Allingham
|
||||
# Copyright (C) 2001-2005 Donald N. Allingham
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -20,13 +19,9 @@
|
||||
|
||||
# $Id$
|
||||
|
||||
"""
|
||||
Handles the place view for GRAMPS.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GTK modules
|
||||
# GTK/Gnome modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
@ -34,15 +29,22 @@ import gtk.gdk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Gramps modules
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import RelLib
|
||||
import PageView
|
||||
import EditPlace
|
||||
import DisplayModels
|
||||
import const
|
||||
|
||||
import Utils
|
||||
from QuestionDialog import QuestionDialog, ErrorDialog
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# internationalization
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
column_names = [
|
||||
@ -59,239 +61,100 @@ column_names = [
|
||||
_('Last Changed'),
|
||||
]
|
||||
|
||||
_HANDLE_COL = len(column_names)
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# PlaceView class
|
||||
# PlaceView
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class PlaceView:
|
||||
|
||||
def __init__(self,parent,db,glade):
|
||||
self.parent = parent
|
||||
self.parent.connect('database-changed',self.change_db)
|
||||
class PlaceView(PageView.ListView):
|
||||
def __init__(self,dbstate,uistate):
|
||||
|
||||
self.glade = glade
|
||||
self.list = glade.get_widget("place_list")
|
||||
self.list.connect('button-press-event',self.button_press)
|
||||
self.list.connect('key-press-event',self.key_press)
|
||||
self.selection = self.list.get_selection()
|
||||
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
|
||||
self.renderer = gtk.CellRendererText()
|
||||
self.model = DisplayModels.PlaceModel(self.parent.db)
|
||||
|
||||
self.list.set_model(self.model)
|
||||
self.topWindow = self.glade.get_widget("gramps")
|
||||
self.sort_col = 0
|
||||
|
||||
self.columns = []
|
||||
self.change_db(db)
|
||||
signal_map = {
|
||||
'event-add' : self.row_add,
|
||||
'event-update' : self.row_update,
|
||||
'event-delete' : self.row_delete,
|
||||
'event-rebuild' : 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
|
||||
PageView.ListView.__init__(self,'Place View',dbstate,uistate,
|
||||
column_names,len(column_names),
|
||||
DisplayModels.PlaceModel,
|
||||
signal_map)
|
||||
|
||||
def column_order(self):
|
||||
return self.dbstate.db.get_place_column_order()
|
||||
|
||||
def get_stock(self):
|
||||
return 'gramps-place'
|
||||
|
||||
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_double_click(self,obj,event):
|
||||
handle = self.first_selected()
|
||||
colmap = self.parent.db.get_place_column_order()
|
||||
place = self.dbstate.db.get_place_from_handle(handle)
|
||||
EditPlace.EditPlace(place,self.dbstate, self.uistate)
|
||||
|
||||
self.model = DisplayModels.PlaceModel(self.parent.db,
|
||||
self.scol_map[self.sort_col],order)
|
||||
self.list.set_model(self.model)
|
||||
def add(self,obj):
|
||||
EditPlace.EditPlace(RelLib.Place(),self.dbstate, self.uistate)
|
||||
|
||||
|
||||
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==self.sort_col)
|
||||
self.columns[self.sort_col].set_sort_order(order)
|
||||
|
||||
def build_columns(self):
|
||||
for column in self.columns:
|
||||
self.list.remove_column(column)
|
||||
def remove(self,obj):
|
||||
for event_handle in self.selected_handles():
|
||||
db = self.dbstate.db
|
||||
person_list = [ handle for handle in
|
||||
db.get_person_handles(False)
|
||||
if db.get_person_from_handle(handle).has_handle_reference('Place',event_handle) ]
|
||||
family_list = [ handle for handle in
|
||||
db.get_family_handles()
|
||||
if db.get_family_from_handle(handle).has_handle_reference('Place',event_handle) ]
|
||||
|
||||
column = gtk.TreeViewColumn(_('Place Name'), self.renderer,text=0)
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(225)
|
||||
column.connect('clicked',self.column_clicked,0)
|
||||
column.set_clickable(True)
|
||||
self.list.append_column(column)
|
||||
self.scol_map = [0]
|
||||
self.columns = [column]
|
||||
event = db.get_event_from_handle(event_handle)
|
||||
|
||||
index = 1
|
||||
for pair in self.parent.db.get_place_column_order():
|
||||
if not pair[0]:
|
||||
continue
|
||||
self.scol_map.append(pair[1])
|
||||
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)
|
||||
index += 1
|
||||
self.columns.append(column)
|
||||
self.list.append_column(column)
|
||||
ans = EditPlace.DelPlaceQuery(event,db,
|
||||
person_list,family_list)
|
||||
|
||||
def place_add(self,handle_list):
|
||||
for handle in handle_list:
|
||||
self.model.add_row_by_handle(handle)
|
||||
|
||||
def place_update(self,handle_list):
|
||||
for handle in handle_list:
|
||||
self.model.update_row_by_handle(handle)
|
||||
|
||||
def place_delete(self,handle_list):
|
||||
for handle in handle_list:
|
||||
self.model.delete_row_by_handle(handle)
|
||||
|
||||
def change_db(self,db):
|
||||
db.connect('place-add', self.place_add)
|
||||
db.connect('place-update', self.place_update)
|
||||
db.connect('place-delete', self.place_delete)
|
||||
db.connect('place-rebuild',self.build_tree)
|
||||
|
||||
self.build_columns()
|
||||
self.build_tree()
|
||||
|
||||
def build_tree(self):
|
||||
self.model = DisplayModels.PlaceModel(self.parent.db)
|
||||
self.list.set_model(self.model)
|
||||
self.selection = self.list.get_selection()
|
||||
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
|
||||
|
||||
def button_press(self,obj,event):
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
if mlist:
|
||||
place = self.parent.db.get_place_from_handle(mlist[0])
|
||||
EditPlace.EditPlace(self.parent,place,self.topWindow)
|
||||
return 1
|
||||
elif event.type == gtk.gdk.BUTTON_PRESS and 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):
|
||||
"""Builds the menu with editing operations on the place's list"""
|
||||
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
if mlist:
|
||||
sel_sensitivity = 1
|
||||
else:
|
||||
sel_sensitivity = 0
|
||||
entries = [
|
||||
(gtk.STOCK_ADD, self.on_add_place_clicked,1),
|
||||
(gtk.STOCK_REMOVE, self.on_delete_clicked,sel_sensitivity),
|
||||
(_("Edit"), self.on_edit_clicked,sel_sensitivity),
|
||||
]
|
||||
|
||||
menu = gtk.Menu()
|
||||
menu.set_title(_('Place Menu'))
|
||||
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 on_add_place_clicked(self,obj):
|
||||
EditPlace.EditPlace(self.parent,RelLib.Place())
|
||||
|
||||
def delete_place(self,place):
|
||||
trans = self.parent.db.transaction_begin()
|
||||
place_handle = place.get_handle()
|
||||
self.parent.db.remove_place(place_handle,trans)
|
||||
title_msg = _("Delete Place (%s)") % place.get_title()
|
||||
self.parent.db.transaction_commit(trans,title_msg)
|
||||
|
||||
def is_used(self,place_handle):
|
||||
for handle in self.parent.db.get_person_handles(sort_handles=False):
|
||||
person = self.parent.db.get_person_from_handle(handle)
|
||||
if person.has_handle_reference('Place',place_handle):
|
||||
return True
|
||||
|
||||
for handle in self.parent.db.get_family_handles():
|
||||
family = self.parent.db.get_family_from_handle(handle)
|
||||
if family.has_handle_reference('Place',place_handle):
|
||||
return True
|
||||
|
||||
for handle in self.parent.db.get_event_handles():
|
||||
event = self.parent.db.get_event_from_handle(handle)
|
||||
if event.has_handle_reference('Place',place_handle):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def on_delete_clicked(self,obj):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
|
||||
for place_handle in mlist:
|
||||
place = self.parent.db.get_place_from_handle(place_handle)
|
||||
if self.is_used(place_handle):
|
||||
ans = EditPlace.DeletePlaceQuery(place,self.parent.db)
|
||||
QuestionDialog(
|
||||
_('Delete %s?') % place.get_title(),
|
||||
_('This place is currently being used by at least one '
|
||||
'record in the database. Deleting it will remove it '
|
||||
'from the database and remove it from all records '
|
||||
'that reference it.'),
|
||||
_('_Delete Place'),
|
||||
ans.query_response)
|
||||
if len(person_list) + len(family_list) > 0:
|
||||
msg = _('This place is currently being used. Deleting it '
|
||||
'will remove it from the database and from all '
|
||||
'people and families that reference it.')
|
||||
else:
|
||||
self.delete_place(place)
|
||||
msg = _('Deleting place will remove it from the database.')
|
||||
|
||||
msg = "%s %s" % (msg,Utils.data_recover_msg)
|
||||
descr = event.get_description()
|
||||
if descr == "":
|
||||
descr = event.get_gramps_id()
|
||||
|
||||
def on_edit_clicked(self,obj):
|
||||
"""Display the selected places in the EditPlace display"""
|
||||
QuestionDialog(_('Delete %s?') % descr, msg,
|
||||
_('_Delete Place'),ans.query_response)
|
||||
|
||||
def edit(self,obj):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
|
||||
for place_handle in mlist:
|
||||
place = self.parent.db.get_place_from_handle(place_handle)
|
||||
EditPlace.EditPlace(self.parent, place,self.topWindow)
|
||||
for handle in mlist:
|
||||
place = self.dbstate.db.get_place_from_handle(handle)
|
||||
EditPlace.EditPlace(place, self.dbstate, self.uistate)
|
||||
|
||||
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 merge(self):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
|
||||
if len(mlist) != 2:
|
||||
msg = _("Cannot merge places.")
|
||||
msg2 = _("Exactly two places must be selected to perform a merge. "
|
||||
"A second place can be selected by holding down the "
|
||||
"control key while clicking on the desired place.")
|
||||
ErrorDialog(msg,msg2)
|
||||
else:
|
||||
import MergeData
|
||||
MergeData.MergePlaces(self.parent.db,mlist[0],mlist[1],self.build_tree)
|
||||
|
@ -33,6 +33,7 @@ import gtk.gdk
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import RelLib
|
||||
import PageView
|
||||
import EditSource
|
||||
import DisplayModels
|
||||
import const
|
||||
@ -46,7 +47,6 @@ from QuestionDialog import QuestionDialog, ErrorDialog
|
||||
#-------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
|
||||
column_names = [
|
||||
_('Title'),
|
||||
_('ID'),
|
||||
@ -56,222 +56,100 @@ column_names = [
|
||||
_('Last Changed'),
|
||||
]
|
||||
|
||||
_HANDLE_COL = len(column_names)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# SouceView
|
||||
#
|
||||
# SourceView
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class SourceView:
|
||||
def __init__(self,parent,db,glade):
|
||||
self.parent = parent
|
||||
self.parent.connect('database-changed',self.change_db)
|
||||
class SourceView(PageView.ListView):
|
||||
def __init__(self,dbstate,uistate):
|
||||
|
||||
self.glade = glade
|
||||
self.list = glade.get_widget("source_list")
|
||||
self.list.connect('button-press-event',self.button_press)
|
||||
self.list.connect('key-press-event',self.key_press)
|
||||
self.selection = self.list.get_selection()
|
||||
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
|
||||
self.renderer = gtk.CellRendererText()
|
||||
self.model = DisplayModels.SourceModel(self.parent.db,0)
|
||||
self.sort_col = 0
|
||||
|
||||
self.list.set_model(self.model)
|
||||
self.list.set_headers_clickable(True)
|
||||
self.topWindow = self.glade.get_widget("gramps")
|
||||
signal_map = {
|
||||
'event-add' : self.row_add,
|
||||
'event-update' : self.row_update,
|
||||
'event-delete' : self.row_delete,
|
||||
'event-rebuild' : self.build_tree,
|
||||
}
|
||||
|
||||
self.columns = []
|
||||
self.change_db(db)
|
||||
PageView.ListView.__init__(self,'Source View',dbstate,uistate,
|
||||
column_names,len(column_names),
|
||||
DisplayModels.SourceModel,
|
||||
signal_map)
|
||||
|
||||
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 column_order(self):
|
||||
return self.dbstate.db.get_source_column_order()
|
||||
|
||||
def get_stock(self):
|
||||
return 'gramps-source'
|
||||
|
||||
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_double_click(self,obj,event):
|
||||
handle = self.first_selected()
|
||||
self.model = DisplayModels.SourceModel(self.parent.db,
|
||||
self.scol_map[self.sort_col],order)
|
||||
self.list.set_model(self.model)
|
||||
colmap = self.parent.db.get_place_column_order()
|
||||
source = self.dbstate.db.get_source_from_handle(handle)
|
||||
EditSource.EditSource(source,self.dbstate, self.uistate)
|
||||
|
||||
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==self.sort_col)
|
||||
self.columns[self.sort_col].set_sort_order(order)
|
||||
def add(self,obj):
|
||||
EditSource.EditSource(RelLib.Source(),self.dbstate, self.uistate)
|
||||
|
||||
def build_columns(self):
|
||||
for column in self.columns:
|
||||
self.list.remove_column(column)
|
||||
def remove(self,obj):
|
||||
for event_handle in self.selected_handles():
|
||||
db = self.dbstate.db
|
||||
person_list = [ handle for handle in
|
||||
db.get_person_handles(False)
|
||||
if db.get_person_from_handle(handle).has_handle_reference('Source',event_handle) ]
|
||||
family_list = [ handle for handle in
|
||||
db.get_family_handles()
|
||||
if db.get_family_from_handle(handle).has_handle_reference('Source',event_handle) ]
|
||||
|
||||
column = gtk.TreeViewColumn(_('Title'), self.renderer,text=0)
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(225)
|
||||
column.set_clickable(True)
|
||||
column.connect('clicked',self.column_clicked,0)
|
||||
self.list.append_column(column)
|
||||
self.scol_map = [0]
|
||||
self.columns = [column]
|
||||
event = db.get_event_from_handle(event_handle)
|
||||
|
||||
index = 1
|
||||
for pair in self.parent.db.get_source_column_order():
|
||||
if not pair[0]:
|
||||
continue
|
||||
self.scol_map.append(pair[1])
|
||||
name = column_names[pair[1]]
|
||||
column = gtk.TreeViewColumn(name, self.renderer, text=pair[1])
|
||||
column.connect('clicked',self.column_clicked,index)
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(75)
|
||||
column.set_clickable(True)
|
||||
self.columns.append(column)
|
||||
self.list.append_column(column)
|
||||
index += 1
|
||||
ans = EditSource.DelSourceQuery(event,db,
|
||||
person_list,family_list)
|
||||
|
||||
def change_db(self,db):
|
||||
db.connect('source-add', self.source_add)
|
||||
db.connect('source-update', self.source_update)
|
||||
db.connect('source-delete', self.source_delete)
|
||||
db.connect('source-rebuild',self.build_tree)
|
||||
self.build_columns()
|
||||
self.build_tree()
|
||||
|
||||
def build_tree(self):
|
||||
self.list.set_model(None)
|
||||
self.model = DisplayModels.SourceModel(self.parent.db,self.sort_col)
|
||||
self.list.set_model(self.model)
|
||||
self.selection = self.list.get_selection()
|
||||
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
|
||||
|
||||
def button_press(self,obj,event):
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
if mlist:
|
||||
handle = mlist[0]
|
||||
source = self.parent.db.get_source_from_handle(handle)
|
||||
EditSource.EditSource(source,self.parent.db,self.parent,
|
||||
self.topWindow)
|
||||
return True
|
||||
return False
|
||||
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||
self.build_context_menu(event)
|
||||
return True
|
||||
return False
|
||||
|
||||
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 True
|
||||
return False
|
||||
|
||||
def build_context_menu(self,event):
|
||||
"""Builds the menu with editing operations on the source's list"""
|
||||
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
if mlist:
|
||||
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"), self.on_edit_clicked,sel_sensitivity),
|
||||
]
|
||||
|
||||
menu = gtk.Menu()
|
||||
menu.set_title(_('Source Menu'))
|
||||
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 on_add_clicked(self,obj):
|
||||
EditSource.EditSource(RelLib.Source(),self.parent.db,self.parent,
|
||||
self.topWindow)
|
||||
|
||||
def on_delete_clicked(self,obj):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
|
||||
for handle in mlist:
|
||||
source = self.parent.db.get_source_from_handle(handle)
|
||||
|
||||
the_lists = Utils.get_source_referents(handle,self.parent.db)
|
||||
ans = EditSource.DelSrcQuery(source,self.parent.db,the_lists)
|
||||
|
||||
if filter(None,the_lists): # quick test for non-emptiness
|
||||
if len(person_list) + len(family_list) > 0:
|
||||
msg = _('This source is currently being used. Deleting it '
|
||||
'will remove it from the database and from all '
|
||||
'records that reference it.')
|
||||
'people and families that reference it.')
|
||||
else:
|
||||
msg = _('Deleting source will remove it from the database.')
|
||||
|
||||
msg = "%s %s" % (msg,Utils.data_recover_msg)
|
||||
QuestionDialog(_('Delete %s?') % source.get_title(), msg,
|
||||
_('_Delete Source'),ans.query_response,
|
||||
self.topWindow)
|
||||
descr = event.get_description()
|
||||
if descr == "":
|
||||
descr = event.get_gramps_id()
|
||||
|
||||
QuestionDialog(_('Delete %s?') % descr, msg,
|
||||
_('_Delete Source'),ans.query_response)
|
||||
|
||||
def on_edit_clicked(self,obj):
|
||||
def edit(self,obj):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
|
||||
for handle in mlist:
|
||||
source = self.parent.db.get_source_from_handle(handle)
|
||||
EditSource.EditSource(source, self.parent.db, self.parent,
|
||||
self.topWindow)
|
||||
source = self.dbstate.db.get_source_from_handle(handle)
|
||||
EditSource.EditSource(source, self.dbstate, self.uistate)
|
||||
|
||||
def source_add(self,handle_list):
|
||||
for handle in handle_list:
|
||||
self.model.add_row_by_handle(handle)
|
||||
|
||||
def source_update(self,handle_list):
|
||||
for handle in handle_list:
|
||||
self.model.update_row_by_handle(handle)
|
||||
|
||||
def source_delete(self,handle_list):
|
||||
for handle in handle_list:
|
||||
self.model.delete_row_by_handle(handle)
|
||||
|
||||
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,sel_list):
|
||||
handle = store.get_value(iter,_HANDLE_COL)
|
||||
sel_list.append(handle)
|
||||
|
||||
def merge(self):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.blist,mlist)
|
||||
|
||||
if len(mlist) != 2:
|
||||
msg = _("Cannot merge sources.")
|
||||
msg2 = _("Exactly two sources must be selected to perform a merge. "
|
||||
"A second source can be selected by holding down the "
|
||||
"control key while clicking on the desired source.")
|
||||
ErrorDialog(msg,msg2)
|
||||
else:
|
||||
import MergeData
|
||||
MergeData.MergeSources(self.parent.db,mlist[0],mlist[1],
|
||||
self.build_tree)
|
||||
|
@ -25,7 +25,9 @@ import ViewManager
|
||||
import PersonView
|
||||
import PedView
|
||||
import MapView
|
||||
import PlaceView
|
||||
import EventView
|
||||
import SourceView
|
||||
import ArgHandler
|
||||
import DisplayTrace
|
||||
import GrampsKeys
|
||||
@ -46,26 +48,25 @@ iconpaths = [".","/usr/share/gramps"]
|
||||
|
||||
def register_stock_icons ():
|
||||
import os
|
||||
items = {
|
||||
'people48.png': ('gramps-person', 'Person', gtk.gdk.CONTROL_MASK, 0, ''),
|
||||
'family48.png': ('gramps-family', 'Family', 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, ''),
|
||||
'sources.png' : ('gramps-source', 'Sources', gtk.gdk.CONTROL_MASK, 0, ''),
|
||||
'events.png' : ('gramps-event', 'Events', gtk.gdk.CONTROL_MASK, 0, ''),
|
||||
'place.png' : ('gramps-place', 'Places', gtk.gdk.CONTROL_MASK, 0, ''),
|
||||
}
|
||||
items = [
|
||||
('people48.png',('gramps-person', 'Person', gtk.gdk.CONTROL_MASK, 0, '')),
|
||||
('family48.png',('gramps-family', 'Family', 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, '')),
|
||||
('sources.png',('gramps-source', 'Sources', gtk.gdk.CONTROL_MASK, 0, '')),
|
||||
('events.png',('gramps-event', 'Events', gtk.gdk.CONTROL_MASK, 0, '')),
|
||||
('place.png',('gramps-place', 'Places', gtk.gdk.CONTROL_MASK, 0, '')),
|
||||
('place.png',('gramps-map', 'Map', gtk.gdk.CONTROL_MASK, 0, '')),
|
||||
]
|
||||
|
||||
# Register our stock items
|
||||
gtk.stock_add (items.values())
|
||||
gtk.stock_add (map(lambda x: x[1],items))
|
||||
|
||||
# Add our custom icon factory to the list of defaults
|
||||
factory = gtk.IconFactory ()
|
||||
factory.add_default ()
|
||||
|
||||
|
||||
keys = items.keys()
|
||||
for key in keys:
|
||||
for (key,data) in items:
|
||||
|
||||
for dirname in iconpaths:
|
||||
icon_file = os.path.expanduser(os.path.join(dirname,key))
|
||||
@ -80,48 +81,10 @@ def register_stock_icons ():
|
||||
# Register icon to accompany stock item
|
||||
if pixbuf:
|
||||
icon_set = gtk.IconSet (pixbuf)
|
||||
factory.add (items[key][0], icon_set)
|
||||
factory.add (data[0], icon_set)
|
||||
else:
|
||||
print 'failed to load GTK logo for toolbar'
|
||||
|
||||
# class EventView(ListView):
|
||||
|
||||
# def __init__(self):
|
||||
# PageView.__init__(self,'Events')
|
||||
|
||||
# def define_actions(self):
|
||||
# self.add_action('Add', gtk.STOCK_ADD, '_Add', callback=self.add),
|
||||
# self.add_action('Edit', gtk.STOCK_EDIT, "_Edit")
|
||||
# self.add_action('Remove',gtk.STOCK_REMOVE,"_Remove")
|
||||
|
||||
# def get_stock(self):
|
||||
# return 'gramps-event'
|
||||
|
||||
# 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>
|
||||
# </ui>'''
|
||||
|
||||
# def add(self,obj):
|
||||
# print "Event Add"
|
||||
|
||||
|
||||
|
||||
class Gramps:
|
||||
|
||||
def __init__(self,args):
|
||||
@ -193,6 +156,8 @@ class Gramps:
|
||||
a.register_view(PersonView.PersonView)
|
||||
a.register_view(PedView.PedView)
|
||||
a.register_view(EventView.EventView)
|
||||
a.register_view(SourceView.SourceView)
|
||||
a.register_view(PlaceView.PlaceView)
|
||||
a.register_view(MapView.MapView)
|
||||
a.init_interface()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user