diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 07df3d647..850822a08 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,11 @@ +2006-01-17 Richard Taylor + * src/ListBox.py: added import for gettext + * src/ObjectSelector/_Factories.py, src/ObjectSelector/_FamilyFrame.py + src/ObjectSelector/_ObjectFrameBase.py, src/ObjectSelector/_ObjectSelectorWindow.py + src/ObjectSelector/_PersonFrame.py, src/ObjectSelector/_PersonTreeFrame.py: added New button + for Person view + + 2006-01-18 Don Allingham * src/GrampsDb/_ReadGedcom.py: fix MARNM * src/GrampsWidgets.py: edit label for column header diff --git a/gramps2/src/ListBox.py b/gramps2/src/ListBox.py index afd30e13f..adbd1d32f 100644 --- a/gramps2/src/ListBox.py +++ b/gramps2/src/ListBox.py @@ -25,6 +25,7 @@ # Standard python modules # #------------------------------------------------------------------------- +from gettext import gettext as _ import cPickle as pickle from sets import Set import locale diff --git a/gramps2/src/ObjectSelector/_Factories.py b/gramps2/src/ObjectSelector/_Factories.py index ebf184dd5..6704d9a4d 100644 --- a/gramps2/src/ObjectSelector/_Factories.py +++ b/gramps2/src/ObjectSelector/_Factories.py @@ -8,7 +8,7 @@ class ObjectFrameFactory(object): __frame_creators = {ObjectTypes.PERSON: PersonFrame, ObjectTypes.FAMILY: FamilyFrame} - def get_frame(self,object_type,dbstate): - return self.__class__.__frame_creators[object_type](dbstate) + def get_frame(self,object_type,dbstate,uistate): + return self.__class__.__frame_creators[object_type](dbstate,uistate) diff --git a/gramps2/src/ObjectSelector/_FamilyFrame.py b/gramps2/src/ObjectSelector/_FamilyFrame.py index fd5bae06d..4583e982b 100644 --- a/gramps2/src/ObjectSelector/_FamilyFrame.py +++ b/gramps2/src/ObjectSelector/_FamilyFrame.py @@ -28,10 +28,12 @@ class FamilyFrame(ObjectFrameBase): __person_id_field = 0 def __init__(self, - dbstate): + dbstate, + uistate): ObjectFrameBase.__init__(self, dbstate=dbstate, + uistate=uistate, filter_frame = FamilyFilterFrame(dbstate), preview_frame = FamilyPreviewFrame(dbstate), tree_frame = FamilyTreeFrame(dbstate)) @@ -41,6 +43,8 @@ class FamilyFrame(ObjectFrameBase): self._tree_frame.get_selection().connect('changed',self.set_preview,self.__class__.__person_id_field) self._tree_frame.get_tree().connect('row-activated',self._on_row_activated) + def new_object(self,button): + pass def _handle_selection(self,treeselection): (model, iter) = treeselection.get_selected() diff --git a/gramps2/src/ObjectSelector/_ObjectFrameBase.py b/gramps2/src/ObjectSelector/_ObjectFrameBase.py index 0e04e2520..b368ef3e8 100644 --- a/gramps2/src/ObjectSelector/_ObjectFrameBase.py +++ b/gramps2/src/ObjectSelector/_ObjectFrameBase.py @@ -15,6 +15,7 @@ class ObjectFrameBase(gtk.Frame): def __init__(self, dbstate, + uistate, filter_frame, preview_frame, tree_frame): @@ -22,6 +23,7 @@ class ObjectFrameBase(gtk.Frame): gtk.Frame.__init__(self) self._dbstate = dbstate + self._uistate = uistate self._filter_frame = filter_frame self._preview_frame = preview_frame self._tree_frame = tree_frame @@ -73,7 +75,7 @@ class ObjectFrameBase(gtk.Frame): if gtk.pygtk_version < (2,8,0): - gobject.type_register(PersonFrame) + gobject.type_register(ObjectFrameBase) if __name__ == "__main__": pass diff --git a/gramps2/src/ObjectSelector/_ObjectSelectorWindow.py b/gramps2/src/ObjectSelector/_ObjectSelectorWindow.py index 894a14669..008c3a316 100644 --- a/gramps2/src/ObjectSelector/_ObjectSelectorWindow.py +++ b/gramps2/src/ObjectSelector/_ObjectSelectorWindow.py @@ -1,6 +1,8 @@ #for debug, remove later import sys sys.path.append("..") +sys.path.append(".") +sys.path.append("ObjectSelector") import gtk import gobject @@ -15,14 +17,17 @@ class _ObjectTypeWidgets(object): self.frame = None self.sel_label = None self.selected_id = None + self.new_button = None def show(self): self.frame.show_all() self.sel_label.show_all() + self.new_button.show() def hide(self): self.frame.hide_all() self.sel_label.hide_all() + self.new_button.hide() def set_selected_id(self,id): self.selected_id = id @@ -48,12 +53,14 @@ class ObjectSelectorWindow(gtk.Window): def __init__(self, dbstate, + uistate, default_object_type = ObjectTypes.PERSON, object_list = OBJECT_LIST): gtk.Window.__init__(self) self._dbstate = dbstate + self._uistate = dbstate self._object_list = object_list self._current_object_type = None @@ -66,6 +73,16 @@ class ObjectSelectorWindow(gtk.Window): self.set_title("Add Person") # Selected object label + + new_button_box = gtk.VBox() + new_button_box.show() + + for object_type in object_list: + new_button = gtk.Button(stock=gtk.STOCK_NEW) + + self._object_frames[object_type].new_button = new_button + new_button_box.pack_start(new_button) + label = gtk.Label("Selected:") label.set_use_markup(True) label.set_alignment(xalign=0.9,yalign=0.5) @@ -92,6 +109,7 @@ class ObjectSelectorWindow(gtk.Window): sel_frame.show() label_box = gtk.HBox() + label_box.pack_start(new_button_box,False,False) label_box.pack_start(label,False,False) label_box.pack_start(sel_frame,True,True) label_box.show() @@ -104,8 +122,8 @@ class ObjectSelectorWindow(gtk.Window): self.__class__.__default_border_width) - person_pixbuf = gtk.gdk.pixbuf_new_from_file("../person.svg") - flist_pixbuf = gtk.gdk.pixbuf_new_from_file("../flist.svg") + person_pixbuf = gtk.gdk.pixbuf_new_from_file("./person.svg") + flist_pixbuf = gtk.gdk.pixbuf_new_from_file("./flist.svg") self._tool_list = gtk.ListStore(gtk.gdk.Pixbuf, str,int) @@ -160,7 +178,7 @@ class ObjectSelectorWindow(gtk.Window): for object_type in object_list: self._object_frames[object_type].frame = \ - _Factories.ObjectFrameFactory().get_frame(object_type,dbstate) + _Factories.ObjectFrameFactory().get_frame(object_type,dbstate,uistate) # connect signals self._object_frames[object_type].frame.connect( @@ -181,6 +199,9 @@ class ObjectSelectorWindow(gtk.Window): 'add-object', self.on_add) + self._object_frames[object_type].new_button.connect( + 'clicked', + self._object_frames[object_type].frame.new_object) frame_box.pack_start(self._object_frames[object_type].frame,True,True) @@ -223,6 +244,7 @@ class ObjectSelectorWindow(gtk.Window): self.add(align) self._set_object_type(default_object_type) + self.set_default_size(700,300) def _set_object_type(self,selected_object_type): @@ -272,12 +294,13 @@ class ObjectSelectorWindow(gtk.Window): if gtk.pygtk_version < (2,8,0): - gobject.type_register(PersonSearchCriteriaWidget) + gobject.type_register(ObjectSelectorWindow) if __name__ == "__main__": import GrampsDb + import ViewManager import const import logging @@ -296,6 +319,9 @@ if __name__ == "__main__": def cb(d): pass + state = GrampsDb.DbState() + vm = ViewManager.ViewManager(state) + db = GrampsDb.gramps_db_factory(const.app_gramps)() db.load(os.path.realpath(sys.argv[1]), cb, # callback @@ -308,9 +334,9 @@ if __name__ == "__main__": w = ObjectSelectorWindow(dbstate=dbstate, - default_object_type = ObjectTypes.FAMILY, - object_list=[ObjectTypes.FAMILY, - ObjectTypes.PERSON]) + uistate=vm.uistate, + default_object_type = ObjectTypes.PERSON, + object_list=[ObjectTypes.PERSON]) w.show() w.connect("destroy", gtk.main_quit) diff --git a/gramps2/src/ObjectSelector/_PersonFrame.py b/gramps2/src/ObjectSelector/_PersonFrame.py index 02af87596..ac689463c 100644 --- a/gramps2/src/ObjectSelector/_PersonFrame.py +++ b/gramps2/src/ObjectSelector/_PersonFrame.py @@ -5,6 +5,9 @@ sys.path.append("..") import gtk import gobject +from RelLib import Person +from EditPerson import EditPerson + from _ObjectFrameBase import ObjectFrameBase from _PersonFilterFrame import PersonFilterFrame from _PersonPreviewFrame import PersonPreviewFrame @@ -29,10 +32,12 @@ class PersonFrame(ObjectFrameBase): __person_id_field = 1 def __init__(self, - dbstate): + dbstate, + uistate): ObjectFrameBase.__init__(self, dbstate=dbstate, + uistate=uistate, filter_frame = PersonFilterFrame(dbstate), preview_frame = PersonPreviewFrame(dbstate), tree_frame = PersonTreeFrame(dbstate)) @@ -56,7 +61,11 @@ class PersonFrame(ObjectFrameBase): (model, iter) = widget.get_selection().get_selected() if iter and model.get_value(iter,self.__class__.__person_id_field): self.emit('add-object') - + + def new_object(self,button): + person = Person() + EditPerson(self._dbstate,self._uistate,[],person) + if gtk.pygtk_version < (2,8,0): gobject.type_register(PersonFrame) diff --git a/gramps2/src/ObjectSelector/_PersonTreeFrame.py b/gramps2/src/ObjectSelector/_PersonTreeFrame.py index 4445eed36..f52cbf9d2 100644 --- a/gramps2/src/ObjectSelector/_PersonTreeFrame.py +++ b/gramps2/src/ObjectSelector/_PersonTreeFrame.py @@ -4,6 +4,7 @@ import gtk import gobject from PeopleModel import PeopleModel +import NameDisplay column_names = [ _('Name'), @@ -35,12 +36,16 @@ class PersonTreeFrame(gtk.Frame): self._dbstate = dbstate self._selection = None self._model = None + self._data_filter = None 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) + self._tree.connect('row-activated',self._on_row_activated) + + renderer = gtk.CellRendererText() column = gtk.TreeViewColumn(_('Name'), renderer,text=0) @@ -67,16 +72,125 @@ class PersonTreeFrame(gtk.Frame): self.add(scrollwindow) - self.set_model(self._dbstate.db) + self.change_db(self._dbstate.db) - def set_model(self,db): + def _on_row_activated(self,widget,path,col): + """Expand / colapse row""" - self._model = PeopleModel(db) + if self._tree.row_expanded(path): + self._tree.collapse_row(path) + else: + self._tree.expand_row(path,False) + + def change_db(self,db): + self.set_model(db) + db.connect('person-add', self.person_added) + db.connect('person-update', self.person_updated) + db.connect('person-delete', self.person_removed) + + def set_model(self,db,data_filter=None): + + self._model = PeopleModel(db,data_filter=data_filter) self._tree.set_model(self._model) self._selection = self._tree.get_selection() + # expand the first row so that the tree is a sensible size. + self._tree.expand_row((0,),False) + + def person_added(self,handle_list): + for node in handle_list: + person = self._dbstate.db.get_person_from_handle(node) + top = NameDisplay.displayer.name_grouping(self._dbstate.db,person) + self._model.rebuild_data(self._data_filter) + if not self._model.is_visable(node): + continue + if (not self._model.sname_sub.has_key(top) or + len(self._model.sname_sub[top]) == 1): + path = self._model.on_get_path(top) + pnode = self._model.get_iter(path) + self._model.row_inserted(path,pnode) + path = self._model.on_get_path(node) + pnode = self._model.get_iter(path) + self._model.row_inserted(path,pnode) + self._tree.expand_to_path(path) + self._tree.set_cursor(path) + + def person_removed(self,handle_list): + for node in handle_list: + person = self._dbstate.db.get_person_from_handle(node) + if not self._model.is_visable(node): + continue + top = NameDisplay.displayer.name_grouping(self._dbstate.db,person) + mylist = self._model.sname_sub.get(top,[]) + if mylist: + try: + path = self._model.on_get_path(node) + self._model.row_deleted(path) + if len(mylist) == 1: + path = self._model.on_get_path(top) + self._model.row_deleted(path) + except KeyError: + pass + self._model.rebuild_data(self.DataFilter,skip=node) + + def person_updated(self,handle_list): + for node in handle_list: + person = self._dbstate.db.get_person_from_handle(node) + try: + oldpath = self._model.iter2path[node] + except: + return + pathval = self._model.on_get_path(node) + pnode = self._model.get_iter(pathval) + + # calculate the new data + + surname = NameDisplay.displayer.name_grouping(self._dbstate.db,person) + + if oldpath[0] == surname: + self._model.build_sub_entry(surname) + else: + self._model.calculate_data(self.DataFilter) + + # find the path of the person in the new data build + newpath = self._model.temp_iter2path[node] + + # if paths same, just issue row changed signal + + if oldpath == newpath: + self._model.row_changed(pathval,pnode) + else: + # paths different, get the new surname list + + mylist = self._model.temp_sname_sub.get(oldpath[0],[]) + path = self._model.on_get_path(node) + + # delete original + self._model.row_deleted(pathval) + + # delete top node of original if necessar + if len(mylist)==0: + self._model.row_deleted(pathval[0]) + + # determine if we need to insert a new top node', + insert = not self._model.sname_sub.has_key(newpath[0]) + + # assign new data + self._model.assign_data() + + # insert new row if needed + if insert: + path = self._model.on_get_path(newpath[0]) + pnode = self._model.get_iter(path) + self._model.row_inserted(path,pnode) + + # insert new person + path = self._model.on_get_path(node) + pnode = self._model.get_iter(path) + self._model.row_inserted(path,pnode) + def get_selection(self): return self._selection