From 632586ccc12489c46bd40e4f01b408802d6d4e32 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Tue, 25 Sep 2007 12:09:25 +0000 Subject: [PATCH] 2007-09-25 Benny Malengier * src/DataViews/_MediaView.py: COLUMN_NAMES as class constant for reuse * src/DataViews/_RepositoryView.py: COLUMN_NAMES as class constant for reuse * src/DataViews/_SourceView.py: COLUMN_NAMES as class constant for reuse * src/DataViews/_EventView.py: COLUMN_NAMES as class constant for reuse * src/DataViews/_FamilyList.py: COLUMN_NAMES as class constant for reuse * src/DataViews/_PlaceView.py: COLUMN_NAMES as class constant for reuse * src/DataViews/_NoteView.py: COLUMN_NAMES as class constant for reuse * src/Selectors/_BaseSelector.py: add hideable searchbar to selector * src/Selectors/_SelectRepository.py: implement new BaseSelector methods * src/Selectors/_SelectSource.py: implement new BaseSelector methods * src/Selectors/_SelectEvent.py: implement new BaseSelector methods * src/Selectors/_SelectFamily.py: implement new BaseSelector methods, fix bug with wrong handle column * src/Selectors/_SelectPlace.py: implement new BaseSelector methods * src/Selectors/_SelectObject.py: implement new BaseSelector methods svn: r9005 --- ChangeLog | 17 ++++++ src/DataViews/_EventView.py | 23 ++++---- src/DataViews/_FamilyList.py | 23 ++++---- src/DataViews/_MediaView.py | 22 ++++---- src/DataViews/_NoteView.py | 19 +++---- src/DataViews/_PlaceView.py | 36 +++++++------ src/DataViews/_RepositoryView.py | 35 ++++++------ src/DataViews/_SourceView.py | 24 +++++---- src/Selectors/_BaseSelector.py | 85 ++++++++++++++++++++++++++++-- src/Selectors/_SelectEvent.py | 14 +++++ src/Selectors/_SelectFamily.py | 15 +++++- src/Selectors/_SelectObject.py | 13 +++++ src/Selectors/_SelectPlace.py | 13 +++++ src/Selectors/_SelectRepository.py | 13 +++++ src/Selectors/_SelectSource.py | 13 +++++ 15 files changed, 274 insertions(+), 91 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ef010a67..a0d37cb1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2007-09-25 Benny Malengier + * src/DataViews/_MediaView.py: COLUMN_NAMES as class constant for reuse + * src/DataViews/_RepositoryView.py: COLUMN_NAMES as class constant for reuse + * src/DataViews/_SourceView.py: COLUMN_NAMES as class constant for reuse + * src/DataViews/_EventView.py: COLUMN_NAMES as class constant for reuse + * src/DataViews/_FamilyList.py: COLUMN_NAMES as class constant for reuse + * src/DataViews/_PlaceView.py: COLUMN_NAMES as class constant for reuse + * src/DataViews/_NoteView.py: COLUMN_NAMES as class constant for reuse + * src/Selectors/_BaseSelector.py: add hideable searchbar to selector + * src/Selectors/_SelectRepository.py: implement new BaseSelector methods + * src/Selectors/_SelectSource.py: implement new BaseSelector methods + * src/Selectors/_SelectEvent.py: implement new BaseSelector methods + * src/Selectors/_SelectFamily.py: implement new BaseSelector methods, + fix bug with wrong handle column + * src/Selectors/_SelectPlace.py: implement new BaseSelector methods + * src/Selectors/_SelectObject.py: implement new BaseSelector methods + 2007-09-25 Zsolt Foldvari * src/glade/Makefile.am: * po/POTFILES.in: diff --git a/src/DataViews/_EventView.py b/src/DataViews/_EventView.py index 6e580d39c..c4a1c1f4b 100644 --- a/src/DataViews/_EventView.py +++ b/src/DataViews/_EventView.py @@ -50,14 +50,6 @@ from Filters.SideBar import EventSidebarFilter #------------------------------------------------------------------------- from gettext import gettext as _ -column_names = [ - _('Description'), - _('ID'), - _('Type'), - _('Date'), - _('Place'), - _('Last Changed'), - ] #------------------------------------------------------------------------- # @@ -68,7 +60,15 @@ class EventView(PageView.ListView): """ EventView class, derived from the ListView """ - + COLUMN_NAMES = [ + _('Description'), + _('ID'), + _('Type'), + _('Date'), + _('Place'), + _('Last Changed'), + ] + ADD_MSG = _("Add a new event") EDIT_MSG = _("Edit the selected event") DEL_MSG = _("Delete the selected event") @@ -93,7 +93,8 @@ class EventView(PageView.ListView): PageView.ListView.__init__( self, _('Events'), dbstate, uistate, - column_names, len(column_names), DisplayModels.EventModel, + EventView.COLUMN_NAMES, len(EventView.COLUMN_NAMES), + DisplayModels.EventModel, signal_map, dbstate.db.get_event_bookmarks(), Bookmarks.EventBookmarks, filter_class=EventSidebarFilter) @@ -189,7 +190,7 @@ class EventView(PageView.ListView): _('Select Event Columns'), self.uistate, self.dbstate.db.get_event_column_order(), - column_names, + EventView.COLUMN_NAMES, self.set_column_order) def set_column_order(self, clist): diff --git a/src/DataViews/_FamilyList.py b/src/DataViews/_FamilyList.py index f7f77a1d6..53c310198 100644 --- a/src/DataViews/_FamilyList.py +++ b/src/DataViews/_FamilyList.py @@ -48,21 +48,21 @@ from ReportBase import CATEGORY_QR_FAMILY from gettext import gettext as _ import gtk -column_names = [ - _('ID'), - _('Father'), - _('Mother'), - _('Relationship'), - _('Marriage Date'), - _('Last Changed'), - ] - #------------------------------------------------------------------------- # # FamilyListView # #------------------------------------------------------------------------- class FamilyListView(PageView.ListView): + + COLUMN_NAMES = [ + _('ID'), + _('Father'), + _('Mother'), + _('Relationship'), + _('Marriage Date'), + _('Last Changed'), + ] ADD_MSG = _("Add a new family") EDIT_MSG = _("Edit the selected family") @@ -86,7 +86,8 @@ class FamilyListView(PageView.ListView): PageView.ListView.__init__( self, _('Family List'), dbstate, uistate, - column_names, len(column_names), DisplayModels.FamilyModel, + FamilyListView.COLUMN_NAMES, len(FamilyListView.COLUMN_NAMES), + DisplayModels.FamilyModel, signal_map, dbstate.db.get_family_bookmarks(), Bookmarks.FamilyBookmarks, filter_class=FamilySidebarFilter) @@ -103,7 +104,7 @@ class FamilyListView(PageView.ListView): _('Select Family List Columns'), self.uistate, self.dbstate.db.get_family_list_column_order(), - column_names, + FamilyListView.COLUMN_NAMES, self.set_column_order) def set_column_order(self, clist): diff --git a/src/DataViews/_MediaView.py b/src/DataViews/_MediaView.py index 555d2ddca..7d5e2d0b3 100644 --- a/src/DataViews/_MediaView.py +++ b/src/DataViews/_MediaView.py @@ -64,14 +64,6 @@ from QuestionDialog import QuestionDialog, ErrorDialog from Filters.SideBar import MediaSidebarFilter from DdTargets import DdTargets -COLUMN_NAMES = [ - _('Title'), - _('ID'), - _('Type'), - _('Path'), - _('Last Changed'), - _('Date'), - ] #------------------------------------------------------------------------- # @@ -87,6 +79,15 @@ class MediaView(PageView.ListView): selection changes or when the selected media object changes. """ + COLUMN_NAMES = [ + _('Title'), + _('ID'), + _('Type'), + _('Path'), + _('Last Changed'), + _('Date'), + ] + ADD_MSG = _("Add a new media object") EDIT_MSG = _("Edit the selected media object") DEL_MSG = _("Delete the selected media object") @@ -105,7 +106,8 @@ class MediaView(PageView.ListView): PageView.ListView.__init__( self, _('Media'), dbstate, uistate, - COLUMN_NAMES, len(COLUMN_NAMES), DisplayModels.MediaModel, + MediaView.COLUMN_NAMES, len(MediaView.COLUMN_NAMES), + DisplayModels.MediaModel, signal_map, dbstate.db.get_media_bookmarks(), Bookmarks.MediaBookmarks, filter_class=MediaSidebarFilter) @@ -247,7 +249,7 @@ class MediaView(PageView.ListView): _('Select Media Columns'), self.uistate, self.dbstate.db.get_media_column_order(), - COLUMN_NAMES, + MediaView.COLUMN_NAMES, self.set_column_order) def set_column_order(self, clist): diff --git a/src/DataViews/_NoteView.py b/src/DataViews/_NoteView.py index 3c83c037b..0c64603df 100644 --- a/src/DataViews/_NoteView.py +++ b/src/DataViews/_NoteView.py @@ -58,12 +58,6 @@ from Editors import EditNote, DeleteNoteQuery #------------------------------------------------------------------------- from gettext import gettext as _ -column_names = [ - _('ID'), - _('Type'), - _('Marker'), - _('Preview'), - ] #------------------------------------------------------------------------- # @@ -71,6 +65,13 @@ column_names = [ # #------------------------------------------------------------------------- class NoteView(PageView.ListView): + + COLUMN_NAMES = [ + _('ID'), + _('Type'), + _('Marker'), + _('Preview'), + ] ADD_MSG = _("Add a new note") EDIT_MSG = _("Edit the selected note") @@ -92,8 +93,8 @@ class NoteView(PageView.ListView): } PageView.ListView.__init__( - self, _('Notes'), dbstate, uistate, column_names, - len(column_names), DisplayModels.NoteModel, signal_map, + self, _('Notes'), dbstate, uistate, NoteView.COLUMN_NAMES, + len(NoteView.COLUMN_NAMES), DisplayModels.NoteModel, signal_map, dbstate.db.get_note_bookmarks(), Bookmarks.NoteBookmarks, filter_class=NoteSidebarFilter, @@ -184,7 +185,7 @@ class NoteView(PageView.ListView): _('Select Note Columns'), self.uistate, self.dbstate.db.get_note_column_order(), - column_names, + NoteView.COLUMN_NAMES, self.set_column_order) def set_column_order(self, clist): diff --git a/src/DataViews/_PlaceView.py b/src/DataViews/_PlaceView.py index cddeee795..f0c1998bf 100644 --- a/src/DataViews/_PlaceView.py +++ b/src/DataViews/_PlaceView.py @@ -57,20 +57,6 @@ from Filters.SideBar import PlaceSidebarFilter #------------------------------------------------------------------------- from gettext import gettext as _ -column_names = [ - _('Place Name'), - _('ID'), - _('Church Parish'), - _('ZIP/Postal Code'), - _('City'), - _('County'), - _('State'), - _('Country'), - _('Longitude'), - _('Latitude'), - _('Last Changed'), - _('Street'), - ] #------------------------------------------------------------------------- # @@ -78,6 +64,21 @@ column_names = [ # #------------------------------------------------------------------------- class PlaceView(PageView.ListView): + + COLUMN_NAMES = [ + _('Place Name'), + _('ID'), + _('Church Parish'), + _('ZIP/Postal Code'), + _('City'), + _('County'), + _('State'), + _('Country'), + _('Longitude'), + _('Latitude'), + _('Last Changed'), + _('Street'), + ] ADD_MSG = _("Add a new place") EDIT_MSG = _("Edit the selected place") @@ -99,8 +100,9 @@ class PlaceView(PageView.ListView): } PageView.ListView.__init__( - self, _('Places'), dbstate, uistate, column_names, - len(column_names), DisplayModels.PlaceModel, signal_map, + self, _('Places'), dbstate, uistate, PlaceView.COLUMN_NAMES, + len(PlaceView.COLUMN_NAMES), + DisplayModels.PlaceModel, signal_map, dbstate.db.get_place_bookmarks(), Bookmarks.PlaceBookmarks, multiple=True, @@ -158,7 +160,7 @@ class PlaceView(PageView.ListView): _('Select Place Columns'), self.uistate, self.dbstate.db.get_place_column_order(), - column_names, + PlaceView.COLUMN_NAMES, self.set_column_order) def set_column_order(self, clist): diff --git a/src/DataViews/_RepositoryView.py b/src/DataViews/_RepositoryView.py index 28ffb0211..a5c09dafd 100644 --- a/src/DataViews/_RepositoryView.py +++ b/src/DataViews/_RepositoryView.py @@ -58,20 +58,6 @@ from Filters.SideBar import RepoSidebarFilter #------------------------------------------------------------------------- from gettext import gettext as _ -column_names = [ - _('Name'), - _('ID'), - _('Type'), - _('Home URL'), - _('Street'), - _('ZIP/Postal Code'), - _('City'), - _('County'), - _('State'), - _('Country'), - _('Email'), - _('Search URL'), - ] #------------------------------------------------------------------------- # @@ -79,7 +65,22 @@ column_names = [ # #------------------------------------------------------------------------- class RepositoryView(PageView.ListView): - + + COLUMN_NAMES = [ + _('Name'), + _('ID'), + _('Type'), + _('Home URL'), + _('Street'), + _('ZIP/Postal Code'), + _('City'), + _('County'), + _('State'), + _('Country'), + _('Email'), + _('Search URL'), + ] + ADD_MSG = _("Add a new repository") EDIT_MSG = _("Edit the selected repository") DEL_MSG = _("Delete the selected repository") @@ -101,7 +102,7 @@ class RepositoryView(PageView.ListView): PageView.ListView.__init__( self, _('Repositories'), dbstate, uistate, - column_names, len(column_names), + RepositoryView.COLUMN_NAMES, len(RepositoryView.COLUMN_NAMES), DisplayModels.RepositoryModel, signal_map, dbstate.db.get_repo_bookmarks(), Bookmarks.RepoBookmarks,filter_class=RepoSidebarFilter) @@ -129,7 +130,7 @@ class RepositoryView(PageView.ListView): _('Select Repository Columns'), self.uistate, self.dbstate.db.get_repository_column_order(), - column_names, + RepositoryView.COLUMN_NAMES, self.set_column_order) def set_column_order(self, clist): diff --git a/src/DataViews/_SourceView.py b/src/DataViews/_SourceView.py index 245bf7885..223feac87 100644 --- a/src/DataViews/_SourceView.py +++ b/src/DataViews/_SourceView.py @@ -57,14 +57,6 @@ from Filters.SideBar import SourceSidebarFilter #------------------------------------------------------------------------- from gettext import gettext as _ -column_names = [ - _('Title'), - _('ID'), - _('Author'), - _('Abbreviation'), - _('Publication Information'), - _('Last Changed'), - ] #------------------------------------------------------------------------- # @@ -73,6 +65,15 @@ column_names = [ #------------------------------------------------------------------------- class SourceView(PageView.ListView): + COLUMN_NAMES = [ + _('Title'), + _('ID'), + _('Author'), + _('Abbreviation'), + _('Publication Information'), + _('Last Changed'), + ] + ADD_MSG = _("Add a new source") EDIT_MSG = _("Edit the selected source") DEL_MSG = _("Delete the selected source") @@ -93,8 +94,9 @@ class SourceView(PageView.ListView): } PageView.ListView.__init__( - self, _('Sources'), dbstate, uistate, column_names, - len(column_names), DisplayModels.SourceModel, signal_map, + self, _('Sources'), dbstate, uistate, + SourceView.COLUMN_NAMES, len(SourceView.COLUMN_NAMES), + DisplayModels.SourceModel, signal_map, dbstate.db.get_source_bookmarks(), Bookmarks.SourceBookmarks, multiple=True, filter_class=SourceSidebarFilter) @@ -124,7 +126,7 @@ class SourceView(PageView.ListView): _('Select Source Columns'), self.uistate, self.dbstate.db.get_source_column_order(), - column_names, + SourceView.COLUMN_NAMES, self.set_column_order) def set_column_order(self, clist): diff --git a/src/Selectors/_BaseSelector.py b/src/Selectors/_BaseSelector.py index d772421ab..418cb8703 100644 --- a/src/Selectors/_BaseSelector.py +++ b/src/Selectors/_BaseSelector.py @@ -35,6 +35,7 @@ import pango #------------------------------------------------------------------------- import const import ManagedWindow +from Filters import SearchBar #------------------------------------------------------------------------- # @@ -42,12 +43,22 @@ import ManagedWindow # #------------------------------------------------------------------------- class BaseSelector(ManagedWindow.ManagedWindow): + """Base class for the selectors, showing a dialog from which to select + one of the primary objects + """ + NONE = -1 TEXT = 0 MARKUP = 1 IMAGE = 2 - def __init__(self, dbstate, uistate, track=[], filter=None, skip=set()): + def __init__(self, dbstate, uistate, track=[], filter=None, skip=set(), + show_search_bar = True): + '''Set up the dialog with the dbstate and uistate, track of parent + windows for ManagedWindow, initial filter for the model, skip with + set of handles to skip in the view, and search_bar to show the + SearchBar at the top or not. + ''' self.title = self.get_window_title() ManagedWindow.ManagedWindow.__init__(self, uistate, track, self) @@ -59,18 +70,34 @@ class BaseSelector(ManagedWindow.ManagedWindow): self.glade = gtk.glade.XML(const.GLADE_FILE,"select_person","gramps") window = self.glade.get_widget('select_person') title_label = self.glade.get_widget('title') + vbox = self.glade.get_widget('select_person_vbox') self.tree = self.glade.get_widget('plist') self.tree.connect('row-activated', self._on_row_activated) + + self.colinfo = self.column_view_names() + #add the search bar + self.search_bar = SearchBar(dbstate, uistate, + self.build_tree) + filter_box = self.search_bar.build() + self.setup_filter() + vbox.pack_start(filter_box, False, False) + vbox.reorder_child(filter_box, 1) self.set_window(window,title_label,self.title) - self.model = self.get_model_class()(self.db,skip=skip) + self.skip_list=skip + self.build_tree() self.selection = self.tree.get_selection() - - self.tree.set_model(self.model) self.add_columns(self.tree) + self._local_init() + self.show() + #show or hide search bar? + self.set_show_search_bar(show_search_bar) + #Hide showall always (used in person selector only) + showbox = self.glade.get_widget('showall') + showbox.hide() def add_columns(self,tree): tree.set_fixed_height_mode(True) @@ -139,3 +166,53 @@ class BaseSelector(ManagedWindow.ManagedWindow): def get_handle_column(self): # return 3 assert False, "Must be defined in the subclass" + + def set_show_search_bar(self, value): + '''make the search bar at the top shown + ''' + self.show_search_bar = value + if not self.search_bar : + return + if self.show_search_bar : + self.search_bar.show() + else : + self.search_bar.hide() + + def column_order(self): + """ + Column order for db columns + + Derived classes must override this function. + """ + raise NotImplementedError + + def column_view_names(self): + """ + Get correct column view names on which model is based + + Derived classes must override this function. + """ + raise NotImplementedError + + def setup_filter(self): + """ + Builds the default filters and add them to the filter bar. + """ + cols = [] + for pair in [pair for pair in self.column_order() if pair[0]]: + cols.append((self.colinfo[pair[1]], pair[1])) + self.search_bar.setup_filter(cols) + + def build_tree(self): + """ + Builds the selection people see in the Selector + """ + #search info for the + filter_info = (False, self.search_bar.get_value()) + #reset the model + self.model = self.get_model_class()(self.db, skip=self.skip_list, + search=filter_info) + + self.tree.set_model(self.model) + + diff --git a/src/Selectors/_SelectEvent.py b/src/Selectors/_SelectEvent.py index cf1669e5d..397dcb0bc 100644 --- a/src/Selectors/_SelectEvent.py +++ b/src/Selectors/_SelectEvent.py @@ -66,3 +66,17 @@ class SelectEvent(BaseSelector): def get_handle_column(self): return 6 + + + def column_order(self): + """ + returns a tuple indicating the column order of the model + """ + return self.db.get_event_column_order() + + def column_view_names(self): + """ + Get correct column view names on which model is based + """ + import DataViews + return DataViews.EventView.COLUMN_NAMES diff --git a/src/Selectors/_SelectFamily.py b/src/Selectors/_SelectFamily.py index 2512f30ec..87d326ba1 100644 --- a/src/Selectors/_SelectFamily.py +++ b/src/Selectors/_SelectFamily.py @@ -59,4 +59,17 @@ class SelectFamily(BaseSelector): return self.db.get_family_from_handle def get_handle_column(self): - return 5 + return 6 + + def column_order(self): + """ + returns a tuple indicating the column order of the model + """ + return self.db.get_family_list_column_order() + + def column_view_names(self): + """ + Get correct column view names on which model is based + """ + import DataViews + return DataViews.FamilyListView.COLUMN_NAMES diff --git a/src/Selectors/_SelectObject.py b/src/Selectors/_SelectObject.py index 320f1b55d..005e0ab28 100644 --- a/src/Selectors/_SelectObject.py +++ b/src/Selectors/_SelectObject.py @@ -93,3 +93,16 @@ class SelectObject(BaseSelector): pix = ThumbNails.get_thumbnail_image(obj.get_path()) self.preview.set_from_pixbuf(pix) gc.collect() + + def column_order(self): + """ + returns a tuple indicating the column order of the model + """ + return self.db.get_media_column_order() + + def column_view_names(self): + """ + Get correct column view names on which model is based + """ + import DataViews + return DataViews.MediaView.COLUMN_NAMES diff --git a/src/Selectors/_SelectPlace.py b/src/Selectors/_SelectPlace.py index c6c8fc0f5..c16c9e4ee 100644 --- a/src/Selectors/_SelectPlace.py +++ b/src/Selectors/_SelectPlace.py @@ -59,3 +59,16 @@ class SelectPlace(BaseSelector): def get_handle_column(self): return PlaceModel.HANDLE_COL + + def column_order(self): + """ + returns a tuple indicating the column order of the model + """ + return self.db.get_place_column_order() + + def column_view_names(self): + """ + Get correct column view names on which model is based + """ + import DataViews + return DataViews.PlaceView.COLUMN_NAMES diff --git a/src/Selectors/_SelectRepository.py b/src/Selectors/_SelectRepository.py index a1152d9f7..9800512e7 100644 --- a/src/Selectors/_SelectRepository.py +++ b/src/Selectors/_SelectRepository.py @@ -59,3 +59,16 @@ class SelectRepository(BaseSelector): def get_from_handle_func(self): return self.db.get_repository_from_handle + + def column_order(self): + """ + returns a tuple indicating the column order of the model + """ + return self.db.get_repository_column_order() + + def column_view_names(self): + """ + Get correct column view names on which model is based + """ + import DataViews + return DataViews.RepositoryView.COLUMN_NAMES diff --git a/src/Selectors/_SelectSource.py b/src/Selectors/_SelectSource.py index b92635d34..951ab0246 100644 --- a/src/Selectors/_SelectSource.py +++ b/src/Selectors/_SelectSource.py @@ -59,3 +59,16 @@ class SelectSource(BaseSelector): def get_handle_column(self): return 6 + + def column_order(self): + """ + returns a tuple indicating the column order of the model + """ + return self.db.get_source_column_order() + + def column_view_names(self): + """ + Get correct column view names on which model is based + """ + import DataViews + return DataViews.SourceView.COLUMN_NAMES