From d265fadc1fc95c47d3bb85b0d3d70ba33ca26a83 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Fri, 4 Aug 2006 20:29:26 +0000 Subject: [PATCH] * src/FilterEditor/_FilterEditor.py (__init__): Remove unneeded argument, namespace is enough to get the filter class via factory; (add_new_filter): Use factory; (get_all_handles): Get handles for any object type. * src/FilterEditor/_ShowResults.py (get_name_id): Add method to return name and id for different object types; (sort_val_from_handle): Support different object types. (__init__): Accept namespace as an argument. * src/Filters/__init__.py: Do not expose GenericFamilyFilter; expose GenericFilterFactory instead. * src/Filters/_FamilySidebarFilter.py (GenericFamilyFilter): Use factory. svn: r7122 --- ChangeLog | 12 ++++++++ src/FilterEditor/_FilterEditor.py | 17 ++++++----- src/FilterEditor/_ShowResults.py | 46 ++++++++++++++++++----------- src/Filters/_FamilySidebarFilter.py | 3 +- src/Filters/__init__.py | 2 +- 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index b4fc4bdb8..4e9931c7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,16 @@ 2006-08-04 Alex Roitman + * src/FilterEditor/_FilterEditor.py (__init__): Remove unneeded + argument, namespace is enough to get the filter class via factory; + (add_new_filter): Use factory; (get_all_handles): Get handles for + any object type. + * src/FilterEditor/_ShowResults.py (get_name_id): Add method to + return name and id for different object types; + (sort_val_from_handle): Support different object types. + (__init__): Accept namespace as an argument. + * src/Filters/__init__.py: Do not expose GenericFamilyFilter; + expose GenericFilterFactory instead. + * src/Filters/_FamilySidebarFilter.py (GenericFamilyFilter): Use + factory. * src/FilterEditor/_EditRule.py (MyID.name_from_gramps_id): Remove debugginb output. * src/DataViews/_MediaView.py (row_change): Work around older pygtk. diff --git a/src/FilterEditor/_FilterEditor.py b/src/FilterEditor/_FilterEditor.py index 89d7671f7..1702fbdce 100644 --- a/src/FilterEditor/_FilterEditor.py +++ b/src/FilterEditor/_FilterEditor.py @@ -54,7 +54,7 @@ import GrampsDisplay # #------------------------------------------------------------------------- import const -from Filters import GenericFilter, FilterList, \ +from Filters import GenericFilterFactory, FilterList, \ reload_custom_filters, reload_system_filters import ListModel import ManagedWindow @@ -65,11 +65,10 @@ import ManagedWindow # #------------------------------------------------------------------------- class FilterEditor(ManagedWindow.ManagedWindow): - def __init__(self, space, filterdb, dbstate, uistate, ftype=GenericFilter): + def __init__(self, space, filterdb, dbstate, uistate): ManagedWindow.ManagedWindow.__init__(self, uistate, [], FilterEditor) - self.ftype = ftype self.dbstate = dbstate self.db = dbstate.db self.filterdb = FilterList(filterdb) @@ -138,7 +137,7 @@ class FilterEditor(ManagedWindow.ManagedWindow): def add_new_filter(self,obj): from _EditFilter import EditFilter - the_filter = self.ftype() + the_filter = GenericFilterFactory(self.space)() EditFilter(self.space, self.dbstate, self.uistate, self.track, the_filter, self.filterdb, self.draw_filters) @@ -157,10 +156,9 @@ class FilterEditor(ManagedWindow.ManagedWindow): from _ShowResults import ShowResults filt = self.clist.get_object(node) - handle_list = filt.apply( - self.db, self.db.get_person_handles(sort_handles=False)) + handle_list = filt.apply(self.db,self.get_all_handles()) ShowResults(self.db, self.uistate, self.track, handle_list, - filt.get_name()) + filt.get_name(),self.space) def delete_filter(self,obj): store,node = self.clist.get_selected() @@ -169,3 +167,8 @@ class FilterEditor(ManagedWindow.ManagedWindow): self.filterdb.get_filters(self.space).remove(gfilter) self.draw_filters() + def get_all_handles(self): + if self.space == 'Person': + return self.db.get_person_handles(sort_handles=False) + elif self.space == 'Family': + return self.db.get_family_handles() diff --git a/src/FilterEditor/_ShowResults.py b/src/FilterEditor/_ShowResults.py index 38e0e0d22..b077359a7 100644 --- a/src/FilterEditor/_ShowResults.py +++ b/src/FilterEditor/_ShowResults.py @@ -56,7 +56,8 @@ import gtk #------------------------------------------------------------------------- import const import ManagedWindow -import NameDisplay +from NameDisplay import displayer as _nd +import Utils #------------------------------------------------------------------------- # @@ -64,18 +65,19 @@ import NameDisplay # #------------------------------------------------------------------------- class ShowResults(ManagedWindow.ManagedWindow): - def __init__(self, db, uistate, track, handle_list, filtname): + def __init__(self, db, uistate, track, handle_list, filtname, space): ManagedWindow.ManagedWindow.__init__(self, uistate, track, self) + self.db = db self.filtname = filtname + self.space = space self.define_glade('test', const.rule_glade,) self.set_window( self.get_widget('test'), self.get_widget('title'), _('Filter Test')) - nd = NameDisplay.displayer render = gtk.CellRendererText() tree = self.get_widget('list') @@ -88,25 +90,35 @@ class ShowResults(ManagedWindow.ManagedWindow): column_n = gtk.TreeViewColumn(_('ID'), render, text=1) tree.append_column(column_n) - self.get_widget('close').connect('clicked',self.close_window) + self.get_widget('close').connect('clicked',self.close) - new_list = [self.sort_val_from_handle(db, h) for h in handle_list] + new_list = [self.sort_val_from_handle(h) for h in handle_list] new_list.sort() handle_list = [ h[1] for h in new_list ] - for p_handle in handle_list: - person = db.get_person_from_handle(p_handle) - name = nd.sorted(person) - gid = person.get_gramps_id() - + for handle in handle_list: + name,gid = self.get_name_id(handle) model.append(row=[name, gid]) self.show() - def sort_val_from_handle(self, db, h): - n = db.get_person_from_handle(h).get_primary_name() - return (locale.strxfrm(NameDisplay.displayer.sort_string(n)),h) - - def close_window(self,obj): - self.close() - + def get_name_id(self,handle): + if self.space == 'Person': + person = self.db.get_person_from_handle(handle) + name = _nd.sorted(person) + gid = person.get_gramps_id() + elif self.space == 'Family': + family = self.db.get_family_from_handle(handle) + name = Utils.family_name(family,self.db) + gid = family.get_gramps_id() + return (name,gid) + + def sort_val_from_handle(self, handle): + if self.space == 'Person': + name = self.db.get_person_from_handle(handle).get_primary_name() + sortname = locale.strxfrm(_nd.sort_string(name)) + elif self.space == 'Family': + name = Utils.family_name( + self.db.get_family_from_handle(handle),self.db) + sortname = locale.strxfrm(name) + return (sortname,handle) diff --git a/src/Filters/_FamilySidebarFilter.py b/src/Filters/_FamilySidebarFilter.py index 8cda09074..409fabc80 100644 --- a/src/Filters/_FamilySidebarFilter.py +++ b/src/Filters/_FamilySidebarFilter.py @@ -43,9 +43,10 @@ import GrampsWidgets import RelLib from _SidebarFilter import SidebarFilter -from Filters import GenericFamilyFilter, build_filter_model, Rules +from Filters import GenericFilterFactory, build_filter_model, Rules from Filters.Rules.Family import * +GenericFamilyFilter = GenericFilterFactory('Family') #------------------------------------------------------------------------- # # PersonSidebarFilter class diff --git a/src/Filters/__init__.py b/src/Filters/__init__.py index 515a70f85..e5849b942 100644 --- a/src/Filters/__init__.py +++ b/src/Filters/__init__.py @@ -31,7 +31,7 @@ CustomFilters = None from const import system_filters, custom_filters from _FilterList import FilterList -from _GenericFilter import GenericFilter, GenericFamilyFilter +from _GenericFilter import GenericFilter, GenericFilterFactory from _ParamFilter import ParamFilter def reload_system_filters():