basic object selection now working

svn: r5773
This commit is contained in:
Richard Taylor 2006-01-17 08:38:34 +00:00
parent 06731ccf4f
commit c6329f948c
7 changed files with 163 additions and 36 deletions

View File

@ -1,3 +1,12 @@
2006-01-17 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/ObjectSelector/_FamilyFrame.py: basic object selection now working
* src/ObjectSelector/_FamilyTreeFrame.py: basic object selection now working
* src/ObjectSelector/_ObjectFrameBase.py: basic object selection now working
* src/ObjectSelector/_ObjectSelectorWindow.py: basic object selection now working
* src/ObjectSelector/_PersonFrame.py: basic object selection now working
* src/ObjectSelector/_PersonTreeFrame.py: basic object selection now working
2006-01-16 Don Allingham <don@gramps-project.org>
* src/AddMedia.py: glade path
* src/AddrEdit.py: glade path
@ -31,6 +40,7 @@
* src/gramps.glade: reposition add/delete buttons, remove separator
between parents and relationship info
2006-01-16 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/ObjectSelector/_Factories.py: refactored object frame
* src/ObjectSelector/_FamilyFrame.py: refactored object frame

View File

@ -14,7 +14,12 @@ class FamilyFrame(ObjectFrameBase):
__gproperties__ = {}
__gsignals__ = {}
__gsignals__ = {
'selection-changed' : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_STRING,
gobject.TYPE_STRING)),
}
__default_border_width = 5
@ -27,6 +32,31 @@ class FamilyFrame(ObjectFrameBase):
preview_frame = FamilyPreviewFrame(dbstate),
tree_frame = FamilyTreeFrame(dbstate))
def handle_selection(treeselection):
(model, iter) = treeselection.get_selected()
if iter:
self.emit('selection-changed', "%s / %s (%s)" % (
str(model.get_value(iter,1)),
str(model.get_value(iter,2)),
str(model.get_value(iter,0))),
model.get_value(iter,0))
else:
self.emit('selection-changed',"No Selection","")
self._tree_frame.get_selection().connect('changed',handle_selection)
def set_preview_frame_sensitivity(treeselection):
(model, iter) = treeselection.get_selected()
if iter:
self._preview_frame.set_sensitive(True)
else:
self._preview_frame.set_sensitive(False)
self._tree_frame.get_selection().connect('changed',set_preview_frame_sensitivity)
if gtk.pygtk_version < (2,8,0):

View File

@ -16,6 +16,9 @@ class FamilyTreeFrame(gtk.Frame):
def __init__(self,dbstate):
gtk.Frame.__init__(self)
self._selection = None
self._model = None
self._dbstate = dbstate
self._list = gtk.TreeView()
@ -60,6 +63,11 @@ class FamilyTreeFrame(gtk.Frame):
self._model = FamilyModel(db)
self._list.set_model(self._model)
self._selection = self._list.get_selection()
def get_selection(self):
return self._selection
if gtk.pygtk_version < (2,8,0):
gobject.type_register(FamilyTreeFrame)

View File

@ -25,6 +25,8 @@ class ObjectFrameBase(gtk.Frame):
self._filter_frame = filter_frame
self._preview_frame = preview_frame
self._tree_frame = tree_frame
self._preview_frame.set_sensitive(False)
# Create the widgets for each of the object types
@ -55,6 +57,9 @@ class ObjectFrameBase(gtk.Frame):
self.add(pane_align)
def get_selection(self):
return self._tree_frame.get_selection()
if gtk.pygtk_version < (2,8,0):
gobject.type_register(PersonFrame)

View File

@ -12,12 +12,15 @@ class _ObjectTypeWidgets(object):
def __init__(self):
self.frame = None
self.sel_label = None
def show(self):
self.frame.show_all()
self.sel_label.show_all()
def hide(self):
self.frame.hide_all()
self.sel_label.hide_all()
OBJECT_LIST = [ObjectTypes.PERSON, ObjectTypes.FAMILY,
ObjectTypes.SOURCE, ObjectTypes.EVENT,
@ -51,12 +54,26 @@ class ObjectSelectorWindow(gtk.Window):
label = gtk.Label("Selected:")
label.set_alignment(xalign=1,yalign=0.5)
label.show()
sel_label = gtk.Label("No Selected Object")
sel_frame = gtk.Frame()
sel_frame.set_shadow_type(gtk.SHADOW_IN)
sel_frame.set_border_width(self.__class__.__default_border_width*2)
sel_frame.add(sel_label)
sel_label_box = gtk.HBox()
sel_label_box.show()
self._object_frames = {}
for object_type in object_list:
self._object_frames[object_type] = _ObjectTypeWidgets()
sel_label = gtk.Label("No Selected Object")
sel_label.set_alignment(xalign=0,yalign=0.5)
sel_label_box.pack_start(sel_label)
self._object_frames[object_type].sel_label = sel_label
sel_frame.add(sel_label_box)
sel_frame.show()
label_box = gtk.HBox()
@ -74,10 +91,13 @@ class ObjectSelectorWindow(gtk.Window):
flist_pixbuf = gtk.gdk.pixbuf_new_from_file("../flist.svg")
self._tool_list = gtk.ListStore(gtk.gdk.Pixbuf, str,int)
self._tool_list.append([person_pixbuf,'People',ObjectTypes.PERSON])
self._tool_list.append([flist_pixbuf,'Families',ObjectTypes.FAMILY])
self._tool_list.append([person_pixbuf,'Events',ObjectTypes.EVENT])
d={ObjectTypes.PERSON: [person_pixbuf,'People',ObjectTypes.PERSON],
ObjectTypes.FAMILY: [flist_pixbuf,'Families',ObjectTypes.FAMILY],
ObjectTypes.EVENT: [person_pixbuf,'Events',ObjectTypes.EVENT]}
for object_type in self._object_list:
self._tool_list.append(d[object_type])
self._tool_combo = gtk.ComboBox(self._tool_list)
@ -113,15 +133,20 @@ class ObjectSelectorWindow(gtk.Window):
frame_box = gtk.HBox()
frame_box.show()
self._object_frames = {}
for object_type in object_list:
self._object_frames[object_type] = _ObjectTypeWidgets()
self._object_frames[object_type].frame = \
_Factories.ObjectFrameFactory().get_frame(object_type,dbstate)
# connect signals
self._object_frames[object_type].frame.connect(
'selection-changed',
lambda widget,text,handle,label: label.set_text(text),
self._object_frames[object_type].sel_label)
frame_box.pack_start(self._object_frames[object_type].frame,True,True)
self._set_object_type(default_object_type)
@ -193,7 +218,7 @@ if __name__ == "__main__":
pass
db = GrampsDb.gramps_db_factory(const.app_gramps)()
db.load("/home/rtaylor/devel/Personal/gramps/test/Untitled_1.grdb",
db.load("/home/rtaylor/devel/Personal/gramps/test/Untitled_2.grdb",
cb, # callback
"w")
class D:
@ -204,8 +229,9 @@ if __name__ == "__main__":
w = ObjectSelectorWindow(dbstate=dbstate,
default_object_type = ObjectTypes.PERSON,
object_list=[ObjectTypes.PERSON,ObjectTypes.FAMILY])
default_object_type = ObjectTypes.FAMILY,
object_list=[ObjectTypes.FAMILY,
ObjectTypes.PERSON])
w.show()
w.connect("destroy", gtk.main_quit)

View File

@ -14,9 +14,12 @@ class PersonFrame(ObjectFrameBase):
__gproperties__ = {}
__gsignals__ = {}
__default_border_width = 5
__gsignals__ = {
'selection-changed' : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_STRING,
gobject.TYPE_STRING)),
}
def __init__(self,
dbstate):
@ -27,6 +30,15 @@ class PersonFrame(ObjectFrameBase):
preview_frame = PersonPreviewFrame(dbstate),
tree_frame = PersonTreeFrame(dbstate))
def handle_selection(treeselection):
(model, iter) = treeselection.get_selected()
self.emit('selection-changed', "%s (%s)" % (
str(model.get_value(iter,0)),
str(model.get_value(iter,1))),
model.get_value(iter,0))
self._tree_frame.get_selection().connect('changed',handle_selection)
if gtk.pygtk_version < (2,8,0):

View File

@ -1,6 +1,23 @@
from gettext import gettext as _
import gtk
import gobject
from PeopleModel import PeopleModel
column_names = [
_('Name'),
_('ID') ,
_('Gender'),
_('Birth Date'),
_('Birth Place'),
_('Death Date'),
_('Death Place'),
_('Spouse'),
_('Last Change'),
_('Cause of Death'),
]
class PersonTreeFrame(gtk.Frame):
@ -15,29 +32,48 @@ class PersonTreeFrame(gtk.Frame):
def __init__(self,dbstate):
gtk.Frame.__init__(self)
# dummy data for testing
self.treestore = gtk.TreeStore(str)
self._dbstate = dbstate
self._selection = None
self._model = None
# we'll add some data now - 4 rows with 3 child rows each
for parent in range(4):
piter = self.treestore.append(None, ['parent %i' % parent])
for child in range(3):
self.treestore.append(piter, ['child %i of parent %i' %
(child, parent)])
self.person_tree = gtk.TreeView(self.treestore)
self.tvcolumn = gtk.TreeViewColumn('Column 0')
self.person_tree.append_column(self.tvcolumn)
self.cell = gtk.CellRendererText()
self.tvcolumn.pack_start(self.cell, True)
self.tvcolumn.add_attribute(self.cell, 'text', 0)
self.person_tree.set_search_column(0)
self.tvcolumn.set_sort_column_id(0)
self.person_tree.set_reorderable(True)
self._tree = gtk.TreeView()
self._tree.set_rules_hint(True)
self._tree.set_headers_visible(True)
#self._tree.connect('key-press-event',self.key_press)
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn(_('Name'), renderer,text=0)
column.set_resizable(True)
column.set_min_width(225)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
self._tree.append_column(column)
for pair in self._dbstate.db.get_person_column_order():
if not pair[0]:
continue
name = column_names[pair[1]]
column = gtk.TreeViewColumn(name, renderer, markup=pair[1])
column.set_resizable(True)
column.set_min_width(60)
column.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY)
self._tree.append_column(column)
self.add(self.person_tree)
self.add(self._tree)
self.set_shadow_type(gtk.SHADOW_IN)
self.set_model(self._dbstate.db)
def set_model(self,db):
self._model = PeopleModel(db)
self._tree.set_model(self._model)
self._selection = self._tree.get_selection()
def get_selection(self):
return self._selection
if gtk.pygtk_version < (2,8,0):
gobject.type_register(PersonTreeFrame)