Merge lp:~joerlend.schinstad-deactivatedaccount/quidgets/main into lp:quidgets

Proposed by Jo-Erlend Schinstad
Status: Merged
Merged at revision: 162
Proposed branch: lp:~joerlend.schinstad-deactivatedaccount/quidgets/main
Merge into: lp:quidgets
Diff against target: 297 lines (+92/-93)
3 files modified
quickly/widgets/couch_grid.py (+25/-3)
quickly/widgets/dictionary_grid.py (+12/-4)
quickly/widgets/grid_column.py (+55/-86)
To merge this branch: bzr merge lp:~joerlend.schinstad-deactivatedaccount/quidgets/main
Reviewer Review Type Date Requested Status
Rick Spencer Approve
Review via email: mp+72232@code.launchpad.net

Description of the change

I had branched from the wrong revision. Everything should be fine now, but if you'll have a look at it, I appreciate it. All tests pass, but I haven't actually tested everything manually.

I mean, I haven't actually built any applications using the features after I merged with the correct revision.

To post a comment you must log in.
161. By Michael Terry

* debian/control, debian/compat, debian/rules:
  - Convert to dh 8
  - Convert to dh_python2
  - Remove obsolete langpack.make include, causing FTBFS (LP: #835770)
* __init__.py:
  - Remove, it was getting installed to an inappropriately global
    location (LP: #826062)

162. By Rick Spencer

merge in bug fixes from jo-erlend bug #812266, bug #812281, and bug #812038

Revision history for this message
Rick Spencer (rick-rickspencer3) wrote :

Tests passed, code reviewed, it all looks great.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'quickly/widgets/couch_grid.py'
2--- quickly/widgets/couch_grid.py 2010-09-02 01:03:54 +0000
3+++ quickly/widgets/couch_grid.py 2011-08-19 17:27:23 +0000
4@@ -66,8 +66,6 @@
5 from quickly.widgets.dictionary_grid import DictionaryGrid
6 from quickly.widgets.grid_column import CheckColumn
7
8-#TODO: a delete_selected_rows function would be nice and not too hard
9-
10 class CouchGrid(DictionaryGrid):
11 def __init__(
12 self, database_name, record_type=None, dictionaries=None, editable=False, keys=None, type_hints=None, uri=None):
13@@ -127,11 +125,30 @@
14 if record_type is not None:
15 self._record_type = record_type
16
17+ #QUESTION: What is the purpose of this?
18+ #if dictionaries is not None and keys is None:
19+ # DictionaryGrid.__init__(self, None, editable, keys, type_hints)
20+ #else:
21+ # DictionaryGrid.__init__(self, None, editable, keys, type_hints)
22+
23+ # Have to leave it in for now. But this is certainly a bug.
24+ # Note: adding dicts to a CG adds to empty cols in the model between the key values and the couch dict.
25 if dictionaries is not None and keys is None:
26 DictionaryGrid.__init__(self, None, editable, keys, type_hints)
27 else:
28 DictionaryGrid.__init__(self, None, editable, keys, type_hints)
29-
30+
31+
32+ """
33+ if dictionaries is not None and keys is not None:
34+ DictionaryGrid.__init__(self, dictionaries, editable, keys, type_hints)
35+ elif keys is None:
36+ DictionaryGrid.__init__(self, dictionaries, editable, None, type_hints)
37+ elif dictionaries is None:
38+ DictionaryGrid.__init__(self, None, editable, keys, type_hints)
39+ """
40+
41+
42 if self.uri:
43 self._db = CouchDatabase(database_name, create=True, uri=self.uri)
44 else:
45@@ -272,6 +289,9 @@
46 self._dictionaries = dicts
47 DictionaryGrid._refresh_treeview(self)
48
49+
50+ # CheckColumn is special because it is a one-shot change. A StringColumn
51+ # should not be saved for each keystroke, but CheckColumn should.
52 for c in self.get_columns():
53 if type(c) == CheckColumn:
54 c.renderer.connect("toggled",self._edited_toggled, c)
55@@ -308,11 +328,13 @@
56 dictionary["record_type"] = self.record_type
57 rec = Record(dictionary)
58 #meh, best not to save an empty row
59+ # Perhaps we should raise an exception if not?
60 if len(dictionary) > 1:
61 doc_id = self._db.put_record(rec)
62 dictionary["__desktopcouch_id"] = doc_id
63 dictionary["__record_type"] = self.record_type
64 del(dictionary["record_type"])
65+
66
67 def _edited_toggled(self, cell, path, col):
68 """ _edited_toggled - internal signal handler.
69
70=== modified file 'quickly/widgets/dictionary_grid.py'
71--- quickly/widgets/dictionary_grid.py 2010-11-21 19:20:40 +0000
72+++ quickly/widgets/dictionary_grid.py 2011-08-19 17:27:23 +0000
73@@ -1,3 +1,4 @@
74+#!/usr/bin/env python
75 # -*- coding: utf-8 -*-
76 ### BEGIN LICENSE
77 # Copyright (C) 2010 Rick Spencer rick.spencer@canonical.com
78@@ -183,10 +184,17 @@
79
80 @editable.setter
81 def editable(self, editable):
82- self._editable = editable
83-
84 #refresh the treeview if possible
85- self._refresh_treeview()
86+ #self._refresh_treeview()
87+
88+ # Refreshing the treeview has no benefits but many negative
89+ # side effects. Better to loop over the columns, setting the property
90+ # on each renderer. The columns should probably expose this property
91+ # themselves, but for now this works.
92+
93+ for column in self.get_columns():
94+ column.renderer.set_property("editable", editable)
95+ self._editable = editable
96
97 @property
98 def columns(self):
99@@ -473,7 +481,7 @@
100 tv.get_buffer().set_text(string)
101
102 if __name__ == "__main__":
103- """creates a test CouchGrid if called directly"""
104+ """creates a test DictionaryGrid if called directly"""
105
106 dicts = [{"key?": True, "price":0.00,"tags" : "aaa bbb ccc","_foo":"bar","bing count":20},
107 {"ID": 11, "key?": False, "price":2.00,"tags" : "bbb ccc ddd","_foo":"bar"},
108
109=== modified file 'quickly/widgets/grid_column.py'
110--- quickly/widgets/grid_column.py 2010-09-17 22:04:49 +0000
111+++ quickly/widgets/grid_column.py 2011-08-19 17:27:23 +0000
112@@ -108,7 +108,52 @@
113 print "some dependencies for GridFilter are not available"
114 raise inst
115
116-class StringColumn( gtk.TreeViewColumn ):
117+class GridColumn( gtk.TreeViewColumn ):
118+ """GridColumn - Base class that provides features that is important
119+ to all columns used in a DictionaryGrid or decendants. Currently
120+ it's useful only to StringColumn and CheckColumn, but should make it
121+ easier to make new "top-level" column types.
122+ """
123+
124+ def __init__(self, key, index, dictionary_index, renderer, editable=True, format_function = None ):
125+ gtk.TreeViewColumn.__init__(self, key, renderer, text=index)
126+
127+ self.set_clickable(True)
128+ self.set_resizable(True)
129+
130+ self.index = index
131+ self.key = key
132+ self.dictionary_index = dictionary_index
133+ self.list_store = None
134+
135+
136+ self.connect('clicked', self.sort_rows)
137+
138+
139+ def sort_rows(self, widget):
140+ sort_order = widget.get_sort_order()
141+
142+ rows = [tuple(r) + (i,) for i, r in enumerate(self.list_store)]
143+
144+ # I NEED TO HAVE A LOOK AT THIS IF-BLOCK. At least, it needs a comment.
145+ if sort_order == gtk.SORT_ASCENDING:
146+ sort_order = gtk.SORT_DESCENDING
147+ else:
148+ sort_order = gtk.SORT_ASCENDING
149+
150+ self.set_sort_order(sort_order)
151+ self.set_sort_indicator(True)
152+
153+ if sort_order == gtk.SORT_ASCENDING:
154+ rows.sort(self._sort_ascending)
155+ else:
156+ rows.sort(self._sort_descending)
157+
158+ self.list_store.reorder([r[-1] for r in rows])
159+
160+
161+class StringColumn( GridColumn ):
162+
163 """StringColumn - Displays strings and tracks data as string.
164 Uses a CellRendererText for display and editing. Not typically created
165 directly in code, but rather created by a DictionaryGrid or descendant.
166@@ -140,47 +185,13 @@
167
168 """
169
170- self.index = index
171- self.key = key
172- self.list_store = None
173- self.dictionary_index = dictionary_index
174+
175 self._initialize_renderer(editable, index)
176-
177- gtk.TreeViewColumn.__init__( self, key, self.renderer, text=index)
178+ GridColumn.__init__( self, key, index, dictionary_index, self.renderer, editable, format_function)
179+
180 if format_function is not None:
181 self.set_cell_data_func(self.renderer, self._on_format, format_function)
182
183- self.set_clickable(True)
184- self.connect('clicked', self.sort_rows)
185- self.set_resizable(True)
186-
187- def sort_rows(self, widget):
188- """sort_rows - when called, the DictionaryGrid will resort
189- from this column. The state of the sort button in the header
190- will determine the sort order.
191-
192- """
193-
194- sort_order = widget.get_sort_order()
195-
196- rows = [tuple(r) + (i,) for i, r in enumerate(self.list_store)]
197- if sort_order == gtk.SORT_ASCENDING:
198- sort_order = gtk.SORT_DESCENDING
199-
200- else:
201- sort_order = gtk.SORT_ASCENDING
202-
203- self.set_sort_indicator(True)
204- self.set_sort_order(sort_order)
205-
206- if sort_order == gtk.SORT_ASCENDING:
207- rows.sort(self._sort_ascending)
208- else:
209- rows.sort(self._sort_descending)
210-
211- self.list_store.reorder([r[-1] for r in rows])
212-
213-
214 def _sort_ascending(self, x, y):
215 """_sort_ascending - internal sort function that sorts two values
216 in the column from least value to greatest value.
217@@ -404,21 +415,7 @@
218 try:
219 return str(float(val))
220 except:
221- return "" """Creates a CurrencyColumn
222-
223- Arguments:
224- key - the key from the dict for the row. Also used as the title for the
225- column by default.
226-
227- index - the position of the column in the grid.
228-
229- dictionary_index - the index in the ListStore where the dictionary
230- for the row is stored. Typically len(dict).
231-
232- editable - False if the column does not allow the user to edit the
233- values in the column. Defaults to True.
234-
235- """
236+ return ""
237
238
239 def real_val(self, val):
240@@ -638,7 +635,7 @@
241 return 1
242
243
244-class CheckColumn( gtk.TreeViewColumn ):
245+class CheckColumn( GridColumn ):
246 """CheckColumn - display data as checkboxes. Store real values as bool.
247
248 Inherits from gtk.TreeViewColumn.
249@@ -665,44 +662,16 @@
250
251 format_function - and optional function to handle formatting of
252 of the string to display. Defaults to None.
253-
254 """
255
256- self.index = index
257- self.key = key
258+ # self.key is set in GridColumn, but needs to be set for tests to pass. Fix.
259+ self.key = key
260 self._initialize_renderer(editable, index)
261- self.list_store = None
262- self.dictionary_index = dictionary_index
263-
264- gtk.TreeViewColumn.__init__( self, key, self.renderer)
265-
266- self.set_clickable(True)
267- self.connect('clicked', self.sort_rows)
268+ GridColumn.__init__( self, key, index, dictionary_index, self.renderer, editable, format_function)
269+
270 self.set_cell_data_func(self.renderer, self._on_format)
271 self.extra_format_function = format_function
272
273- self.set_resizable(True)
274-
275- def sort_rows(self, widget):
276- sort_order = widget.get_sort_order()
277-
278- rows = [tuple(r) + (i,) for i, r in enumerate(self.list_store)]
279- if sort_order == gtk.SORT_ASCENDING:
280- sort_order = gtk.SORT_DESCENDING
281-
282- else:
283- sort_order = gtk.SORT_ASCENDING
284-
285- self.set_sort_order(sort_order)
286- self.set_sort_indicator(True)
287-
288- if sort_order == gtk.SORT_ASCENDING:
289- rows.sort(self._sort_ascending)
290- else:
291- rows.sort(self._sort_descending)
292-
293- self.list_store.reorder([r[-1] for r in rows])
294-
295 def _sort_ascending(self, x, y):
296 x = x[self.index]
297 y = y[self.index]

Subscribers

People subscribed via source and target branches

to all changes: