New EventView

svn: r5053
This commit is contained in:
Don Allingham 2005-08-11 22:13:44 +00:00
parent 88dbc3b776
commit 5a68231d1d
6 changed files with 232 additions and 173 deletions

View File

@ -1,11 +1,13 @@
2005-08-11 Don Allingham <don@gramps-project.org>
* src/DbState.py: handle self.index == -1
* src/PageView.py: Provide PersonNavPage to handle page views
that to person navigation
that to person navigation, add start of a ListView
* src/PedView.py: Derive from PersonNavPage
* src/PersonView.py: Derive from PersonNavPage
* src/ViewManager.py: Call new change_page to make sure history
buttons are correct for the view.
* src/EventView.py: merged in new EventView.
* src/gramps_main.py: register EventView
2005-08-11 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/PedView.py: More work on it.

View File

@ -90,27 +90,27 @@ def get_place(field,pmap,db):
#-------------------------------------------------------------------------
class EventEditor:
def __init__(self,event,db,parent,parent_window):
self.parent = parent
self.db = db
def __init__(self,event,dbstate,uistate):
#self.parent = parent
self.db = dbstate.db
read_only = self.db.readonly
noedit = self.db.readonly
if event:
if self.parent.child_windows.has_key(event.get_handle()):
self.parent.child_windows[event.get_handle()].present(None)
return
else:
self.win_key = event.get_handle()
else:
self.win_key = self
# if event:
# if self.parent.child_windows.has_key(event.get_handle()):
# self.parent.child_windows[event.get_handle()].present(None)
# return
# else:
# self.win_key = event.get_handle()
# else:
# self.win_key = self
self.event = event
self.child_windows = {}
# self.child_windows = {}
self.path = self.db.get_save_path()
self.plist = []
self.pmap = {}
for key in self.parent.db.get_place_handles():
title = self.parent.db.get_place_from_handle(key).get_title()
for key in self.db.get_place_handles():
title = self.db.get_place_from_handle(key).get_title()
self.pmap[title] = key
if event:
@ -247,11 +247,11 @@ class EventEditor:
Utils.bold_label(self.general_label)
try:
self.window.set_transient_for(self.parent.window)
except AttributeError:
pass
self.add_itself_to_menu()
# try:
# self.window.set_transient_for(self.parent.window)
# except AttributeError:
# pass
# self.add_itself_to_menu()
self.window.show()
def on_delete_event(self,obj,b):
@ -266,11 +266,13 @@ class EventEditor:
self.window.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.event:
label = _("New Event")
@ -294,6 +296,7 @@ class EventEditor:
self.winsmenu.append(self.menu_item)
def remove_itself_from_menu(self):
return
if self.window:
del self.parent.child_windows[self.win_key]
self.menu_item.destroy()
@ -301,6 +304,7 @@ class EventEditor:
self.parent_menu_item.destroy()
def present(self,obj):
return
self.window.present()
def on_help_clicked(self,obj):
@ -425,8 +429,8 @@ class EventRefEditor:
self.child_windows = {}
self.pmap = {}
for key in self.parent.db.get_place_handles():
title = self.parent.db.get_place_from_handle(key).get_title()
for key in self.db.get_place_handles():
title = self.db.get_place_from_handle(key).get_title()
self.pmap[title] = key
self.title = _('Event Reference Editor')
@ -594,6 +598,7 @@ class EventRefEditor:
self.winsmenu.append(self.menu_item)
def remove_itself_from_menu(self):
return
del self.win_parent.child_windows[self.win_key]
self.menu_item.destroy()
self.winsmenu.destroy()

View File

@ -33,6 +33,7 @@ import gtk.gdk
#
#-------------------------------------------------------------------------
import RelLib
import PageView
import EventEdit
import DisplayModels
import const
@ -56,122 +57,62 @@ column_names = [
_('Last Changed'),
]
_HANDLE_COL = len(column_names)
#-------------------------------------------------------------------------
#
# EventView
#
#-------------------------------------------------------------------------
class EventView:
def __init__(self,parent,db,glade):
self.parent = parent
self.parent.connect('database-changed',self.change_db)
class EventView(PageView.ListView):
def __init__(self,dbstate,uistate):
self.glade = glade
self.list = glade.get_widget("event_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.EventModel(self.parent.db,0)
self.sort_col = 0
signal_map = {
'event-add' : self.row_add,
'event-update' : self.row_update,
'event-delete' : self.row_delete,
'event-rebuild' : self.build_tree,
}
self.list.set_model(self.model)
self.list.set_headers_clickable(True)
self.topWindow = self.glade.get_widget("gramps")
PageView.ListView.__init__(self,'Event View',dbstate,uistate,
column_names,len(column_names),
DisplayModels.EventModel,
signal_map)
self.columns = []
self.change_db(db)
def get_stock(self):
return 'gramps-event'
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()
self.model = DisplayModels.EventModel(self.parent.db,
self.sort_col,order)
self.list.set_model(self.model)
colmap = self.parent.db.get_repository_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 build_columns(self):
for column in self.columns:
self.list.remove_column(column)
## column = gtk.TreeViewColumn(_('Type'), 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.columns = [column]
self.columns = []
index = 0
for pair in self.parent.db.get_event_column_order():
if not pair[0]:
continue
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
def change_db(self,db):
db.connect('event-add', self.event_add)
db.connect('event-update', self.event_update)
db.connect('event-delete', self.event_delete)
db.connect('event-rebuild',self.build_tree)
self.build_columns()
self.build_tree()
def build_tree(self):
self.list.set_model(None)
self.model = DisplayModels.EventModel(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 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 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.parent.db.get_event_from_handle(handle)
EventEdit.EventEditor(the_event,self.parent.db,self.parent,
self.topWindow)
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 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 repository's list"""
@ -184,7 +125,7 @@ class EventView:
entries = [
(gtk.STOCK_ADD, self.on_add_clicked,1),
(gtk.STOCK_REMOVE, self.on_delete_clicked,sel_sensitivity),
(gtk.STOCK_REMOVE, self.on_deletze_clicked,sel_sensitivity),
(_("Edit"), self.on_edit_clicked,sel_sensitivity),
]
@ -199,26 +140,25 @@ class EventView:
menu.append(item)
menu.popup(None,None,None,event.button,event.time)
def on_add_clicked(self,obj):
EventEdit.EventEditor(RelLib.Event(),self.parent.db,self.parent,
self.topWindow)
def add(self,obj):
EventEdit.EventEditor(RelLib.Event(),self.dbstate, self.uistate)
def on_delete_clicked(self,obj):
def remove(self,obj):
mlist = []
self.selection.selected_foreach(self.blist,mlist)
for event_handle in mlist:
db = self.dbstate.db
person_list = [ handle for handle in
self.parent.db.get_person_handles(False)
if self.parent.db.get_person_from_handle(handle).has_handle_reference('Event',event_handle) ]
db.get_person_handles(False)
if db.get_person_from_handle(handle).has_handle_reference('Event',event_handle) ]
family_list = [ handle for handle in
self.parent.db.get_family_handles()
if self.parent.db.get_family_from_handle(handle).has_handle_reference('Event',event_handle) ]
db.get_family_handles()
if db.get_family_from_handle(handle).has_handle_reference('Event',event_handle) ]
event = self.parent.db.get_event_from_handle(event_handle)
event = db.get_event_from_handle(event_handle)
ans = EventEdit.DelEventQuery(event,self.parent.db,
ans = EventEdit.DelEventQuery(event,db,
person_list,family_list)
if len(person_list) + len(family_list) > 0:
@ -233,52 +173,11 @@ class EventView:
_('_Delete Event'),ans.query_response,
self.topWindow)
def on_edit_clicked(self,obj):
def edit(self,obj):
mlist = []
self.selection.selected_foreach(self.blist,mlist)
for handle in mlist:
event = self.parent.db.get_event_from_handle(handle)
print "0", handle
print "1", event
EventEdit.EventEditor(event, self.parent.db, self.parent,
self.topWindow)
event = self.dbstate.db.get_event_from_handle(handle)
EventEdit.EventEditor(event, self.dbstate, self.uistate)
def event_add(self,handle_list):
for handle in handle_list:
self.model.add_row_by_handle(handle)
def event_update(self,handle_list):
for handle in handle_list:
self.model.update_row_by_handle(handle)
def event_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 repositorys.")
## msg2 = _("Exactly two repositorys must be selected to perform a merge. "
## "A second repository can be selected by holding down the "
## "control key while clicking on the desired repository.")
## ErrorDialog(msg,msg2)
## else:
## import MergeData
## MergeData.MergeRepositorys(self.parent.db,mlist[0],mlist[1],
## self.build_tree)

View File

@ -104,6 +104,13 @@ class PageView:
def change_page(self):
pass
def key_press(self,obj,event):
ret_key = gtk.gdk.keyval_from_name("Return")
if event.keyval == ret_key and not event.state:
self.edit(obj)
return True
return False
class PersonNavView(PageView):
def __init__(self,title,dbstate,uistate):
PageView.__init__(self,title,dbstate,uistate)
@ -218,3 +225,146 @@ class PersonNavView(PageView):
print hobj.at_end(), hobj.at_front()
self.fwd_action.set_sensitive(not hobj.at_end())
self.back_action.set_sensitive(not hobj.at_front())
class ListView(PageView):
def __init__(self, title, dbstate, uistate, columns, handle_col,
make_model, signal_map):
PageView.__init__(self, title, dbstate, uistate)
self.renderer = gtk.CellRendererText()
self.sort_col = 0
self.columns = []
self.colinfo = columns
self.handle_col = handle_col
self.make_model = make_model
self.signal_map = signal_map
dbstate.connect('database-changed',self.change_db)
def build_widget(self):
"""
Builds the interface and returns a gtk.Container type that
contains the interface. This containter will be inserted into
a gtk.Notebook page.
"""
self.list = gtk.TreeView()
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('key-press-event',self.key_press)
scrollwindow = gtk.ScrolledWindow()
scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrollwindow.set_shadow_type(gtk.SHADOW_ETCHED_IN)
scrollwindow.add(self.list)
self.renderer = gtk.CellRendererText()
self.inactive = False
self.columns = []
self.build_columns()
self.selection = self.list.get_selection()
#self.selection.connect('changed',self.row_changed)
return scrollwindow
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()
self.model = DisplayModels.EventModel(self.dbstate.db,
self.sort_col,order)
self.list.set_model(self.model)
colmap = self.dbstate.db.get_repository_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 build_columns(self):
for column in self.columns:
self.list.remove_column(column)
self.columns = []
index = 0
for pair in self.dbstate.db.get_event_column_order():
if not pair[0]:
continue
name = self.colinfo[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
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)
self.selection = self.list.get_selection()
def change_db(self,db):
for sig in self.signal_map:
db.connect(sig, self.signal_map[sig])
self.model = self.make_model(self.dbstate.db,0)
self.list.set_model(self.model)
self.build_columns()
self.build_tree()
def row_add(self,handle_list):
for handle in handle_list:
self.model.add_row_by_handle(handle)
def row_update(self,handle_list):
for handle in handle_list:
self.model.update_row_by_handle(handle)
def row_delete(self,handle_list):
for handle in handle_list:
self.model.delete_row_by_handle(handle)
def define_actions(self):
"""
Required define_actions function for PageView. Builds the action
group information required. We extend beyond the normal here,
since we want to have more than one action group for the PersonView.
Most PageViews really won't care about this.
"""
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)
def key_press(self,obj,event):
ret_key = gtk.gdk.keyval_from_name("Return")
if event.keyval == ret_key and not event.state:
self.edit(obj)
return True
return False

View File

@ -136,6 +136,7 @@ class PersonView(PageView.PersonNavView):
self.person_tree = gtk.TreeView()
self.person_tree.set_rules_hint(True)
self.person_tree.set_headers_visible(True)
self.person_tree.connect('key-press-event',self.key_press)
scrollwindow = gtk.ScrolledWindow()
scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

View File

@ -25,6 +25,7 @@ import ViewManager
import PersonView
import PedView
import MapView
import EventView
import ArgHandler
import DisplayTrace
import GrampsKeys
@ -191,6 +192,7 @@ class Gramps:
a = ViewManager.ViewManager(state)
a.register_view(PersonView.PersonView)
a.register_view(PedView.PedView)
a.register_view(EventView.EventView)
a.register_view(MapView.MapView)
a.init_interface()