From 6d00c95e8c07b3dd4c3fe654639710105cc3ca83 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 19 May 2005 15:44:39 +0000 Subject: [PATCH] media sorting enabled svn: r4631 --- gramps2/ChangeLog | 4 ++++ gramps2/src/DisplayModels.py | 4 ++-- gramps2/src/MediaView.py | 43 +++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 21266e186..9d4020444 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,7 @@ +2005-05-19 Don Allingham + * src/MediaView.py: enable sorting by columns + * src/DisplayModels.py: enable sorting by columns for MediaModel + 2005-05-19 Alex Roitman * src/MergePeople.py (merge_family_pair): Properly use handles. diff --git a/gramps2/src/DisplayModels.py b/gramps2/src/DisplayModels.py index 241f81612..6e5db0cff 100644 --- a/gramps2/src/DisplayModels.py +++ b/gramps2/src/DisplayModels.py @@ -428,7 +428,7 @@ class PlaceModel(BaseModel): #------------------------------------------------------------------------- class MediaModel(BaseModel): - def __init__(self,db): + def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): self.gen_cursor = db.get_media_cursor self.map = db.media_map @@ -452,7 +452,7 @@ class MediaModel(BaseModel): self.column_place, self.column_handle, ] - BaseModel.__init__(self,db) + BaseModel.__init__(self,db,scol,order) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/gramps2/src/MediaView.py b/gramps2/src/MediaView.py index a9c91fc38..f03319fb8 100644 --- a/gramps2/src/MediaView.py +++ b/gramps2/src/MediaView.py @@ -84,6 +84,7 @@ class MediaView: self.topWindow = glade.get_widget("gramps") self.renderer = gtk.CellRendererText() self.model = DisplayModels.MediaModel(self.db) + self.sort_col = 0 self.selection = self.list.get_selection() self.list.set_model(self.model) @@ -130,13 +131,51 @@ class MediaView: self.build_columns() self.build_tree() + def column_clicked(self,obj,data): + if self.sort_col != data: + order = gtk.SORT_ASCENDING + else: + if (self.columns[data].get_sort_order() == gtk.SORT_DESCENDING + or self.columns[data].get_sort_indicator() == False): + order = gtk.SORT_ASCENDING + else: + order = gtk.SORT_DESCENDING + self.sort_col = data + handle = self.first_selected() + self.model = DisplayModels.MediaModel(self.parent.db, + self.sort_col,order) + self.list.set_model(self.model) + + colmap = self.parent.db.get_place_column_order() + + if handle: + path = self.model.on_get_path(handle) + self.selection.select_path(path) + self.list.scroll_to_cell(path,None,1,0.5,0) + for i in range(0,len(self.columns)): + self.columns[i].set_sort_indicator(i==colmap[data][1]-1) + self.columns[self.sort_col].set_sort_order(order) + + def first_selected(self): + mlist = [] + self.selection.selected_foreach(self.blist,mlist) + if mlist: + return mlist[0] + else: + return None + + def blist(self,store,path,iter,list): + handle = store.get_value(iter,_HANDLE_COL) + list.append(handle) + def build_columns(self): for column in self.columns: self.list.remove_column(column) column = gtk.TreeViewColumn(_('Title'), self.renderer,text=0) column.set_resizable(True) - + column.connect('clicked',self.column_clicked,0) + column.set_clickable(True) column.set_min_width(225) self.list.append_column(column) self.columns = [column] @@ -149,6 +188,8 @@ class MediaView: column = gtk.TreeViewColumn(name, self.renderer, text=pair[1]) column.set_resizable(True) column.set_min_width(75) + column.set_clickable(True) + column.connect('clicked',self.column_clicked,index) self.columns.append(column) self.list.append_column(column) index += 1