2006-01-15 03:51:56 +05:30
|
|
|
#for debug, remove later
|
|
|
|
import sys
|
|
|
|
sys.path.append("..")
|
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
import _Factories
|
|
|
|
from _Constants import ObjectTypes
|
2006-01-13 03:39:42 +05:30
|
|
|
from _PersonSearchCriteriaWidget import PersonSearchCriteriaWidget
|
|
|
|
from _PersonPreviewFrame import PersonPreviewFrame
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
class _ObjectTypeWidgets(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.filter_frame = None
|
|
|
|
self.preview_frame = None
|
|
|
|
self.tree_frame = None
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
self.filter_frame.show_all()
|
|
|
|
self.preview_frame.show_all()
|
|
|
|
self.tree_frame.show_all()
|
|
|
|
|
|
|
|
def hide(self):
|
|
|
|
self.filter_frame.hide_all()
|
|
|
|
self.preview_frame.hide_all()
|
|
|
|
self.tree_frame.hide_all()
|
|
|
|
|
|
|
|
OBJECT_LIST = [ObjectTypes.PERSON, ObjectTypes.FAMILY,
|
|
|
|
ObjectTypes.SOURCE, ObjectTypes.EVENT,
|
|
|
|
ObjectTypes.MEDIA, ObjectTypes.PLACE,
|
|
|
|
ObjectTypes.REPOSITORY, ObjectTypes.REFERENCE]
|
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
class ObjectSelectorWindow(gtk.Window):
|
|
|
|
|
|
|
|
__gproperties__ = {}
|
|
|
|
|
|
|
|
__gsignals__ = {
|
|
|
|
}
|
|
|
|
|
|
|
|
__default_border_width = 5
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
|
|
|
|
|
|
|
|
def __init__(self,
|
|
|
|
dbstate,
|
|
|
|
default_object_type = ObjectTypes.PERSON,
|
|
|
|
object_list = OBJECT_LIST):
|
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
gtk.Window.__init__(self)
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._dbstate = dbstate
|
|
|
|
self._object_list = object_list
|
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
self.set_title("Add Person")
|
|
|
|
|
|
|
|
# Selected object label
|
|
|
|
label = gtk.Label("Selected:")
|
2006-01-13 20:58:23 +05:30
|
|
|
label.set_alignment(xalign=1,yalign=0.5)
|
2006-01-15 03:51:56 +05:30
|
|
|
label.show()
|
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
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)
|
2006-01-15 03:51:56 +05:30
|
|
|
sel_frame.show()
|
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
label_box = gtk.HBox()
|
|
|
|
label_box.pack_start(label,False,False)
|
|
|
|
label_box.pack_start(sel_frame,True,True)
|
2006-01-15 03:51:56 +05:30
|
|
|
label_box.show()
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-13 20:58:23 +05:30
|
|
|
# Object select
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-13 20:58:23 +05:30
|
|
|
obj_label = gtk.Label("Show")
|
|
|
|
obj_label.set_alignment(xalign=1,yalign=0.5)
|
2006-01-15 03:51:56 +05:30
|
|
|
obj_label.show()
|
|
|
|
|
2006-01-13 20:58:23 +05:30
|
|
|
person_pixbuf = gtk.gdk.pixbuf_new_from_file("../person.svg")
|
|
|
|
flist_pixbuf = gtk.gdk.pixbuf_new_from_file("../flist.svg")
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
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])
|
2006-01-13 03:39:42 +05:30
|
|
|
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._tool_combo = gtk.ComboBox(self._tool_list)
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-13 20:58:23 +05:30
|
|
|
icon_cell = gtk.CellRendererPixbuf()
|
|
|
|
label_cell = gtk.CellRendererText()
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._tool_combo.pack_start(icon_cell, True)
|
|
|
|
self._tool_combo.pack_start(label_cell, True)
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._tool_combo.add_attribute(icon_cell, 'pixbuf', 0)
|
|
|
|
self._tool_combo.add_attribute(label_cell, 'text', 1)
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._tool_combo.set_active(0)
|
|
|
|
self._tool_combo.show()
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._tool_combo.connect('changed', lambda c: self._set_object_type(self._tool_list.get_value(c.get_active_iter(),2)))
|
|
|
|
|
2006-01-13 20:58:23 +05:30
|
|
|
tool_box = gtk.HBox()
|
|
|
|
tool_box.pack_start(obj_label,False,False)
|
2006-01-15 03:51:56 +05:30
|
|
|
tool_box.pack_start(self._tool_combo,False,False)
|
|
|
|
tool_box.show()
|
2006-01-13 20:58:23 +05:30
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
# Top box
|
|
|
|
|
|
|
|
top_box = gtk.HBox()
|
2006-01-13 20:58:23 +05:30
|
|
|
top_box.pack_start(tool_box,False,False)
|
2006-01-13 03:39:42 +05:30
|
|
|
top_box.pack_start(label_box,True,True)
|
2006-01-15 03:51:56 +05:30
|
|
|
top_box.show()
|
|
|
|
|
|
|
|
# Create the widgets for each of the object types
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._object_frames = {}
|
|
|
|
|
|
|
|
vbox = gtk.VBox()
|
|
|
|
vbox.show()
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
vbox2 = gtk.VBox()
|
|
|
|
vbox2.show()
|
|
|
|
|
|
|
|
pane = gtk.HPaned()
|
|
|
|
pane.show()
|
|
|
|
|
|
|
|
for object_type in object_list:
|
|
|
|
self._object_frames[object_type] = _ObjectTypeWidgets()
|
|
|
|
|
|
|
|
# Filters
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._object_frames[object_type].filter_frame = _Factories.FilterFactory().get_frame(object_type,dbstate)
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
# Preview
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._object_frames[object_type].preview_frame = _Factories.PreviewFactory().get_frame(object_type,dbstate)
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
# Tree
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._object_frames[object_type].tree_frame = _Factories.TreeFactory().get_frame(object_type,dbstate)
|
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
vbox.pack_start(self._object_frames[object_type].preview_frame,True,True)
|
|
|
|
vbox.pack_start(self._object_frames[object_type].filter_frame,True,True)
|
|
|
|
vbox2.pack_start(self._object_frames[object_type].tree_frame,True,True)
|
2006-01-13 03:39:42 +05:30
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
self._set_object_type(default_object_type)
|
|
|
|
|
|
|
|
pane.pack1(vbox2,True,False)
|
2006-01-13 03:39:42 +05:30
|
|
|
pane.pack2(vbox,False,True)
|
|
|
|
|
|
|
|
pane_align = gtk.Alignment()
|
|
|
|
pane_align.add(pane)
|
|
|
|
pane_align.set_padding(self.__class__.__default_border_width,
|
|
|
|
self.__class__.__default_border_width,
|
|
|
|
self.__class__.__default_border_width,
|
|
|
|
self.__class__.__default_border_width)
|
|
|
|
pane_align.set(0.5,0.5,1,1)
|
2006-01-15 03:51:56 +05:30
|
|
|
pane_align.show()
|
2006-01-13 03:39:42 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Bottom buttons
|
|
|
|
add_button = gtk.Button(stock=gtk.STOCK_ADD)
|
|
|
|
add_button.set_sensitive(False)
|
2006-01-15 03:51:56 +05:30
|
|
|
add_button.show()
|
2006-01-13 03:39:42 +05:30
|
|
|
|
|
|
|
cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL)
|
2006-01-15 03:51:56 +05:30
|
|
|
cancel_button.show()
|
|
|
|
|
2006-01-13 20:58:23 +05:30
|
|
|
cancel_button.connect_object("clicked", gtk.Widget.destroy, self)
|
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
bottom_button_bar = gtk.HButtonBox()
|
|
|
|
bottom_button_bar.set_layout(gtk.BUTTONBOX_SPREAD)
|
|
|
|
bottom_button_bar.set_spacing(self.__class__.__default_border_width/2)
|
|
|
|
bottom_button_bar.set_border_width(self.__class__.__default_border_width)
|
|
|
|
bottom_button_bar.add(cancel_button)
|
|
|
|
bottom_button_bar.add(add_button)
|
2006-01-15 03:51:56 +05:30
|
|
|
bottom_button_bar.show()
|
2006-01-13 03:39:42 +05:30
|
|
|
|
|
|
|
box = gtk.VBox()
|
|
|
|
box.pack_start(top_box,False,False)
|
|
|
|
box.pack_start(pane_align,True,True)
|
|
|
|
box.pack_start(bottom_button_bar,False,False)
|
2006-01-15 03:51:56 +05:30
|
|
|
box.show()
|
|
|
|
|
2006-01-13 03:39:42 +05:30
|
|
|
align = gtk.Alignment()
|
|
|
|
align.set_padding(self.__class__.__default_border_width,
|
|
|
|
self.__class__.__default_border_width,
|
|
|
|
self.__class__.__default_border_width,
|
|
|
|
self.__class__.__default_border_width)
|
|
|
|
align.set(0.5,0.5,1,1)
|
|
|
|
align.add(box)
|
2006-01-15 03:51:56 +05:30
|
|
|
align.show()
|
2006-01-13 03:39:42 +05:30
|
|
|
|
|
|
|
self.add(align)
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
|
|
|
|
def _set_object_type(self,selected_object_type):
|
|
|
|
# enable default
|
|
|
|
self._object_frames[selected_object_type].show()
|
|
|
|
|
|
|
|
# disable all the others
|
|
|
|
[ self._object_frames[object_type].hide() for object_type in self._object_list
|
|
|
|
if object_type != selected_object_type]
|
|
|
|
|
|
|
|
store = self._tool_list
|
|
|
|
it = store.get_iter_first()
|
|
|
|
while it:
|
|
|
|
if store.get(it, 2)[0] == selected_object_type:
|
|
|
|
break
|
|
|
|
it = store.iter_next(it)
|
|
|
|
|
|
|
|
if it != None:
|
|
|
|
self._tool_combo.set_active_iter(it)
|
2006-01-13 03:39:42 +05:30
|
|
|
|
|
|
|
if gtk.pygtk_version < (2,8,0):
|
|
|
|
gobject.type_register(PersonSearchCriteriaWidget)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2006-01-15 03:51:56 +05:30
|
|
|
|
|
|
|
import GrampsDb
|
|
|
|
import const
|
|
|
|
|
|
|
|
def cb(d):
|
|
|
|
pass
|
|
|
|
|
|
|
|
db = GrampsDb.gramps_db_factory(const.app_gramps)()
|
|
|
|
db.load("/home/gramps/lib/gramps.rjt/gramps2.grdb",
|
|
|
|
cb, # callback
|
|
|
|
"w")
|
|
|
|
class D:
|
|
|
|
pass
|
|
|
|
|
|
|
|
dbstate = D()
|
|
|
|
dbstate.db = db
|
|
|
|
|
|
|
|
|
|
|
|
w = ObjectSelectorWindow(dbstate=dbstate,
|
|
|
|
default_object_type = ObjectTypes.FAMILY,
|
|
|
|
object_list=[ObjectTypes.PERSON,ObjectTypes.FAMILY])
|
|
|
|
w.show()
|
2006-01-13 20:58:23 +05:30
|
|
|
w.connect("destroy", gtk.main_quit)
|
2006-01-13 03:39:42 +05:30
|
|
|
|
|
|
|
gtk.main()
|