Merge lp:~alexlauni/groundcontrol/bugfix-lp-518031 into lp:groundcontrol

Proposed by Alex Launi
Status: Merged
Merged at revision: not available
Proposed branch: lp:~alexlauni/groundcontrol/bugfix-lp-518031
Merge into: lp:groundcontrol
Diff against target: 55 lines (+29/-1)
1 file modified
GroundControl/projects.py (+29/-1)
To merge this branch: bzr merge lp:~alexlauni/groundcontrol/bugfix-lp-518031
Reviewer Review Type Date Requested Status
Ground Controllers Pending
Review via email: mp+19306@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Launi (alexlauni) wrote :

Implements sorting on the projects view. Sorts the projects by a string comparison to the search term.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'GroundControl/projects.py'
2--- GroundControl/projects.py 2010-02-09 21:28:27 +0000
3+++ GroundControl/projects.py 2010-02-15 02:21:14 +0000
4@@ -235,6 +235,7 @@
5 self.widget("searchLabel").set_text(
6 _("Searching Launchpad - please wait..."))
7 result = self.widget("term").get_text()
8+ self.slist.search_term(term=result)
9 #Trad: Thread(target=self.lpp.search, args=(result))
10 self.start_thread(self.lpp.search, result)
11 #Old: self.lpp.search(result)
12@@ -275,11 +276,31 @@
13 img2 = img.scale_simple(64, 64, gtk.gdk.INTERP_BILINEAR)
14 cell.set_property("pixbuf", img2)
15 cell.set_property("visible", True)
16+
17+ def sort_projects_func(model, iter1, iter2):
18+ """Sorts projects by name to have them ordered by search param,
19+ rather than the order returned by LP"""
20+ search_term = self.search_term().lower()
21+
22+ proj1 = str(model.get_value(iter1, 0).name).lower()
23+ proj2 = str(model.get_value(iter2, 0).name).lower()
24+ proj1 = cmp(search_term, proj1)
25+ proj2 = cmp(search_term, proj2)
26+
27+ if proj1 == 0:
28+ return -1
29+ elif proj2 == 0:
30+ return 1
31+ else:
32+ return 0
33
34 svlist = super(ProjectsView, self).setup()
35+ model = svlist.get_model()
36+ model.set_sort_func(0, sort_projects_func)
37+ model.set_sort_column_id(0, gtk.SORT_ASCENDING)
38+
39 column = gtk.TreeViewColumn((_("Online Projects")))
40 column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
41- #column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
42 column.set_expand(True)
43 # The icon
44 renderer_icon = gtk.CellRendererPixbuf()
45@@ -295,4 +316,11 @@
46 column.set_cell_data_func(renderer, text_cell_func)
47 # Add the required coluns to the treeview
48 svlist.append_column(column)
49+
50+ def search_term(self, term=None):
51+ """ Returns the most recently searched term, and sets search term
52+ when passed as a named parameter"""
53+ if term is not None:
54+ self._search_term = term
55+ return self._search_term if hasattr(self, '_search_term') else ""
56

Subscribers

People subscribed via source and target branches