* src/DisplayModels.py: provide sorting support
* src/PlaceView.py: add sorting by columns * src/SourceView.py: add sorting by columns svn: r4597
This commit is contained in:
parent
a4f66df140
commit
9c37651ddf
@ -1,3 +1,8 @@
|
||||
2005-05-15 Don Allingham <don@gramps-project.org>
|
||||
* src/DisplayModels.py: provide sorting support
|
||||
* src/PlaceView.py: add sorting by columns
|
||||
* src/SourceView.py: add sorting by columns
|
||||
|
||||
2005-05-14 Don Allingham <don@gramps-project.org>
|
||||
* src/ReadGedcom.py: add a few more items to parse from Legacy
|
||||
generated GEDCOM files
|
||||
|
@ -61,14 +61,30 @@ _codeset = locale.nl_langinfo(locale.CODESET)
|
||||
#-------------------------------------------------------------------------
|
||||
class BaseModel(gtk.GenericTreeModel):
|
||||
|
||||
def __init__(self,db):
|
||||
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING):
|
||||
gtk.GenericTreeModel.__init__(self)
|
||||
self.set_property("leak_references",False)
|
||||
self.db = db
|
||||
self.sort_func = self.smap[scol]
|
||||
self.sort_col = scol
|
||||
self.reverse = (order == gtk.SORT_DESCENDING)
|
||||
self.rebuild_data()
|
||||
|
||||
def set_sort_column(self,col):
|
||||
self.sort_func = self.smap[col]
|
||||
|
||||
def sort_keys(self):
|
||||
return []
|
||||
cursor = self.gen_cursor()
|
||||
sarray = []
|
||||
data = cursor.next()
|
||||
while data:
|
||||
sarray.append((self.sort_func(data[1]),data[0]))
|
||||
data = cursor.next()
|
||||
cursor.close()
|
||||
sarray.sort()
|
||||
if self.reverse:
|
||||
sarray.reverse()
|
||||
return map(lambda x: x[1], sarray)
|
||||
|
||||
def rebuild_data(self):
|
||||
if self.db.is_open():
|
||||
@ -255,9 +271,9 @@ class ChildModel(gtk.ListStore):
|
||||
#-------------------------------------------------------------------------
|
||||
class SourceModel(BaseModel):
|
||||
|
||||
def __init__(self,db):
|
||||
self.sort_keys = db.get_source_handles
|
||||
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING):
|
||||
self.map = db.source_map
|
||||
self.gen_cursor = db.get_source_cursor
|
||||
self.fmap = [
|
||||
self.column_title,
|
||||
self.column_id,
|
||||
@ -267,7 +283,15 @@ class SourceModel(BaseModel):
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
]
|
||||
BaseModel.__init__(self,db)
|
||||
self.smap = [
|
||||
self.column_title,
|
||||
self.column_id,
|
||||
self.column_author,
|
||||
self.column_abbrev,
|
||||
self.column_pubinfo,
|
||||
self.sort_change,
|
||||
]
|
||||
BaseModel.__init__(self,db,scol,order)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
@ -293,6 +317,8 @@ class SourceModel(BaseModel):
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime(_date_format,time.localtime(data[8])),
|
||||
_codeset)
|
||||
def sort_change(self,data):
|
||||
return time.localtime(data[8])
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -301,8 +327,8 @@ class SourceModel(BaseModel):
|
||||
#-------------------------------------------------------------------------
|
||||
class PlaceModel(BaseModel):
|
||||
|
||||
def __init__(self,db):
|
||||
self.sort_keys = db.get_place_handles
|
||||
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING):
|
||||
self.gen_cursor = db.get_place_cursor
|
||||
self.map = db.place_map
|
||||
self.fmap = [
|
||||
self.column_name,
|
||||
@ -318,7 +344,21 @@ class PlaceModel(BaseModel):
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
]
|
||||
BaseModel.__init__(self,db)
|
||||
self.smap = [
|
||||
self.column_name,
|
||||
self.column_id,
|
||||
self.column_parish,
|
||||
self.column_postal_code,
|
||||
self.column_city,
|
||||
self.column_county,
|
||||
self.column_state,
|
||||
self.column_country,
|
||||
self.column_longitude,
|
||||
self.column_latitude,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
]
|
||||
BaseModel.__init__(self,db,scol,order)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
@ -374,6 +414,9 @@ class PlaceModel(BaseModel):
|
||||
except:
|
||||
return u''
|
||||
|
||||
def sort_change(self,data):
|
||||
return time.localtime(data[11])
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime(_date_format,time.localtime(data[11])),
|
||||
_codeset)
|
||||
@ -386,7 +429,7 @@ class PlaceModel(BaseModel):
|
||||
class MediaModel(BaseModel):
|
||||
|
||||
def __init__(self,db):
|
||||
self.sort_keys = db.get_media_object_handles
|
||||
self.gen_cursor = db.get_media_cursor
|
||||
self.map = db.media_map
|
||||
|
||||
self.fmap = [
|
||||
@ -399,6 +442,16 @@ class MediaModel(BaseModel):
|
||||
self.column_place,
|
||||
self.column_handle,
|
||||
]
|
||||
self.smap = [
|
||||
self.column_description,
|
||||
self.column_id,
|
||||
self.column_mime,
|
||||
self.column_path,
|
||||
self.sort_change,
|
||||
self.column_date,
|
||||
self.column_place,
|
||||
self.column_handle,
|
||||
]
|
||||
BaseModel.__init__(self,db)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
@ -434,6 +487,9 @@ class MediaModel(BaseModel):
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def sort_change(self,data):
|
||||
return time.localtime(data[8])
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime(_date_format,time.localtime(data[8])),
|
||||
_codeset)
|
||||
|
@ -82,18 +82,42 @@ class PlaceView:
|
||||
|
||||
self.list.set_model(self.model)
|
||||
self.topWindow = self.glade.get_widget("gramps")
|
||||
|
||||
self.sort_col = 0
|
||||
|
||||
self.columns = []
|
||||
self.change_db(db)
|
||||
|
||||
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.PlaceModel(self.parent.db,
|
||||
self.sort_col,order)
|
||||
self.list.set_model(self.model)
|
||||
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==data)
|
||||
self.columns[data].set_sort_order(order)
|
||||
|
||||
def build_columns(self):
|
||||
for column in self.columns:
|
||||
self.list.remove_column(column)
|
||||
|
||||
column = gtk.TreeViewColumn(_('Place Name'), self.renderer,text=0)
|
||||
column.set_resizable(True)
|
||||
|
||||
column.set_min_width(225)
|
||||
column.connect('clicked',self.column_clicked,0)
|
||||
column.set_clickable(True)
|
||||
self.list.append_column(column)
|
||||
self.columns = [column]
|
||||
|
||||
@ -104,6 +128,8 @@ class PlaceView:
|
||||
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,pair[1])
|
||||
self.columns.append(column)
|
||||
self.list.append_column(column)
|
||||
|
||||
@ -236,6 +262,14 @@ class PlaceView:
|
||||
place = self.parent.db.get_place_from_handle(place_handle)
|
||||
EditPlace.EditPlace(self.parent, place,self.topWindow)
|
||||
|
||||
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)
|
||||
|
@ -67,21 +67,45 @@ class SourceView:
|
||||
def __init__(self,parent,db,glade):
|
||||
self.parent = parent
|
||||
self.parent.connect('database-changed',self.change_db)
|
||||
|
||||
self.glade = glade
|
||||
self.list = glade.get_widget("source_list")
|
||||
#self.list.set_property('fixed-height-mode',True)
|
||||
self.list.connect('button-press-event',self.button_press)
|
||||
self.list.connect('key-press-event',self.key_press)
|
||||
self.selection = self.list.get_selection()
|
||||
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
|
||||
|
||||
self.renderer = gtk.CellRendererText()
|
||||
|
||||
self.model = DisplayModels.SourceModel(self.parent.db)
|
||||
self.model = DisplayModels.SourceModel(self.parent.db,0)
|
||||
self.sort_col = 0
|
||||
|
||||
self.list.set_model(self.model)
|
||||
self.list.set_headers_clickable(True)
|
||||
self.topWindow = self.glade.get_widget("gramps")
|
||||
|
||||
self.columns = []
|
||||
self.change_db(db)
|
||||
|
||||
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.SourceModel(self.parent.db,
|
||||
self.sort_col,order)
|
||||
self.list.set_model(self.model)
|
||||
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==data)
|
||||
self.columns[data].set_sort_order(order)
|
||||
|
||||
def build_columns(self):
|
||||
for column in self.columns:
|
||||
@ -90,21 +114,24 @@ class SourceView:
|
||||
column = gtk.TreeViewColumn(_('Title'), self.renderer,text=0)
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(225)
|
||||
column.set_clickable(True)
|
||||
column.connect('clicked',self.column_clicked,0)
|
||||
self.list.append_column(column)
|
||||
self.columns = [column]
|
||||
|
||||
index = 1
|
||||
for pair in self.parent.db.get_source_column_order():
|
||||
if not pair[0]:
|
||||
continue
|
||||
name = column_names[pair[1]]
|
||||
column = gtk.TreeViewColumn(name, self.renderer, text=pair[1])
|
||||
column.connect('clicked',self.column_clicked,pair[1])
|
||||
column.set_resizable(True)
|
||||
column.set_min_width(75)
|
||||
column.set_clickable(True)
|
||||
self.columns.append(column)
|
||||
self.list.append_column(column)
|
||||
|
||||
def on_click(self,column):
|
||||
self.click_col = column
|
||||
index += 1
|
||||
|
||||
def change_db(self,db):
|
||||
db.connect('source-add', self.source_add)
|
||||
@ -116,7 +143,7 @@ class SourceView:
|
||||
|
||||
def build_tree(self):
|
||||
self.list.set_model(None)
|
||||
self.model = DisplayModels.SourceModel(self.parent.db)
|
||||
self.model = DisplayModels.SourceModel(self.parent.db,self.sort_col)
|
||||
self.list.set_model(self.model)
|
||||
self.selection = self.list.get_selection()
|
||||
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
|
||||
@ -216,6 +243,14 @@ class SourceView:
|
||||
for handle in handle_list:
|
||||
self.model.delete_row_by_handle(handle)
|
||||
|
||||
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,sel_list):
|
||||
handle = store.get_value(iter,_HANDLE_COL)
|
||||
sel_list.append(handle)
|
||||
|
Loading…
Reference in New Issue
Block a user