Merge lp:~joerlend.schinstad-deactivatedaccount/quidgets/main into lp:quidgets
- main
- Merge into trunk
Proposed by
Jo-Erlend Schinstad
Status: | Superseded | ||||||||
---|---|---|---|---|---|---|---|---|---|
Proposed branch: | lp:~joerlend.schinstad-deactivatedaccount/quidgets/main | ||||||||
Merge into: | lp:quidgets | ||||||||
Diff against target: |
7493 lines (+7316/-0) (has conflicts) 31 files modified
.bzr-builddeb/default.conf (+2/-0) .quickly (+3/-0) Copyright (+14/-0) LICENSE (+676/-0) debian/changelog (+65/-0) debian/compat (+1/-0) debian/control (+36/-0) debian/copyright (+22/-0) debian/python-quickly.widgets.install (+1/-0) debian/rules (+7/-0) debian/source/format (+1/-0) po/quickly-widgets.pot (+182/-0) quickly/prompts/__init__.py (+1024/-0) quickly/tests/test_prompts.py (+37/-0) quickly/widgets/asynch_task_progressbox.py (+310/-0) quickly/widgets/conventions.py (+40/-0) quickly/widgets/couch_grid.py (+444/-0) quickly/widgets/dictionary_grid.py (+525/-0) quickly/widgets/grid_column.py (+881/-0) quickly/widgets/grid_filter.py (+845/-0) quickly/widgets/media_player_box.py (+510/-0) quickly/widgets/press_and_hold_button.py (+76/-0) quickly/widgets/tests/_trial_temp/test.log (+1/-0) quickly/widgets/tests/test_asycnh_task_progress_box.py (+51/-0) quickly/widgets/tests/test_couch_grid.py (+284/-0) quickly/widgets/tests/test_dictionary_grid.py (+276/-0) quickly/widgets/tests/test_grid_filter.py (+138/-0) quickly/widgets/text_editor.py (+398/-0) quickly/widgets/url_fetch_progressbox.py (+125/-0) quickly/widgets/web_cam_box.py (+297/-0) setup.py (+44/-0) Conflict adding file .quickly. Moved existing file to .quickly.moved. Conflict adding file Copyright. Moved existing file to Copyright.moved. Conflict adding file LICENSE. Moved existing file to LICENSE.moved. Conflict adding file __init__.py. Moved existing file to __init__.py.moved. Conflict adding file debian. Moved existing file to debian.moved. Conflict adding file po. Moved existing file to po.moved. Conflict adding file quickly. Moved existing file to quickly.moved. Conflict adding file setup.py. Moved existing file to setup.py.moved. |
||||||||
To merge this branch: | bzr merge lp:~joerlend.schinstad-deactivatedaccount/quidgets/main | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Quickly Developers | Pending | ||
Review via email: mp+68272@code.launchpad.net |
Commit message
Description of the change
Fixed a _very_ tiny and insignificant bug. The main purpose is to learn how these stuff works so I don't make any mistakes when I make some real changes.
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
- 163. By Jo-Erlend Schinstad
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory '.bzr-builddeb' |
2 | === added file '.bzr-builddeb/default.conf' |
3 | --- .bzr-builddeb/default.conf 1970-01-01 00:00:00 +0000 |
4 | +++ .bzr-builddeb/default.conf 2011-07-25 07:14:30 +0000 |
5 | @@ -0,0 +1,2 @@ |
6 | +[BUILDDEB] |
7 | +native = True |
8 | |
9 | === added file '.quickly' |
10 | --- .quickly 1970-01-01 00:00:00 +0000 |
11 | +++ .quickly 2011-07-25 07:14:30 +0000 |
12 | @@ -0,0 +1,3 @@ |
13 | +project = quidgets |
14 | +template = python-library |
15 | +format = 0.3 |
16 | |
17 | === renamed file '.quickly' => '.quickly.moved' |
18 | === added file 'Copyright' |
19 | --- Copyright 1970-01-01 00:00:00 +0000 |
20 | +++ Copyright 2011-07-25 07:14:30 +0000 |
21 | @@ -0,0 +1,14 @@ |
22 | +# Copyright (C) 2010 Rick Spencer <rick.spencer@canonical.com> |
23 | +### BEGIN AUTOMATIC LICENSE GENERATION |
24 | +#This program is free software: you can redistribute it and/or modify it |
25 | +#under the terms of the GNU General Public License version 3, as published |
26 | +#by the Free Software Foundation. |
27 | +# |
28 | +#This program is distributed in the hope that it will be useful, but |
29 | +#WITHOUT ANY WARRANTY; without even the implied warranties of |
30 | +#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
31 | +#PURPOSE. See the GNU General Public License for more details. |
32 | +# |
33 | +#You should have received a copy of the GNU General Public License along |
34 | +#with this program. If not, see <http://www.gnu.org/licenses/>. |
35 | +### END AUTOMATIC LICENSE GENERATION |
36 | |
37 | === renamed file 'Copyright' => 'Copyright.moved' |
38 | === added file 'LICENSE' |
39 | --- LICENSE 1970-01-01 00:00:00 +0000 |
40 | +++ LICENSE 2011-07-25 07:14:30 +0000 |
41 | @@ -0,0 +1,676 @@ |
42 | + |
43 | + GNU GENERAL PUBLIC LICENSE |
44 | + Version 3, 29 June 2007 |
45 | + |
46 | + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
47 | + Everyone is permitted to copy and distribute verbatim copies |
48 | + of this license document, but changing it is not allowed. |
49 | + |
50 | + Preamble |
51 | + |
52 | + The GNU General Public License is a free, copyleft license for |
53 | +software and other kinds of works. |
54 | + |
55 | + The licenses for most software and other practical works are designed |
56 | +to take away your freedom to share and change the works. By contrast, |
57 | +the GNU General Public License is intended to guarantee your freedom to |
58 | +share and change all versions of a program--to make sure it remains free |
59 | +software for all its users. We, the Free Software Foundation, use the |
60 | +GNU General Public License for most of our software; it applies also to |
61 | +any other work released this way by its authors. You can apply it to |
62 | +your programs, too. |
63 | + |
64 | + When we speak of free software, we are referring to freedom, not |
65 | +price. Our General Public Licenses are designed to make sure that you |
66 | +have the freedom to distribute copies of free software (and charge for |
67 | +them if you wish), that you receive source code or can get it if you |
68 | +want it, that you can change the software or use pieces of it in new |
69 | +free programs, and that you know you can do these things. |
70 | + |
71 | + To protect your rights, we need to prevent others from denying you |
72 | +these rights or asking you to surrender the rights. Therefore, you have |
73 | +certain responsibilities if you distribute copies of the software, or if |
74 | +you modify it: responsibilities to respect the freedom of others. |
75 | + |
76 | + For example, if you distribute copies of such a program, whether |
77 | +gratis or for a fee, you must pass on to the recipients the same |
78 | +freedoms that you received. You must make sure that they, too, receive |
79 | +or can get the source code. And you must show them these terms so they |
80 | +know their rights. |
81 | + |
82 | + Developers that use the GNU GPL protect your rights with two steps: |
83 | +(1) assert copyright on the software, and (2) offer you this License |
84 | +giving you legal permission to copy, distribute and/or modify it. |
85 | + |
86 | + For the developers' and authors' protection, the GPL clearly explains |
87 | +that there is no warranty for this free software. For both users' and |
88 | +authors' sake, the GPL requires that modified versions be marked as |
89 | +changed, so that their problems will not be attributed erroneously to |
90 | +authors of previous versions. |
91 | + |
92 | + Some devices are designed to deny users access to install or run |
93 | +modified versions of the software inside them, although the manufacturer |
94 | +can do so. This is fundamentally incompatible with the aim of |
95 | +protecting users' freedom to change the software. The systematic |
96 | +pattern of such abuse occurs in the area of products for individuals to |
97 | +use, which is precisely where it is most unacceptable. Therefore, we |
98 | +have designed this version of the GPL to prohibit the practice for those |
99 | +products. If such problems arise substantially in other domains, we |
100 | +stand ready to extend this provision to those domains in future versions |
101 | +of the GPL, as needed to protect the freedom of users. |
102 | + |
103 | + Finally, every program is threatened constantly by software patents. |
104 | +States should not allow patents to restrict development and use of |
105 | +software on general-purpose computers, but in those that do, we wish to |
106 | +avoid the special danger that patents applied to a free program could |
107 | +make it effectively proprietary. To prevent this, the GPL assures that |
108 | +patents cannot be used to render the program non-free. |
109 | + |
110 | + The precise terms and conditions for copying, distribution and |
111 | +modification follow. |
112 | + |
113 | + TERMS AND CONDITIONS |
114 | + |
115 | + 0. Definitions. |
116 | + |
117 | + "This License" refers to version 3 of the GNU General Public License. |
118 | + |
119 | + "Copyright" also means copyright-like laws that apply to other kinds of |
120 | +works, such as semiconductor masks. |
121 | + |
122 | + "The Program" refers to any copyrightable work licensed under this |
123 | +License. Each licensee is addressed as "you". "Licensees" and |
124 | +"recipients" may be individuals or organizations. |
125 | + |
126 | + To "modify" a work means to copy from or adapt all or part of the work |
127 | +in a fashion requiring copyright permission, other than the making of an |
128 | +exact copy. The resulting work is called a "modified version" of the |
129 | +earlier work or a work "based on" the earlier work. |
130 | + |
131 | + A "covered work" means either the unmodified Program or a work based |
132 | +on the Program. |
133 | + |
134 | + To "propagate" a work means to do anything with it that, without |
135 | +permission, would make you directly or secondarily liable for |
136 | +infringement under applicable copyright law, except executing it on a |
137 | +computer or modifying a private copy. Propagation includes copying, |
138 | +distribution (with or without modification), making available to the |
139 | +public, and in some countries other activities as well. |
140 | + |
141 | + To "convey" a work means any kind of propagation that enables other |
142 | +parties to make or receive copies. Mere interaction with a user through |
143 | +a computer network, with no transfer of a copy, is not conveying. |
144 | + |
145 | + An interactive user interface displays "Appropriate Legal Notices" |
146 | +to the extent that it includes a convenient and prominently visible |
147 | +feature that (1) displays an appropriate copyright notice, and (2) |
148 | +tells the user that there is no warranty for the work (except to the |
149 | +extent that warranties are provided), that licensees may convey the |
150 | +work under this License, and how to view a copy of this License. If |
151 | +the interface presents a list of user commands or options, such as a |
152 | +menu, a prominent item in the list meets this criterion. |
153 | + |
154 | + 1. Source Code. |
155 | + |
156 | + The "source code" for a work means the preferred form of the work |
157 | +for making modifications to it. "Object code" means any non-source |
158 | +form of a work. |
159 | + |
160 | + A "Standard Interface" means an interface that either is an official |
161 | +standard defined by a recognized standards body, or, in the case of |
162 | +interfaces specified for a particular programming language, one that |
163 | +is widely used among developers working in that language. |
164 | + |
165 | + The "System Libraries" of an executable work include anything, other |
166 | +than the work as a whole, that (a) is included in the normal form of |
167 | +packaging a Major Component, but which is not part of that Major |
168 | +Component, and (b) serves only to enable use of the work with that |
169 | +Major Component, or to implement a Standard Interface for which an |
170 | +implementation is available to the public in source code form. A |
171 | +"Major Component", in this context, means a major essential component |
172 | +(kernel, window system, and so on) of the specific operating system |
173 | +(if any) on which the executable work runs, or a compiler used to |
174 | +produce the work, or an object code interpreter used to run it. |
175 | + |
176 | + The "Corresponding Source" for a work in object code form means all |
177 | +the source code needed to generate, install, and (for an executable |
178 | +work) run the object code and to modify the work, including scripts to |
179 | +control those activities. However, it does not include the work's |
180 | +System Libraries, or general-purpose tools or generally available free |
181 | +programs which are used unmodified in performing those activities but |
182 | +which are not part of the work. For example, Corresponding Source |
183 | +includes interface definition files associated with source files for |
184 | +the work, and the source code for shared libraries and dynamically |
185 | +linked subprograms that the work is specifically designed to require, |
186 | +such as by intimate data communication or control flow between those |
187 | +subprograms and other parts of the work. |
188 | + |
189 | + The Corresponding Source need not include anything that users |
190 | +can regenerate automatically from other parts of the Corresponding |
191 | +Source. |
192 | + |
193 | + The Corresponding Source for a work in source code form is that |
194 | +same work. |
195 | + |
196 | + 2. Basic Permissions. |
197 | + |
198 | + All rights granted under this License are granted for the term of |
199 | +copyright on the Program, and are irrevocable provided the stated |
200 | +conditions are met. This License explicitly affirms your unlimited |
201 | +permission to run the unmodified Program. The output from running a |
202 | +covered work is covered by this License only if the output, given its |
203 | +content, constitutes a covered work. This License acknowledges your |
204 | +rights of fair use or other equivalent, as provided by copyright law. |
205 | + |
206 | + You may make, run and propagate covered works that you do not |
207 | +convey, without conditions so long as your license otherwise remains |
208 | +in force. You may convey covered works to others for the sole purpose |
209 | +of having them make modifications exclusively for you, or provide you |
210 | +with facilities for running those works, provided that you comply with |
211 | +the terms of this License in conveying all material for which you do |
212 | +not control copyright. Those thus making or running the covered works |
213 | +for you must do so exclusively on your behalf, under your direction |
214 | +and control, on terms that prohibit them from making any copies of |
215 | +your copyrighted material outside their relationship with you. |
216 | + |
217 | + Conveying under any other circumstances is permitted solely under |
218 | +the conditions stated below. Sublicensing is not allowed; section 10 |
219 | +makes it unnecessary. |
220 | + |
221 | + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. |
222 | + |
223 | + No covered work shall be deemed part of an effective technological |
224 | +measure under any applicable law fulfilling obligations under article |
225 | +11 of the WIPO copyright treaty adopted on 20 December 1996, or |
226 | +similar laws prohibiting or restricting circumvention of such |
227 | +measures. |
228 | + |
229 | + When you convey a covered work, you waive any legal power to forbid |
230 | +circumvention of technological measures to the extent such circumvention |
231 | +is effected by exercising rights under this License with respect to |
232 | +the covered work, and you disclaim any intention to limit operation or |
233 | +modification of the work as a means of enforcing, against the work's |
234 | +users, your or third parties' legal rights to forbid circumvention of |
235 | +technological measures. |
236 | + |
237 | + 4. Conveying Verbatim Copies. |
238 | + |
239 | + You may convey verbatim copies of the Program's source code as you |
240 | +receive it, in any medium, provided that you conspicuously and |
241 | +appropriately publish on each copy an appropriate copyright notice; |
242 | +keep intact all notices stating that this License and any |
243 | +non-permissive terms added in accord with section 7 apply to the code; |
244 | +keep intact all notices of the absence of any warranty; and give all |
245 | +recipients a copy of this License along with the Program. |
246 | + |
247 | + You may charge any price or no price for each copy that you convey, |
248 | +and you may offer support or warranty protection for a fee. |
249 | + |
250 | + 5. Conveying Modified Source Versions. |
251 | + |
252 | + You may convey a work based on the Program, or the modifications to |
253 | +produce it from the Program, in the form of source code under the |
254 | +terms of section 4, provided that you also meet all of these conditions: |
255 | + |
256 | + a) The work must carry prominent notices stating that you modified |
257 | + it, and giving a relevant date. |
258 | + |
259 | + b) The work must carry prominent notices stating that it is |
260 | + released under this License and any conditions added under section |
261 | + 7. This requirement modifies the requirement in section 4 to |
262 | + "keep intact all notices". |
263 | + |
264 | + c) You must license the entire work, as a whole, under this |
265 | + License to anyone who comes into possession of a copy. This |
266 | + License will therefore apply, along with any applicable section 7 |
267 | + additional terms, to the whole of the work, and all its parts, |
268 | + regardless of how they are packaged. This License gives no |
269 | + permission to license the work in any other way, but it does not |
270 | + invalidate such permission if you have separately received it. |
271 | + |
272 | + d) If the work has interactive user interfaces, each must display |
273 | + Appropriate Legal Notices; however, if the Program has interactive |
274 | + interfaces that do not display Appropriate Legal Notices, your |
275 | + work need not make them do so. |
276 | + |
277 | + A compilation of a covered work with other separate and independent |
278 | +works, which are not by their nature extensions of the covered work, |
279 | +and which are not combined with it such as to form a larger program, |
280 | +in or on a volume of a storage or distribution medium, is called an |
281 | +"aggregate" if the compilation and its resulting copyright are not |
282 | +used to limit the access or legal rights of the compilation's users |
283 | +beyond what the individual works permit. Inclusion of a covered work |
284 | +in an aggregate does not cause this License to apply to the other |
285 | +parts of the aggregate. |
286 | + |
287 | + 6. Conveying Non-Source Forms. |
288 | + |
289 | + You may convey a covered work in object code form under the terms |
290 | +of sections 4 and 5, provided that you also convey the |
291 | +machine-readable Corresponding Source under the terms of this License, |
292 | +in one of these ways: |
293 | + |
294 | + a) Convey the object code in, or embodied in, a physical product |
295 | + (including a physical distribution medium), accompanied by the |
296 | + Corresponding Source fixed on a durable physical medium |
297 | + customarily used for software interchange. |
298 | + |
299 | + b) Convey the object code in, or embodied in, a physical product |
300 | + (including a physical distribution medium), accompanied by a |
301 | + written offer, valid for at least three years and valid for as |
302 | + long as you offer spare parts or customer support for that product |
303 | + model, to give anyone who possesses the object code either (1) a |
304 | + copy of the Corresponding Source for all the software in the |
305 | + product that is covered by this License, on a durable physical |
306 | + medium customarily used for software interchange, for a price no |
307 | + more than your reasonable cost of physically performing this |
308 | + conveying of source, or (2) access to copy the |
309 | + Corresponding Source from a network server at no charge. |
310 | + |
311 | + c) Convey individual copies of the object code with a copy of the |
312 | + written offer to provide the Corresponding Source. This |
313 | + alternative is allowed only occasionally and noncommercially, and |
314 | + only if you received the object code with such an offer, in accord |
315 | + with subsection 6b. |
316 | + |
317 | + d) Convey the object code by offering access from a designated |
318 | + place (gratis or for a charge), and offer equivalent access to the |
319 | + Corresponding Source in the same way through the same place at no |
320 | + further charge. You need not require recipients to copy the |
321 | + Corresponding Source along with the object code. If the place to |
322 | + copy the object code is a network server, the Corresponding Source |
323 | + may be on a different server (operated by you or a third party) |
324 | + that supports equivalent copying facilities, provided you maintain |
325 | + clear directions next to the object code saying where to find the |
326 | + Corresponding Source. Regardless of what server hosts the |
327 | + Corresponding Source, you remain obligated to ensure that it is |
328 | + available for as long as needed to satisfy these requirements. |
329 | + |
330 | + e) Convey the object code using peer-to-peer transmission, provided |
331 | + you inform other peers where the object code and Corresponding |
332 | + Source of the work are being offered to the general public at no |
333 | + charge under subsection 6d. |
334 | + |
335 | + A separable portion of the object code, whose source code is excluded |
336 | +from the Corresponding Source as a System Library, need not be |
337 | +included in conveying the object code work. |
338 | + |
339 | + A "User Product" is either (1) a "consumer product", which means any |
340 | +tangible personal property which is normally used for personal, family, |
341 | +or household purposes, or (2) anything designed or sold for incorporation |
342 | +into a dwelling. In determining whether a product is a consumer product, |
343 | +doubtful cases shall be resolved in favor of coverage. For a particular |
344 | +product received by a particular user, "normally used" refers to a |
345 | +typical or common use of that class of product, regardless of the status |
346 | +of the particular user or of the way in which the particular user |
347 | +actually uses, or expects or is expected to use, the product. A product |
348 | +is a consumer product regardless of whether the product has substantial |
349 | +commercial, industrial or non-consumer uses, unless such uses represent |
350 | +the only significant mode of use of the product. |
351 | + |
352 | + "Installation Information" for a User Product means any methods, |
353 | +procedures, authorization keys, or other information required to install |
354 | +and execute modified versions of a covered work in that User Product from |
355 | +a modified version of its Corresponding Source. The information must |
356 | +suffice to ensure that the continued functioning of the modified object |
357 | +code is in no case prevented or interfered with solely because |
358 | +modification has been made. |
359 | + |
360 | + If you convey an object code work under this section in, or with, or |
361 | +specifically for use in, a User Product, and the conveying occurs as |
362 | +part of a transaction in which the right of possession and use of the |
363 | +User Product is transferred to the recipient in perpetuity or for a |
364 | +fixed term (regardless of how the transaction is characterized), the |
365 | +Corresponding Source conveyed under this section must be accompanied |
366 | +by the Installation Information. But this requirement does not apply |
367 | +if neither you nor any third party retains the ability to install |
368 | +modified object code on the User Product (for example, the work has |
369 | +been installed in ROM). |
370 | + |
371 | + The requirement to provide Installation Information does not include a |
372 | +requirement to continue to provide support service, warranty, or updates |
373 | +for a work that has been modified or installed by the recipient, or for |
374 | +the User Product in which it has been modified or installed. Access to a |
375 | +network may be denied when the modification itself materially and |
376 | +adversely affects the operation of the network or violates the rules and |
377 | +protocols for communication across the network. |
378 | + |
379 | + Corresponding Source conveyed, and Installation Information provided, |
380 | +in accord with this section must be in a format that is publicly |
381 | +documented (and with an implementation available to the public in |
382 | +source code form), and must require no special password or key for |
383 | +unpacking, reading or copying. |
384 | + |
385 | + 7. Additional Terms. |
386 | + |
387 | + "Additional permissions" are terms that supplement the terms of this |
388 | +License by making exceptions from one or more of its conditions. |
389 | +Additional permissions that are applicable to the entire Program shall |
390 | +be treated as though they were included in this License, to the extent |
391 | +that they are valid under applicable law. If additional permissions |
392 | +apply only to part of the Program, that part may be used separately |
393 | +under those permissions, but the entire Program remains governed by |
394 | +this License without regard to the additional permissions. |
395 | + |
396 | + When you convey a copy of a covered work, you may at your option |
397 | +remove any additional permissions from that copy, or from any part of |
398 | +it. (Additional permissions may be written to require their own |
399 | +removal in certain cases when you modify the work.) You may place |
400 | +additional permissions on material, added by you to a covered work, |
401 | +for which you have or can give appropriate copyright permission. |
402 | + |
403 | + Notwithstanding any other provision of this License, for material you |
404 | +add to a covered work, you may (if authorized by the copyright holders of |
405 | +that material) supplement the terms of this License with terms: |
406 | + |
407 | + a) Disclaiming warranty or limiting liability differently from the |
408 | + terms of sections 15 and 16 of this License; or |
409 | + |
410 | + b) Requiring preservation of specified reasonable legal notices or |
411 | + author attributions in that material or in the Appropriate Legal |
412 | + Notices displayed by works containing it; or |
413 | + |
414 | + c) Prohibiting misrepresentation of the origin of that material, or |
415 | + requiring that modified versions of such material be marked in |
416 | + reasonable ways as different from the original version; or |
417 | + |
418 | + d) Limiting the use for publicity purposes of names of licensors or |
419 | + authors of the material; or |
420 | + |
421 | + e) Declining to grant rights under trademark law for use of some |
422 | + trade names, trademarks, or service marks; or |
423 | + |
424 | + f) Requiring indemnification of licensors and authors of that |
425 | + material by anyone who conveys the material (or modified versions of |
426 | + it) with contractual assumptions of liability to the recipient, for |
427 | + any liability that these contractual assumptions directly impose on |
428 | + those licensors and authors. |
429 | + |
430 | + All other non-permissive additional terms are considered "further |
431 | +restrictions" within the meaning of section 10. If the Program as you |
432 | +received it, or any part of it, contains a notice stating that it is |
433 | +governed by this License along with a term that is a further |
434 | +restriction, you may remove that term. If a license document contains |
435 | +a further restriction but permits relicensing or conveying under this |
436 | +License, you may add to a covered work material governed by the terms |
437 | +of that license document, provided that the further restriction does |
438 | +not survive such relicensing or conveying. |
439 | + |
440 | + If you add terms to a covered work in accord with this section, you |
441 | +must place, in the relevant source files, a statement of the |
442 | +additional terms that apply to those files, or a notice indicating |
443 | +where to find the applicable terms. |
444 | + |
445 | + Additional terms, permissive or non-permissive, may be stated in the |
446 | +form of a separately written license, or stated as exceptions; |
447 | +the above requirements apply either way. |
448 | + |
449 | + 8. Termination. |
450 | + |
451 | + You may not propagate or modify a covered work except as expressly |
452 | +provided under this License. Any attempt otherwise to propagate or |
453 | +modify it is void, and will automatically terminate your rights under |
454 | +this License (including any patent licenses granted under the third |
455 | +paragraph of section 11). |
456 | + |
457 | + However, if you cease all violation of this License, then your |
458 | +license from a particular copyright holder is reinstated (a) |
459 | +provisionally, unless and until the copyright holder explicitly and |
460 | +finally terminates your license, and (b) permanently, if the copyright |
461 | +holder fails to notify you of the violation by some reasonable means |
462 | +prior to 60 days after the cessation. |
463 | + |
464 | + Moreover, your license from a particular copyright holder is |
465 | +reinstated permanently if the copyright holder notifies you of the |
466 | +violation by some reasonable means, this is the first time you have |
467 | +received notice of violation of this License (for any work) from that |
468 | +copyright holder, and you cure the violation prior to 30 days after |
469 | +your receipt of the notice. |
470 | + |
471 | + Termination of your rights under this section does not terminate the |
472 | +licenses of parties who have received copies or rights from you under |
473 | +this License. If your rights have been terminated and not permanently |
474 | +reinstated, you do not qualify to receive new licenses for the same |
475 | +material under section 10. |
476 | + |
477 | + 9. Acceptance Not Required for Having Copies. |
478 | + |
479 | + You are not required to accept this License in order to receive or |
480 | +run a copy of the Program. Ancillary propagation of a covered work |
481 | +occurring solely as a consequence of using peer-to-peer transmission |
482 | +to receive a copy likewise does not require acceptance. However, |
483 | +nothing other than this License grants you permission to propagate or |
484 | +modify any covered work. These actions infringe copyright if you do |
485 | +not accept this License. Therefore, by modifying or propagating a |
486 | +covered work, you indicate your acceptance of this License to do so. |
487 | + |
488 | + 10. Automatic Licensing of Downstream Recipients. |
489 | + |
490 | + Each time you convey a covered work, the recipient automatically |
491 | +receives a license from the original licensors, to run, modify and |
492 | +propagate that work, subject to this License. You are not responsible |
493 | +for enforcing compliance by third parties with this License. |
494 | + |
495 | + An "entity transaction" is a transaction transferring control of an |
496 | +organization, or substantially all assets of one, or subdividing an |
497 | +organization, or merging organizations. If propagation of a covered |
498 | +work results from an entity transaction, each party to that |
499 | +transaction who receives a copy of the work also receives whatever |
500 | +licenses to the work the party's predecessor in interest had or could |
501 | +give under the previous paragraph, plus a right to possession of the |
502 | +Corresponding Source of the work from the predecessor in interest, if |
503 | +the predecessor has it or can get it with reasonable efforts. |
504 | + |
505 | + You may not impose any further restrictions on the exercise of the |
506 | +rights granted or affirmed under this License. For example, you may |
507 | +not impose a license fee, royalty, or other charge for exercise of |
508 | +rights granted under this License, and you may not initiate litigation |
509 | +(including a cross-claim or counterclaim in a lawsuit) alleging that |
510 | +any patent claim is infringed by making, using, selling, offering for |
511 | +sale, or importing the Program or any portion of it. |
512 | + |
513 | + 11. Patents. |
514 | + |
515 | + A "contributor" is a copyright holder who authorizes use under this |
516 | +License of the Program or a work on which the Program is based. The |
517 | +work thus licensed is called the contributor's "contributor version". |
518 | + |
519 | + A contributor's "essential patent claims" are all patent claims |
520 | +owned or controlled by the contributor, whether already acquired or |
521 | +hereafter acquired, that would be infringed by some manner, permitted |
522 | +by this License, of making, using, or selling its contributor version, |
523 | +but do not include claims that would be infringed only as a |
524 | +consequence of further modification of the contributor version. For |
525 | +purposes of this definition, "control" includes the right to grant |
526 | +patent sublicenses in a manner consistent with the requirements of |
527 | +this License. |
528 | + |
529 | + Each contributor grants you a non-exclusive, worldwide, royalty-free |
530 | +patent license under the contributor's essential patent claims, to |
531 | +make, use, sell, offer for sale, import and otherwise run, modify and |
532 | +propagate the contents of its contributor version. |
533 | + |
534 | + In the following three paragraphs, a "patent license" is any express |
535 | +agreement or commitment, however denominated, not to enforce a patent |
536 | +(such as an express permission to practice a patent or covenant not to |
537 | +sue for patent infringement). To "grant" such a patent license to a |
538 | +party means to make such an agreement or commitment not to enforce a |
539 | +patent against the party. |
540 | + |
541 | + If you convey a covered work, knowingly relying on a patent license, |
542 | +and the Corresponding Source of the work is not available for anyone |
543 | +to copy, free of charge and under the terms of this License, through a |
544 | +publicly available network server or other readily accessible means, |
545 | +then you must either (1) cause the Corresponding Source to be so |
546 | +available, or (2) arrange to deprive yourself of the benefit of the |
547 | +patent license for this particular work, or (3) arrange, in a manner |
548 | +consistent with the requirements of this License, to extend the patent |
549 | +license to downstream recipients. "Knowingly relying" means you have |
550 | +actual knowledge that, but for the patent license, your conveying the |
551 | +covered work in a country, or your recipient's use of the covered work |
552 | +in a country, would infringe one or more identifiable patents in that |
553 | +country that you have reason to believe are valid. |
554 | + |
555 | + If, pursuant to or in connection with a single transaction or |
556 | +arrangement, you convey, or propagate by procuring conveyance of, a |
557 | +covered work, and grant a patent license to some of the parties |
558 | +receiving the covered work authorizing them to use, propagate, modify |
559 | +or convey a specific copy of the covered work, then the patent license |
560 | +you grant is automatically extended to all recipients of the covered |
561 | +work and works based on it. |
562 | + |
563 | + A patent license is "discriminatory" if it does not include within |
564 | +the scope of its coverage, prohibits the exercise of, or is |
565 | +conditioned on the non-exercise of one or more of the rights that are |
566 | +specifically granted under this License. You may not convey a covered |
567 | +work if you are a party to an arrangement with a third party that is |
568 | +in the business of distributing software, under which you make payment |
569 | +to the third party based on the extent of your activity of conveying |
570 | +the work, and under which the third party grants, to any of the |
571 | +parties who would receive the covered work from you, a discriminatory |
572 | +patent license (a) in connection with copies of the covered work |
573 | +conveyed by you (or copies made from those copies), or (b) primarily |
574 | +for and in connection with specific products or compilations that |
575 | +contain the covered work, unless you entered into that arrangement, |
576 | +or that patent license was granted, prior to 28 March 2007. |
577 | + |
578 | + Nothing in this License shall be construed as excluding or limiting |
579 | +any implied license or other defenses to infringement that may |
580 | +otherwise be available to you under applicable patent law. |
581 | + |
582 | + 12. No Surrender of Others' Freedom. |
583 | + |
584 | + If conditions are imposed on you (whether by court order, agreement or |
585 | +otherwise) that contradict the conditions of this License, they do not |
586 | +excuse you from the conditions of this License. If you cannot convey a |
587 | +covered work so as to satisfy simultaneously your obligations under this |
588 | +License and any other pertinent obligations, then as a consequence you may |
589 | +not convey it at all. For example, if you agree to terms that obligate you |
590 | +to collect a royalty for further conveying from those to whom you convey |
591 | +the Program, the only way you could satisfy both those terms and this |
592 | +License would be to refrain entirely from conveying the Program. |
593 | + |
594 | + 13. Use with the GNU Affero General Public License. |
595 | + |
596 | + Notwithstanding any other provision of this License, you have |
597 | +permission to link or combine any covered work with a work licensed |
598 | +under version 3 of the GNU Affero General Public License into a single |
599 | +combined work, and to convey the resulting work. The terms of this |
600 | +License will continue to apply to the part which is the covered work, |
601 | +but the special requirements of the GNU Affero General Public License, |
602 | +section 13, concerning interaction through a network will apply to the |
603 | +combination as such. |
604 | + |
605 | + 14. Revised Versions of this License. |
606 | + |
607 | + The Free Software Foundation may publish revised and/or new versions of |
608 | +the GNU General Public License from time to time. Such new versions will |
609 | +be similar in spirit to the present version, but may differ in detail to |
610 | +address new problems or concerns. |
611 | + |
612 | + Each version is given a distinguishing version number. If the |
613 | +Program specifies that a certain numbered version of the GNU General |
614 | +Public License "or any later version" applies to it, you have the |
615 | +option of following the terms and conditions either of that numbered |
616 | +version or of any later version published by the Free Software |
617 | +Foundation. If the Program does not specify a version number of the |
618 | +GNU General Public License, you may choose any version ever published |
619 | +by the Free Software Foundation. |
620 | + |
621 | + If the Program specifies that a proxy can decide which future |
622 | +versions of the GNU General Public License can be used, that proxy's |
623 | +public statement of acceptance of a version permanently authorizes you |
624 | +to choose that version for the Program. |
625 | + |
626 | + Later license versions may give you additional or different |
627 | +permissions. However, no additional obligations are imposed on any |
628 | +author or copyright holder as a result of your choosing to follow a |
629 | +later version. |
630 | + |
631 | + 15. Disclaimer of Warranty. |
632 | + |
633 | + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY |
634 | +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT |
635 | +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY |
636 | +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, |
637 | +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
638 | +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM |
639 | +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF |
640 | +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
641 | + |
642 | + 16. Limitation of Liability. |
643 | + |
644 | + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
645 | +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS |
646 | +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY |
647 | +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE |
648 | +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF |
649 | +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD |
650 | +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), |
651 | +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
652 | +SUCH DAMAGES. |
653 | + |
654 | + 17. Interpretation of Sections 15 and 16. |
655 | + |
656 | + If the disclaimer of warranty and limitation of liability provided |
657 | +above cannot be given local legal effect according to their terms, |
658 | +reviewing courts shall apply local law that most closely approximates |
659 | +an absolute waiver of all civil liability in connection with the |
660 | +Program, unless a warranty or assumption of liability accompanies a |
661 | +copy of the Program in return for a fee. |
662 | + |
663 | + END OF TERMS AND CONDITIONS |
664 | + |
665 | + How to Apply These Terms to Your New Programs |
666 | + |
667 | + If you develop a new program, and you want it to be of the greatest |
668 | +possible use to the public, the best way to achieve this is to make it |
669 | +free software which everyone can redistribute and change under these terms. |
670 | + |
671 | + To do so, attach the following notices to the program. It is safest |
672 | +to attach them to the start of each source file to most effectively |
673 | +state the exclusion of warranty; and each file should have at least |
674 | +the "copyright" line and a pointer to where the full notice is found. |
675 | + |
676 | + <one line to give the program's name and a brief idea of what it does.> |
677 | + Copyright (C) <year> <name of author> |
678 | + |
679 | + This program is free software: you can redistribute it and/or modify |
680 | + it under the terms of the GNU General Public License as published by |
681 | + the Free Software Foundation, either version 3 of the License, or |
682 | + (at your option) any later version. |
683 | + |
684 | + This program is distributed in the hope that it will be useful, |
685 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
686 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
687 | + GNU General Public License for more details. |
688 | + |
689 | + You should have received a copy of the GNU General Public License |
690 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
691 | + |
692 | +Also add information on how to contact you by electronic and paper mail. |
693 | + |
694 | + If the program does terminal interaction, make it output a short |
695 | +notice like this when it starts in an interactive mode: |
696 | + |
697 | + <program> Copyright (C) <year> <name of author> |
698 | + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
699 | + This is free software, and you are welcome to redistribute it |
700 | + under certain conditions; type `show c' for details. |
701 | + |
702 | +The hypothetical commands `show w' and `show c' should show the appropriate |
703 | +parts of the General Public License. Of course, your program's commands |
704 | +might be different; for a GUI interface, you would use an "about box". |
705 | + |
706 | + You should also get your employer (if you work as a programmer) or school, |
707 | +if any, to sign a "copyright disclaimer" for the program, if necessary. |
708 | +For more information on this, and how to apply and follow the GNU GPL, see |
709 | +<http://www.gnu.org/licenses/>. |
710 | + |
711 | + The GNU General Public License does not permit incorporating your program |
712 | +into proprietary programs. If your program is a subroutine library, you |
713 | +may consider it more useful to permit linking proprietary applications with |
714 | +the library. If this is what you want to do, use the GNU Lesser General |
715 | +Public License instead of this License. But first, please read |
716 | +<http://www.gnu.org/philosophy/why-not-lgpl.html>. |
717 | + |
718 | |
719 | === renamed file 'LICENSE' => 'LICENSE.moved' |
720 | === added file '__init__.py' |
721 | === renamed file '__init__.py' => '__init__.py.moved' |
722 | === added directory 'debian' |
723 | === renamed directory 'debian' => 'debian.moved' |
724 | === added file 'debian/changelog' |
725 | --- debian/changelog 1970-01-01 00:00:00 +0000 |
726 | +++ debian/changelog 2011-07-25 07:14:30 +0000 |
727 | @@ -0,0 +1,65 @@ |
728 | +quickly-widgets (11.03.1) natty; urgency=low |
729 | + |
730 | + * New upstream release |
731 | + * debian/copyright: |
732 | + - Update to latest version of spec |
733 | + * debian/source/format: |
734 | + - Use '3.0 (native)' |
735 | + |
736 | + -- Michael Terry <mterry@ubuntu.com> Thu, 03 Feb 2011 13:14:25 -0500 |
737 | + |
738 | +quickly-widgets (11.03.0.1) natty; urgency=low |
739 | + |
740 | + * debian/control: |
741 | + - Whoops, should have renamed the package to python-quickly.widgets, |
742 | + not python-quickly-widgets. |
743 | + |
744 | + -- Michael Terry <mterry@ubuntu.com> Mon, 06 Dec 2010 15:24:15 -0500 |
745 | + |
746 | +quickly-widgets (11.03) natty; urgency=low |
747 | + |
748 | + * New upstream release |
749 | + * debian/control: |
750 | + - Rename to python-quickly-widgets (LP: #517179) |
751 | + - No-change update to Standards-Version 3.9.1 |
752 | + |
753 | + -- Michael Terry <mterry@ubuntu.com> Mon, 06 Dec 2010 14:55:52 -0500 |
754 | + |
755 | +quickly-widgets (10.09) maverick; urgency=low |
756 | + |
757 | + * New upstream release (LP: #637188) |
758 | + |
759 | + -- Didier Roche <didrocks@ubuntu.com> Mon, 13 Sep 2010 15:52:56 +0200 |
760 | + |
761 | +quickly-widgets (10.04.1) lucid; urgency=low |
762 | + |
763 | + * New bugfix release (LP: #555935) |
764 | + |
765 | + -- Didier Roche <didrocks@ubuntu.com> Tue, 06 Apr 2010 12:10:58 +0200 |
766 | + |
767 | +quickly-widgets (10.04) lucid; urgency=low |
768 | + |
769 | + * New bugfix release |
770 | + * debian/control: |
771 | + - depends on python-quickly-core (LP: #519633) |
772 | + - bump Standards-Version to 3.8.4 |
773 | + |
774 | + -- Didier Roche <didrocks@ubuntu.com> Fri, 02 Apr 2010 10:33:44 +0200 |
775 | + |
776 | +quickly-widgets (10.02.2) lucid; urgency=low |
777 | + |
778 | + * Add a dependency on quickly (LP: #517441) |
779 | + |
780 | + -- Brian Murray <brian@ubuntu.com> Fri, 12 Feb 2010 15:52:09 -0800 |
781 | + |
782 | +quickly-widgets (10.02.1) lucid; urgency=low |
783 | + |
784 | + * Remove __init__.py file conflicting with Quickly |
785 | + |
786 | + -- Didier Roche <didrocks@ubuntu.com> Wed, 03 Feb 2010 15:11:09 -0800 |
787 | + |
788 | +quickly-widgets (10.02) lucid; urgency=low |
789 | + |
790 | + * This is the initial release |
791 | + |
792 | + -- Didier Roche <didrocks@ubuntu.com> Wed, 03 Feb 2010 11:27:01 -0800 |
793 | |
794 | === added file 'debian/compat' |
795 | --- debian/compat 1970-01-01 00:00:00 +0000 |
796 | +++ debian/compat 2011-07-25 07:14:30 +0000 |
797 | @@ -0,0 +1,1 @@ |
798 | +6 |
799 | |
800 | === added file 'debian/control' |
801 | --- debian/control 1970-01-01 00:00:00 +0000 |
802 | +++ debian/control 2011-07-25 07:14:30 +0000 |
803 | @@ -0,0 +1,36 @@ |
804 | +Source: quickly-widgets |
805 | +Section: python |
806 | +Priority: extra |
807 | +Build-Depends: cdbs (>= 0.4.43), |
808 | + debhelper (>= 6), |
809 | + python, |
810 | + python-central (>= 0.6.11), |
811 | + python-distutils-extra (>= 2.10) |
812 | +Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
813 | +Standards-Version: 3.9.1 |
814 | +XS-Python-Version: current |
815 | + |
816 | +Package: python-quickly.widgets |
817 | +Architecture: all |
818 | +XB-Python-Version: ${python:Versions} |
819 | +Depends: ${misc:Depends}, |
820 | + ${python:Depends}, |
821 | + python-quickly-core, |
822 | + python-gobject, |
823 | + python-testtools, |
824 | + python-pygame, |
825 | + python-gtk2 |
826 | +Provides: ${python:Provides} |
827 | +Replaces: quickly-widgets (<< 11.03) |
828 | +Conflicts: quickly-widgets (<< 11.03) |
829 | +Description: Library for easing some PyGtk coding tasks |
830 | + Library for easing some PyGtk coding tasks. Note that this is experimental, |
831 | + the API will change, there are bugs. |
832 | + |
833 | +Package: quickly-widgets |
834 | +Architecture: all |
835 | +Section: oldlibs |
836 | +Depends: ${misc:Depends}, python-quickly.widgets |
837 | +Description: Transitional package for python-quickly.widgets |
838 | + This is a transitional package for python-quickly.widgets and can be safely |
839 | + removed after the installation is complete. |
840 | |
841 | === added file 'debian/copyright' |
842 | --- debian/copyright 1970-01-01 00:00:00 +0000 |
843 | +++ debian/copyright 2011-07-25 07:14:30 +0000 |
844 | @@ -0,0 +1,22 @@ |
845 | +Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=166 |
846 | +Upstream-Name: Quickly Widgets |
847 | +Upstream-Contact: Rick Spencer <rick.spencer@canonical.com> |
848 | +Source: https://code.launchpad.net/~quickly-committers/quidgets/trunk |
849 | + |
850 | +Files: * |
851 | +Copyright: 2010,2011 Rick Spencer <rick.spencer@canonical.com> |
852 | +License: GPL-3 |
853 | + This program is free software: you can redistribute it and/or modify |
854 | + it under the terms of the GNU General Public License as published by |
855 | + the Free Software Foundation, version 3 of the License. |
856 | + . |
857 | + This program is distributed in the hope that it will be useful, |
858 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
859 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
860 | + GNU General Public License for more details. |
861 | + . |
862 | + You should have received a copy of the GNU General Public License |
863 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
864 | + . |
865 | + On Debian systems, the full text of the GNU General Public License |
866 | + version 3 can be found in the file /usr/share/common-licenses/GPL-3. |
867 | |
868 | === added file 'debian/python-quickly.widgets.install' |
869 | --- debian/python-quickly.widgets.install 1970-01-01 00:00:00 +0000 |
870 | +++ debian/python-quickly.widgets.install 2011-07-25 07:14:30 +0000 |
871 | @@ -0,0 +1,1 @@ |
872 | +debian/tmp/usr/lib/ |
873 | |
874 | === added file 'debian/rules' |
875 | --- debian/rules 1970-01-01 00:00:00 +0000 |
876 | +++ debian/rules 2011-07-25 07:14:30 +0000 |
877 | @@ -0,0 +1,7 @@ |
878 | +#!/usr/bin/make -f |
879 | + |
880 | +DEB_PYTHON_SYSTEM := pycentral |
881 | + |
882 | +include /usr/share/cdbs/1/rules/debhelper.mk |
883 | +include /usr/share/cdbs/1/class/python-distutils.mk |
884 | +include /usr/share/cdbs/1/rules/langpack.mk |
885 | |
886 | === added directory 'debian/source' |
887 | === added file 'debian/source/format' |
888 | --- debian/source/format 1970-01-01 00:00:00 +0000 |
889 | +++ debian/source/format 2011-07-25 07:14:30 +0000 |
890 | @@ -0,0 +1,1 @@ |
891 | +3.0 (native) |
892 | |
893 | === added directory 'po' |
894 | === renamed directory 'po' => 'po.moved' |
895 | === added file 'po/quickly-widgets.pot' |
896 | --- po/quickly-widgets.pot 1970-01-01 00:00:00 +0000 |
897 | +++ po/quickly-widgets.pot 2011-07-25 07:14:30 +0000 |
898 | @@ -0,0 +1,182 @@ |
899 | +# SOME DESCRIPTIVE TITLE. |
900 | +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER |
901 | +# This file is distributed under the same license as the PACKAGE package. |
902 | +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
903 | +# |
904 | +#, fuzzy |
905 | +msgid "" |
906 | +msgstr "" |
907 | +"Project-Id-Version: PACKAGE VERSION\n" |
908 | +"Report-Msgid-Bugs-To: \n" |
909 | +"POT-Creation-Date: 2011-02-03 13:16-0500\n" |
910 | +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
911 | +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
912 | +"Language-Team: LANGUAGE <LL@li.org>\n" |
913 | +"Language: \n" |
914 | +"MIME-Version: 1.0\n" |
915 | +"Content-Type: text/plain; charset=CHARSET\n" |
916 | +"Content-Transfer-Encoding: 8bit\n" |
917 | + |
918 | +#: ../quickly/widgets/grid_column.py:762 |
919 | +msgid "yes" |
920 | +msgstr "" |
921 | + |
922 | +#: ../quickly/widgets/web_cam_box.py:123 |
923 | +msgid "Cannot display web cam output. Ignoring play command" |
924 | +msgstr "" |
925 | + |
926 | +#: ../quickly/widgets/web_cam_box.py:159 |
927 | +msgid "/Pictures/" |
928 | +msgstr "" |
929 | + |
930 | +#: ../quickly/widgets/media_player_box.py:169 |
931 | +msgid "" |
932 | +"WARNING: MediaPlayerBox window not realized.\n" |
933 | +" Will try to play anyway, but bad things could happen\n" |
934 | +" if there is video to play" |
935 | +msgstr "" |
936 | + |
937 | +#: ../quickly/widgets/url_fetch_progressbox.py:59 |
938 | +#, python-format |
939 | +msgid "Downloading %s" |
940 | +msgstr "" |
941 | + |
942 | +#: ../quickly/prompts/__init__.py:105 ../quickly/prompts/__init__.py:149 |
943 | +msgid "Input String" |
944 | +msgstr "" |
945 | + |
946 | +#: ../quickly/prompts/__init__.py:105 ../quickly/prompts/__init__.py:149 |
947 | +msgid "Input a String:" |
948 | +msgstr "" |
949 | + |
950 | +#: ../quickly/prompts/__init__.py:172 ../quickly/prompts/__init__.py:220 |
951 | +msgid "Choose Date" |
952 | +msgstr "" |
953 | + |
954 | +#: ../quickly/prompts/__init__.py:172 ../quickly/prompts/__init__.py:220 |
955 | +msgid "Choose a Date:" |
956 | +msgstr "" |
957 | + |
958 | +#: ../quickly/prompts/__init__.py:247 ../quickly/prompts/__init__.py:306 |
959 | +#: ../quickly/prompts/__init__.py:387 |
960 | +msgid "Enter Number" |
961 | +msgstr "" |
962 | + |
963 | +#: ../quickly/prompts/__init__.py:247 ../quickly/prompts/__init__.py:306 |
964 | +#: ../quickly/prompts/__init__.py:387 |
965 | +msgid "Enter an Integer Value:" |
966 | +msgstr "" |
967 | + |
968 | +#: ../quickly/prompts/__init__.py:324 ../quickly/prompts/__init__.py:433 |
969 | +#: ../quickly/prompts/__init__.py:494 |
970 | +msgid "Enter Price" |
971 | +msgstr "" |
972 | + |
973 | +#: ../quickly/prompts/__init__.py:324 ../quickly/prompts/__init__.py:433 |
974 | +#: ../quickly/prompts/__init__.py:494 |
975 | +msgid "Choose a Price:" |
976 | +msgstr "" |
977 | + |
978 | +#: ../quickly/prompts/__init__.py:525 |
979 | +msgid "Choose Yes or No" |
980 | +msgstr "" |
981 | + |
982 | +#: ../quickly/prompts/__init__.py:576 |
983 | +msgid "Choose an option" |
984 | +msgstr "" |
985 | + |
986 | +#: ../quickly/prompts/__init__.py:623 |
987 | +msgid "Warning" |
988 | +msgstr "" |
989 | + |
990 | +#: ../quickly/prompts/__init__.py:642 |
991 | +msgid "Error" |
992 | +msgstr "" |
993 | + |
994 | +#: ../quickly/prompts/__init__.py:662 |
995 | +msgid "Information" |
996 | +msgstr "" |
997 | + |
998 | +#: ../quickly/prompts/__init__.py:726 ../quickly/prompts/__init__.py:871 |
999 | +msgid "Choose an Image" |
1000 | +msgstr "" |
1001 | + |
1002 | +#: ../quickly/prompts/__init__.py:894 |
1003 | +msgid "Choose a Directory" |
1004 | +msgstr "" |
1005 | + |
1006 | +#: ../quickly/widgets/asynch_task_progressbox.py:160 |
1007 | +msgid "Working" |
1008 | +msgstr "" |
1009 | + |
1010 | +#: ../quickly/widgets/grid_filter.py:113 |
1011 | +msgid "M_atch All of the following" |
1012 | +msgstr "" |
1013 | + |
1014 | +#: ../quickly/widgets/grid_filter.py:117 |
1015 | +msgid "Match any _of the following" |
1016 | +msgstr "" |
1017 | + |
1018 | +#: ../quickly/widgets/grid_filter.py:403 |
1019 | +msgid "contains" |
1020 | +msgstr "" |
1021 | + |
1022 | +#: ../quickly/widgets/grid_filter.py:404 |
1023 | +msgid "does not contain" |
1024 | +msgstr "" |
1025 | + |
1026 | +#: ../quickly/widgets/grid_filter.py:405 |
1027 | +msgid "starts with" |
1028 | +msgstr "" |
1029 | + |
1030 | +#: ../quickly/widgets/grid_filter.py:406 |
1031 | +msgid "ends with" |
1032 | +msgstr "" |
1033 | + |
1034 | +#: ../quickly/widgets/grid_filter.py:440 |
1035 | +msgid "has any of these tags" |
1036 | +msgstr "" |
1037 | + |
1038 | +#: ../quickly/widgets/grid_filter.py:441 |
1039 | +msgid "has all of these tags" |
1040 | +msgstr "" |
1041 | + |
1042 | +#: ../quickly/widgets/grid_filter.py:442 |
1043 | +msgid "does not have one of these tags" |
1044 | +msgstr "" |
1045 | + |
1046 | +#: ../quickly/widgets/grid_filter.py:443 |
1047 | +msgid "does not have any of these tags" |
1048 | +msgstr "" |
1049 | + |
1050 | +#: ../quickly/widgets/grid_filter.py:630 |
1051 | +msgid "before" |
1052 | +msgstr "" |
1053 | + |
1054 | +#: ../quickly/widgets/grid_filter.py:631 |
1055 | +msgid "on or before" |
1056 | +msgstr "" |
1057 | + |
1058 | +#: ../quickly/widgets/grid_filter.py:632 |
1059 | +msgid "on" |
1060 | +msgstr "" |
1061 | + |
1062 | +#: ../quickly/widgets/grid_filter.py:633 |
1063 | +msgid "on or after" |
1064 | +msgstr "" |
1065 | + |
1066 | +#: ../quickly/widgets/grid_filter.py:634 |
1067 | +msgid "after" |
1068 | +msgstr "" |
1069 | + |
1070 | +#: ../quickly/widgets/grid_filter.py:722 |
1071 | +msgid "checked" |
1072 | +msgstr "" |
1073 | + |
1074 | +#: ../quickly/widgets/grid_filter.py:723 |
1075 | +msgid "not Checked" |
1076 | +msgstr "" |
1077 | + |
1078 | +#: ../quickly/widgets/grid_filter.py:724 |
1079 | +msgid "unset" |
1080 | +msgstr "" |
1081 | |
1082 | === added directory 'quickly' |
1083 | === renamed directory 'quickly' => 'quickly.moved' |
1084 | === added directory 'quickly/prompts' |
1085 | === added file 'quickly/prompts/__init__.py' |
1086 | --- quickly/prompts/__init__.py 1970-01-01 00:00:00 +0000 |
1087 | +++ quickly/prompts/__init__.py 2011-07-25 07:14:30 +0000 |
1088 | @@ -0,0 +1,1024 @@ |
1089 | +### BEGIN LICENSE |
1090 | +# Copyright (C) 2010 Rick Spencer rick.spencer@canonical.com |
1091 | +#This program is free software: you can redistribute it and/or modify it |
1092 | +#under the terms of the GNU General Public License version 3, as published |
1093 | +#by the Free Software Foundation. |
1094 | +# |
1095 | +#This program is distributed in the hope that it will be useful, but |
1096 | +#WITHOUT ANY WARRANTY; without even the implied warranties of |
1097 | +#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1098 | +#PURPOSE. See the GNU General Public License for more details. |
1099 | +# |
1100 | +#You should have received a copy of the GNU General Public License along |
1101 | +#with this program. If not, see <http://www.gnu.org/licenses/>. |
1102 | +### END LICENSE |
1103 | + |
1104 | +import gtk |
1105 | +import gobject |
1106 | +import os |
1107 | +import glib |
1108 | +import gettext |
1109 | +from gettext import gettext as _ |
1110 | +gettext.textdomain('quickly-widgets') |
1111 | + |
1112 | +#TODO: stop using **kwargs and go back to named arguments so you can pass them from the function to the class |
1113 | + |
1114 | +class Prompt(gtk.Dialog): |
1115 | + """A base class for some quickly.prompts - creates Ok and Cancel buttons, |
1116 | + displays a title and a label. |
1117 | + |
1118 | + qiuckly.prompts.Prompt is intended for receiving information back |
1119 | + from users. If you only want to display a message, use a |
1120 | + quickly.prompts.Alert. |
1121 | + |
1122 | + Useful subclasses and helper functions are provided: |
1123 | + quickly.prompts.string() uses quickly.prompts.StringPrompt |
1124 | + quickly.prompts.date() uses quickly.prompts.DatePrompt |
1125 | + quickly.prompts.integer() uses quickly.prompts.IntegerPrompt |
1126 | + quickly.prompts.decimal() uses quickly.prompts.DecimalPrompt |
1127 | + quickly.prompts.price() uses quickly.prompts.PricePrompt |
1128 | + |
1129 | + Using |
1130 | + A quickly.prompts.prompt object is not intended to be used without |
1131 | + configuring or extending it. Otherwise, it will only display a |
1132 | + blank dialog with OK and Cancel buttons and a label. |
1133 | + |
1134 | + Configuring |
1135 | + #add some widgets to the prompt using the |
1136 | + #the prompt's content_box member (which is a gtk.VBox) |
1137 | + #These widgets will appear below the label |
1138 | + #StringPrompt works similar to this: |
1139 | + p = quickly.prompts.Prompt(title,text) |
1140 | + entry = gtk.Entry() |
1141 | + entry.set_text(default_value) |
1142 | + entry.set_activates_default(True) |
1143 | + entry.show() |
1144 | + p.content_box.pack_end(entry, True, True, 5) |
1145 | + response = p.run() |
1146 | + if response = gtk.RESPONSE_OK: |
1147 | + my_string = entry.get_text() |
1148 | + |
1149 | + #A Prompt is a gtk.Dialog, so you can use gtk.DialogMembers |
1150 | + action_area = p.get_action_area() |
1151 | + |
1152 | + Extending |
1153 | + #Typically you will add widgets to a prompt and override the |
1154 | + #get_value function to return the appropriate value entered by the user. |
1155 | + #String prompt is implemented as follows: |
1156 | + class StringPrompt(Prompt): |
1157 | + def __init__(self, title = "Input String", |
1158 | + text = "Input a String:", default_value = ""): |
1159 | + Prompt.__init__(self, title, text) |
1160 | + self._entry = gtk.Entry() |
1161 | + self._entry.set_text(default_value) |
1162 | + self._entry.set_activates_default(True) |
1163 | + self._entry.show() |
1164 | + self.content_box.pack_end(self._entry, True, True, 5) |
1165 | + |
1166 | + def get_value(self): |
1167 | + return self._entry.get_text() |
1168 | + |
1169 | + """ |
1170 | + |
1171 | + def __init__(self, title, text): |
1172 | + """Creates a Prompt |
1173 | + arguments: |
1174 | + title - The title for the dialog window |
1175 | + text - The string to display in the Prompts label |
1176 | + |
1177 | + """ |
1178 | + |
1179 | + gtk.Dialog.__init__(self, title, None, gtk.DIALOG_MODAL,(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) |
1180 | + self.set_has_separator(False) |
1181 | + content_area = self.get_content_area() |
1182 | + content_area.set_border_width(5) |
1183 | + self.set_default_response(gtk.RESPONSE_OK) |
1184 | + |
1185 | + self.content_box = gtk.VBox(False, 10) |
1186 | + label = gtk.Label(text) |
1187 | + label.set_line_wrap(True) |
1188 | + self.content_box.pack_start(label,False, False, 5) |
1189 | + content_area.pack_start(self.content_box) |
1190 | + self.content_box.show() |
1191 | + label.show() |
1192 | + |
1193 | +def string(title = _("Input String"), text = _("Input a String:"), default_value = ""): |
1194 | + """string - prompts to enter a string via a dialog box. |
1195 | + |
1196 | + aguments: |
1197 | + title - a string to be the title of the dialog |
1198 | + text - a string to provide a prompt for the user within dialog |
1199 | + default_value - a string to see the entry in the dialog box |
1200 | + |
1201 | + returns a tuple of (gtk.DialogResponse, string value) |
1202 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1203 | + the user cancelled (gtk.RESPONSE_CANCEL) or dismissed the dialog |
1204 | + (gtk.RESPONSE_DELETE_EVENT) |
1205 | + |
1206 | + """ |
1207 | + |
1208 | + sp = StringPrompt(title, text, default_value) |
1209 | + response = sp.run() |
1210 | + val = sp.get_value() |
1211 | + sp.destroy() |
1212 | + return (response, val) |
1213 | + |
1214 | +class StringPrompt(Prompt): |
1215 | + """A class for receiving a string from a user |
1216 | + |
1217 | + Using |
1218 | + #Collect a string from the user by using the |
1219 | + #quickly.prompts.string() helper function |
1220 | + reponse, val = string("String select test","String select test") |
1221 | + if response == gtk.RESPONSE_OK: |
1222 | + my_string = val |
1223 | + |
1224 | + Configuring |
1225 | + #Add widgets to the conent_box member |
1226 | + sp = StringPrompt(title, text, default_string) |
1227 | + sp.content_box.pack_end(my_additional_widget) |
1228 | + |
1229 | + #Modify the _entry member |
1230 | + sp._entry.set_max_length(144) |
1231 | + |
1232 | + Extending |
1233 | + A StringPrompt is a Prompt which is gtk.Dialog |
1234 | + |
1235 | + """ |
1236 | + |
1237 | + def __init__(self, title = _("Input String"), text = _("Input a String:"), default_value = ""): |
1238 | + """Create a StringPrompt |
1239 | + arguments: |
1240 | + title - a string to be the title of the dialog |
1241 | + text - a string to provide a prompt for the user within dialog |
1242 | + default_value - a string to see the entry in the dialog box |
1243 | + |
1244 | + """ |
1245 | + |
1246 | + Prompt.__init__(self, title, text) |
1247 | + self._entry = gtk.Entry() |
1248 | + self._entry.set_text(default_value) |
1249 | + self._entry.set_activates_default(True) |
1250 | + self._entry.show() |
1251 | + self.content_box.pack_end(self._entry, True, True, 5) |
1252 | + |
1253 | + def get_value(self): |
1254 | + """get_value - returns the value the user has entered into the gtk.Entry |
1255 | + |
1256 | + """ |
1257 | + |
1258 | + return self._entry.get_text() |
1259 | + |
1260 | +def date(title = _("Choose Date"), text = _("Choose a Date:"), default_value = None): |
1261 | + """date - prompts to enter a date using a calendar via a dialog box. |
1262 | + |
1263 | + aguments: |
1264 | + title - a string to be the title of the dialog |
1265 | + text - a string to provide a prompt for the user within dialog |
1266 | + default_value - a tuple in the form of integers for (year,month,day) |
1267 | + where month is zero indexed (Jaunary is 0, December is 11) |
1268 | + |
1269 | + returns a tuple of (gtk.DialogResponse, tuple) |
1270 | + The returnd tuple is in the form of integers for (year,month,day) |
1271 | + where month is zero indexed (Jaunary is 0, December is 11) |
1272 | + |
1273 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1274 | + the user cancelled (gtk.RESPONSE_CANCEL) or dismissed the dialog |
1275 | + (gtk.RESPONSE_DELETE_EVENT) |
1276 | + |
1277 | + """ |
1278 | + dp = DatePrompt(title, text, default_value) |
1279 | + |
1280 | + response = dp.run() |
1281 | + val = dp.get_value() |
1282 | + dp.destroy() |
1283 | + return (response, val) |
1284 | + |
1285 | +class DatePrompt(Prompt): |
1286 | + """A class for receiving a date from a user |
1287 | + |
1288 | + Using |
1289 | + #Collect a date from the user by using the |
1290 | + #quickly.prompts.date() helper function |
1291 | + reponse, val = date("Date prompt title","Date prompt message") |
1292 | + if response == gtk.RESPONSE_OK: |
1293 | + my_date = val |
1294 | + |
1295 | + Configuring |
1296 | + #Add widgets to the content_box member |
1297 | + dp = DatePrompt(title, text, default_integer) |
1298 | + dp.content_box.pack_end(my_additional_widget) |
1299 | + |
1300 | + #Modify the _calendar member |
1301 | + dp._calendar.set_display_options(gtk.CALENDAR_SHOW_DAY_NAMES) |
1302 | + |
1303 | + Extending |
1304 | + A DatePrompt is a Prompt which is a gtk.Dialog. |
1305 | + |
1306 | + """ |
1307 | + |
1308 | + def __init__(self, title = _("Choose Date"), text = _("Choose a Date:"), default_value = None): |
1309 | + """Creates a DatePrompt |
1310 | + title - a string to be the title of the dialog |
1311 | + text - a string to provide a prompt for the user within dialog |
1312 | + default_value - a tuple in the form of integers for (year,month,day) |
1313 | + where month is zero indexed (Jaunary is 0, December is 11) |
1314 | + |
1315 | + """ |
1316 | + Prompt.__init__(self, title, text) |
1317 | + self._calendar = gtk.Calendar() |
1318 | + self._calendar.show() |
1319 | + self.content_box.pack_end(self._calendar, True, True, 5) |
1320 | + |
1321 | + if default_value is not None and len(default_value) is 3: |
1322 | + year, month, day = default_value |
1323 | + self._calendar.select_month(month, year) |
1324 | + self._calendar.select_day(day) |
1325 | + |
1326 | + def get_value(self): |
1327 | + """get_value - return the date currently set in the _calendar member |
1328 | + A tuple is in the form of integers for (year,month,day) |
1329 | + where month is zero indexed (Jaunary is 0, December is 11) |
1330 | + |
1331 | + """ |
1332 | + |
1333 | + return self._calendar.get_date() |
1334 | + |
1335 | +def integer(title = _("Enter Number"), text = _("Enter an Integer Value:"), |
1336 | + default_value=0, min_value = -1000000000, max_value=1000000000, |
1337 | + step = 1): |
1338 | + """integer - prompts to enter an integer using a spinner via a dialog box. |
1339 | + |
1340 | + arguments: |
1341 | + title - a string to be the title of the dialog |
1342 | + text - a string to provide a prompt for the user within dialog |
1343 | + default_value - an integer to display by default, should be greater than |
1344 | + |
1345 | + keyword arguments: |
1346 | + the min_value and less then the max_value |
1347 | + min_value - the lowest number accepted by the spinner, |
1348 | + defaults to -1000000000 |
1349 | + step - set the incriments for each click of the spinner buttons, |
1350 | + defaults to 1 |
1351 | + max_value, the highest number accepted by the spinner, |
1352 | + defaults to 1000000000 |
1353 | + |
1354 | + returns a tuple of (gtk.DialogResponse, integer) |
1355 | + |
1356 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1357 | + the user cancelled (gtk.RESPONSE_CANCEL) or dismissed the dialog |
1358 | + (gtk.RESPONSE_DELETE_EVENT) |
1359 | + |
1360 | + """ |
1361 | + |
1362 | + ip = IntegerPrompt(title,text,default_value, min_value, max_value, step) |
1363 | + response = ip.run() |
1364 | + val = ip.get_value() |
1365 | + ip.destroy() |
1366 | + return (response, val) |
1367 | + |
1368 | + |
1369 | +class IntegerPrompt(Prompt): |
1370 | + """A Prompt for collecting an integer number value from user. Uses |
1371 | + a gtk.Spinner for data entry. |
1372 | + |
1373 | + |
1374 | + Using |
1375 | + #Collect an integer value from the user by using the |
1376 | + #quickly.prompts.integer() helper function |
1377 | + reponse, val = integer("Integer prompt title","Integer prompt message") |
1378 | + if response == gtk.RESPONSE_OK: |
1379 | + my_date = val |
1380 | + |
1381 | + Configuring |
1382 | + #Add widgets to the content_box member |
1383 | + dp = IntegerPrompt(title, text, default_date) |
1384 | + dp.content_box.pack_end(my_additional_widget) |
1385 | + |
1386 | + #Modify the _spinner member |
1387 | + dp._spinner.set_value(20) |
1388 | + |
1389 | + Extending |
1390 | + An IntegerPrompt is a Prompt which is a gtk.Dialog |
1391 | + |
1392 | + """ |
1393 | + |
1394 | + def __init__(self, title=_("Enter Number"), text=_("Enter an Integer Value:"), |
1395 | + default_value=0, min_value = -1000000000, max_value=1000000000, |
1396 | + step = 1): |
1397 | + """Creates an Integer Prompt |
1398 | + |
1399 | + """ |
1400 | + |
1401 | + Prompt.__init__(self, title, text) |
1402 | + adj = gtk.Adjustment(default_value,min_value,max_value,step) |
1403 | + self._spinner = gtk.SpinButton(adj,1,0) |
1404 | + self._spinner.set_activates_default(True) |
1405 | + self._spinner.show() |
1406 | + self._spinner.set_numeric(True) |
1407 | + self.content_box.pack_end(self._spinner, True, True, 5) |
1408 | + |
1409 | + def get_value(self): |
1410 | + return self._spinner.get_value_as_int() |
1411 | + |
1412 | +def decimal(title=_("Enter Price"), text=_("Choose a Price:"), |
1413 | + default_value=0, min_value=-1000000000, max_value=1000000000, |
1414 | + step=1,digits=20): |
1415 | + """decimal - prompts to enter a number that inlcudes |
1416 | + decimal places using a spinner via a dialog box. |
1417 | + |
1418 | + aguments: |
1419 | + title - a string to be the title of the dialog |
1420 | + text - a string to provide a prompt for the user within dialog |
1421 | + |
1422 | + keyword arguments: |
1423 | + default_value - an integer to display by default, should be greater than |
1424 | + the min_value and less then the max_value |
1425 | + min_value - the lowest number accepted by the spinner, |
1426 | + defaults to -1000000000 |
1427 | + step - set the incriments for each click of the spinner buttons, |
1428 | + defaults to 1 |
1429 | + max_value, the highest number accepted by the spinner, |
1430 | + defaults to 1000000000 |
1431 | + digits - the number of decimal places to include, defaults to 20 |
1432 | + supports a maximum of 20 decimal places. Values great than 20 will |
1433 | + be converted to 20, and values less than 0 will be converted to 0 |
1434 | + |
1435 | + returns a tuple of (gtk.DialogResponse, number) |
1436 | + |
1437 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1438 | + the user cancelled (gtk.RESPONSE_CANCEL) or dismissed the dialog |
1439 | + (gtk.RESPONSE_DELETE_EVENT) |
1440 | + |
1441 | + """ |
1442 | + |
1443 | + dp = DecimalPrompt(title, text, default_value, min_value, max_value, |
1444 | + step, digits) |
1445 | + response = dp.run() |
1446 | + val = dp.get_value() |
1447 | + dp.destroy() |
1448 | + return (response, val) |
1449 | + |
1450 | +class DecimalPrompt(Prompt): |
1451 | + """A Prompt for collecting a decimal number value from user. Uses |
1452 | + a gtk.Spinner for data entry. |
1453 | + |
1454 | + Using |
1455 | + #Collect a number from the user by using the |
1456 | + #quickly.prompts.decimal() helper function |
1457 | + reponse, val = decimal("Decimal prompt title","Decimal prompt message") |
1458 | + if response == gtk.RESPONSE_OK: |
1459 | + my_date = val |
1460 | + |
1461 | + Configuring |
1462 | + #Add widgets to the content_box member |
1463 | + dp = DecimalPrompt(title, text, default_number) |
1464 | + dp.content_box.pack_end(my_additional_widget) |
1465 | + |
1466 | + #Modify the _spinner member |
1467 | + dp._spinner.set_value(20.0) |
1468 | + |
1469 | + Extending |
1470 | + An DecimalPrompt is a Prompt which is a gtk.Dialog |
1471 | + |
1472 | + |
1473 | + """ |
1474 | + |
1475 | + def __init__(self, title=_("Enter Number"), text=_("Enter an Integer Value:"), |
1476 | + default_value=0, min_value=-1000000000, max_value=1000000000, |
1477 | + step=1, digits=20): |
1478 | + """Creates a DecimalPrompt |
1479 | + arguments: |
1480 | + title - a string to be the title of the dialog |
1481 | + text - a string to provide a prompt for the user within dialog |
1482 | + default_value - an integer to display by default, should be greater than |
1483 | + |
1484 | + keyword arguments: |
1485 | + default_value - an integer to display by default, should be greater than |
1486 | + the min_value and less then the max_value |
1487 | + min_value - the lowest number accepted by the spinner, |
1488 | + defaults to -1000000000 |
1489 | + step - set the incriments for each click of the spinner buttons, |
1490 | + defaults to 1 |
1491 | + max_value, the highest number accepted by the spinner, |
1492 | + defaults to 1000000000 |
1493 | + digits - the number of decimal places to include, defaults to 20 |
1494 | + supports a maximum of 20 decimal places. Values great than 20 will |
1495 | + be converted to 20, and values less than 0 will be converted to 0 |
1496 | + |
1497 | + returns a tuple of (gtk.DialogResponse, number) |
1498 | + |
1499 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1500 | + the user cancelled (gtk.RESPONSE_CANCEL) or dismissed the dialog |
1501 | + (gtk.RESPONSE_DELETE_EVENT) |
1502 | + |
1503 | + """ |
1504 | + |
1505 | + Prompt.__init__(self, title, text) |
1506 | + |
1507 | + self._adjustment = gtk.Adjustment(default_value,min_value,max_value,step) |
1508 | + if digits > 20: |
1509 | + digits = 20 |
1510 | + if digits < 0: |
1511 | + digits = 0 |
1512 | + self._spinner = gtk.SpinButton(self._adjustment,1,digits) |
1513 | + self._spinner.set_activates_default(True) |
1514 | + self._spinner.show() |
1515 | + self._spinner.set_numeric(True) |
1516 | + self.content_box.pack_end(self._spinner, True, True, 5) |
1517 | + |
1518 | + def get_value(self): |
1519 | + return self._spinner.get_value() |
1520 | + |
1521 | +def price(title=_("Enter Price"), text=_("Choose a Price:"), |
1522 | + default_value=0, min_value=-1000000000, max_value=1000000000, |
1523 | + step=1): |
1524 | + """price - prompts to enter a number up to the |
1525 | + hundreths place using a spinner via a dialog box. |
1526 | + |
1527 | + aguments: |
1528 | + title - a string to be the title of the dialog |
1529 | + text - a string to provide a prompt for the user within dialog |
1530 | + default_value - an integer to display by default, should be greater than |
1531 | + |
1532 | + keyword arguments: |
1533 | + the min_value and less then the max_value |
1534 | + min_value - the lowest number accepted by the spinner, |
1535 | + defaults to -1000000000 |
1536 | + max_value, the highest number accepted by the spinner, |
1537 | + defaults to 1000000000 |
1538 | + step - set the incriments for each click of the spinner buttons, |
1539 | + defaults to 1 |
1540 | + |
1541 | + returns a tuple of (gtk.DialogResponse, number) |
1542 | + |
1543 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1544 | + the user cancelled (gtk.RESPONSE_CANCEL) or dismissed the dialog |
1545 | + (gtk.RESPONSE_DELETE_EVENT) |
1546 | + |
1547 | + """ |
1548 | + |
1549 | + pp = PricePrompt(title, text, default_value, min_value, max_value, |
1550 | + step) |
1551 | + response = pp.run() |
1552 | + val = pp.get_value() |
1553 | + pp.destroy() |
1554 | + return (response, val) |
1555 | + |
1556 | +class PricePrompt(DecimalPrompt): |
1557 | + """A Prompt for collecting a decimal number value from the user, |
1558 | + formatted with two decimal places appropriate for entering |
1559 | + a currence ammount. Uses a gtk.Spinner for data entry. |
1560 | + |
1561 | + Using |
1562 | + #Collect a number from the user by using the |
1563 | + #quickly.prompts.price() helper function |
1564 | + reponse, val = price("Price prompt title","Price prompt message") |
1565 | + if response == gtk.RESPONSE_OK: |
1566 | + my_date = val |
1567 | + |
1568 | + Configuring |
1569 | + #Add widgets to the content_box member |
1570 | + pp = PricePrompt(title, text, default_number) |
1571 | + pp.content_box.pack_end(my_additional_widget) |
1572 | + |
1573 | + #Modify the _spinner member |
1574 | + pp._spinner.set_value(20.00) |
1575 | + |
1576 | + Extending |
1577 | + An PricePrompt is Decimal Prompt which is a Prompt which is a gtk.Dialog |
1578 | + |
1579 | + |
1580 | + """ |
1581 | + |
1582 | + def __init__(self, title=_("Enter Price"), text=_("Choose a Price:"), |
1583 | + default_value=0, min_value=-1000000000, max_value=1000000000, |
1584 | + step=1): |
1585 | + """Creates a DecimalPrompt |
1586 | + arguments: |
1587 | + title - a string to be the title of the dialog |
1588 | + text - a string to provide a prompt for the user within dialog |
1589 | + default_value - an integer to display by default, should be greater than |
1590 | + |
1591 | + keywrod arguments: |
1592 | + keyword arguments: |
1593 | + the min_value and less then the max_value |
1594 | + min_value - the lowest number accepted by the spinner, |
1595 | + defaults to -1000000000 |
1596 | + max_value, the highest number accepted by the spinner, |
1597 | + defaults to 1000000000 |
1598 | + step - set the incriments for each click of the spinner buttons, |
1599 | + defaults to 1 |
1600 | + |
1601 | + returns a tuple of (gtk.DialogResponse, number) |
1602 | + |
1603 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1604 | + the user cancelled (gtk.RESPONSE_CANCEL) or dismissed the dialog |
1605 | + (gtk.RESPONSE_DELETE_EVENT) |
1606 | + |
1607 | + """ |
1608 | + |
1609 | + DecimalPrompt.__init__(self,title,text,default_value,min_value, |
1610 | + max_value, step) |
1611 | + self._spinner.set_digits(2) |
1612 | + |
1613 | +def yes_no(title = _("Choose Yes or No"), text = "", yes="", no=""): |
1614 | + """yes_no - prompts the user to choose between two options, |
1615 | + one "yes" and one "no", though typically the button labels |
1616 | + should be set as verbs. |
1617 | + |
1618 | + aguments: |
1619 | + title - a string to be the title of the dialog |
1620 | + text - a string, typically a question, prompting the |
1621 | + user to choose Yes or No |
1622 | + yes - a string that is a verb representing the Yes action |
1623 | + no - a string that is a verb representing the No action |
1624 | + |
1625 | + returns a gtk.DialogResponse |
1626 | + gtk.RESPONSE_YES means the user clicked the "YES" button, otherwise |
1627 | + gtk.RESPONSE_NO means the user clicked the "NO" button, otherwise |
1628 | + the user dismissed the dialogv(gtk.RESPONSE_DELETE_EVENT) |
1629 | + |
1630 | + """ |
1631 | + yn = YesNoPrompt(title,text,yes,no) |
1632 | + response = yn.run() |
1633 | + yn.destroy() |
1634 | + return response |
1635 | + |
1636 | +class YesNoPrompt(gtk.Dialog): |
1637 | + """A prompt to collect a user choice between two options, |
1638 | + one "yes" and one "no", though typically the button labels |
1639 | + should be set as verbs. |
1640 | + |
1641 | + Using |
1642 | + #Collect a response from the user using the |
1643 | + #quickly.prompts.yes_no() helper function |
1644 | + reponse = decimal(title,message,"Do it", "Don't do it") |
1645 | + if response == gtk.RESPONSE_YES: |
1646 | + yes = True |
1647 | + else: |
1648 | + yes = False |
1649 | + |
1650 | + Configuring |
1651 | + #Add widgets to the content_box member |
1652 | + dp = DecimalPrompt(title, text, default_number) |
1653 | + dp.content_box.pack_end(my_additional_widget) |
1654 | + |
1655 | + #add a widget to the response by creating it and |
1656 | + #passing it in with a Gtk.RESPONSE_ID |
1657 | + dp.add_action_widget(new_widget, response_id) |
1658 | + |
1659 | + Extending |
1660 | + An YesNoPrompt is a gtk.Dialog |
1661 | + |
1662 | + """ |
1663 | + |
1664 | + def __init__(self, title=_("Choose an option"),text="",yes="",no=""): |
1665 | + """creaets a YesNoPrompt. |
1666 | + |
1667 | + aguments: |
1668 | + title - a string to be the title of the dialog |
1669 | + text - a string, typically a question, prompting the |
1670 | + user to choose Yes or No |
1671 | + yes - a string that is a verb representing the Yes action |
1672 | + no - a string that is a verb representing the No action |
1673 | + |
1674 | + """ |
1675 | + |
1676 | + gtk.Dialog.__init__(self, title, None, gtk.DIALOG_MODAL) |
1677 | + |
1678 | + if no == "": |
1679 | + no_button = gtk.Button(stock=gtk.STOCK_NO) |
1680 | + else: |
1681 | + no_button = gtk.Button(label=no) |
1682 | + self.add_action_widget(no_button,gtk.RESPONSE_NO) |
1683 | + no_button.show() |
1684 | + |
1685 | + if yes == "": |
1686 | + yes_button = gtk.Button(stock=gtk.STOCK_YES) |
1687 | + else: |
1688 | + yes_button = gtk.Button(label=yes) |
1689 | + self.add_action_widget(yes_button,gtk.RESPONSE_YES) |
1690 | + yes_button.show() |
1691 | + yes_button.set_flags(gtk.CAN_DEFAULT) |
1692 | + |
1693 | + |
1694 | + self.set_has_separator(False) |
1695 | + content_area = self.get_content_area() |
1696 | + content_area.set_border_width(5) |
1697 | + self.set_default_response(gtk.RESPONSE_YES) |
1698 | + |
1699 | + self.content_box = gtk.HBox(False, 10) |
1700 | + img = gtk.Image() |
1701 | + img.set_from_stock(gtk.STOCK_DIALOG_QUESTION,gtk.ICON_SIZE_DIALOG) |
1702 | + self.content_box.pack_start(img) |
1703 | + label = gtk.Label(text) |
1704 | + label.set_line_wrap(True) |
1705 | + self.content_box.pack_start(label,False, False, 5) |
1706 | + content_area.pack_start(self.content_box) |
1707 | + self.content_box.show() |
1708 | + label.show() |
1709 | + img.show() |
1710 | + |
1711 | +def warning(title = _("Warning"), text = ""): |
1712 | + """warning - displays a warning to the user, includes an appropriate icon |
1713 | + and an OK button |
1714 | + |
1715 | + aguments: |
1716 | + title - a string to be the title of the dialog |
1717 | + text - a string describing the warning |
1718 | + |
1719 | + returns a gtk.DialogResponse |
1720 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1721 | + the user dismissed the dialogv(gtk.RESPONSE_DELETE_EVENT) |
1722 | + |
1723 | + """ |
1724 | + |
1725 | + w = Alert(title,text,gtk.STOCK_DIALOG_WARNING) |
1726 | + response = w.run() |
1727 | + w.destroy() |
1728 | + return response |
1729 | + |
1730 | +def error(title = _("Error"), text = ""): |
1731 | + """error - displays an error to the user, includes an appropriate icon |
1732 | + and an OK button |
1733 | + |
1734 | + aguments: |
1735 | + title - a string to be the title of the dialog |
1736 | + text - a string describing the error |
1737 | + |
1738 | + returns a gtk.DialogResponse |
1739 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1740 | + the user dismissed the dialogv(gtk.RESPONSE_DELETE_EVENT) |
1741 | + |
1742 | + """ |
1743 | + |
1744 | + e = Alert(title,text,gtk.STOCK_DIALOG_ERROR) |
1745 | + response = e.run() |
1746 | + e.destroy() |
1747 | + return response |
1748 | + |
1749 | + |
1750 | +def info(title = _("Information"), text = ""): |
1751 | + """info - displays information to the user, includes an appropriate |
1752 | + icon and an OK button |
1753 | + |
1754 | + aguments: |
1755 | + title - a string to be the title of the dialog |
1756 | + text - a string providing the information |
1757 | + |
1758 | + returns a gtk.DialogResponse |
1759 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1760 | + the user dismissed the dialogv(gtk.RESPONSE_DELETE_EVENT) |
1761 | + |
1762 | + """ |
1763 | + |
1764 | + i = Alert(title,text,gtk.STOCK_DIALOG_INFO) |
1765 | + response = i.run() |
1766 | + i.destroy() |
1767 | + return response |
1768 | + |
1769 | +class Alert(gtk.Dialog): |
1770 | + """Displays an icon, a message, and an OK button to users. |
1771 | + Used by quickly.prompts.info(), quickly.prompts.warning(), |
1772 | + and quickly.prompts.error(). |
1773 | + |
1774 | + Using |
1775 | + #Display a message to the user using one of the helper functions |
1776 | + quickly.prompts.info(title,useful_message) |
1777 | + |
1778 | + Configuring |
1779 | + #Add widgets to the content_box member |
1780 | + alert = Alert(title, text, image) |
1781 | + alert.content_box.pack_end(my_additional_widget) |
1782 | + |
1783 | + #change the image by passing in a stock gtk image |
1784 | + alert.set_image(stock_image) |
1785 | + |
1786 | + Extending |
1787 | + An Alert is a gtk.Dialog. |
1788 | + |
1789 | + """ |
1790 | + |
1791 | + def __init__(self,title="",text="",image=None): |
1792 | + gtk.Dialog.__init__(self, title,None,gtk.DIALOG_MODAL,(gtk.STOCK_OK, gtk.RESPONSE_OK)) |
1793 | + self.set_has_separator(False) |
1794 | + content_area = self.get_content_area() |
1795 | + content_area.set_border_width(5) |
1796 | + self.set_default_response(gtk.RESPONSE_OK) |
1797 | + |
1798 | + self.content_box = gtk.HBox(False, 10) |
1799 | + label = gtk.Label(text) |
1800 | + label.set_line_wrap(True) |
1801 | + self._image = gtk.Image() |
1802 | + self._image.set_from_stock(image,gtk.ICON_SIZE_DIALOG) |
1803 | + self.content_box.pack_start(self._image, False, False, 5) |
1804 | + self.content_box.pack_end(label,False, False, 5) |
1805 | + content_area.pack_start(self.content_box) |
1806 | + self.content_box.show() |
1807 | + label.show() |
1808 | + self._image.show() |
1809 | + |
1810 | + def set_image(self, image): |
1811 | + self._image.set_from_stock(image,gtk.ICON_SIZE_DIALOG) |
1812 | + |
1813 | + |
1814 | +def save_image_file(title=_("Choose an Image"),path=None): |
1815 | + """save_image_file - prompts the user to choose an image file |
1816 | + |
1817 | + aguments: |
1818 | + title - a string to be the title of the dialog |
1819 | + path - a string providing a path to a directory where the |
1820 | + dialog should start. Defaults to Pictures directory. |
1821 | + |
1822 | + returns a gtk.DialogResponse |
1823 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1824 | + the user clicked "Cancel" or the userdismissed the |
1825 | + dialogv(gtk.RESPONSE_DELETE_EVENT) |
1826 | + |
1827 | + """ |
1828 | + |
1829 | + sid = SaveImageDialog(title,path) |
1830 | + response = sid.run() |
1831 | + value = sid.get_filename() |
1832 | + sid.destroy() |
1833 | + return (response, value) |
1834 | + |
1835 | + |
1836 | +class ImageDialog(gtk.FileChooserDialog): |
1837 | + """A base class for OpenImageDialog and SaveImageDialog |
1838 | + |
1839 | + Sets up typical mime types and file name patterns suitable |
1840 | + for saving images. |
1841 | + |
1842 | + This class is not typically used configured or extended directly, |
1843 | + but rather through OpenImageDialog and SaveImageDialog. |
1844 | + |
1845 | + """ |
1846 | + |
1847 | + |
1848 | + def __init__(self, action, button, title="", path=None): |
1849 | + """Create an ImageDialog. |
1850 | + |
1851 | + arguments: |
1852 | + action - a file chooser action, either gtk.FILE_CHOOSER_ACTION_SAVE |
1853 | + or gtk.FILE_CHOOSER_ACTION_OPEN |
1854 | + button - a gtk stock button for the intended action, either |
1855 | + gtk.STOCK_SAVE or gtk.STOCK_OPEN |
1856 | + |
1857 | + keyword arguments: |
1858 | + title - a title for the dialog, defaults to an empty string |
1859 | + path - a directory path to initially open to, defaults to |
1860 | + ~/Pictures |
1861 | + |
1862 | + """ |
1863 | + |
1864 | + gtk.FileChooserDialog.__init__(self,title, |
1865 | + None, |
1866 | + action, |
1867 | + (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, |
1868 | + button, gtk.RESPONSE_OK)) |
1869 | + |
1870 | + self.set_default_response(gtk.RESPONSE_OK) |
1871 | + |
1872 | + if path == None: |
1873 | + path = glib.get_user_special_dir(glib.USER_DIRECTORY_PICTURES) |
1874 | + self.set_current_folder(path) |
1875 | + |
1876 | + self._filter = gtk.FileFilter() |
1877 | + self._filter.set_name("All files") |
1878 | + self._filter.add_pattern("*") |
1879 | + self.add_filter(self._filter) |
1880 | + |
1881 | + self._filter = gtk.FileFilter() |
1882 | + self._filter.set_name("Images") |
1883 | + self._filter.add_mime_type("image/png") |
1884 | + self._filter.add_mime_type("image/jpeg") |
1885 | + self._filter.add_mime_type("image/gif") |
1886 | + self._filter.add_pattern("*.png") |
1887 | + self._filter.add_pattern("*.jpg") |
1888 | + self._filter.add_pattern("*.gif") |
1889 | + self._filter.add_pattern("*.tif") |
1890 | + self._filter.add_pattern("*.xpm") |
1891 | + self.add_filter(self._filter) |
1892 | + self.set_do_overwrite_confirmation(True) |
1893 | + |
1894 | +class SaveImageDialog(ImageDialog): |
1895 | + """ |
1896 | + A dialog to prompt the user for a place to save an image file. |
1897 | + |
1898 | + Using |
1899 | + #Collect a location using the quickly.prompts.save_image_file() |
1900 | + #helper function |
1901 | + response, path = save_image_file(title) |
1902 | + if response == gtk.RESPONSE_OK: |
1903 | + save_to_path = path |
1904 | + |
1905 | + Configuring |
1906 | + #Modify the _filter member |
1907 | + sid._filter.add_mime_type("image/svg") |
1908 | + sid._filter.add_pattern("*.svg") |
1909 | + |
1910 | + Extending |
1911 | + A SaveImageDialog is an ImageDialog which is a gtk.FileChooserDialog |
1912 | + |
1913 | + """ |
1914 | + |
1915 | + def __init__(self, title="Choose File Location", path=None): |
1916 | + """Create a SaveImageDialog. |
1917 | + |
1918 | + keyword arguments: |
1919 | + title - a title for the dialog, defaults to an empty string |
1920 | + path - a directory path to initially open to, defaults to |
1921 | + ~/Pictures |
1922 | + |
1923 | + """ |
1924 | + |
1925 | + ImageDialog.__init__(self,gtk.FILE_CHOOSER_ACTION_SAVE, gtk.STOCK_SAVE, title,path) |
1926 | + |
1927 | +class OpenImageDialog(ImageDialog): |
1928 | + """ |
1929 | + A dialog to prompt the user for an image to open |
1930 | + |
1931 | + Using |
1932 | + #Collect a location using the quickly.prompts.open_image_file() |
1933 | + #helper function |
1934 | + response, path = open_image_file(title) |
1935 | + if response == gtk.RESPONSE_OK: |
1936 | + path_to_image = path |
1937 | + |
1938 | + Configuring |
1939 | + #Modify the _filter member |
1940 | + sid._filter.add_mime_type("image/svg") |
1941 | + sid._filter.add_pattern("*.svg") |
1942 | + |
1943 | + Extending |
1944 | + A SaveImageDialog is an ImageDialog which is a gtk.FileChooserDialog |
1945 | + |
1946 | + """ |
1947 | + |
1948 | + def __init__(self, title="Choose File Location", path=None): |
1949 | + """Create an OpenImageDialog. |
1950 | + |
1951 | + keyword arguments: |
1952 | + title - a title for the dialog, defaults to an empty string |
1953 | + path - a directory path to initially open to, defaults to |
1954 | + ~/Pictures |
1955 | + |
1956 | + """ |
1957 | + ImageDialog.__init__(self,gtk.FILE_CHOOSER_ACTION_OPEN, gtk.STOCK_OPEN, title,path) |
1958 | + |
1959 | +def open_image_file(title=_("Choose an Image"),path=None): |
1960 | + """open_image_file - prompts the user to choose an image file |
1961 | + |
1962 | + aguments: |
1963 | + title - a string to be the title of the dialog |
1964 | + path - a string providing a path to a directory where the |
1965 | + dialog should start. Defaults to Pictures directory. |
1966 | + |
1967 | + returns a tuple of (gtk.DialogResponse, str) |
1968 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1969 | + the user cancelled (gtk.RESPONSE_CANCEL) or dismissed the dialog |
1970 | + (gtk.RESPONSE_DELETE_EVENT) |
1971 | + The str is the path to the image chosen by the user, if any. |
1972 | + |
1973 | + |
1974 | + """ |
1975 | + |
1976 | + oid = OpenImageDialog(title,path) |
1977 | + response = oid.run() |
1978 | + value = oid.get_filename() |
1979 | + oid.destroy() |
1980 | + return (response, value) |
1981 | + |
1982 | +def choose_directory(title=_("Choose a Directory"),path=None): |
1983 | + """choose_directory - prompts the user to choose an directory |
1984 | + |
1985 | + aguments: |
1986 | + title - a string to be the title of the dialog |
1987 | + path - a string providing a path to a directory where the |
1988 | + dialog should start. |
1989 | + |
1990 | + |
1991 | + returns a tuple of (gtk.DialogResponse, str) |
1992 | + gtk.RESPONSE_OK means the user clicked the "OK" button, otherwise |
1993 | + the user cancelled (gtk.RESPONSE_CANCEL) or dismissed the dialog |
1994 | + (gtk.RESPONSE_DELETE_EVENT) |
1995 | + The str is the path to the directory chosen by the user, if any. |
1996 | + |
1997 | + """ |
1998 | + |
1999 | + dcd = DirectoryChooserDialog(title, path) |
2000 | + response = dcd.run() |
2001 | + value = dcd.get_filename() |
2002 | + dcd.destroy() |
2003 | + return (response, value) |
2004 | + |
2005 | +class DirectoryChooserDialog(gtk.FileChooserDialog): |
2006 | + """A Dialog to prompt the user to choose a directory path. |
2007 | + |
2008 | + Using |
2009 | + #prompt the user to provide a directory path using |
2010 | + quickly.prompts.choose_directory(title) |
2011 | + |
2012 | + Configuring |
2013 | + #A DirectoryChooseDialog is a gtk.FileChooserDialog, so you can |
2014 | + #use gtk.FileChooseDialog members |
2015 | + dcd = DirectoryChooserDialog(title) |
2016 | + dcd.set_local_only(False) |
2017 | + |
2018 | + Extending |
2019 | + #A DirectoryChooseDialog is a gtk.FileChooserDialog |
2020 | + |
2021 | + """ |
2022 | + |
2023 | + def __init__(self, title, path=None): |
2024 | + """Creates a DirectoryChooseDialog |
2025 | + |
2026 | + arguments: |
2027 | + title - A title for the dialog |
2028 | + |
2029 | + keyword arguments: |
2030 | + path - a default location for opening the dialogs |
2031 | + |
2032 | + """ |
2033 | + |
2034 | + gtk.FileChooserDialog.__init__(self, title, |
2035 | + None, |
2036 | + gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, |
2037 | + (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, |
2038 | + gtk.STOCK_OPEN, gtk.RESPONSE_OK)) |
2039 | + self.set_default_response(gtk.RESPONSE_OK) |
2040 | + if path is not None: |
2041 | + self.set_current_folder(path) |
2042 | + |
2043 | + |
2044 | +if __name__ == "__main__": |
2045 | + """test code to try out the dialogs""" |
2046 | + #these don't have return values to test for |
2047 | + warning("Warning Prompt","Warning Prompt") |
2048 | + info("Information Prompt","Information Prompt") |
2049 | + error("Error Prompt","Error Prompt") |
2050 | + |
2051 | + #the rest of values to test for |
2052 | + response, val = choose_directory("directory choose test") |
2053 | + if response == gtk.RESPONSE_OK: |
2054 | + print "response was OK" |
2055 | + else: |
2056 | + print "response was not OK" |
2057 | + print "selected directory was " + val |
2058 | + |
2059 | + response, val = open_image_file("image open test") |
2060 | + if response == gtk.RESPONSE_OK: |
2061 | + print "response was OK" |
2062 | + else: |
2063 | + print "response was not OK" |
2064 | + print "selected locations was " + str(val) |
2065 | + |
2066 | + response, val = save_image_file("image save test") |
2067 | + if response == gtk.RESPONSE_OK: |
2068 | + print "response was OK" |
2069 | + else: |
2070 | + print "response was not OK" |
2071 | + print "selected locations was " + str(val) |
2072 | + |
2073 | + reponse, val = string("String select test","String select test") |
2074 | + if response == gtk.RESPONSE_OK: |
2075 | + print "response was OK" |
2076 | + else: |
2077 | + print "response was not OK" |
2078 | + print "string was " + str(val) |
2079 | + |
2080 | + reponse, val = date("Date select test","Date select test") |
2081 | + if response == gtk.RESPONSE_OK: |
2082 | + print "response was OK" |
2083 | + else: |
2084 | + print "response was not OK" |
2085 | + print "date was " + str(val) |
2086 | + |
2087 | + reponse, val = integer("Integer select test","Integer select test",default_value=20) |
2088 | + if response == gtk.RESPONSE_OK: |
2089 | + print "response was OK" |
2090 | + else: |
2091 | + print "response was not OK" |
2092 | + print "integer was " + str(val) |
2093 | + |
2094 | + reponse, val = decimal("Price select test","Price select test",default_value=20,digits=5) |
2095 | + if response == gtk.RESPONSE_OK: |
2096 | + print "response was OK" |
2097 | + else: |
2098 | + print "response was not OK" |
2099 | + print "decimal was " + str(val) |
2100 | + |
2101 | + reponse, val = price("Price select test","Price select test",default_value=20) |
2102 | + if response == gtk.RESPONSE_OK: |
2103 | + print "response was OK" |
2104 | + else: |
2105 | + print "response was not OK" |
2106 | + print "price was " + str(val) |
2107 | + |
2108 | + response = yes_no("Yes/No Test","Yes/No Test", "_Yes Verb","_No Verb") |
2109 | + if response == gtk.RESPONSE_YES: |
2110 | + print "response was yes" |
2111 | + |
2112 | + |
2113 | |
2114 | === added directory 'quickly/tests' |
2115 | === added file 'quickly/tests/__init__.py' |
2116 | === added file 'quickly/tests/test_prompts.py' |
2117 | --- quickly/tests/test_prompts.py 1970-01-01 00:00:00 +0000 |
2118 | +++ quickly/tests/test_prompts.py 2011-07-25 07:14:30 +0000 |
2119 | @@ -0,0 +1,37 @@ |
2120 | +# -*- coding: utf-8 -*- |
2121 | +### BEGIN LICENSE |
2122 | +# Copyright (C) 2010 Rick Spencer rick.spencer@canonical.com |
2123 | +#This program is free software: you can redistribute it and/or modify it |
2124 | +#under the terms of the GNU General Public License version 3, as published |
2125 | +#by the Free Software Foundation. |
2126 | +# |
2127 | +#This program is distributed in the hope that it will be useful, but |
2128 | +#WITHOUT ANY WARRANTY; without even the implied warranties of |
2129 | +#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2130 | +#PURPOSE. See the GNU General Public License for more details. |
2131 | +# |
2132 | +#You should have received a copy of the GNU General Public License along |
2133 | +#with this program. If not, see <http://www.gnu.org/licenses/>. |
2134 | +### END LICENSE |
2135 | + |
2136 | +"""Tests for the DictionaryGrid""" |
2137 | + |
2138 | +from testtools import TestCase |
2139 | +import quickly.prompts |
2140 | + |
2141 | +class TestDictionaryGrid(TestCase): |
2142 | + """Test the CouchGrid functionality""" |
2143 | + |
2144 | + def setUp(self): |
2145 | + pass |
2146 | + |
2147 | + def tearDown(self): |
2148 | + pass |
2149 | + |
2150 | + def test_string_prompt(self): |
2151 | + """Test a simple creating An AsynchTaskProgressBox |
2152 | + and then adding keys and dictionaries after creation |
2153 | + |
2154 | + """ |
2155 | + pass |
2156 | + #response, val = quickly.prompts.string() |
2157 | |
2158 | === added directory 'quickly/widgets' |
2159 | === added file 'quickly/widgets/__init__.py' |
2160 | === added file 'quickly/widgets/asynch_task_progressbox.py' |
2161 | --- quickly/widgets/asynch_task_progressbox.py 1970-01-01 00:00:00 +0000 |
2162 | +++ quickly/widgets/asynch_task_progressbox.py 2011-07-25 07:14:30 +0000 |
2163 | @@ -0,0 +1,310 @@ |
2164 | +### BEGIN LICENSE |
2165 | +# Copyright (C) 2010 Rick Spencer rick.spencer@canonical.com |
2166 | +#This program is free software: you can redistribute it and/or modify it |
2167 | +#under the terms of the GNU General Public License version 3, as published |
2168 | +#by the Free Software Foundation. |
2169 | +# |
2170 | +#This program is distributed in the hope that it will be useful, but |
2171 | +#WITHOUT ANY WARRANTY; without even the implied warranties of |
2172 | +#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2173 | +#PURPOSE. See the GNU General Public License for more details. |
2174 | +# |
2175 | +#You should have received a copy of the GNU General Public License along |
2176 | +#with this program. If not, see <http://www.gnu.org/licenses/>. |
2177 | +### END LICENSE |
2178 | + |
2179 | +try: |
2180 | + import pygtk |
2181 | + pygtk.require("2.0") |
2182 | + import gtk |
2183 | + import threading |
2184 | + import time |
2185 | + import gobject |
2186 | + import gettext |
2187 | + from gettext import gettext as _ |
2188 | + gettext.textdomain('quickly-widgets') |
2189 | + |
2190 | +except: |
2191 | + print "couldn't load depencies" |
2192 | + |
2193 | +class AsynchTaskProgressBox( gtk.HBox ): |
2194 | + """AsynchTaskProgressBox: encapsulates a pulstating progressbar, a cancel |
2195 | + button, and a long running task. Use an AsynchTaskProgressBox when you want |
2196 | + a window to perform a long running task in the background without freezing |
2197 | + the UI for the user. |
2198 | + |
2199 | + """ |
2200 | + |
2201 | + def __init__(self, run_function, params = None, cancelable = True): |
2202 | + """Create an AsycnTaskProgressBox |
2203 | + |
2204 | + Keyword arguments: |
2205 | + run_function -- the function to run asynchronously |
2206 | + params -- optional dictionary of parameters to be pass into run_function |
2207 | + cancelable -- optional value to determine whether to show cancel button. Defaults to True. |
2208 | + Do not use a value with the key of 'kill' in the params dictionary |
2209 | + |
2210 | + """ |
2211 | + |
2212 | + gtk.HBox.__init__( self, False, 2 ) |
2213 | + |
2214 | + self.progressbar = gtk.ProgressBar() |
2215 | + self.progressbar.show() |
2216 | + self.pack_start(self.progressbar, True) |
2217 | + |
2218 | + self.cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL) |
2219 | + if cancelable: |
2220 | + self.cancel_button.show() |
2221 | + if params is None: |
2222 | + params = {} |
2223 | + params["update_progress_function"] = self.update |
2224 | + self.cancel_button.set_sensitive(False) |
2225 | + self.cancel_button.connect("clicked",self.__stop_clicked) |
2226 | + self.pack_end(self.cancel_button, False) |
2227 | + |
2228 | + self.run_function = run_function |
2229 | + self.pulse_thread = None |
2230 | + self.work_thread = None |
2231 | + self.params = params |
2232 | + |
2233 | + self.connect("destroy", self.__destroy) |
2234 | + |
2235 | + __gsignals__ = {'complete' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
2236 | + (gobject.TYPE_PYOBJECT,)), |
2237 | + 'cancelrequested' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
2238 | + (gobject.TYPE_PYOBJECT,)) |
2239 | + } |
2240 | + |
2241 | + def start(self, caption = "Working"): |
2242 | + """executes run_function asynchronously and starts pulsating the progressbar |
2243 | + Keyword arguments: |
2244 | + caption -- optional text to display in the progressbar |
2245 | + """ |
2246 | + #Throw an exception if the user tries to start an operating thread |
2247 | + if self.pulse_thread != None: |
2248 | + raise RuntimeError("AsynchTaskProgressBox already started.") |
2249 | + |
2250 | + #Create and start a thread to run the users task |
2251 | + #pass in a callback and the user's params |
2252 | + self.work_thread = KillableThread(self.run_function, self.__on_complete, self.params) |
2253 | + self.work_thread.start() |
2254 | + |
2255 | + #create a thread to display the user feedback |
2256 | + self.pulse_thread = PulseThread(self.progressbar, caption) |
2257 | + self.pulse_thread.start() |
2258 | + |
2259 | + #enable the button so the user can try to kill the task |
2260 | + self.cancel_button.set_sensitive( True ) |
2261 | + |
2262 | + def update(self, fraction = None, displaytext = "Working"): |
2263 | + """updates the progress bar with a given percentage and/or changes the |
2264 | + caption. |
2265 | + Keyword arguments: |
2266 | + fraction -- the current percentage complete |
2267 | + displaytext -- the new caption to display""" |
2268 | + if self.pulse_thread != None: |
2269 | + self.pulse_thread.update(fraction, displaytext) |
2270 | + |
2271 | + #call back function for after run_function returns |
2272 | + def __on_complete( self, data ): |
2273 | + self.emit("complete", data) |
2274 | + self.kill() |
2275 | + |
2276 | + #call back function for cancel button |
2277 | + def __stop_clicked( self, widget, data = None ): |
2278 | + self.cancel() |
2279 | + |
2280 | + def cancel(self): |
2281 | + self.kill() |
2282 | + #emit the cancelrequested event |
2283 | + #note that this only signals that the kill function was called |
2284 | + #the thread may or may not have actually stopped |
2285 | + self.emit("cancelrequested", self) |
2286 | + |
2287 | + def kill( self ): |
2288 | + """ |
2289 | + Stops pulstating the progressbar if the progressbar is working. |
2290 | + Sets the value of 'kill' to True in the run_function. |
2291 | + |
2292 | + """ |
2293 | + |
2294 | + #stop the pulse_thread and remove a reference to it if there is one |
2295 | + if self.pulse_thread != None: |
2296 | + self.pulse_thread.kill() |
2297 | + self.pulse_thread = None |
2298 | + |
2299 | + #disable the cancel button since the task is about to be told to stop |
2300 | + gobject.idle_add(self.__disable_cancel_button) |
2301 | + |
2302 | + #tell the users function tostop if it's thread exists |
2303 | + if self.work_thread != None: |
2304 | + self.work_thread.kill() |
2305 | + |
2306 | + #called when the widget is destroyed, attempts to clean up |
2307 | + #the work thread and the pulse thread |
2308 | + def __destroy(self, widget, data = None): |
2309 | + if self.work_thread != None: |
2310 | + self.work_thread.kill() |
2311 | + if self.pulse_thread != None: |
2312 | + self.pulse_thread.kill() |
2313 | + |
2314 | + def __disable_cancel_button(self): |
2315 | + gtk.gdk.threads_enter() |
2316 | + self.cancel_button.set_sensitive( False ) |
2317 | + gtk.gdk.threads_leave() |
2318 | + |
2319 | +class PulseThread ( threading.Thread ): |
2320 | + """Class for use by AsynchTaskProgressBox. Not for general use. |
2321 | + |
2322 | + """ |
2323 | + def __init__(self,progressbar,displaytext = _("Working")): |
2324 | + threading.Thread.__init__(self) |
2325 | + self.displaytext = displaytext |
2326 | + self.setDaemon(False) |
2327 | + self.progressbar = progressbar |
2328 | + self.__kill = False |
2329 | + self.fraction = float(0) |
2330 | + |
2331 | + def kill(self): |
2332 | + self.__kill = True |
2333 | + |
2334 | + def update(self, fraction, displaytext): |
2335 | + self.displaytext = displaytext |
2336 | + self.fraction = fraction |
2337 | + |
2338 | + #As a subclass of Thread, this function runs when start() is called |
2339 | + #It will cause the progressbar to pulse, showing that a task is running |
2340 | + def run ( self ): |
2341 | + self.progressbar.set_text(self.displaytext) |
2342 | + #keep running until the __kill flag is set to True |
2343 | + while not self.__kill: |
2344 | + time.sleep(.1) |
2345 | + #get ahold of the UI thread and command the progress bar to pulse |
2346 | + gtk.gdk.threads_enter() |
2347 | + if self.fraction == 0: |
2348 | + self.progressbar.pulse() |
2349 | + else: |
2350 | + self.progressbar.set_fraction(self.fraction) |
2351 | + self.progressbar.set_text(self.displaytext) |
2352 | + gtk.gdk.threads_leave() |
2353 | + #before exiting, reset the progressbar to show that no task is running |
2354 | + gtk.gdk.threads_enter() |
2355 | + self.progressbar.set_fraction(0) |
2356 | + self.progressbar.set_text("") |
2357 | + gtk.gdk.threads_leave() |
2358 | + |
2359 | +class KillableThread( threading.Thread ): |
2360 | + """Class for use by AsynchTaskProgressBox. Not for general use. |
2361 | + |
2362 | + """ |
2363 | + def __init__(self,run_function, on_complete, params = None): |
2364 | + threading.Thread.__init__(self) |
2365 | + self.setDaemon(False) |
2366 | + self.run_function = run_function |
2367 | + self.params = params |
2368 | + self.on_complete = on_complete |
2369 | + |
2370 | + #As a subclass of Thread, this function runs when start() is called |
2371 | + #It will run the user's function on this thread |
2372 | + def run( self ): |
2373 | + #set up params and include the kill flag |
2374 | + if self.params == None: |
2375 | + self.params = {} |
2376 | + self.params["kill"] = False |
2377 | + #tell the function to run |
2378 | + data = self.run_function(self.params) |
2379 | + #return any data from the function so it can be sent in the complete signal |
2380 | + self.on_complete(data) |
2381 | + |
2382 | + #Tell the user's function that it should stop |
2383 | + #Note the user's function may not check this |
2384 | + def kill( self ): |
2385 | + self.params["kill"] = True |
2386 | + |
2387 | +class TestWindow(gtk.Window): |
2388 | + """For testing and demonstrating AsycnTaskProgressBox. |
2389 | + |
2390 | + """ |
2391 | + def __init__(self): |
2392 | + #create a window a VBox to hold the controls |
2393 | + gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL) |
2394 | + self.set_title("AsynchTaskProgressBox Test Window") |
2395 | + windowbox = gtk.VBox(False, 2) |
2396 | + windowbox.show() |
2397 | + self.add(windowbox) |
2398 | + |
2399 | + #create params for use by the function that should run asynchronously |
2400 | + params = {"start": 100, "stop": 110} |
2401 | + |
2402 | + #pass in the function and the params, then add to the window |
2403 | + self.thread_progressbox = AsynchTaskProgressBox(self.asynch_function, params) |
2404 | + self.thread_progressbox.show() |
2405 | + windowbox.add(self.thread_progressbox) |
2406 | + |
2407 | + #start the task, and set the text for the progressbar to "Testing" |
2408 | + #This will start the function and start the progressbar pulsating |
2409 | + self.thread_progressbox.start("Testing") |
2410 | + |
2411 | + #connect to the complete event to respond when the task is complete |
2412 | + self.thread_progressbox.connect("complete",self.complete_function) |
2413 | + |
2414 | + #connect to the cancel requested event for demonstration purposes |
2415 | + self.thread_progressbox.connect("cancelrequested", self.canceled_function) |
2416 | + |
2417 | + #create a button for starting the task and add it to the window |
2418 | + start_button = gtk.Button(stock=gtk.STOCK_EXECUTE) |
2419 | + start_button.show() |
2420 | + windowbox.add(start_button) |
2421 | + start_button.connect("clicked",self.start_clicked) |
2422 | + self.show() |
2423 | + |
2424 | + #finish wiring up the window |
2425 | + self.connect("destroy", self.destroy) |
2426 | + |
2427 | + #start up gtk.main in a threaded environment |
2428 | + gtk.gdk.threads_init() |
2429 | + gtk.gdk.threads_enter() |
2430 | + gtk.main() |
2431 | + gtk.gdk.threads_leave() |
2432 | + |
2433 | + #called when the window is destroyed |
2434 | + def destroy(self, widget, data = None): |
2435 | + gtk.main_quit() |
2436 | + |
2437 | + #start the AsynchTaskProgressBox when the button is clicked |
2438 | + def start_clicked(self, widget, data = None): |
2439 | + self.thread_progressbox.start("Testing") |
2440 | + |
2441 | + #The function to run asynchronously |
2442 | + def asynch_function( self, params ): |
2443 | + # do something interminate and cpu intensive at startup |
2444 | + print "starting..." |
2445 | + time.sleep(2) |
2446 | + #pull values from the params that were set above |
2447 | + total = float(abs(params["stop"]-params["start"])) |
2448 | + for x in range(params["start"],params["stop"]): |
2449 | + #check if to see if the user has told the task to stop |
2450 | + if params["kill"] == True: |
2451 | + #return a string if the user stopped the task |
2452 | + return "stopped at " + str(x) |
2453 | + else: |
2454 | + #if the user did not try to stop the task, go ahead and do something |
2455 | + print x |
2456 | + fraction=abs(x-params["start"])/total |
2457 | + # call the update_progress_function function with the current percentage and caption |
2458 | + params["update_progress_function"](fraction=fraction, displaytext=str(x)) |
2459 | + #this is a processor intensive task, so |
2460 | + #sleep the loop to keep the UI from bogging down |
2461 | + time.sleep(.5) |
2462 | + #if the loop completes, return a string |
2463 | + return "counted all" |
2464 | + |
2465 | + #called when the task completes |
2466 | + def complete_function(self, widget, data = None): |
2467 | + print "returned " + str(data) |
2468 | + |
2469 | + def canceled_function(self, widget, data=None): |
2470 | + print "cancel requested" |
2471 | +if __name__== "__main__": |
2472 | + test = TestWindow() |
2473 | + |
2474 | |
2475 | === added file 'quickly/widgets/conventions.py' |
2476 | --- quickly/widgets/conventions.py 1970-01-01 00:00:00 +0000 |
2477 | +++ quickly/widgets/conventions.py 2011-07-25 07:14:30 +0000 |
2478 | @@ -0,0 +1,40 @@ |
2479 | +### BEGIN LICENSE |
2480 | +# Copyright (C) 2010 Rick Spencer rick.spencer@canonical.com |
2481 | +#This program is free software: you can redistribute it and/or modify it |
2482 | +#under the terms of the GNU General Public License version 3, as published |
2483 | +#by the Free Software Foundation. |
2484 | +# |
2485 | +#This program is distributed in the hope that it will be useful, but |
2486 | +#WITHOUT ANY WARRANTY; without even the implied warranties of |
2487 | +#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2488 | +#PURPOSE. See the GNU General Public License for more details. |
2489 | +# |
2490 | +#You should have received a copy of the GNU General Public License along |
2491 | +#with this program. If not, see <http://www.gnu.org/licenses/>. |
2492 | +### END LICENSE |
2493 | + |
2494 | +import gtk |
2495 | +import gobject |
2496 | +from grid_column import StringColumn, CurrencyColumn, CheckColumn |
2497 | +from grid_column import IntegerColumn, TagsColumn, DateColumn |
2498 | + |
2499 | +def get_column(key, index, dictionary_index, editable): |
2500 | + if key.lower() == "id": |
2501 | + return IntegerColumn(key, index, dictionary_index, editable) |
2502 | + elif key.endswith("?"): |
2503 | + return CheckColumn(key, index, dictionary_index, editable) |
2504 | + elif key.lower().endswith(" price") or key.lower() == "price": |
2505 | + return CurrencyColumn(key, index, dictionary_index, editable) |
2506 | + elif key.lower() == "tags": |
2507 | + return TagsColumn(key, index, dictionary_index, editable) |
2508 | + elif key.lower().endswith(" count") or key.lower() == "count": |
2509 | + return IntegerColumn(key, index, dictionary_index, editable) |
2510 | + elif key.lower().endswith(" date") or key.lower() == "date": |
2511 | + return DateColumn(key, index, dictionary_index, editable) |
2512 | + |
2513 | + else: |
2514 | + return StringColumn(key, index, dictionary_index, editable) |
2515 | + |
2516 | + |
2517 | + |
2518 | + |
2519 | |
2520 | === added file 'quickly/widgets/couch_grid.py' |
2521 | --- quickly/widgets/couch_grid.py 1970-01-01 00:00:00 +0000 |
2522 | +++ quickly/widgets/couch_grid.py 2011-07-25 07:14:30 +0000 |
2523 | @@ -0,0 +1,444 @@ |
2524 | +# -*- coding: utf-8 -*- |
2525 | +### BEGIN LICENSE |
2526 | +# Copyright (C) 2010 Rick Spencer rick.spencer@canonical.com |
2527 | +#This program is free software: you can redistribute it and/or modify it |
2528 | +#under the terms of the GNU General Public License version 3, as published |
2529 | +#by the Free Software Foundation. |
2530 | +# |
2531 | +#This program is distributed in the hope that it will be useful, but |
2532 | +#WITHOUT ANY WARRANTY; without even the implied warranties of |
2533 | +#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2534 | +#PURPOSE. See the GNU General Public License for more details. |
2535 | +# |
2536 | +#You should have received a copy of the GNU General Public License along |
2537 | +#with this program. If not, see <http://www.gnu.org/licenses/>. |
2538 | +### END LICENSE |
2539 | + |
2540 | +"""A Treeview for Desktop CouchDB |
2541 | +Displays and persists data in desktopcouch, handles presentation |
2542 | +of the UI in a Gtk.TreeView, as well handles persistence to a backend |
2543 | +desktopcouch database. |
2544 | + |
2545 | +Using |
2546 | +#define the database and record type |
2547 | +database = "couch_widget_test" |
2548 | +record_type="test_record_type" |
2549 | + |
2550 | +#create a dictionary if you don't already have one |
2551 | +dicts = [{"test?":True,"price":100,"foo count":100,"Key4":"1004"}, |
2552 | + {"test?":True,"price":100,"foo count":100,"Key4":"1004"}, |
2553 | + {"test?":True,"price":100,"foo count":100,"Key4":"1004"}] |
2554 | + |
2555 | +#create the CouchGrid |
2556 | +cg = CouchGrid(database, record_type=record_type, dictionaries=dicts) |
2557 | + |
2558 | +Configuring |
2559 | +#Define columns to display |
2560 | +keys=["price","test?"] |
2561 | +cg = CouchGrid(database, record_type=record_type, dictionaries=dicts,keys=keys) |
2562 | + |
2563 | +#Define column types to use |
2564 | +hints = {"price": StringColumn} |
2565 | +cg = CouchGrid(database, record_type=record_type, dictionaries=dicts,keys=keys, type_hints = hints) |
2566 | + |
2567 | +#A CouchGrid is a Dictionary Grid whcih is a TreeView, |
2568 | +#so you can use DicationaryGrid and TreeView members |
2569 | +cg.editable = True |
2570 | +cg.get_column(0).set_title("Price") |
2571 | + |
2572 | +Extending |
2573 | +To change the way CouchGrid persists data, change _refresh_treeview to |
2574 | +handle persistence of data if needed, calling DictionaryGrid._populate_treeivew |
2575 | +to handle the UI. You should do the same with append_row. |
2576 | + |
2577 | +You may also want to override _edited and _edited_toggled to handle persistence |
2578 | +when the UI is changed. |
2579 | + |
2580 | +It is only useful to extend CouchGrid if you are using desktopcouch for |
2581 | +persistence. Otherwise, derive from DictionaryGrid. |
2582 | + |
2583 | +""" |
2584 | + |
2585 | +import gtk |
2586 | +import gobject |
2587 | +from desktopcouch.records.server import CouchDatabase |
2588 | +from desktopcouch.records.record import Record |
2589 | +from quickly.widgets.dictionary_grid import DictionaryGrid |
2590 | +from quickly.widgets.grid_column import CheckColumn |
2591 | + |
2592 | +#TODO: a delete_selected_rows function would be nice and not too hard |
2593 | + |
2594 | +class CouchGrid(DictionaryGrid): |
2595 | + def __init__( |
2596 | + self, database_name, record_type=None, dictionaries=None, editable=False, keys=None, type_hints=None, uri=None): |
2597 | + """Create a new Couchwidget |
2598 | + arguments: |
2599 | + database_name - specify the name of the database in the desktop |
2600 | + couchdb to use. If the specified database does not exist, it |
2601 | + will be created. |
2602 | + |
2603 | + optional arguments: |
2604 | + record_type - a string to specify the record_type to use in |
2605 | + retrieving and creating records. Note that if no records exist |
2606 | + in the CouchDB then the keys argument must also be used or |
2607 | + a RuntimeError will result. |
2608 | + |
2609 | + dictionaries - a list of dictionaries to initialize in the |
2610 | + grid. If these haven't been added to desktopcouch, they will |
2611 | + be automatically persisted and updated using the record_type |
2612 | + specified. Any previously saved data of the same record_type will |
2613 | + also be displayed. |
2614 | + |
2615 | + keys - a list of strings specifying keys to use in |
2616 | + the columns of the CouchGrid. The keys will also be used for the |
2617 | + column titles and keys in desktop couch. |
2618 | + |
2619 | + If a record does not contain a value for a specified key |
2620 | + the CouchGrid will simply display an empty cell of the |
2621 | + appropriate type. If the widget is set to editable, |
2622 | + the user will be able to add values to the database. |
2623 | + |
2624 | + The types for the columns will be inferred by the key based on |
2625 | + some conventions. the key "id" is assumed to be an integer, as |
2626 | + is any key ending in " count". A key ending in "?" is assumed |
2627 | + to be a Boolean displayed with a checkbox. The key "price" is |
2628 | + assumed to be currency, as is any key ending in "count". There |
2629 | + may be others. Defaults can be overridden using type-hints. All |
2630 | + other keys will be assumed to be strings. |
2631 | + |
2632 | + type-hints - a dictionary containing keys specificed for the |
2633 | + TreeView and GridColumns. Used to override types inferred |
2634 | + by convention, or for changing the type of a column from |
2635 | + the default of a string to something else. |
2636 | + |
2637 | + uri - A uri for the DesktopCouch. This is only used to |
2638 | + choose a Couch database running remotely. The default is |
2639 | + to use the local desktopcouch database. |
2640 | + |
2641 | + """ |
2642 | + |
2643 | + if type(database_name) is not type(str()): |
2644 | + raise TypeError("database_name is required and must be a string") |
2645 | + |
2646 | + #set up the database before trying to use it |
2647 | + self.uri = uri |
2648 | + self._record_type = None |
2649 | + self._db = None |
2650 | + if record_type is not None: |
2651 | + self._record_type = record_type |
2652 | + |
2653 | + #QUESTION: What is the purpose of this? |
2654 | + #if dictionaries is not None and keys is None: |
2655 | + # DictionaryGrid.__init__(self, None, editable, keys, type_hints) |
2656 | + #else: |
2657 | + # DictionaryGrid.__init__(self, None, editable, keys, type_hints) |
2658 | + |
2659 | + if dictionaries is not None and keys is not None: |
2660 | + DictionaryGrid.__init__(self, dictionaries, editable, keys, type_hints) |
2661 | + elif keys is None: |
2662 | + DictionaryGrid.__init__(self, dictionaries, editable, None, type_hints) |
2663 | + elif dictionaries is None: |
2664 | + DictionaryGrid.__init__(self, None, editable, keys, type_hints) |
2665 | + |
2666 | + if self.uri: |
2667 | + self._db = CouchDatabase(database_name, create=True, uri=self.uri) |
2668 | + else: |
2669 | + self._db = CouchDatabase(database_name, create=True) |
2670 | + |
2671 | + if dictionaries is not None: |
2672 | + for d in dictionaries: |
2673 | + self._persist_dict_to_couch(d) |
2674 | + |
2675 | + self._refresh_treeview() |
2676 | + |
2677 | + @property |
2678 | + def database(self): |
2679 | + """database - gets an instance to the CouchDB. |
2680 | + Set to a string to change the database. |
2681 | + |
2682 | + """ |
2683 | + return self._db |
2684 | + |
2685 | + @database.setter |
2686 | + def database(self, db_name): |
2687 | + if self.uri: |
2688 | + self._db = CouchDatabase(db_name, create=True, uri=self.uri) |
2689 | + else: |
2690 | + self._db = CouchDatabase(db_name, create=True) |
2691 | + if self.record_type != None: |
2692 | + self._refresh_treeview()#first time treeview is reset |
2693 | + |
2694 | + @property |
2695 | + def record_type(self): |
2696 | + """record_type - a string specifying the record type of |
2697 | + the documents to retrieve from the CouchDB. |
2698 | + |
2699 | + Will cause the TreeView to refresh when set. |
2700 | + """ |
2701 | + return self._record_type |
2702 | + |
2703 | + @record_type.setter |
2704 | + def record_type(self, record_type): |
2705 | + |
2706 | + #store the record type string |
2707 | + self._record_type = record_type |
2708 | + self._refresh_treeview() |
2709 | + |
2710 | + @property |
2711 | + def selected_record_ids(self): |
2712 | + """ selected_record_ids - a list of document ids that are |
2713 | + selected in the CouchGrid. Throws an IndexError if |
2714 | + a specified id is not found in the list when setting |
2715 | + this property. |
2716 | + |
2717 | + This property is read/write |
2718 | + |
2719 | + """ |
2720 | + ids = [] |
2721 | + for row in self.selected_rows: |
2722 | + id_ = None |
2723 | + |
2724 | + if "__desktopcouch_id" in row: |
2725 | + id_ = row["__desktopcouch_id"] |
2726 | + ids.append(id_) |
2727 | + return ids |
2728 | + |
2729 | + @selected_record_ids.setter |
2730 | + def selected_record_ids(self, indexes): |
2731 | + rows = [] #a list of rows to select |
2732 | + for id in indexes: |
2733 | + id_found = False #track if the id was found |
2734 | + |
2735 | + for i,r in enumerate(self.list_store): |
2736 | + dictionary = r[len(self.keys)] #this dictionary always last column |
2737 | + if "__desktopcouch_id" in dictionary: |
2738 | + if dictionary["__desktopcouch_id"] == id: |
2739 | + id_found = True #id was good |
2740 | + if r not in rows: #don't have duplicates to select |
2741 | + rows.append(i) |
2742 | + if not id_found: #stop if a requested id was not in the list |
2743 | + raise IndexError("id %s not found" %id) |
2744 | + |
2745 | + #select the requested ids |
2746 | + selection = self.get_selection() |
2747 | + selection.unselect_all() |
2748 | + for r in rows: |
2749 | + selection.select_path(r) |
2750 | + |
2751 | + def remove_selected_rows(self, delete=False): |
2752 | + rows_to_delete = self.selected_rows |
2753 | + if delete: |
2754 | + for r in rows_to_delete: |
2755 | + self.database.delete_record(r["__desktopcouch_id"]) |
2756 | + DictionaryGrid.remove_selected_rows(self) |
2757 | + |
2758 | + def _refresh_treeview(self): |
2759 | + """ |
2760 | + _refresh_treeview: internal function to handle rebuilding |
2761 | + the gtk.TreeView along with columns and cell renderers. extends |
2762 | + DictionaryGrid._refresh_treeview by retrieving stored desktopcouch |
2763 | + records before calling DictionaryGrid._refresh_treeview. |
2764 | + |
2765 | + _refresh_treeview is not typically called directly, |
2766 | + but may be useful to override in subclasses. |
2767 | + |
2768 | + """ |
2769 | + |
2770 | + #if the database is not set up, just return |
2771 | + if self._db is None or self._record_type is None: |
2772 | + return |
2773 | + |
2774 | + #if keys aren't set, infer them from the collection |
2775 | + if len(self._dictionaries) > 0 and self.keys is None: |
2776 | + self._infer_keys_from_dictionaries() |
2777 | + |
2778 | + #retrieve the docs for the record_type, if any |
2779 | + results = self._db.get_records( |
2780 | + record_type=self._record_type,create_view=True) |
2781 | + |
2782 | + |
2783 | + #if there are no rows and no keys set, there is no |
2784 | + #way to build the grid, just raise an error |
2785 | + if len(results) == 0 and self._keys is None: |
2786 | + raise RuntimeError("Cannot infer columns for CouchGrid") |
2787 | + |
2788 | + dicts = [] |
2789 | + for r in results: |
2790 | + d = r.value |
2791 | + |
2792 | + #hmmm, maybe make these so they get hidden rather than delete them |
2793 | + #hide the desktopcouch variabls |
2794 | + for key in d: |
2795 | + if key.startswith("_") and not key.startswith("__desktopcouch"): |
2796 | + d["__desktopcouch" + key] = d[key] |
2797 | + del(d[key]) |
2798 | + |
2799 | + d["__record_type"] = d["record_type"] |
2800 | + del(d["record_type"]) |
2801 | + dicts.append(d) |
2802 | + |
2803 | + self._dictionaries = dicts |
2804 | + DictionaryGrid._refresh_treeview(self) |
2805 | + |
2806 | + for c in self.get_columns(): |
2807 | + if type(c) == CheckColumn: |
2808 | + c.renderer.connect("toggled",self._edited_toggled, c) |
2809 | + else: |
2810 | + c.renderer.connect("edited",self._edited, c) |
2811 | + |
2812 | + def append_row(self, dictionary): |
2813 | + """append_row: add a row to the TreeView and to DesktopCouch. |
2814 | + If keys are already set up only the the keys in the dictionary |
2815 | + matching the keys used for columns will be displayed, though |
2816 | + all the key value pairs will be saved to the DesktopCouch. |
2817 | + If no keys are set up, and this is the first row, keys will be |
2818 | + inferred from the dictionary keys. |
2819 | + |
2820 | + arguments: |
2821 | + dictionary - a dictionary to add to the Treeview and to DesktopCouch |
2822 | + |
2823 | + """ |
2824 | + |
2825 | + if dictionary is None: |
2826 | + dictionary = {} |
2827 | + |
2828 | + #Here we add rows to desktopcouch if needed |
2829 | + if "__desktopcouch_id" not in dictionary: |
2830 | + self._persist_dict_to_couch(dictionary) |
2831 | + DictionaryGrid.append_row(self,dictionary) |
2832 | + |
2833 | + def _persist_dict_to_couch(self,dictionary): |
2834 | + """ _persist_dict_to_couch - internal implementation. may be useful |
2835 | + a subclass of CouchGrid, but not normally called directly. |
2836 | + |
2837 | + """ |
2838 | + |
2839 | + dictionary["record_type"] = self.record_type |
2840 | + rec = Record(dictionary) |
2841 | + #meh, best not to save an empty row |
2842 | + if len(dictionary) > 1: |
2843 | + doc_id = self._db.put_record(rec) |
2844 | + dictionary["__desktopcouch_id"] = doc_id |
2845 | + dictionary["__record_type"] = self.record_type |
2846 | + del(dictionary["record_type"]) |
2847 | + |
2848 | + def _edited_toggled(self, cell, path, col): |
2849 | + """ _edited_toggled - internal signal handler. |
2850 | + Updates the database if a cell in the Treeview |
2851 | + has been edited special cased for CheckColumns. |
2852 | + |
2853 | + """ |
2854 | + |
2855 | + iter = self.list_store.get_iter(path) |
2856 | + key = col.key |
2857 | + active = not cell.get_active() |
2858 | + self._edited(cell, path, active, col) |
2859 | + |
2860 | + def _edited(self, cell, path, new_val, col): |
2861 | + """ _edited - internal signal handler. |
2862 | + Updates the database if a cell in the Treeview |
2863 | + has been edited. |
2864 | + |
2865 | + """ |
2866 | + iter = self.list_store.get_iter(path) |
2867 | + key = col.key |
2868 | + dictionary = self.list_store.get_value(iter,len(self.keys)) |
2869 | + |
2870 | + if "__desktopcouch_id" not in dictionary: #the row has not been stored |
2871 | + #create a document |
2872 | + dictionary["record_type"] = self.record_type |
2873 | + rec = Record(dictionary) |
2874 | + doc_id = self._db.put_record(rec) |
2875 | + dictionary["__desktopcouch_id"] = doc_id |
2876 | + self.list_store.set_value(iter, len(self.keys), dictionary) |
2877 | + |
2878 | + else: #it has been saved |
2879 | + #get the record id from the dictionary |
2880 | + #then update the datbase with the change |
2881 | + id = dictionary["__desktopcouch_id"] |
2882 | + key = col.key |
2883 | + self._db.update_fields(id,{key:new_val}) |
2884 | + |
2885 | +def __show_selected(widget, row, widgets): |
2886 | + """Test function for selection properties of CouchGrid""" |
2887 | + tv, cg = widgets |
2888 | + disp = "Rows:\n" |
2889 | + for r in cg.selected_rows: |
2890 | + disp += str(r) + "\n" |
2891 | + |
2892 | + disp += "\n\n_Ids:\n" |
2893 | + for r in cg.selected_record_ids: |
2894 | + disp += str(r) + "\n" |
2895 | + |
2896 | + tv.get_buffer().set_text(disp) |
2897 | + |
2898 | +def __select_ids(widget, widgets): |
2899 | + """Test function for selecting ids.""" |
2900 | + entry, cg, lbl = widgets |
2901 | + cg.selected_record_ids = entry.get_text().split(",") |
2902 | + |
2903 | +if __name__ == "__main__": |
2904 | + """creates a test CouchGrid if called directly""" |
2905 | + |
2906 | + from quickly.widgets.grid_column import StringColumn |
2907 | + |
2908 | + #create and show a test window and container |
2909 | + win = gtk.Window(gtk.WINDOW_TOPLEVEL) |
2910 | + win.set_title("CouchGrid Test Window") |
2911 | + win.connect("destroy",gtk.main_quit) |
2912 | + win.show() |
2913 | + vbox = gtk.VBox(False, False) |
2914 | + vbox.show() |
2915 | + win.add(vbox) |
2916 | + |
2917 | + #create a test widget with test database values |
2918 | + dicts = [{"test?":True,"price":100,"foo count":100,"Key4":"1004"}, |
2919 | + {"test?":True,"price":100,"foo count":100,"Key4":"1004"}, |
2920 | + {"test?":True,"price":100,"foo count":100,"Key4":"1004"}] |
2921 | + |
2922 | + #create some settings |
2923 | + database = "couch_widget_test" |
2924 | + record_type="test_record_type" |
2925 | + keys=["price","test?"] |
2926 | + hints = {"price": StringColumn} |
2927 | + |
2928 | + #create it and part a bit |
2929 | + cg = CouchGrid(database, record_type=record_type, dictionaries=dicts,keys=keys, type_hints = hints) |
2930 | + cg.editable = True |
2931 | + cg.get_column(0).set_title("Price") |
2932 | + |
2933 | + #finish out and run the test UI |
2934 | + cg.show() |
2935 | + vbox.pack_start(cg, False, True) |
2936 | + hbox = gtk.HBox(False, 5) |
2937 | + hbox.show() |
2938 | + tv = gtk.TextView() |
2939 | + tv.show() |
2940 | + tv.set_wrap_mode(gtk.WRAP_CHAR) |
2941 | + tv.set_size_request(300,-1) |
2942 | + cg.connect("selection-changed",__show_selected, (tv,cg)) |
2943 | + |
2944 | + id_vbox = gtk.VBox(False, 5) |
2945 | + id_vbox.show() |
2946 | + |
2947 | + fb_lbl = gtk.Label("paste ids into the edit box to select them") |
2948 | + fb_lbl.show() |
2949 | + |
2950 | + entry = gtk.Entry() |
2951 | + entry.show() |
2952 | + |
2953 | + btn = gtk.Button("select ids") |
2954 | + btn.show() |
2955 | + btn.connect("clicked", __select_ids, (entry,cg, fb_lbl)) |
2956 | + |
2957 | + id_vbox.pack_start(fb_lbl, False, False) |
2958 | + id_vbox.pack_start(entry, False, False) |
2959 | + id_vbox.pack_end(btn, False, False) |
2960 | + |
2961 | + hbox.pack_start(tv, False, False) |
2962 | + vbox.pack_end(hbox, False, False) |
2963 | + hbox.pack_end(id_vbox, False, False) |
2964 | + |
2965 | + #run the test app |
2966 | + gtk.main() |
2967 | + |
2968 | |
2969 | === added file 'quickly/widgets/dictionary_grid.py' |
2970 | --- quickly/widgets/dictionary_grid.py 1970-01-01 00:00:00 +0000 |
2971 | +++ quickly/widgets/dictionary_grid.py 2011-07-25 07:14:30 +0000 |
2972 | @@ -0,0 +1,525 @@ |
2973 | +#!/usr/bin/env python |
2974 | +# -*- coding: utf-8 -*- |
2975 | +### BEGIN LICENSE |
2976 | +# Copyright (C) 2010 Rick Spencer rick.spencer@canonical.com |
2977 | +#This program is free software: you can redistribute it and/or modify it |
2978 | +#under the terms of the GNU General Public License version 3, as published |
2979 | +#by the Free Software Foundation. |
2980 | +# |
2981 | +#This program is distributed in the hope that it will be useful, but |
2982 | +#WITHOUT ANY WARRANTY; without even the implied warranties of |
2983 | +#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
2984 | +#PURPOSE. See the GNU General Public License for more details. |
2985 | +# |
2986 | +#You should have received a copy of the GNU General Public License along |
2987 | +#with this program. If not, see <http://www.gnu.org/licenses/>. |
2988 | +### END LICENSE |
2989 | +"""A gtk.TreeView for Dictionaries |
2990 | +Displays and persists data in a gtk.TreeView. Handles the |
2991 | +set up of the gtk.TreeView, gtk.ListModel, gtk.TreeViewColumns, |
2992 | +and gtk.CellRenderers. |
2993 | + |
2994 | +Using |
2995 | +#create a dictionary if you don't already have one |
2996 | +dicts = [{"test?":True,"price":100,"foo count":100,"Key4":"1004"}, |
2997 | + {"test?":True,"price":100,"foo count":100,"Key4":"1004"}, |
2998 | + {"test?":True,"price":100,"foo count":100,"Key4":"1004"}] |
2999 | + |
3000 | +#create the DictionaryGrid |
3001 | +dg = DictionaryGrid(dictionaries=dicts) |
3002 | + |
3003 | +Configuring |
3004 | +#set UI to be editable |
3005 | +dg.editable = True |
3006 | + |
3007 | +#Define columns to display |
3008 | +keys=["price","test?"] |
3009 | +dg = DictionaryGrid(dictionaries=dicts,keys=keys) |
3010 | + |
3011 | +#Define column types to use |
3012 | +hints = {"price": StringColumn} |
3013 | +dg = CouchGrid(dictionaries=dicts,keys=keys, type_hints = hints) |
3014 | + |
3015 | +#A CouchGrid is gtk.TreeView, so you can use gtk.TreeView members |
3016 | +dg.get_column(0).set_title("Price") |
3017 | + |
3018 | +#Use the selection-changed signal and read from the DictionaryGrid |
3019 | +dg.connect("selection-changed", __handle_selection_changed) |
3020 | +def __handle_selection_changed(widget, dictionaries, data = None): |
3021 | + for dictionary in dictionaries: |
3022 | + print dictionary["price"] |
3023 | + |
3024 | +#Use the cell-edited signal to track changes |
3025 | +dg.connect("cell-edited", __handle_edited_cells) |
3026 | +def __handle_edited_cells(widget, cell, row, key, new_value, data=None): |
3027 | + print new_value |
3028 | + |
3029 | +Extending |
3030 | +To change what a DictionaryGrid does every time it builds itself |
3031 | +override DictionaryGrid._refresh_treeview. Here you can read data |
3032 | +form a data store, change the way the columns from |
3033 | +quickly.widgetsgrid_column are built, etc... |
3034 | + |
3035 | +To change what a DictionaryGrid does every time a row of data is |
3036 | +add, override "append_row". Here you can change add data to store |
3037 | +with the dictionary being added, change the data itself, change |
3038 | +how the data is being displayed, etc... |
3039 | + |
3040 | +""" |
3041 | + |
3042 | +import gtk |
3043 | +import gobject |
3044 | +import conventions |
3045 | +from quickly.widgets.grid_column import StringColumn |
3046 | +from grid_column import CheckColumn |
3047 | + |
3048 | +class DictionaryGrid(gtk.TreeView): |
3049 | + __gtype_name__ = "DictionaryGrid" |
3050 | + |
3051 | + def __init__(self, dictionaries=None, editable = False, keys=None, type_hints=None): |
3052 | + """ |
3053 | + Creates a new DictionaryGrid |
3054 | + arguments: |
3055 | + |
3056 | + dictionaries - a list of dictionaries to initialize in the |
3057 | + grid. |
3058 | + |
3059 | + keys - a list of strings specifying keys to use in |
3060 | + the columns of the DictionaryGrid. |
3061 | + |
3062 | + The types for the columns will be inferred by the key based on |
3063 | + some conventions. the key "id" is assumed to be an integer, as |
3064 | + is any key ending in " count". A key ending in "?" is assumed |
3065 | + to be a Boolean displayed with a checkbox. The key "price" is |
3066 | + assumed to be currency, as is any key ending in "count". There |
3067 | + may be others. Defaults can be overridden using type-hints. All |
3068 | + other keys will be assumed to be strings. |
3069 | + |
3070 | + type-hints - a dictionary containing keys specificed for the |
3071 | + TreeView and GridColumns. Used to override types inferred |
3072 | + by convention, or for changing the type of a column from |
3073 | + the default of a string to something else. |
3074 | + |
3075 | + """ |
3076 | + |
3077 | + gtk.TreeView.__init__(self) |
3078 | + self.list_store = None |
3079 | + self.unfiltered_store = None |
3080 | + self._keys = keys |
3081 | + self._editable = editable |
3082 | + if dictionaries is None: |
3083 | + self._dictionaries = [] |
3084 | + else: |
3085 | + self._dictionaries = dictionaries |
3086 | + if type_hints is None: |
3087 | + self._type_hints = {} |
3088 | + else: |
3089 | + self._type_hints = type_hints |
3090 | + self.get_selection().set_mode(gtk.SELECTION_MULTIPLE) |
3091 | + self._refresh_treeview() |
3092 | + |
3093 | + #signal handlers to track selection in the treeview |
3094 | + #utlmiately these all emit the "selection_changed signal |
3095 | + self.connect("cursor_changed", self.__selection_changed) |
3096 | + self.connect("move-cursor", self.__cursor_moved) |
3097 | + self.connect("select-all", self.__selection_all) |
3098 | + self.connect("select-cursor-row", self.__selection_changed) |
3099 | + self.connect("unselect-all", self.__selection_none) |
3100 | + self.connect("toggle-cursor-row", self.__selection_changed) |
3101 | + |
3102 | + def __cursor_moved(self, grid, step, count, data=None): |
3103 | + self.__selection_changed(self) |
3104 | + |
3105 | + def __selection_all(self, treeview, data=None): |
3106 | + self.emit("selection-changed", self.rows) |
3107 | + |
3108 | + def __selection_none(self, treeview, data=None): |
3109 | + self.emit("selection-changed", []) |
3110 | + |
3111 | + def __selection_changed(self, treeiew, data=None): |
3112 | + self.emit("selection-changed", self.selected_rows) |
3113 | + |
3114 | + def __edited_toggled(self, cell, path, col): |
3115 | + iter = self.get_model().get_iter(path) |
3116 | + key = col.key |
3117 | + active = not cell.get_active() |
3118 | + self.__edited(cell, path, active, col) |
3119 | + |
3120 | + def __edited(self, cell, path, new_val, col): |
3121 | + """ _edited - internal signal handler. |
3122 | + Updates the database if a cell in the Treeview |
3123 | + has been edited. |
3124 | + |
3125 | + """ |
3126 | + iter = self.get_model().get_iter(path) |
3127 | + row_dict = self.get_model().get_value(iter,len(self.keys)) |
3128 | + key = col.key |
3129 | + dictionary = self.get_model().get_value(iter,len(self.keys)) |
3130 | + self.emit("cell-edited",cell, path, key, new_val, row_dict) |
3131 | + |
3132 | + @property |
3133 | + def keys(self): |
3134 | + """ keys - A list of strings to act as keys for the |
3135 | + backing dictionaries and the default titles for the columns. |
3136 | + |
3137 | + Setting this property will cause the widget to reload. |
3138 | + |
3139 | + """ |
3140 | + |
3141 | + return self._keys |
3142 | + |
3143 | + @keys.setter |
3144 | + def keys(self, keys): |
3145 | + self._keys = keys |
3146 | + self._refresh_treeview() |
3147 | + |
3148 | + @property |
3149 | + def editable(self): |
3150 | + """editable - bool value, True to make editable |
3151 | + |
3152 | + Setting this property will cause the widget to reload. |
3153 | + |
3154 | + """ |
3155 | + return self._editable |
3156 | + |
3157 | + @editable.setter |
3158 | + def editable(self, editable): |
3159 | + #refresh the treeview if possible |
3160 | + #self._refresh_treeview() |
3161 | + |
3162 | + # Refreshing the treeview has no benefits but many negative |
3163 | + # side effects. Better to loop over the columns, setting the property |
3164 | + # on each renderer. The columns should probably expose this property |
3165 | + # themselves, but for now this works. |
3166 | + |
3167 | + for column in self.get_columns(): |
3168 | + column.renderer.set_property("editable", editable) |
3169 | + self._editable = editable |
3170 | + |
3171 | + @property |
3172 | + def columns(self): |
3173 | + """ columns - A dictionary of the GridColumns indexed by the |
3174 | + keys for that column. This allows access to columns by the key, |
3175 | + for example to change the title of a specific column: |
3176 | + grid.columns["complete?"].set_title(_("Completed")) |
3177 | + |
3178 | + This property is read only. |
3179 | + |
3180 | + """ |
3181 | + |
3182 | + cols = {} |
3183 | + for c in self.get_columns(): |
3184 | + cols[c.key] = c |
3185 | + return cols |
3186 | + |
3187 | + def set_column_titles(self, titles): |
3188 | + """set_column_titles - sets the specified titles for the GridColumns |
3189 | + in the DictionaryGrid. Use a dictionary of strings indexed by keys. |
3190 | + For example: |
3191 | + titles = {"complete?":_("Complete"),"id":_("ID")} |
3192 | + grid.set_column_titles(titles) |
3193 | + |
3194 | + """ |
3195 | + |
3196 | + for t in titles: |
3197 | + if t in self.columns: |
3198 | + self.columns[t].set_title(titles[t]) |
3199 | + |
3200 | + def get_dictionaries_copy(self): |
3201 | + """get_dictionaries_copy -returns a copy of the dictionaries in |
3202 | + the dictionary grid. |
3203 | + |
3204 | + """ |
3205 | + return self._dictionaries[:] |
3206 | + |
3207 | + def _infer_keys_from_dictionaries(self): |
3208 | + """_infer_keys_from_dictionaries: an internal function to |
3209 | + set _keys suitable for column titles from a set of dictionaries. |
3210 | + |
3211 | + _infer_keys_from_dictionaries is not typically called directly, |
3212 | + but may be useful to override in subclasses. |
3213 | + |
3214 | + """ |
3215 | + key_collector = [] |
3216 | + for r in self._dictionaries: |
3217 | + for k in r.keys(): |
3218 | + if k not in key_collector and not k.startswith("__"): |
3219 | + key_collector.append(k) |
3220 | + |
3221 | + self._keys = key_collector |
3222 | + |
3223 | + def _refresh_treeview(self): |
3224 | + """ |
3225 | + _refresh_treeview: internal function to handle rebuilding |
3226 | + the gtk.TreeView along with columns and cell renderers.. |
3227 | + |
3228 | + _refresh_treeview is not typically called directly, |
3229 | + but may be useful to override in subclasses. |
3230 | + |
3231 | + """ |
3232 | + |
3233 | + #if keys are already set, set up titles and columns |
3234 | + if self.keys is not None: |
3235 | + self.__reset_model() |
3236 | + |
3237 | + #if keys aren't set, infer them from the collection |
3238 | + if len(self._dictionaries) > 0 and self.keys is None: |
3239 | + self._infer_keys_from_dictionaries() |
3240 | + self.__reset_model() |
3241 | + |
3242 | + for dictionary in self._dictionaries: |
3243 | + #lists have to match the list_store columns in length |
3244 | + #so we have to make rows as long as the headerings |
3245 | + #note that the last value is reserved for extra data |
3246 | + self.append_row(dictionary) |
3247 | + |
3248 | + #apply the model to the Treeview if possible |
3249 | + if self.list_store != None: |
3250 | + self.unfiltered_store = self.list_store |
3251 | + self.set_model(self.list_store) |
3252 | + |
3253 | + def append_row(self, dictionary): |
3254 | + """append_row: add a row to the TreeView. If keys are already set up |
3255 | + only the the keys in the dictionary matching the keys used |
3256 | + for columns will be used. If no keys are set up, and this is the |
3257 | + first row, keys will be inferred from the dictionary keys. |
3258 | + |
3259 | + arguments: |
3260 | + dictionary - a dictionary to the TreeView. |
3261 | + |
3262 | + """ |
3263 | + |
3264 | + new_row = [] |
3265 | + |
3266 | + for i, k in enumerate(self.keys): |
3267 | + if k in dictionary: |
3268 | + display_val = self.__columns_map[k].display_val(dictionary[k]) |
3269 | + real_val = self.__columns_map[k].real_val(dictionary[k]) |
3270 | + #TODO: store a "real_val" instead of display val |
3271 | + #that was "converted_val" |
3272 | + dictionary[k] = real_val |
3273 | + else: |
3274 | + display_val = self.__columns_map[k].default_display_val() |
3275 | + new_row.append(display_val) |
3276 | + new_row.append(dictionary) |
3277 | + self.list_store.append(new_row) |
3278 | + |
3279 | + @property |
3280 | + def rows(self): |
3281 | + """ rows - returns a list of dictionaries |
3282 | + for each row in the grid. |
3283 | + |
3284 | + This property is read only. |
3285 | + |
3286 | + """ |
3287 | + model = self.get_model() |
3288 | + rows = [] #list of rows to return |
3289 | + model.foreach(self.__append_dict, rows) |
3290 | + return rows |
3291 | + |
3292 | + def __append_dict(self, model, path, iter, rows): |
3293 | + """ __append_dict: internal function, do not call directly""" |
3294 | + |
3295 | + row = model.get_value(iter,len(self.keys)) |
3296 | + rows.append(row) |
3297 | + |
3298 | + @property |
3299 | + def selected_rows(self): |
3300 | + """ selected_rows - returns a list of dictionaries |
3301 | + for each row selected. |
3302 | + |
3303 | + This property is read only. |
3304 | + |
3305 | + """ |
3306 | + |
3307 | + #get the selected rows in the ListStore |
3308 | + selection = self.get_selection() |
3309 | + model, model_rows = selection.get_selected_rows() |
3310 | + |
3311 | + rows = [] #list of rows to return |
3312 | + |
3313 | + for mr in model_rows: |
3314 | + row = {} #a row to be added to the list of rows |
3315 | + iter = model.get_iter(mr) |
3316 | + |
3317 | + row = model.get_value(iter,len(self.keys)) |
3318 | + rows.append(row) |
3319 | + return rows |
3320 | + |
3321 | + def remove_selected_rows(self): |
3322 | + """ |
3323 | + remove_selected_rows: removes the rows currently selected |
3324 | + in the TreeView UI from the TreeView as well as the backing |
3325 | + gtk.ListStore. |
3326 | + |
3327 | + """ |
3328 | + |
3329 | + #get the selected rows, and return if nothing is selected |
3330 | + model, rows = self.get_selection().get_selected_rows() |
3331 | + |
3332 | + if len(rows) == 0: |
3333 | + return |
3334 | + |
3335 | + #store the last selected row to reselect after removal |
3336 | + next_to_select = rows[-1][0] + 1 - len(rows) |
3337 | + |
3338 | + #loop through and remove |
3339 | + |
3340 | + if type(model) is not gtk.ListStore: |
3341 | + iters = [model.get_model().get_iter(path) for path in rows] |
3342 | + store_iters = [] |
3343 | + |
3344 | + for i in iters: |
3345 | + store_iters.append(model.get_model().convert_iter_to_child_iter(i)) |
3346 | + |
3347 | + for store_iter in store_iters: |
3348 | + self.unfiltered_store.remove(store_iter) |
3349 | + |
3350 | + else: |
3351 | + iters = [model.get_iter(path) for path in rows] |
3352 | + |
3353 | + for i in iters: |
3354 | + model.remove(i) |
3355 | + |
3356 | + #select a row for the user, nicer that way |
3357 | + rows_remaining = len(self.get_model()) |
3358 | + |
3359 | + #don't try to select anything if there are no rows left |
3360 | + if rows_remaining < 1: |
3361 | + return |
3362 | + |
3363 | + #select the next row down, unless it's out of range |
3364 | + #in which case just select the last row |
3365 | + if next_to_select < rows_remaining: |
3366 | + self.get_selection().select_path(next_to_select) |
3367 | + else: |
3368 | + self.get_selection().select_path(rows_remaining - 1) |
3369 | + |
3370 | + |
3371 | + def __reset_model(self): |
3372 | + """ __reset_model - internal funciton, do not call directly. |
3373 | + This function is typically called when the TreeView needs |
3374 | + to be rebuilt. Creates new columns. |
3375 | + |
3376 | + """ |
3377 | + |
3378 | + #remove the current columns from the TreeView |
3379 | + cols = self.get_columns() |
3380 | + for c in cols: |
3381 | + self.remove_column(c) |
3382 | + |
3383 | + #reinitialize the column variables |
3384 | + col_count = len(self.keys) + 1 |
3385 | + col_types = [] |
3386 | + self.__columns_map = {} |
3387 | + |
3388 | + #create a column for each key |
3389 | + for i, k in enumerate(self.keys): |
3390 | + #use any supllied columns |
3391 | + if k in self._type_hints: |
3392 | + column = self._type_hints[k](k,i,len(self.keys)) |
3393 | + else: |
3394 | + #no column supplied, use conventions to get a column |
3395 | + column = conventions.get_column(k,i,len(self.keys), self.editable) |
3396 | + |
3397 | + #add the created column, and remember it's key |
3398 | + self.append_column(column) |
3399 | + self.__columns_map[k] = column |
3400 | + |
3401 | + #store the into for creating the list store |
3402 | + col_types.append(column.column_type) |
3403 | + |
3404 | + #create the liststore with the designated types |
3405 | + #the last column is always for storing the backing dict |
3406 | + col_types.append(gobject.TYPE_PYOBJECT) |
3407 | + self.list_store = gtk.ListStore(*col_types) |
3408 | + |
3409 | + for c in self.get_columns(): |
3410 | + self.__last_sorted_col = None |
3411 | + c.list_store = self.list_store |
3412 | + |
3413 | + #TODO: store and delete these, this is a leak |
3414 | + c.connect("clicked",self.__remove_sort_icon) |
3415 | + |
3416 | + #connect to the edit events to rip it a |
3417 | + if type(c) == CheckColumn: |
3418 | + c.renderer.connect("toggled",self.__edited_toggled, c) |
3419 | + else: |
3420 | + c.renderer.connect("edited",self.__edited, c) |
3421 | + |
3422 | + |
3423 | + def __remove_sort_icon(self, column): |
3424 | + """__remove_sort_icon: internal function used in handling |
3425 | + display of sort buttons. Do not call this function directly. |
3426 | + |
3427 | + """ |
3428 | + |
3429 | + if self.__last_sorted_col is not None: |
3430 | + if self.__last_sorted_col is not column: |
3431 | + self.__last_sorted_col.set_sort_indicator(False) |
3432 | + self.__last_sorted_col = column |
3433 | + |
3434 | + __gsignals__ = {'cell-edited' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
3435 | + (gobject.TYPE_PYOBJECT,gobject.TYPE_PYOBJECT,gobject.TYPE_PYOBJECT,gobject.TYPE_PYOBJECT,gobject.TYPE_PYOBJECT)), |
3436 | + |
3437 | + 'selection-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
3438 | + (gobject.TYPE_PYOBJECT,)) |
3439 | + } |
3440 | + |
3441 | +def __show_selected(widget, selected_rows, data=None): |
3442 | + """handles displaying text for test app""" |
3443 | + |
3444 | + tv.get_buffer().set_text(str(selected_rows)) |
3445 | + |
3446 | +def __on_edited(widget, cell, row, key, new_value, row_dict, tv): |
3447 | + """handles displaying text for test app""" |
3448 | + |
3449 | + string = "row: " + str(row) |
3450 | + string += ", key: " + str(key) |
3451 | + string += ", new value: " + str(new_value) |
3452 | + string += "\n" + str(row_dict) |
3453 | + tv.get_buffer().set_text(string) |
3454 | + |
3455 | +if __name__ == "__main__": |
3456 | + """creates a test DictionaryGrid if called directly""" |
3457 | + |
3458 | + dicts = [{"key?": True, "price":0.00,"tags" : "aaa bbb ccc","_foo":"bar","bing count":20}, |
3459 | + {"ID": 11, "key?": False, "price":2.00,"tags" : "bbb ccc ddd","_foo":"bar"}, |
3460 | + {"key?": True, "price":33.00,"tags" : "ccc ddd eee","_foo":"bar","bing count":15}, |
3461 | + {"ID": 3, "tags" : "ddd eee fff","_foo":"bar"}, |
3462 | + {"ID": 4, "price":5.00,"_foo":"bar"}] |
3463 | + #create and show a test window |
3464 | + win = gtk.Window(gtk.WINDOW_TOPLEVEL) |
3465 | + win.set_title("DictionaryGrid Test Window") |
3466 | + win.connect("destroy",gtk.main_quit) |
3467 | + win.show() |
3468 | + |
3469 | + #create a top level container |
3470 | + vbox = gtk.VBox(False, False) |
3471 | + vbox.show() |
3472 | + win.add(vbox) |
3473 | + |
3474 | + #create a test widget with test database values |
3475 | + grid = DictionaryGrid(dicts, editable=True)#, ["ID","tags","price","bing count","key?"]) |
3476 | + |
3477 | + #allow editing |
3478 | + #grid.editable = True |
3479 | + |
3480 | + #show the control, add it to the window, and run the main loop |
3481 | + grid.show() |
3482 | + vbox.pack_start(grid, False, True) |
3483 | + |
3484 | + #create a test display area |
3485 | + hbox = gtk.HBox(False, 5) |
3486 | + hbox.show() |
3487 | + tv = gtk.TextView() |
3488 | + tv.show() |
3489 | + grid.connect("selection-changed",__show_selected, tv) |
3490 | + grid.connect("cell-edited",__on_edited, tv) |
3491 | + |
3492 | + hbox.pack_start(tv, False, False) |
3493 | + vbox.pack_end(hbox, False, False) |
3494 | + |
3495 | + #run the test app |
3496 | + gtk.main() |
3497 | + |
3498 | |
3499 | === added file 'quickly/widgets/grid_column.py' |
3500 | --- quickly/widgets/grid_column.py 1970-01-01 00:00:00 +0000 |
3501 | +++ quickly/widgets/grid_column.py 2011-07-25 07:14:30 +0000 |
3502 | @@ -0,0 +1,881 @@ |
3503 | +# -*- coding: utf-8 -*- |
3504 | +### BEGIN LICENSE |
3505 | +# Copyright (C) 2010 Rick Spencer rick.spencer@canonical.com |
3506 | +#This program is free software: you can redistribute it and/or modify it |
3507 | +#under the terms of the GNU General Public License version 3, as published |
3508 | +#by the Free Software Foundation. |
3509 | +# |
3510 | +#This program is distributed in the hope that it will be useful, but |
3511 | +#WITHOUT ANY WARRANTY; without even the implied warranties of |
3512 | +#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
3513 | +#PURPOSE. See the GNU General Public License for more details. |
3514 | +# |
3515 | +#You should have received a copy of the GNU General Public License along |
3516 | +#with this program. If not, see <http://www.gnu.org/licenses/>. |
3517 | +### END LICENSE |
3518 | +"""Specializations of Gtk.TreeViewColumns designer to work with |
3519 | +DictionaryGrid and descendants. |
3520 | + |
3521 | +Using |
3522 | +Grid columns are not normally created directly, but rather created |
3523 | +automatically when a DictionaryGrid displays it's data. See the |
3524 | +DictionaryGrid documentation for how to use type hints and conventions |
3525 | +to control the type of column used for a key in a dictionary. |
3526 | + |
3527 | +Customizing |
3528 | +The column types in this module are all descendants of gtk.TreeView, so |
3529 | +you can use all of the gtk.TreeView methods and properties to control |
3530 | +how a grid column looks or works. |
3531 | + |
3532 | +#Find a grid column and change the title |
3533 | +for c in my_dictionary_grid.get_columns(): |
3534 | + if c.key = my_key: |
3535 | + c.set_title("New Title") |
3536 | + |
3537 | +Extending |
3538 | +To display data in a column with a string, such as to display words and |
3539 | +numbers, you should extend StringColumn. Otherwise, extend gtk.TreeView |
3540 | +directly. In either case, you will need to implement a set of functions. |
3541 | + |
3542 | +A Grid Column must track two different data, a "real" value, which is tracked |
3543 | +in the dictionary for the row, and the "display" value, which is used |
3544 | +to determine a value to display to users. For example, CheckColumn stores |
3545 | +a real value of True, False, or None, but a display value of -1, 0, or 1, |
3546 | +and uses the display value to set the checkbox in it's CellRenderer. |
3547 | + |
3548 | +Every new column must have the following function to support real |
3549 | +and display values: |
3550 | + |
3551 | +display_val(self, val) - takes a real value and returns the cooresponding |
3552 | +display value |
3553 | + |
3554 | +real_val(self, val) - takes a display value and returns the cooresponding |
3555 | +real value |
3556 | + |
3557 | +default_display_val(self) - reutrn the value to display in the case where |
3558 | +a row does not contain a key, value pair for the specified column. For example |
3559 | +StringColumn returns an empty string ("") |
3560 | + |
3561 | +A new column type will often require a specially configured gtk.CellRenderer. |
3562 | +If you are deriving from StringColumn, but are using a custom renderer, |
3563 | +you need to override the _initialize_renderer method, and set the |
3564 | +columns renderer property to the renderer. You should also connect the |
3565 | +CellRenderer's edit signal to a function that will update the underlying |
3566 | +dictionary when the cell is edited. |
3567 | + |
3568 | + |
3569 | +For instance, a CurrencyColumn has the following implemention for |
3570 | +_initialize_renderer: |
3571 | + |
3572 | + def _initialize_renderer( self, editable, index ): |
3573 | + self.renderer = gtk.CellRendererSpin() |
3574 | + adj = gtk.Adjustment(0,-10000000000,10000000000,1) |
3575 | + self.renderer.set_property("adjustment", adj) |
3576 | + self.renderer.set_property("editable", editable) |
3577 | + self.renderer.set_property("digits",2) |
3578 | + self.renderer.connect("edited", self._cell_edited) |
3579 | + |
3580 | +You also need to define two class variable: |
3581 | +1. column_type, the gobject type for the column's display value. |
3582 | +This is needed so that the DictionaryGrid can create a ListStore |
3583 | + |
3584 | +2. default_filter, the grid_filter type to use in cases where a |
3585 | +GridFilter is associate with the column. |
3586 | + |
3587 | +For example, CurrencyColumn defines the following class variables: |
3588 | +column_type = gobject.TYPE_STRING |
3589 | +default_filter = grid_filter.NumericFilterBox |
3590 | + |
3591 | +""" |
3592 | + |
3593 | + |
3594 | + |
3595 | +import sys |
3596 | +import datetime |
3597 | +import gettext |
3598 | +from gettext import gettext as _ |
3599 | +gettext.textdomain('quickly-widgets') |
3600 | + |
3601 | +try: |
3602 | + import pygtk |
3603 | + pygtk.require("2.0") |
3604 | + import gtk |
3605 | + import gobject |
3606 | + import grid_filter |
3607 | + |
3608 | + |
3609 | +except Exception, inst: |
3610 | + print "some dependencies for GridFilter are not available" |
3611 | + raise inst |
3612 | + |
3613 | +class GridColumn( gtk.TreeViewColumn ): |
3614 | + """GridColumn - Base class that provides features that is important |
3615 | + to all columns used in a DictionaryGrid or decendants. Currently |
3616 | + it's useful only to StringColumn and CheckColumn, but should make it |
3617 | + easier to make new "top-level" column types. |
3618 | + """ |
3619 | + |
3620 | + def __init__(self, key, index, dictionary_index, renderer, editable=True, format_function = None ): |
3621 | + self.set_clickable(True) |
3622 | + self.set_resizable(True) |
3623 | + |
3624 | + self.index = index |
3625 | + self.key = key |
3626 | + self.dictionary_index = dictionary_index |
3627 | + self.list_store = None |
3628 | + |
3629 | + gtk.TreeViewColumn.__init__(self, key, renderer, text=index) |
3630 | + |
3631 | + self.connect('clicked', self.sort_rows) |
3632 | + |
3633 | + |
3634 | + def sort_rows(self, widget): |
3635 | + sort_order = widget.get_sort_order() |
3636 | + |
3637 | + rows = [tuple(r) + (i,) for i, r in enumerate(self.list_store)] |
3638 | + |
3639 | + # I NEED TO HAVE A LOOK AT THIS IF-BLOCK. At least, it needs a comment. |
3640 | + if sort_order == gtk.SORT_ASCENDING: |
3641 | + sort_order = gtk.SORT_DESCENDING |
3642 | + else: |
3643 | + sort_order = gtk.SORT_ASCENDING |
3644 | + |
3645 | + self.set_sort_order(sort_order) |
3646 | + self.set_sort_indicator(True) |
3647 | + |
3648 | + if sort_order == gtk.SORT_ASCENDING: |
3649 | + rows.sort(self._sort_ascending) |
3650 | + else: |
3651 | + rows.sort(self._sort_descending) |
3652 | + |
3653 | + self.list_store.reorder([r[-1] for r in rows]) |
3654 | + |
3655 | + |
3656 | +class StringColumn( GridColumn ): |
3657 | + |
3658 | + """StringColumn - Displays strings and tracks data as string. |
3659 | + Uses a CellRendererText for display and editing. Not typically created |
3660 | + directly in code, but rather created by a DictionaryGrid or descendant. |
3661 | + |
3662 | + Suitable as a base class for any column that needs to display a string. |
3663 | + |
3664 | + """ |
3665 | + |
3666 | + column_type = gobject.TYPE_STRING |
3667 | + __sort_order = None |
3668 | + default_filter = grid_filter.StringFilterBox |
3669 | + def __init__(self, key, index, dictionary_index, editable=True, format_function = None ): |
3670 | + """Creates a StringColumn |
3671 | + |
3672 | + Arguments: |
3673 | + key - the key from the dict for the row. Also used as the title for the |
3674 | + column by default. |
3675 | + |
3676 | + index - the position of the column in the grid. |
3677 | + |
3678 | + dictionary_index - the index in the ListStore where the dictionary |
3679 | + for the row is stored. Typically len(dict). |
3680 | + |
3681 | + editable - False if the column does not allow the user to edit the |
3682 | + values in the column. Defaults to True. |
3683 | + |
3684 | + format_function - and optional function to handle formatting of |
3685 | + of the string to display. Defaults to None. |
3686 | + """ |
3687 | + |
3688 | + |
3689 | + self._initialize_renderer(editable, index) |
3690 | + GridColumn.__init__( self, key, index, dictionary_index, self.renderer, editable, format_function) |
3691 | + |
3692 | + if format_function is not None: |
3693 | + self.set_cell_data_func(self.renderer, self._on_format, format_function) |
3694 | + |
3695 | + def _sort_ascending(self, x, y): |
3696 | + """_sort_ascending - internal sort function that sorts two values |
3697 | + in the column from least value to greatest value. |
3698 | + |
3699 | + returns 1 if x > y, 0 if x = y, -1 if x < y |
3700 | + |
3701 | + arguments: |
3702 | + x - the value being compared to |
3703 | + y - the value being compared |
3704 | + |
3705 | + """ |
3706 | + |
3707 | + x = x[self.index] |
3708 | + y = y[self.index] |
3709 | + if x > y: |
3710 | + return 1 |
3711 | + elif x == y: |
3712 | + return 0 |
3713 | + elif x < y: |
3714 | + return -1 |
3715 | + |
3716 | + def _sort_descending(self, x, y): |
3717 | + """_sort_descending - internal sort function that sorts two values |
3718 | + in the column from greatest value to least value. May need to be |
3719 | + implimented or overriden in specialized columns. |
3720 | + |
3721 | + returns 1 if x < y, 0 if x = y, -1 if x > y |
3722 | + |
3723 | + arguments: |
3724 | + x - the value being compared to |
3725 | + y - the value being compared |
3726 | + |
3727 | + """ |
3728 | + x = x[self.index] |
3729 | + y = y[self.index] |
3730 | + if x > y: |
3731 | + return -1 |
3732 | + elif x == y: |
3733 | + return 0 |
3734 | + elif x < y: |
3735 | + return 1 |
3736 | + |
3737 | + def _on_format(self,column, cell_renderer, tree_model, iter, format_function): |
3738 | + """on format - internal signal handler called when the column needs |
3739 | + to reformat the display value. Typically called after editing or when |
3740 | + a value is first inserted. |
3741 | + |
3742 | + arguments: |
3743 | + column - the index of the column, not typically needed |
3744 | + |
3745 | + cell_renderer - a reference to the specific cell_renderer that is |
3746 | + formatting the string |
3747 | + |
3748 | + tree_model - the gtk.ListStore that is the backing data for the |
3749 | + DictionaryGrid that contains the column. |
3750 | + |
3751 | + iter - an iterator that references the row of the the DictionaryGrid |
3752 | + containing the cell that needs to be formatted. |
3753 | + |
3754 | + format_function - a function that takes the string and performs the |
3755 | + actual formatting. |
3756 | + |
3757 | + """ |
3758 | + |
3759 | + string = format_function(tree_model.get_value(iter, self.index), cell_renderer) |
3760 | + if string != None: |
3761 | + cell_renderer.set_property('text', string) |
3762 | + |
3763 | + def _initialize_renderer( self, editable, index ): |
3764 | + """_initialize_renderer - internal function called to set up the |
3765 | + CellRenderer for the column. |
3766 | + |
3767 | + arguments: |
3768 | + |
3769 | + editable - True if the column should support user editing. |
3770 | + |
3771 | + index - the position of the column in the grid |
3772 | + |
3773 | + """ |
3774 | + |
3775 | + self.renderer = gtk.CellRendererText() |
3776 | + self.renderer.mode = gtk.CELL_RENDERER_MODE_EDITABLE |
3777 | + self.renderer.set_property("editable", editable) |
3778 | + self.renderer.connect("edited", self._cell_edited) |
3779 | + |
3780 | + def _cell_edited(self, cellrenderertext, path, new_text, data=None): |
3781 | + """ _cell_edited - internal signal handler called when a |
3782 | + cell in the column is edited. |
3783 | + |
3784 | + arguments: |
3785 | + |
3786 | + cellrenderertext - the CellRenderer that was edited |
3787 | + |
3788 | + path - path to the row in the treeview |
3789 | + |
3790 | + new_text - the text was in the cell after the editing |
3791 | + |
3792 | + """ |
3793 | + |
3794 | + #get an iterator that points to the edited row |
3795 | + if self.list_store is not None: |
3796 | + iter = self.list_store.get_iter(path) |
3797 | + #update the ListStore with the new text |
3798 | + self.list_store.set_value(iter, self.index, self.display_val(new_text)) |
3799 | + |
3800 | + dictionary = self.list_store.get_value(iter,self.dictionary_index) |
3801 | + dictionary[self.key] = self.real_val(new_text) |
3802 | + |
3803 | + def display_val(self, val): |
3804 | + """display_val - takes a real value and returns the cooresponding |
3805 | + display value |
3806 | + |
3807 | + arguments: |
3808 | + |
3809 | + val - the real value to convert |
3810 | + |
3811 | + """ |
3812 | + |
3813 | + if val == None: |
3814 | + return self.default_display_val() |
3815 | + else: |
3816 | + return str(val) |
3817 | + |
3818 | + def real_val(self, val): |
3819 | + """real_val - takes a display value and returns the cooresponding |
3820 | + real value. |
3821 | + |
3822 | + arguments: |
3823 | + |
3824 | + val - the display value to convert |
3825 | + |
3826 | + """ |
3827 | + |
3828 | + #in a StringColumn, the backing data and the display data are the same |
3829 | + return self.display_val(val) |
3830 | + |
3831 | + def default_display_val(self): |
3832 | + """default_dislay_val - return the value to display in the case |
3833 | + where there is no real value for the column for the row. |
3834 | + |
3835 | + """ |
3836 | + |
3837 | + #display an empty string if there is no string for the cell |
3838 | + return "" |
3839 | + |
3840 | +class CurrencyColumn( StringColumn ): |
3841 | + """CurrencyColumn - display data in currency format. Uses a gtk.Spinner |
3842 | + to display data and support editing if enabled. Store real values as float. |
3843 | + |
3844 | + Inherits from StringColumn. |
3845 | + |
3846 | + """ |
3847 | + |
3848 | + column_type = gobject.TYPE_STRING |
3849 | + default_filter = grid_filter.NumericFilterBox |
3850 | + def __init__(self, key, index,dictionary_index, editable=True ): |
3851 | + """Creates a CurrencyColumn |
3852 | + |
3853 | + Arguments: |
3854 | + key - the key from the dict for the row. Also used as the title for the |
3855 | + column by default. |
3856 | + |
3857 | + index - the position of the column in the grid. |
3858 | + |
3859 | + dictionary_index - the index in the ListStore where the dictionary |
3860 | + for the row is stored. Typically len(dict). |
3861 | + |
3862 | + editable - False if the column does not allow the user to edit the |
3863 | + values in the column. Defaults to True. |
3864 | + |
3865 | + """ |
3866 | + |
3867 | + StringColumn.__init__( self, key, index, dictionary_index, editable, self._currency_format) |
3868 | + |
3869 | + def _initialize_renderer( self, editable, index ): |
3870 | + """_initialize_renderer - internal function called to set up the |
3871 | + CellRenderer for the column. |
3872 | + |
3873 | + arguments: |
3874 | + |
3875 | + editable - True if the column should support user editing. |
3876 | + |
3877 | + index - the position of the column in the grid |
3878 | + |
3879 | + """ |
3880 | + |
3881 | + self.renderer = gtk.CellRendererSpin() |
3882 | + adj = gtk.Adjustment(0,-10000000000,10000000000,1) |
3883 | + self.renderer.set_property("adjustment", adj) |
3884 | + self.renderer.set_property("editable", editable) |
3885 | + self.renderer.set_property("digits",2) |
3886 | + self.renderer.connect("edited", self._cell_edited) |
3887 | + |
3888 | + #make sure the value was edited to something that can be |
3889 | + #turned into an int |
3890 | + try: |
3891 | + float(new_text) |
3892 | + except: |
3893 | + return |
3894 | + |
3895 | + #get an iterator that points to the edited row |
3896 | + if self.list_store is not None: |
3897 | + |
3898 | + iter = self.list_store.get_iter(path) |
3899 | + #update the ListStore with the new text |
3900 | + self.list_store.set_value(iter, self.index, self.display_val(new_text)) |
3901 | + dictionary = self.list_store.get_value(iter,self.dictionary_index) |
3902 | + dictionary[self.key] = self.real_val(new_text) |
3903 | + |
3904 | + |
3905 | + def display_val(self, val): |
3906 | + """display_val - takes a real value and returns the cooresponding |
3907 | + display value |
3908 | + |
3909 | + arguments: |
3910 | + |
3911 | + val - the real value to convert |
3912 | + |
3913 | + """ |
3914 | + |
3915 | + try: |
3916 | + return str(float(val)) |
3917 | + except: |
3918 | + return "" |
3919 | + |
3920 | + |
3921 | + def real_val(self, val): |
3922 | + """real_val - takes a display value and returns the cooresponding |
3923 | + real value. |
3924 | + |
3925 | + arguments: |
3926 | + |
3927 | + val - the display value to convert |
3928 | + |
3929 | + """ |
3930 | + |
3931 | + try: |
3932 | + return float(val) |
3933 | + except: |
3934 | + return 0.0 |
3935 | + |
3936 | + def default_display_val(self): |
3937 | + """default_dislay_val - return the value to display in the case |
3938 | + where there is no real value for the column for the row. |
3939 | + |
3940 | + """ |
3941 | + |
3942 | + return "" |
3943 | + |
3944 | + def _sort_ascending(self, x, y): |
3945 | + x = x[self.index] |
3946 | + y = y[self.index] |
3947 | + if x == "" and y == "": |
3948 | + return 0 |
3949 | + if x == "" and y != "": |
3950 | + return -1 |
3951 | + if x != "" and y == "": |
3952 | + return 1 |
3953 | + |
3954 | + x = float(x) |
3955 | + y = float(y) |
3956 | + if x > y: |
3957 | + return 1 |
3958 | + elif x == y: |
3959 | + return 0 |
3960 | + elif x < y: |
3961 | + return -1 |
3962 | + |
3963 | + def _sort_descending(self, x, y): |
3964 | + x = x[self.index] |
3965 | + y = y[self.index] |
3966 | + if x == "" and y == "": |
3967 | + return 0 |
3968 | + if x == "" and y != "": |
3969 | + return 1 |
3970 | + if x != "" and y == "": |
3971 | + return -1 |
3972 | + |
3973 | + x = float(x) |
3974 | + y = float(y) |
3975 | + if x > y: |
3976 | + return -1 |
3977 | + elif x == y: |
3978 | + return 0 |
3979 | + elif x < y: |
3980 | + return 1 |
3981 | + |
3982 | + def _currency_format(self, val, cell_renderer): |
3983 | + try: |
3984 | + return "%.2f" % float(val) |
3985 | + except: |
3986 | + return "" |
3987 | + |
3988 | +class TagsColumn( StringColumn ): |
3989 | + """TagsColumn - A specialization of a StringColumn that differs |
3990 | + only in that it uses a TagsFilterBox for filtering in any |
3991 | + attached GridFilter. |
3992 | + |
3993 | + """ |
3994 | + |
3995 | + column_type = gobject.TYPE_STRING |
3996 | + default_filter = grid_filter.TagsFilterBox |
3997 | + |
3998 | + |
3999 | +class IntegerColumn( StringColumn ): |
4000 | + """IntegerColumn - display data in Integer format. Uses a gtk.Spinner |
4001 | + to display data and support editing if enabled. Store real values as int. |
4002 | + |
4003 | + Inherits from StringColumn. |
4004 | + |
4005 | + """ |
4006 | + |
4007 | + column_type = gobject.TYPE_STRING |
4008 | + default_filter = grid_filter.IntegerFilterBox |
4009 | + |
4010 | + def __init__(self, key, index, dictionary_index, editable=True ): |
4011 | + """Creates an IntegerColumn |
4012 | + |
4013 | + Arguments: |
4014 | + key - the key from the dict for the row. Also used as the title for the |
4015 | + column by default. |
4016 | + |
4017 | + index - the position of the column in the grid. |
4018 | + |
4019 | + dictionary_index - the index in the ListStore where the dictionary |
4020 | + for the row is stored. Typically len(dict). |
4021 | + |
4022 | + editable - False if the column does not allow the user to edit the |
4023 | + values in the column. Defaults to True. |
4024 | + |
4025 | + """ |
4026 | + |
4027 | + StringColumn.__init__( self, key, index, dictionary_index, editable) |
4028 | + |
4029 | + def _initialize_renderer( self, editable, index ): |
4030 | + self.renderer = gtk.CellRendererSpin() |
4031 | + adj = gtk.Adjustment(0,-10000000000,10000000000,1) |
4032 | + self.renderer.set_property("adjustment", adj) |
4033 | + self.renderer.set_property("editable", editable) |
4034 | + self.renderer.connect("edited", self._cell_edited) |
4035 | + |
4036 | + def _cell_edited(self, cellrenderertext, path, new_text, data=None): |
4037 | + """ __edited - internal signal handler. |
4038 | + Updates the dictionary if a cell in the Treeview |
4039 | + has been edited. |
4040 | + |
4041 | + """ |
4042 | + |
4043 | + #make sure the value was edited to something that can be |
4044 | + #turned into an int |
4045 | + try: |
4046 | + int(new_text) |
4047 | + except: |
4048 | + return |
4049 | + |
4050 | + #get an iterator that points to the edited row |
4051 | + if self.list_store is not None: |
4052 | + |
4053 | + iter = self.list_store.get_iter(path) |
4054 | + #update the ListStore with the new text |
4055 | + self.list_store.set_value(iter, self.index, self.display_val(new_text)) |
4056 | + dictionary = self.list_store.get_value(iter,self.dictionary_index) |
4057 | + dictionary[self.key] = self.real_val(new_text) |
4058 | + |
4059 | + |
4060 | + def display_val(self, val): |
4061 | + """display_val - takes a real value and returns the cooresponding |
4062 | + display value |
4063 | + |
4064 | + arguments: |
4065 | + |
4066 | + val - the real value to convert |
4067 | + |
4068 | + """ |
4069 | + |
4070 | + try: |
4071 | + return str(int(val)) |
4072 | + except: |
4073 | + return "" |
4074 | + |
4075 | + def real_val(self, val): |
4076 | + """real_val - takes a display value and returns the cooresponding |
4077 | + real value. |
4078 | + |
4079 | + arguments: |
4080 | + |
4081 | + val - the display value to convert |
4082 | + |
4083 | + """ |
4084 | + |
4085 | + try: |
4086 | + return int(val) |
4087 | + except: |
4088 | + return 0 |
4089 | + |
4090 | + |
4091 | + def default_display_val(self): |
4092 | + """default_dislay_val - return the value to display in the case |
4093 | + where there is no real value for the column for the row. |
4094 | + |
4095 | + """ |
4096 | + |
4097 | + return "" |
4098 | + |
4099 | + def _sort_ascending(self, x, y): |
4100 | + x = x[self.index] |
4101 | + y = y[self.index] |
4102 | + if x == "" and y == "": |
4103 | + return 0 |
4104 | + if x == "" and y != "": |
4105 | + return -1 |
4106 | + if x != "" and y == "": |
4107 | + return 1 |
4108 | + |
4109 | + x = int(x) |
4110 | + y = int(y) |
4111 | + if x > y: |
4112 | + return 1 |
4113 | + elif x == y: |
4114 | + return 0 |
4115 | + elif x < y: |
4116 | + return -1 |
4117 | + |
4118 | + def _sort_descending(self, x, y): |
4119 | + x = x[self.index] |
4120 | + y = y[self.index] |
4121 | + if x == "" and y == "": |
4122 | + return 0 |
4123 | + if x == "" and y != "": |
4124 | + return 1 |
4125 | + if x != "" and y == "": |
4126 | + return -1 |
4127 | + |
4128 | + x = int(x) |
4129 | + y = int(y) |
4130 | + if x > y: |
4131 | + return -1 |
4132 | + elif x == y: |
4133 | + return 0 |
4134 | + elif x < y: |
4135 | + return 1 |
4136 | + |
4137 | + |
4138 | +class CheckColumn( GridColumn ): |
4139 | + """CheckColumn - display data as checkboxes. Store real values as bool. |
4140 | + |
4141 | + Inherits from gtk.TreeViewColumn. |
4142 | + |
4143 | + """ |
4144 | + |
4145 | + column_type = gobject.TYPE_INT |
4146 | + default_filter = grid_filter.CheckFilterBox |
4147 | + |
4148 | + def __init__(self, key, index, dictionary_index, editable=True, format_function = None ): |
4149 | + """Creates a StringColumn |
4150 | + |
4151 | + Arguments: |
4152 | + key - the key from the dict for the row. Also used as the title for the |
4153 | + column by default. |
4154 | + |
4155 | + index - the position of the column in the grid. |
4156 | + |
4157 | + dictionary_index - the index in the ListStore where the dictionary |
4158 | + for the row is stored. Typically len(dict). |
4159 | + |
4160 | + editable - False if the column does not allow the user to edit the |
4161 | + values in the column. Defaults to True. |
4162 | + |
4163 | + format_function - and optional function to handle formatting of |
4164 | + of the string to display. Defaults to None. |
4165 | + """ |
4166 | + |
4167 | + self._initialize_renderer(editable, index) |
4168 | + GridColumn.__init__( self, key, index, dictionary_index, self.renderer, editable, format_function) |
4169 | + |
4170 | + self.set_cell_data_func(self.renderer, self._on_format) |
4171 | + self.extra_format_function = format_function |
4172 | + |
4173 | + def _sort_ascending(self, x, y): |
4174 | + x = x[self.index] |
4175 | + y = y[self.index] |
4176 | + return y - x |
4177 | + |
4178 | + def _sort_descending(self, x, y): |
4179 | + x = x[self.index] |
4180 | + y = y[self.index] |
4181 | + return x - y |
4182 | + |
4183 | + def _on_format(self,column, cell_renderer, tree_model, iter): |
4184 | + cell_val = tree_model.get_value(iter, self.index) |
4185 | + cell_renderer.set_property('inconsistent', False) |
4186 | + if cell_val == 1: |
4187 | + cell_renderer.set_active(True) |
4188 | + elif cell_val == 0: |
4189 | + cell_renderer.set_active(False) |
4190 | + else: |
4191 | + cell_renderer.set_property('inconsistent', True) |
4192 | + #TODO: show it checked, unchecked, inconsistent ... based (-1,0,1) |
4193 | + if self.extra_format_function != None: |
4194 | + self.extra_format_function() |
4195 | + |
4196 | + def _initialize_renderer( self, editable, index ): |
4197 | + self.renderer = gtk.CellRendererToggle() |
4198 | + self.renderer.set_property("activatable", editable) |
4199 | + col = gtk.TreeViewColumn(self.key, self.renderer, active=index) |
4200 | + self.renderer.connect("toggled", self.toggled) |
4201 | + |
4202 | + def toggled(self, cell, path, data=None): |
4203 | + #get an iterator that points to the edited row |
4204 | + new_val = not cell.get_active() |
4205 | + if self.list_store is not None: |
4206 | + iter = self.list_store.get_iter(path) |
4207 | + #update the ListStore with the new text |
4208 | + self.list_store.set_value(iter, self.index, new_val) |
4209 | + |
4210 | + dictionary = self.list_store.get_value(iter,self.dictionary_index) |
4211 | + dictionary[self.key] = new_val |
4212 | + |
4213 | + def display_val(self, val): |
4214 | + """display_val - takes a real value and returns the cooresponding |
4215 | + display value |
4216 | + |
4217 | + arguments: |
4218 | + |
4219 | + val - the real value to convert |
4220 | + |
4221 | + """ |
4222 | + |
4223 | + if type(val) is bool: |
4224 | + if val: |
4225 | + return 1 |
4226 | + else: |
4227 | + return 0 |
4228 | + elif type(val) is str: |
4229 | + if val.lower() == _("yes"): |
4230 | + return 1 |
4231 | + else: |
4232 | + return 0 |
4233 | + elif type(val) is None: |
4234 | + return self.default_display_val() |
4235 | + else: |
4236 | + return bool(val) |
4237 | + |
4238 | + def default_display_val(self): |
4239 | + """default_dislay_val - return the value to display in the case |
4240 | + where there is no real value for the column for the row. |
4241 | + |
4242 | + """ |
4243 | + |
4244 | + return -1 |
4245 | + |
4246 | + |
4247 | + def real_val(self, val): |
4248 | + """real_val - takes a display value and returns the cooresponding |
4249 | + real value. |
4250 | + |
4251 | + arguments: |
4252 | + |
4253 | + val - the display value to convert |
4254 | + |
4255 | + """ |
4256 | + |
4257 | + if type(val) is type(True): |
4258 | + return val |
4259 | + elif type(val) is type("a"): |
4260 | + if val.lower() == "yes": |
4261 | + return True |
4262 | + else: |
4263 | + return False |
4264 | + else: |
4265 | + return bool(val) |
4266 | + |
4267 | +class DateColumn( StringColumn ): |
4268 | + """DateColumn - display data in date format. Uses a gtk.Calendar |
4269 | + to display data and support editing if enabled. Store real values as tuple. |
4270 | + |
4271 | + Inherits from StringColumn. |
4272 | + |
4273 | + """ |
4274 | + |
4275 | + column_type = gobject.TYPE_STRING |
4276 | + default_filter = grid_filter.DateFilterBox |
4277 | + |
4278 | + def __init__(self, key, index,dictionary_index, editable=True ): |
4279 | + """Creates a Date |
4280 | + |
4281 | + Arguments: |
4282 | + key - the key from the dict for the row. Also used as the title for the |
4283 | + column by default. |
4284 | + index - the position of the column in the grid. |
4285 | + |
4286 | + dictionary_index - the index in the ListStore where the dictionary |
4287 | + for the row is stored. Typically len(dict). |
4288 | + |
4289 | + editable - False if the column does not allow the user to edit the |
4290 | + values in the column. Defaults to True. |
4291 | + |
4292 | + """ |
4293 | + self._editable = editable |
4294 | + StringColumn.__init__( self, key, index, dictionary_index, editable) |
4295 | + |
4296 | + def _initialize_renderer( self, editable, index ): |
4297 | + """_initialize_renderer - internal function called to set up the |
4298 | + CellRenderer for the column. |
4299 | + |
4300 | + arguments: |
4301 | + |
4302 | + editable - True if the column should support user editing. |
4303 | + |
4304 | + index - the position of the column in the grid |
4305 | + |
4306 | + """ |
4307 | + |
4308 | + self.renderer = CellRendererDate() |
4309 | + self.renderer.set_property('editable',self._editable) |
4310 | + self.renderer.connect("edited", self._cell_edited) |
4311 | + |
4312 | +class CellRendererDate(gtk.CellRendererText): |
4313 | + def __init__(self): |
4314 | + gtk.CellRendererText.__init__(self) |
4315 | + self.date_format = '%Y-%m-%d' |
4316 | + |
4317 | + self.calendar_window = None |
4318 | + self.calendar = None |
4319 | + |
4320 | + def _create_calendar(self, treeview): |
4321 | + self.calendar_window = gtk.Dialog(parent=treeview.get_toplevel()) |
4322 | + self.calendar_window.action_area.hide() |
4323 | + self.calendar_window.set_decorated(False) |
4324 | + self.calendar_window.set_property('skip-taskbar-hint', True) |
4325 | + |
4326 | + self.calendar = gtk.Calendar() |
4327 | + self.calendar.display_options(gtk.CALENDAR_SHOW_DAY_NAMES | gtk.CALENDAR_SHOW_HEADING) |
4328 | + self.calendar.connect('day-selected-double-click', self._day_selected, None) |
4329 | + self.calendar.connect('key-press-event', self._day_selected) |
4330 | + self.calendar.connect('focus-out-event', self._selection_cancelled) |
4331 | + self.calendar_window.set_transient_for(None) # cancel the modality of dialog |
4332 | + self.calendar_window.vbox.pack_start(self.calendar) |
4333 | + |
4334 | + # necessary for getting the (width, height) of calendar_window |
4335 | + self.calendar.show() |
4336 | + self.calendar_window.realize() |
4337 | + |
4338 | + def do_start_editing(self, event, treeview, path, background_area, cell_area, flags): |
4339 | + if not self.get_property('editable'): |
4340 | + return |
4341 | + |
4342 | + if not self.calendar_window: |
4343 | + self._create_calendar(treeview) |
4344 | + |
4345 | + # select cell's previously stored date if any exists - or today |
4346 | + if self.get_property('text'): |
4347 | + date = datetime.datetime.strptime(self.get_property('text'), self.date_format) |
4348 | + else: |
4349 | + date = datetime.datetime.today() |
4350 | + |
4351 | + self.calendar.freeze() # prevent flicker |
4352 | + (year, month, day) = (date.year, date.month - 1, date.day) # datetime's month starts from one |
4353 | + self.calendar.select_month(int(month), int(year)) |
4354 | + self.calendar.select_day(int(day)) |
4355 | + self.calendar.thaw() |
4356 | + |
4357 | + # position the popup below the edited cell (and try hard to keep the popup within the toplevel window) |
4358 | + (tree_x, tree_y) = treeview.get_bin_window().get_origin() |
4359 | + (tree_w, tree_h) = treeview.window.get_geometry()[2:4] |
4360 | + (calendar_w, calendar_h) = self.calendar_window.window.get_geometry()[2:4] |
4361 | + x = tree_x + min(cell_area.x, tree_w - calendar_w + treeview.get_visible_rect().x) |
4362 | + y = tree_y + min(cell_area.y, tree_h - calendar_h + treeview.get_visible_rect().y) |
4363 | + self.calendar_window.move(x, y) |
4364 | + |
4365 | + response = self.calendar_window.run() |
4366 | + self.calendar_window.hide() |
4367 | + if response == gtk.RESPONSE_OK: |
4368 | + (year, month, day) = self.calendar.get_date() |
4369 | + date = datetime.date(year, month + 1, day).strftime(self.date_format) # gtk.Calendar's month starts from zero |
4370 | + self.emit('edited', path, date) |
4371 | + |
4372 | + return None # don't return any editable, our gtk.Dialog did the work already |
4373 | + |
4374 | + def _day_selected(self, calendar, event): |
4375 | + # event == None for day selected via doubleclick |
4376 | + if not event or event.type == gtk.gdk.KEY_PRESS and gtk.gdk.keyval_name(event.keyval) == 'Return': |
4377 | + self.calendar_window.response(gtk.RESPONSE_OK) |
4378 | + return True |
4379 | + |
4380 | + def _selection_cancelled(self, calendar, event): |
4381 | + self.calendar_window.response(gtk.RESPONSE_CANCEL) |
4382 | + return True |
4383 | + |
4384 | |
4385 | === added file 'quickly/widgets/grid_filter.py' |
4386 | --- quickly/widgets/grid_filter.py 1970-01-01 00:00:00 +0000 |
4387 | +++ quickly/widgets/grid_filter.py 2011-07-25 07:14:30 +0000 |
4388 | @@ -0,0 +1,845 @@ |
4389 | +# -*- coding: utf-8 -*- |
4390 | +### BEGIN LICENSE |
4391 | +# Copyright (C) 2010 Rick Spencer rick.spencer@canonical.com |
4392 | +#This program is free software: you can redistribute it and/or modify it |
4393 | +#under the terms of the GNU General Public License version 3, as published |
4394 | +#by the Free Software Foundation. |
4395 | +# |
4396 | +#This program is distributed in the hope that it will be useful, but |
4397 | +#WITHOUT ANY WARRANTY; without even the implied warranties of |
4398 | +#MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
4399 | +#PURPOSE. See the GNU General Public License for more details. |
4400 | +# |
4401 | +#You should have received a copy of the GNU General Public License along |
4402 | +#with this program. If not, see <http://www.gnu.org/licenses/>. |
4403 | +### END LICENSE |
4404 | + |
4405 | +"""Widgets and Objects for filtering a DictionaryGrid |
4406 | +GridFilter is as gtk.VBox that provides filtering UI for a |
4407 | +DictionaryGrid. Provides multiple filters, and choosing |
4408 | +between "And" and "Or" filtering. Provides default filters appropriate |
4409 | +for each column. |
4410 | + |
4411 | +GridFilter row is a gtk.HBox that is a container for displaying FilterCombos. |
4412 | + |
4413 | +FilterCombos display a filter and handle filtering of rows to |
4414 | +display and hide in the associated DictionaryGrid. The GridColumns |
4415 | +determine the type of filter to use by default. |
4416 | + |
4417 | +Using |
4418 | +#create a DictionaryGrid and use it to create a GridFilter |
4419 | +grid = DictionaryGrid(dictionaries=dicts) |
4420 | +grid.show() |
4421 | + |
4422 | +filt = GridFilter(grid) |
4423 | +filt.show() |
4424 | + |
4425 | +Configuring |
4426 | +#Create a custom filter combo and use it for a column |
4427 | +#the filter functions should take a stored value and a value to filter against |
4428 | +for each row and return True if the results should cause the row to |
4429 | +be displayed and False if the row should not be displayed |
4430 | + |
4431 | +blank_filter = BlankFilterBox() |
4432 | +blank_filter.append("=",custom_equals_function ) |
4433 | +blank_filter.append("<>",custom_no_equals_function ) |
4434 | + |
4435 | +filter_hints = {"status":blank_filter} |
4436 | +filt = GridFilter(grid, filter_hints) |
4437 | +filt.show() |
4438 | + |
4439 | +Extending |
4440 | +A custom filter combo is easiest to create by deriving from BlankFilterBox |
4441 | +and using the BlankFilterBox.append function to display new filters. |
4442 | + |
4443 | +class StringFilterBox( BlankFilterBox ): |
4444 | + def __init__(self): |
4445 | + BlankFilterBox.__init__(self) |
4446 | + self.append("contains",lambda x,y: x.find(y) > -1) |
4447 | + self.append("does not contain",lambda x,y: x.find(y) == -1) |
4448 | + self.append("starts with",lambda x,y: x.startswith(y)) |
4449 | + self.append("ends with",lambda x,y: x.endswith(y)) |
4450 | + |
4451 | +Filter UI could be created to use widgets other than gtk.Combo so long as |
4452 | +the widget has a get_model function that returns a gtk.ListStore with |
4453 | +filtering functions stored as the last value (column) in the liststore. |
4454 | + |
4455 | +""" |
4456 | + |
4457 | +import sys |
4458 | +import datetime |
4459 | +import gettext |
4460 | +from gettext import gettext as _ |
4461 | +gettext.textdomain('quickly-widgets') |
4462 | + |
4463 | +try: |
4464 | + import pygtk |
4465 | + pygtk.require("2.0") |
4466 | + import gtk |
4467 | + import gobject |
4468 | + |
4469 | +except Exception, inst: |
4470 | + print "some dependencies for GridFilter are not available" |
4471 | + raise inst |
4472 | + |
4473 | +class GridFilter( gtk.VBox ): |
4474 | + """GridFilter: A widget that provides a user interface for filtering a |
4475 | + treeview. A GridFilter hosts one ore more GridRows, which in turn host |
4476 | + an active filter. |
4477 | + |
4478 | + """ |
4479 | + def __init__(self, grid, filter_hints={} ): |
4480 | + """Create a GridFilter for filtering an associated treeview. |
4481 | + This class is used by BugsPane. |
4482 | + |
4483 | + arguments: |
4484 | + grid - A DictionaryGrid to filter |
4485 | + |
4486 | + options arguments: |
4487 | + filter_hints - a dictionary of column keys to FilterCombo types to |
4488 | + provide custom filtering. |
4489 | + |
4490 | + """ |
4491 | + |
4492 | + gtk.VBox.__init__( self, False, 10 ) |
4493 | + self.grid = grid |
4494 | + self.store = grid.get_model() |
4495 | + self.filter_hints = filter_hints |
4496 | + |
4497 | + #create the and/or radio buttons |
4498 | + radio_box = gtk.HBox(False,2) |
4499 | + radio_box.show() |
4500 | + self.pack_start(radio_box, False, False) |
4501 | + self.and_button = gtk.RadioButton(None,_("M_atch All of the following"), True) |
4502 | + self.and_button.show() |
4503 | + self.and_button.connect("toggled",self.__filter_changed) |
4504 | + radio_box.pack_start(self.and_button, False, False) |
4505 | + or_button = gtk.RadioButton(self.and_button,_("Match any _of the following"), True) |
4506 | + or_button.show() |
4507 | + radio_box.pack_start(or_button, False, False) |
4508 | + self.rows = [] |
4509 | + self._add_row(self) |
4510 | + |
4511 | + def _add_row(self, widget, data=None): |
4512 | + """_add_row: internal signal handler that receives a request |
4513 | + from a FilterRow to add a new row. Sets up and adds the row to the GridFilter. |
4514 | + |
4515 | + Do not call directly |
4516 | + """ |
4517 | + |
4518 | + #TODO: I suppose this is leaking references to filter rows |
4519 | + row = FilterRow(self.grid, len(self.rows) > 0, self.filter_hints ) |
4520 | + row.connect('add_row_requested',self._add_row) |
4521 | + row.connect('remove_row_requested',self._remove_row) |
4522 | + row.connect('refilter_requested',self.__filter_changed) |
4523 | + row.show() |
4524 | + self.rows.append(row) |
4525 | + self.pack_start(row, False, False) |
4526 | + |
4527 | + def _remove_row(self, widget, data=None): |
4528 | + """_remove_row: internal signal handler that receives a |
4529 | + request from a FilterRow to remove itself from the GridFilter. |
4530 | + |
4531 | + Do not call directly |
4532 | + """ |
4533 | + |
4534 | + self.rows.remove(widget) |
4535 | + self.remove(widget) |
4536 | + self.__filter_changed(self) |
4537 | + |
4538 | + def __filter_changed(self,widget, data=None): |
4539 | + """__filter_changed: internal signal handler that handles |
4540 | + requests to reapply the fitlers in the GridFilter's FilterRows. |
4541 | + |
4542 | + """ |
4543 | + |
4544 | + filt = self.store.filter_new() |
4545 | + sort_mod = gtk.TreeModelSort(filt) |
4546 | + filt.set_visible_func(self.__filter_func, data ) |
4547 | + filt.refilter() |
4548 | + self.grid.set_model(sort_mod) |
4549 | + |
4550 | + def __filter_func(self, model, iter, data): |
4551 | + """filter_func: called for each row in the treeview model in response to |
4552 | + a __filter_changed signal. Determines for each row whether it should be |
4553 | + visible based on the FilterRows in the GridFilter. |
4554 | + |
4555 | + |
4556 | + Do not call directly |
4557 | + """ |
4558 | + #determine whether this is an "and" or an "or" filter |
4559 | + match_all = self.and_button.get_active() |
4560 | + |
4561 | + for r in self.rows: |
4562 | + rez = r.is_match(iter.copy(),model) #check the result of each filter |
4563 | + if match_all: #if it's an "and" filter |
4564 | + if not rez: #and if the filter does not match |
4565 | + return False #then the row should not be visible |
4566 | + else: #but if it's an "or" filter |
4567 | + if rez: #and it is a match |
4568 | + return True #return that the row should be visible |
4569 | + return match_all #all filters match an "and" or none matched an "or" |
4570 | + |
4571 | +class FilterRow( gtk.HBox): |
4572 | + """FilterRow: A widget that displays a single filter in a GridFilter. |
4573 | + Typically, this class will not be used directly, but only via a GridFilter. |
4574 | + |
4575 | + """ |
4576 | + wait_for_input = False |
4577 | + |
4578 | + def __init__(self, grid, removable=True, filter_hints={}): |
4579 | + """Create a FilterRow to be used in a GridFilter. |
4580 | + A FitlerRow is comprised of a combo that lists the treeview headings. |
4581 | + The combo stores the string to display for the heading, as well as |
4582 | + the widget that is used to filter each heading. When the user changes |
4583 | + the value in the dropdown, the FilterRow retrieves the correct filter from |
4584 | + the combo, and displays that filter to the user. |
4585 | + |
4586 | + The FilterRow also handles offering UI for the user to add and remove |
4587 | + FilterRows for the GridFilter containing it. |
4588 | + |
4589 | + grid - |
4590 | + |
4591 | + keyword arguments: |
4592 | + removable - True if the row should be able to be removed from the GridFilter |
4593 | + Typicall False for the first row. |
4594 | + |
4595 | + filter_hints - a dictionary of keys mapped to custom filters to apply to the |
4596 | + column designated by the key |
4597 | + |
4598 | + """ |
4599 | + |
4600 | + gtk.HBox.__init__( self, False, 10 ) |
4601 | + self.store = grid.get_model() |
4602 | + self.grid = grid |
4603 | + |
4604 | + heading_combo_store = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_PYOBJECT,gobject.TYPE_INT) |
4605 | + |
4606 | + #apply default combos |
4607 | + for i, k in enumerate(self.grid.keys): |
4608 | + if k in filter_hints: |
4609 | + filt_combo = filter_hints[k] |
4610 | + else: |
4611 | + filt_combo = grid.get_columns()[i].default_filter() |
4612 | + |
4613 | + column_title = grid.get_columns()[i].get_title() |
4614 | + heading_combo_store.append([column_title,filt_combo,i]) |
4615 | + |
4616 | + filt_combo.connect("changed",self.__filter_changed) |
4617 | + filt_combo.show() |
4618 | + |
4619 | + self.column_combo = gtk.ComboBox(heading_combo_store) |
4620 | + cell = gtk.CellRendererText() |
4621 | + self.column_combo.pack_start(cell, True) |
4622 | + self.column_combo.add_attribute(cell, 'text', 0) |
4623 | + |
4624 | + self.filter_space = gtk.HBox(False,1) |
4625 | + self.filter_space.show() |
4626 | + |
4627 | + self.column_combo.show() |
4628 | + vb = gtk.VBox(False, 5) |
4629 | + vb.show() |
4630 | + vb.pack_start(self.column_combo, True, False) |
4631 | + self.pack_start(vb,False, False) |
4632 | + self.column_combo.connect("changed",self.__column_changed) |
4633 | + self.column_combo.set_active(0) |
4634 | + |
4635 | + self.pack_start(self.filter_space, False, False) |
4636 | + |
4637 | + button_box = gtk.HBox(False,2) |
4638 | + button_box.show() |
4639 | + self.pack_start(button_box,False,False) |
4640 | + |
4641 | + #add a button that can create a new row in the grid filter |
4642 | + add_button = gtk.Button(stock = gtk.STOCK_ADD) |
4643 | + add_button.show() |
4644 | + vb2 = gtk.VBox(False, 5) |
4645 | + vb2.show() |
4646 | + vb2.pack_start(add_button, True, False) |
4647 | + button_box.pack_start(vb2, False, False) |
4648 | + add_button.connect("clicked",lambda x: self.emit('add_row_requested',self) ) |
4649 | + |
4650 | + #add a button to remove the row if applicable |
4651 | + if removable: |
4652 | + rm_button = gtk.Button(stock = gtk.STOCK_REMOVE) |
4653 | + rm_button.show() |
4654 | + vb3 = gtk.VBox(False, 5) |
4655 | + vb3.show() |
4656 | + vb3.pack_start(rm_button, True, False) |
4657 | + rm_button.connect('clicked', lambda x: self.emit("remove_row_requested",self) ) |
4658 | + button_box.pack_start(vb3) |
4659 | + |
4660 | + __gsignals__ = {'add_row_requested' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
4661 | + (gobject.TYPE_PYOBJECT,)), |
4662 | + 'remove_row_requested' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
4663 | + (gobject.TYPE_PYOBJECT,)), |
4664 | + 'refilter_requested' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
4665 | + (gobject.TYPE_PYOBJECT,)) |
4666 | + } |
4667 | + |
4668 | + def __column_changed(self, widget, data = None): |
4669 | + """column_changed: internal signal handler for the user changing |
4670 | + the combo for the column that they wish to apply the filter to. |
4671 | + removes the other filter widgets and replaces them widgets stored in |
4672 | + the filter widget. |
4673 | + |
4674 | + """ |
4675 | + |
4676 | + if len(self.filter_space.get_children()) > 0: |
4677 | + self.filter_space.remove(self.filter_space.get_children()[0]) |
4678 | + iter = widget.get_model().get_iter(widget.get_active()) |
4679 | + filter_box = widget.get_model().get_value(iter,1) |
4680 | + self.filter_space.pack_start(filter_box, False, False) |
4681 | + |
4682 | + def __filter_changed(self,widget, data=None): |
4683 | + """filter_changed: internal signal handler called when the FilterRow has changed. |
4684 | + Used to tell the GridFilter to refilter. Only emits if the filter is |
4685 | + active (a heading is selected in the combo and the user has entered |
4686 | + text in the filter. |
4687 | + |
4688 | + """ |
4689 | + |
4690 | + #if not self.wait_for_input: |
4691 | + #if self.__get_current_filter_combo().get_active > -1: |
4692 | + self.emit('refilter_requested',self) |
4693 | + |
4694 | + def __get_current_filter_combo(self): |
4695 | + """get_current_filter_combo: internal function that retrieves |
4696 | + the combobox stored for the filter for the user selected treeview column. |
4697 | + |
4698 | + """ |
4699 | + iter = self.column_combo.get_model().get_iter(self.column_combo.get_active()) |
4700 | + return self.column_combo.get_model().get_value(iter,1) |
4701 | + |
4702 | + def is_match(self, store_iter, model): |
4703 | + """is_match: returns true if the filter set in the FilterRow matches |
4704 | + the value specified in the column and row. Used to determine whether |
4705 | + to hide or show a row. |
4706 | + |
4707 | + Typically called for each treeview row and each FilterRow in response |
4708 | + to a change in one of the FilterRows. |
4709 | + |
4710 | + arguments: |
4711 | + store_iter: the iter pointing the the row in the treeview to test |
4712 | + model: the treeview model containing the rows being tested |
4713 | + |
4714 | + """ |
4715 | + col_iter = self.column_combo.get_model().get_iter(self.column_combo.get_active()) |
4716 | + filter_widget = self.column_combo.get_model().get_value(col_iter,1) |
4717 | + treeview_col = self.column_combo.get_model().get_value(col_iter,2) |
4718 | + |
4719 | + orig_val = model.get_value(store_iter.copy(), treeview_col) |
4720 | + return filter_widget.filter(orig_val) |
4721 | + |
4722 | +class BlankFilterBox( gtk.HBox): |
4723 | + """BlankFilterBox provides a base class for FilterCombos, as |
4724 | + well as an empty combo that can be used without subclassing |
4725 | + by calling BlankFilterBox.append |
4726 | + |
4727 | + """ |
4728 | + __gsignals__ = {'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
4729 | + (gobject.TYPE_PYOBJECT,)), |
4730 | + } |
4731 | + |
4732 | + |
4733 | + def __init__(self): |
4734 | + """create a BlankFilterBox |
4735 | + |
4736 | + """ |
4737 | + |
4738 | + gtk.HBox.__init__(self,False) |
4739 | + self.__combo_store = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_PYOBJECT) |
4740 | + self.combo = gtk.ComboBox(self.__combo_store) |
4741 | + cell = gtk.CellRendererText() |
4742 | + self.combo.pack_start(cell, True) |
4743 | + self.combo.add_attribute(cell, 'text', 0) |
4744 | + self.combo.show() |
4745 | + self.combo.connect("changed",self.__changed) |
4746 | + self.entry = gtk.Entry() |
4747 | + self.entry.show() |
4748 | + self.entry.connect("changed",self.__changed) |
4749 | + self.pack_start(self.combo, False, False) |
4750 | + self.pack_start(self.entry) |
4751 | + |
4752 | + def filter(self, orig_val): |
4753 | + if self.combo.get_active() == -1: |
4754 | + return True |
4755 | + filt_iter = self.combo.get_model().get_iter(self.combo.get_active()) |
4756 | + filt_func = self.combo.get_model().get_value(filt_iter,1) |
4757 | + target_val = self.entry.get_text() |
4758 | + return filt_func(orig_val, self.entry.get_text()) |
4759 | + |
4760 | + def __changed(self, widget, data=None): |
4761 | + self.emit("changed",data) |
4762 | + |
4763 | + def append(self, text, func): |
4764 | + """append: adds a row to the FilterCombo that includes a |
4765 | + string to display in the combo, and a function to determine |
4766 | + if a row should displayed or hidden by the filter. |
4767 | + |
4768 | + func should take a value indicated by text, and a value entered by |
4769 | + the user in the supplied gtk.TextEntry, and return True if the |
4770 | + row should be displayed or False if it should be hidden. |
4771 | + |
4772 | + """ |
4773 | + |
4774 | + self.__combo_store.append([text, func]) |
4775 | + |
4776 | +class StringFilterBox( BlankFilterBox ): |
4777 | + """StringFilterBox: A default string filter class for use in a FilterRow. |
4778 | + |
4779 | + Lets the user specify if the row should be displayed based on |
4780 | + containing, not containing, starting with, or ending with a user specified |
4781 | + string. |
4782 | + |
4783 | + |
4784 | + """ |
4785 | + def __init__(self): |
4786 | + """create a StringFilterBox. |
4787 | + |
4788 | + """ |
4789 | + |
4790 | + BlankFilterBox.__init__(self) |
4791 | + self.append(_("contains"),self.contains) |
4792 | + self.append(_("does not contain"),self.not_contains) |
4793 | + self.append(_("starts with"),self.starts_with) |
4794 | + self.append(_("ends with"),self.ends_with) |
4795 | + |
4796 | + def contains(self, orig_val, target_val): |
4797 | + if len(self.entry.get_text()) == 0 or orig_val is None: |
4798 | + return True |
4799 | + return orig_val.find(target_val) > -1 |
4800 | + |
4801 | + def not_contains(self, orig_val, target_val): |
4802 | + if len(target_val) == 0 or orig_val is None: |
4803 | + return True |
4804 | + return orig_val.find(target_val) == -1 |
4805 | + |
4806 | + def starts_with(self, orig_val, target_val): |
4807 | + if len(target_val) == 0 or orig_val is None: |
4808 | + return True |
4809 | + return orig_val.startswith(target_val) |
4810 | + |
4811 | + def ends_with(self, orig_val, target_val): |
4812 | + if len(target_val) == 0 or orig_val is None: |
4813 | + return True |
4814 | + return orig_val.endswith(target_val) |
4815 | + |
4816 | + |
4817 | +class TagsFilterBox( BlankFilterBox ): |
4818 | + """TagsFilterBox: A default tag filter class for use in a FilterRow. |
4819 | + |
4820 | + Lets the user specify if the row should be displayed based on |
4821 | + containing a one tag or all tags. Assumes tags are seperated by |
4822 | + spaces. |
4823 | + |
4824 | + """ |
4825 | + |
4826 | + def __init__(self): |
4827 | + BlankFilterBox.__init__(self) |
4828 | + self.append(_("has any of these tags"), self._filter_any) |
4829 | + self.append(_("has all of these tags"), self._filter_all) |
4830 | + self.append(_("does not have one of these tags"), self._filter_not) |
4831 | + self.append(_("does not have any of these tags"), self._filter_not_all) |
4832 | + |
4833 | + def _filter_any(self, orig_val, target_val): |
4834 | + """ |
4835 | + _filter_any: filter function that hides rows |
4836 | + if none of the tags supplied in "bugs_tags_s" are found |
4837 | + in the gtk.TextEntry. |
4838 | + |
4839 | + Do not call directly |
4840 | + |
4841 | + """ |
4842 | + |
4843 | + if len(target_val) == 0: |
4844 | + return True |
4845 | + |
4846 | + tags_on_bug = orig_val.split() |
4847 | + tags_in_filter = target_val.split() |
4848 | + |
4849 | + for tag in tags_in_filter: |
4850 | + if tag in tags_on_bug: |
4851 | + return True |
4852 | + return False |
4853 | + |
4854 | + def _filter_all(self, orig_val, target_val): |
4855 | + """ |
4856 | + _filter_any: filter function that hides rows |
4857 | + if not all of the tags supplied in "bugs_tags_s" are found |
4858 | + in the gtk.TextEntry. |
4859 | + |
4860 | + Do not call directly |
4861 | + |
4862 | + """ |
4863 | + if len(target_val) == 0: |
4864 | + return True |
4865 | + |
4866 | + tags_on_bug = orig_val.split() |
4867 | + tags_in_filter = self.entry.get_text().split() |
4868 | + |
4869 | + for tag in tags_in_filter: |
4870 | + if tag not in tags_on_bug: |
4871 | + return False |
4872 | + return True |
4873 | + |
4874 | + def _filter_not(self, orig_val, target_val): |
4875 | + """ |
4876 | + _filter_not: filter function that hides rows |
4877 | + if one of the tags supplied in "bugs_tags_s" are found |
4878 | + in the gtk.TextEntry. |
4879 | + |
4880 | + Do not call directly |
4881 | + |
4882 | + """ |
4883 | + if len(target_val) == 0: |
4884 | + return True |
4885 | + |
4886 | + tags_on_bug = orig_val.split() |
4887 | + tags_in_filter = target_val.split() |
4888 | + |
4889 | + for tag in tags_in_filter: |
4890 | + if tag not in tags_on_bug: |
4891 | + return True |
4892 | + return False |
4893 | + |
4894 | + def _filter_not_all(self, orig_val, target_val): |
4895 | + """ |
4896 | + _filter_not all: filter function that hides rows |
4897 | + if all of the tags supplied in "bugs_tags_s" are found |
4898 | + in the gtk.TextEntry. |
4899 | + |
4900 | + Do not call directly |
4901 | + |
4902 | + """ |
4903 | + if len(self.entry.get_text()) == 0: |
4904 | + return True |
4905 | + |
4906 | + tags_on_bug = orig_val.split() |
4907 | + tags_in_filter = target_val.split() |
4908 | + |
4909 | + for tag in tags_in_filter: |
4910 | + if tag in tags_on_bug: |
4911 | + return False |
4912 | + return True |
4913 | + |
4914 | +class IntegerFilterBox( gtk.HBox ): |
4915 | + """ |
4916 | + |
4917 | + """ |
4918 | + __gsignals__ = {'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
4919 | + (gobject.TYPE_PYOBJECT,)), |
4920 | + } |
4921 | + |
4922 | + def __init__(self): |
4923 | + gtk.HBox.__init__(self, False, 10) |
4924 | + self.__combo_store = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_PYOBJECT) |
4925 | + self.combo = gtk.ComboBox(self.__combo_store) |
4926 | + cell = gtk.CellRendererText() |
4927 | + self.combo.pack_start(cell, True) |
4928 | + self.combo.add_attribute(cell, 'text', 0) |
4929 | + self.combo.show() |
4930 | + self.combo.connect("changed",self.__changed) |
4931 | + adj = gtk.Adjustment(0,-1000000000,1000000000,1) |
4932 | + |
4933 | + self.spinner = gtk.SpinButton(adj,1,0) |
4934 | + self.spinner.set_activates_default(True) |
4935 | + self.spinner.show() |
4936 | + self.spinner.set_numeric(True) |
4937 | + |
4938 | + self.spinner.connect("value-changed",self.__changed) |
4939 | + self.pack_start(self.combo, False, False) |
4940 | + self.pack_start(self.spinner) |
4941 | + |
4942 | + self.__combo_store.append(["=",self._equals]) |
4943 | + self.__combo_store.append(["<",self._less_than]) |
4944 | + self.__combo_store.append([">",self._greater_than]) |
4945 | + self.__combo_store.append(["<=",self._less_than_equals]) |
4946 | + self.__combo_store.append([">=",self._greater_than_equals]) |
4947 | + |
4948 | + def __changed(self, widget, data=None): |
4949 | + self.emit("changed",data) |
4950 | + |
4951 | + def filter(self, orig_val): |
4952 | + if self.combo.get_active() == -1: |
4953 | + return True |
4954 | + |
4955 | + filt_iter = self.combo.get_model().get_iter(self.combo.get_active()) |
4956 | + filt_func = self.combo.get_model().get_value(filt_iter,1) |
4957 | + |
4958 | + try: |
4959 | + target_val = int(self.spinner.get_value_as_int()) |
4960 | + |
4961 | + |
4962 | + except Exception, inst: |
4963 | + print inst |
4964 | + return False |
4965 | + |
4966 | + return filt_func(orig_val, target_val) |
4967 | + |
4968 | + def _equals(self, orig_val, target_val): |
4969 | + if orig_val == "": |
4970 | + return False |
4971 | + return int(orig_val) == target_val |
4972 | + |
4973 | + def _less_than(self, orig_val, target_val): |
4974 | + if orig_val == "": |
4975 | + return False |
4976 | + return int(orig_val) < target_val |
4977 | + |
4978 | + def _greater_than(self, orig_val, target_val): |
4979 | + if orig_val == "": |
4980 | + return False |
4981 | + return int(orig_val) > target_val |
4982 | + |
4983 | + def _less_than_equals(self, orig_val, target_val): |
4984 | + if orig_val == "": |
4985 | + return False |
4986 | + return int(orig_val) <= target_val |
4987 | + |
4988 | + def _greater_than_equals(self, orig_val, target_val): |
4989 | + if orig_val == "": |
4990 | + return False |
4991 | + return int(orig_val) >= target_val |
4992 | + |
4993 | +class DateFilterBox( gtk.HBox ): |
4994 | + """DateFilterCombo: A default date filter class for use in a FilterRow. |
4995 | + |
4996 | + Lets the user specify if the row should be displayed based on |
4997 | + the settings in a date widget. |
4998 | + |
4999 | + """ |
5000 | + __gsignals__ = {'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, |
The diff has been truncated for viewing.