Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 0bf1d55666245d8a7806ad57a3dd17c9a43f0ba2

Remove bundled dependency
  
1Aleksey Lim <alsroot@member.fsf.org>
port/COPYING
(0 / 340)
  
1 GNU GENERAL PUBLIC LICENSE
2 Version 2, June 1991
3
4 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 Everyone is permitted to copy and distribute verbatim copies
7 of this license document, but changing it is not allowed.
8
9 Preamble
10
11 The licenses for most software are designed to take away your
12freedom to share and change it. By contrast, the GNU General Public
13License is intended to guarantee your freedom to share and change free
14software--to make sure the software is free for all its users. This
15General Public License applies to most of the Free Software
16Foundation's software and to any other program whose authors commit to
17using it. (Some other Free Software Foundation software is covered by
18the GNU Library General Public License instead.) You can apply it to
19your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22price. Our General Public Licenses are designed to make sure that you
23have the freedom to distribute copies of free software (and charge for
24this service if you wish), that you receive source code or can get it
25if you want it, that you can change the software or use pieces of it
26in new free programs; and that you know you can do these things.
27
28 To protect your rights, we need to make restrictions that forbid
29anyone to deny you these rights or to ask you to surrender the rights.
30These restrictions translate to certain responsibilities for you if you
31distribute copies of the software, or if you modify it.
32
33 For example, if you distribute copies of such a program, whether
34gratis or for a fee, you must give the recipients all the rights that
35you have. You must make sure that they, too, receive or can get the
36source code. And you must show them these terms so they know their
37rights.
38
39 We protect your rights with two steps: (1) copyright the software, and
40(2) offer you this license which gives you legal permission to copy,
41distribute and/or modify the software.
42
43 Also, for each author's protection and ours, we want to make certain
44that everyone understands that there is no warranty for this free
45software. If the software is modified by someone else and passed on, we
46want its recipients to know that what they have is not the original, so
47that any problems introduced by others will not reflect on the original
48authors' reputations.
49
50 Finally, any free program is threatened constantly by software
51patents. We wish to avoid the danger that redistributors of a free
52program will individually obtain patent licenses, in effect making the
53program proprietary. To prevent this, we have made it clear that any
54patent must be licensed for everyone's free use or not licensed at all.
55
56 The precise terms and conditions for copying, distribution and
57modification follow.
58
59 GNU GENERAL PUBLIC LICENSE
60 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
62 0. This License applies to any program or other work which contains
63a notice placed by the copyright holder saying it may be distributed
64under the terms of this General Public License. The "Program", below,
65refers to any such program or work, and a "work based on the Program"
66means either the Program or any derivative work under copyright law:
67that is to say, a work containing the Program or a portion of it,
68either verbatim or with modifications and/or translated into another
69language. (Hereinafter, translation is included without limitation in
70the term "modification".) Each licensee is addressed as "you".
71
72Activities other than copying, distribution and modification are not
73covered by this License; they are outside its scope. The act of
74running the Program is not restricted, and the output from the Program
75is covered only if its contents constitute a work based on the
76Program (independent of having been made by running the Program).
77Whether that is true depends on what the Program does.
78
79 1. You may copy and distribute verbatim copies of the Program's
80source code as you receive it, in any medium, provided that you
81conspicuously and appropriately publish on each copy an appropriate
82copyright notice and disclaimer of warranty; keep intact all the
83notices that refer to this License and to the absence of any warranty;
84and give any other recipients of the Program a copy of this License
85along with the Program.
86
87You may charge a fee for the physical act of transferring a copy, and
88you may at your option offer warranty protection in exchange for a fee.
89
90 2. You may modify your copy or copies of the Program or any portion
91of it, thus forming a work based on the Program, and copy and
92distribute such modifications or work under the terms of Section 1
93above, provided that you also meet all of these conditions:
94
95 a) You must cause the modified files to carry prominent notices
96 stating that you changed the files and the date of any change.
97
98 b) You must cause any work that you distribute or publish, that in
99 whole or in part contains or is derived from the Program or any
100 part thereof, to be licensed as a whole at no charge to all third
101 parties under the terms of this License.
102
103 c) If the modified program normally reads commands interactively
104 when run, you must cause it, when started running for such
105 interactive use in the most ordinary way, to print or display an
106 announcement including an appropriate copyright notice and a
107 notice that there is no warranty (or else, saying that you provide
108 a warranty) and that users may redistribute the program under
109 these conditions, and telling the user how to view a copy of this
110 License. (Exception: if the Program itself is interactive but
111 does not normally print such an announcement, your work based on
112 the Program is not required to print an announcement.)
113
114These requirements apply to the modified work as a whole. If
115identifiable sections of that work are not derived from the Program,
116and can be reasonably considered independent and separate works in
117themselves, then this License, and its terms, do not apply to those
118sections when you distribute them as separate works. But when you
119distribute the same sections as part of a whole which is a work based
120on the Program, the distribution of the whole must be on the terms of
121this License, whose permissions for other licensees extend to the
122entire whole, and thus to each and every part regardless of who wrote it.
123
124Thus, it is not the intent of this section to claim rights or contest
125your rights to work written entirely by you; rather, the intent is to
126exercise the right to control the distribution of derivative or
127collective works based on the Program.
128
129In addition, mere aggregation of another work not based on the Program
130with the Program (or with a work based on the Program) on a volume of
131a storage or distribution medium does not bring the other work under
132the scope of this License.
133
134 3. You may copy and distribute the Program (or a work based on it,
135under Section 2) in object code or executable form under the terms of
136Sections 1 and 2 above provided that you also do one of the following:
137
138 a) Accompany it with the complete corresponding machine-readable
139 source code, which must be distributed under the terms of Sections
140 1 and 2 above on a medium customarily used for software interchange; or,
141
142 b) Accompany it with a written offer, valid for at least three
143 years, to give any third party, for a charge no more than your
144 cost of physically performing source distribution, a complete
145 machine-readable copy of the corresponding source code, to be
146 distributed under the terms of Sections 1 and 2 above on a medium
147 customarily used for software interchange; or,
148
149 c) Accompany it with the information you received as to the offer
150 to distribute corresponding source code. (This alternative is
151 allowed only for noncommercial distribution and only if you
152 received the program in object code or executable form with such
153 an offer, in accord with Subsection b above.)
154
155The source code for a work means the preferred form of the work for
156making modifications to it. For an executable work, complete source
157code means all the source code for all modules it contains, plus any
158associated interface definition files, plus the scripts used to
159control compilation and installation of the executable. However, as a
160special exception, the source code distributed need not include
161anything that is normally distributed (in either source or binary
162form) with the major components (compiler, kernel, and so on) of the
163operating system on which the executable runs, unless that component
164itself accompanies the executable.
165
166If distribution of executable or object code is made by offering
167access to copy from a designated place, then offering equivalent
168access to copy the source code from the same place counts as
169distribution of the source code, even though third parties are not
170compelled to copy the source along with the object code.
171
172 4. You may not copy, modify, sublicense, or distribute the Program
173except as expressly provided under this License. Any attempt
174otherwise to copy, modify, sublicense or distribute the Program is
175void, and will automatically terminate your rights under this License.
176However, parties who have received copies, or rights, from you under
177this License will not have their licenses terminated so long as such
178parties remain in full compliance.
179
180 5. You are not required to accept this License, since you have not
181signed it. However, nothing else grants you permission to modify or
182distribute the Program or its derivative works. These actions are
183prohibited by law if you do not accept this License. Therefore, by
184modifying or distributing the Program (or any work based on the
185Program), you indicate your acceptance of this License to do so, and
186all its terms and conditions for copying, distributing or modifying
187the Program or works based on it.
188
189 6. Each time you redistribute the Program (or any work based on the
190Program), the recipient automatically receives a license from the
191original licensor to copy, distribute or modify the Program subject to
192these terms and conditions. You may not impose any further
193restrictions on the recipients' exercise of the rights granted herein.
194You are not responsible for enforcing compliance by third parties to
195this License.
196
197 7. If, as a consequence of a court judgment or allegation of patent
198infringement or for any other reason (not limited to patent issues),
199conditions are imposed on you (whether by court order, agreement or
200otherwise) that contradict the conditions of this License, they do not
201excuse you from the conditions of this License. If you cannot
202distribute so as to satisfy simultaneously your obligations under this
203License and any other pertinent obligations, then as a consequence you
204may not distribute the Program at all. For example, if a patent
205license would not permit royalty-free redistribution of the Program by
206all those who receive copies directly or indirectly through you, then
207the only way you could satisfy both it and this License would be to
208refrain entirely from distribution of the Program.
209
210If any portion of this section is held invalid or unenforceable under
211any particular circumstance, the balance of the section is intended to
212apply and the section as a whole is intended to apply in other
213circumstances.
214
215It is not the purpose of this section to induce you to infringe any
216patents or other property right claims or to contest validity of any
217such claims; this section has the sole purpose of protecting the
218integrity of the free software distribution system, which is
219implemented by public license practices. Many people have made
220generous contributions to the wide range of software distributed
221through that system in reliance on consistent application of that
222system; it is up to the author/donor to decide if he or she is willing
223to distribute software through any other system and a licensee cannot
224impose that choice.
225
226This section is intended to make thoroughly clear what is believed to
227be a consequence of the rest of this License.
228
229 8. If the distribution and/or use of the Program is restricted in
230certain countries either by patents or by copyrighted interfaces, the
231original copyright holder who places the Program under this License
232may add an explicit geographical distribution limitation excluding
233those countries, so that distribution is permitted only in or among
234countries not thus excluded. In such case, this License incorporates
235the limitation as if written in the body of this License.
236
237 9. The Free Software Foundation may publish revised and/or new versions
238of the General Public License from time to time. Such new versions will
239be similar in spirit to the present version, but may differ in detail to
240address new problems or concerns.
241
242Each version is given a distinguishing version number. If the Program
243specifies a version number of this License which applies to it and "any
244later version", you have the option of following the terms and conditions
245either of that version or of any later version published by the Free
246Software Foundation. If the Program does not specify a version number of
247this License, you may choose any version ever published by the Free Software
248Foundation.
249
250 10. If you wish to incorporate parts of the Program into other free
251programs whose distribution conditions are different, write to the author
252to ask for permission. For software which is copyrighted by the Free
253Software Foundation, write to the Free Software Foundation; we sometimes
254make exceptions for this. Our decision will be guided by the two goals
255of preserving the free status of all derivatives of our free software and
256of promoting the sharing and reuse of software generally.
257
258 NO WARRANTY
259
260 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268REPAIR OR CORRECTION.
269
270 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278POSSIBILITY OF SUCH DAMAGES.
279
280 END OF TERMS AND CONDITIONS
281
282 How to Apply These Terms to Your New Programs
283
284 If you develop a new program, and you want it to be of the greatest
285possible use to the public, the best way to achieve this is to make it
286free software which everyone can redistribute and change under these terms.
287
288 To do so, attach the following notices to the program. It is safest
289to attach them to the start of each source file to most effectively
290convey the exclusion of warranty; and each file should have at least
291the "copyright" line and a pointer to where the full notice is found.
292
293 <one line to give the program's name and a brief idea of what it does.>
294 Copyright (C) <year> <name of author>
295
296 This program is free software; you can redistribute it and/or modify
297 it under the terms of the GNU General Public License as published by
298 the Free Software Foundation; either version 2 of the License, or
299 (at your option) any later version.
300
301 This program is distributed in the hope that it will be useful,
302 but WITHOUT ANY WARRANTY; without even the implied warranty of
303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 GNU General Public License for more details.
305
306 You should have received a copy of the GNU General Public License
307 along with this program; if not, write to the Free Software
308 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
309
310
311Also add information on how to contact you by electronic and paper mail.
312
313If the program is interactive, make it output a short notice like this
314when it starts in an interactive mode:
315
316 Gnomovision version 69, Copyright (C) year name of author
317 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318 This is free software, and you are welcome to redistribute it
319 under certain conditions; type `show c' for details.
320
321The hypothetical commands `show w' and `show c' should show the appropriate
322parts of the General Public License. Of course, the commands you use may
323be called something other than `show w' and `show c'; they could even be
324mouse-clicks or menu items--whatever suits your program.
325
326You should also get your employer (if you work as a programmer) or your
327school, if any, to sign a "copyright disclaimer" for the program, if
328necessary. Here is a sample; alter the names:
329
330 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331 `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
333 <signature of Ty Coon>, 1 April 1989
334 Ty Coon, President of Vice
335
336This General Public License does not permit incorporating your program into
337proprietary programs. If your program is a subroutine library, you may
338consider it more useful to permit linking proprietary applications with the
339library. If this is what you want to do, use the GNU Library General
340Public License instead of this License.
port/NEWS
(0 / 8)
  
11
2
3* Add tarball.py
4* Add json import wrapper
5* Add object chooser
6* Add activity classes
7* Add pixbuf methods
8* Add TempoSlider and ScrolledBox widgets
port/README
(0 / 13)
  
1About
2-----
3
4A set of sugar components/libraries/etc to simplify writing activities.
5
6Cornerstone purposes for this project:
7* Total backwards compatibility for sugar-port API
8* Run on all sugar platforms beginning from 0.82
9
10Get it
11------
12
13http://wiki.sugarlabs.org/go/Development_Team/sugar-port
  
1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program; if not, write to the Free Software
13# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14
15"""Extend sugar-toolkit activity class"""
16
17import gtk
18import logging
19import telepathy
20
21import sugar.activity.activity as toolkit
22from sugar.presence.sugartubeconn import SugarTubeConnection
23from sugar.graphics.alert import ConfirmationAlert, NotifyAlert
24
25_NEW_INSTANCE = 0
26_NEW_INSTANCE = 1
27_PRE_INSTANCE = 2
28_POST_INSTANCE = 3
29
30class Activity(toolkit.Activity):
31 """Basic activity class"""
32
33 def new_instance(self):
34 """
35 New instance was created.
36
37 Will be invoked after __init__() instead of resume_instance().
38 Subclass should implement this method to catch creation stage.
39 """
40 pass
41
42 def resume_instance(self, filepath):
43 """
44 Instance was resumed.
45
46 Will be invoked after __init__() instead of new_instance().
47 Subclass should implement this method to catch resuming stage.
48
49 """
50 pass
51
52 def save_instance(self, filepath):
53 """
54 Save activity instance.
55
56 Subclass should implement this method to save activity data.
57 """
58 raise NotImplementedError
59
60 def share_instance(self, connection, is_initiator):
61 """
62 Activity was shared/joined.
63
64 connection -- SugarTubeConnection object
65 wich represents telepathy connection
66
67 is_initiator -- boolean
68 if True activity was shared and
69 (current activity is an initiator of sharing)
70 otherwise activity was joined(to existed sharing session)
71
72 Will be invoked after __init__() and {new,resume}_instance().
73 Subclass should implement this method to catch sharing stage.
74 """
75 pass
76
77 def notify_alert(self, title, msg):
78 """Raise standard notify alert"""
79 alert = NotifyAlert(title=title, msg=msg)
80
81 def response(alert, response_id, self):
82 self.remove_alert(alert)
83
84 alert.connect('response', response, self)
85 alert.show_all()
86 self.add_alert(alert)
87
88 def confirmation_alert(self, title, msg, cb, *cb_args):
89 """Raise standard confirmation alert"""
90 alert = ConfirmationAlert(title=title, msg=msg)
91
92 def response(alert, response_id, self, cb, *cb_args):
93 self.remove_alert(alert)
94 if response_id is gtk.RESPONSE_OK:
95 cb(*cb_args)
96
97 alert.connect('response', response, self, cb, *cb_args)
98 alert.show_all()
99 self.add_alert(alert)
100
101 def __init__(self, canvas, handle):
102 """
103 Initialise the Activity.
104
105 canvas -- gtk.Widget
106 root widget for activity content
107
108 handle -- sugar.activity.activityhandle.ActivityHandle
109 instance providing the activity id and access to the
110 presence service which *may* provide sharing for this
111 application
112
113 """
114 toolkit.Activity.__init__(self, handle)
115
116 if handle.object_id:
117 self.__state = _NEW_INSTANCE
118 else:
119 self.__state = _NEW_INSTANCE
120
121 self.__resume_filename = None
122 self.__postponed_share = []
123
124 # XXX do it after(possible) read_file() invoking
125 # have to rely on calling read_file() from map_cb in sugar-toolkit
126 canvas.connect_after('map', self.__map_canvasactivity_cb)
127 self.set_canvas(canvas)
128
129 def __instance(self):
130 logging.debug('Activity.__instance')
131
132 if self.__resume_filename:
133 self.resume_instance(self.__resume_filename)
134 else:
135 self.new_instance()
136
137 for i in self.__postponed_share:
138 self.share_instance(*i)
139 self.__postponed_share = []
140
141 self.__state = _POST_INSTANCE
142
143 def read_file(self, filepath):
144 """Subclass should not override this method"""
145 logging.debug('Activity.read_file state=%s' % self.__state)
146
147 self.__resume_filename = filepath
148
149 if self.__state == _NEW_INSTANCE:
150 self.__state = _PRE_INSTANCE
151 elif self.__state == _PRE_INSTANCE:
152 self.__instance();
153
154 def write_file(self, filepath):
155 """Subclass should not override this method"""
156 self.save_instance(filepath)
157
158 def __map_canvasactivity_cb(self, widget):
159 logging.debug('Activity.__map_canvasactivity_cb state=%s' % \
160 self.__state)
161
162 if self.__state == _NEW_INSTANCE:
163 self.__instance()
164 elif self.__state == _NEW_INSTANCE:
165 self.__state = _PRE_INSTANCE
166 elif self.__state == _PRE_INSTANCE:
167 self.__instance();
168
169 return False
170
171 def _share(self, tube_conn, initiator):
172 logging.debug('Activity._share state=%s' % self.__state)
173
174 if self.__state == _NEW_INSTANCE:
175 self.__postponed_share.append((tube_conn, initiator))
176 self.__state = _PRE_INSTANCE
177 elif self.__state == _PRE_INSTANCE:
178 self.__postponed_share.append((tube_conn, initiator))
179 self.__instance();
180 elif self.__state == _POST_INSTANCE:
181 self.share_instance(tube_conn, initiator)
182
183class SharedActivity(Activity):
184 """Basic activity class with sharing features"""
185
186 def __init__(self, canvas, service, handle):
187 """
188 Initialise the Activity.
189
190 canvas -- gtk.Widget
191 root widget for activity content
192
193 service -- string
194 dbus service for activity
195
196 handle -- sugar.activity.activityhandle.ActivityHandle
197 instance providing the activity id and access to the
198 presence service which *may* provide sharing for this
199 application
200
201 """
202 Activity.__init__(self, canvas, handle)
203 self.service = service
204
205 self.connect('shared', self._shared_cb)
206
207 # Owner.props.key
208 if self._shared_activity:
209 # We are joining the activity
210 self.connect('joined', self._joined_cb)
211 if self.get_shared():
212 # We've already joined
213 self._joined_cb()
214
215 def _shared_cb(self, activity):
216 logging.debug('My activity was shared')
217 self.__initiator = True
218 self._sharing_setup()
219
220 logging.debug('This is my activity: making a tube...')
221 id = self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(
222 self.service, {})
223
224 def _joined_cb(self, activity):
225 if not self._shared_activity:
226 return
227
228 logging.debug('Joined an existing shared activity')
229
230 self.__initiator = False
231 self._sharing_setup()
232
233 logging.debug('This is not my activity: waiting for a tube...')
234 self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES].ListTubes(
235 reply_handler=self._list_tubes_reply_cb,
236 error_handler=self._list_tubes_error_cb)
237
238 def _sharing_setup(self):
239 if self._shared_activity is None:
240 logging.error('Failed to share or join activity')
241 return
242 self._conn = self._shared_activity.telepathy_conn
243 self._tubes_chan = self._shared_activity.telepathy_tubes_chan
244 self._text_chan = self._shared_activity.telepathy_text_chan
245
246 self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal(
247 'NewTube', self._new_tube_cb)
248
249 def _list_tubes_reply_cb(self, tubes):
250 for tube_info in tubes:
251 self._new_tube_cb(*tube_info)
252
253 def _list_tubes_error_cb(self, e):
254 logging.error('ListTubes() failed: %s', e)
255
256 def _new_tube_cb(self, id, initiator, type, service, params, state):
257 logging.debug('New tube: ID=%d initator=%d type=%d service=%s '
258 'params=%r state=%d', id, initiator, type, service,
259 params, state)
260
261 if (type == telepathy.TUBE_TYPE_DBUS and
262 service == self.service):
263 if state == telepathy.TUBE_STATE_LOCAL_PENDING:
264 self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES] \
265 .AcceptDBusTube(id)
266
267 tube_conn = SugarTubeConnection(self._conn,
268 self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES], id,
269 group_iface=self._text_chan[telepathy.CHANNEL_INTERFACE_GROUP])
270
271 self._share(tube_conn, self.__initiator)
  
1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program; if not, write to the Free Software
13# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14
15"""Object chooser method"""
16
17import gtk
18import logging
19
20from sugar import mime
21from sugar.graphics.objectchooser import ObjectChooser
22
23TEXT = hasattr(mime, 'GENERIC_TYPE_TEXT') and mime.GENERIC_TYPE_TEXT or None
24IMAGE = hasattr(mime, 'GENERIC_TYPE_IMAGE') and mime.GENERIC_TYPE_IMAGE or None
25AUDIO = hasattr(mime, 'GENERIC_TYPE_AUDIO') and mime.GENERIC_TYPE_AUDIO or None
26VIDEO = hasattr(mime, 'GENERIC_TYPE_VIDEO') and mime.GENERIC_TYPE_VIDEO or None
27LINK = hasattr(mime, 'GENERIC_TYPE_LINK') and mime.GENERIC_TYPE_LINK or None
28
29def pick(cb=None, default=None, parent=None, what=None):
30 """
31 Opens object chooser.
32
33 Method returns:
34
35 * cb(jobject), if object was choosen and cb is not None
36 * jobject, if object was choosen and cb is None
37 * None, otherwise
38
39 NOTE: what make sense only for sugar >= 0.84
40 """
41 what = what and {'what_filter': what} or {}
42 chooser = ObjectChooser(parent=parent, **what)
43
44 jobject = None
45 out = None
46
47 try:
48 if chooser.run() == gtk.RESPONSE_ACCEPT:
49 jobject = chooser.get_selected_object()
50 logging.debug('ObjectChooser: %r' % jobject)
51
52 if jobject and jobject.file_path:
53 if cb:
54 out = cb(jobject)
55 else:
56 out = jobject
57 finally:
58 if jobject and id(jobject) != id(out):
59 jobject.destroy()
60 chooser.destroy()
61 del chooser
62
63 if out:
64 return out
65 else:
66 return default
port/epydoc
(0 / 21)
  
1[epydoc]
2
3modules: *.py
4output: html
5target: html/
6verbosity: 0
7debug: 0
8
9# Generation options
10docformat: epytext
11parse: yes
12introspect: no
13inheritance: listed
14private: no
15imports: no
16sourcecode: yes
17
18# Output options
19name: sugar-port
20url: http://wiki.sugarlabs.org/go/Development_Team/sugar-port
21frames: yes
  
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14576) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="50px" height="50px" viewBox="0 0 50 50" enable-background="new 0 0 50 50" xml:space="preserve">
6<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M23.5,6.5c3,3,7,7,9,11c-7,5-4,6-3,26c-1,1-8,1-9,0c0,0,2,1,2-1
7 c0-3-2-7-2-11c0-2,1-4,1-6c0-3-2-1-2-3c0-3,3-8,3-11c0-2-1-1-2-2v-3H23.5z"/>
8</svg>
  
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14576) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="50px" height="50px" viewBox="0 0 50 50" enable-background="new 0 0 50 50" xml:space="preserve">
6<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M27.5,44.5v-3C28.5,42.5,28.5,43.5,27.5,44.5z M26.5,10.5
7 c2,2,2,6,2,8c0,4-3,11-3,13s4,7,7,10c-2,2-4,3-5,5h-6c1-1,2-3,2-5c0-3-2-9-3-14c0,0,0-1-1,0v-6c0-3,3-8,3-11c0-1-2-2-2-6h3
8 C23.5,5.5,26.5,9.5,26.5,10.5z"/>
9</svg>
  
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14576) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="50px" height="50px" viewBox="0 0 50 50" enable-background="new 0 0 50 50" xml:space="preserve">
6<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M30.5,17.5c0,3-2,2-2,4c0,3,4,14,7,21c-1,0-3,1-5,1c1-1,2,0,2-3
7 c0-2-4-7-6-10c-3,3-5,8-7,13c-1,0-3-1-4-1c3-3,7-14,7-18s-1-3-4-4c3-2,4-8,4-14h3C23.5,9.5,30.5,14.5,30.5,17.5z"/>
8</svg>
  
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14576) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="50px" height="50px" viewBox="0 0 50 50" enable-background="new 0 0 50 50" xml:space="preserve">
6<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M34.5,22.5c-1-1-2-4-5-6c-1,2,0,3,0,6c0,2-3,4-3,7c0,2,4,2,4,4
7 c0,3-1,4-2,5c0-1,0-3-1-4c-1,3-2,7-3,10c-4-3,0-6,0-9s-3-11-4-17l-4,4c1-5,8.25-11.12,7.25-16.12c0.68,0.68,3.029,0,2.87,2.12
8 C26.5,10.25,33.62,17.75,34.5,22.5z"/>
9</svg>
  
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14576) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="50px" height="50px" viewBox="0 0 50 50" enable-background="new 0 0 50 50" xml:space="preserve">
6<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M24.5,13.5c2,1,5,3,5,6c0,2-2,3-2,5c0,9,11,4,11,13c-1,0-3-2-4-3
7 c-3-1-9,1-10-3c-2,3-5,7-7,11c-3,0-3-1-4-1c0-2,3-3,4-6s4-8,4-10c0-3-1-3-2-5c-1,0-2,1-3,2c0-1,2-3,2-4c1-2,3-5,2-8c0,0,1-1,4-2
8 C25.5,9.5,25.5,11.5,24.5,13.5z"/>
9</svg>
  
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14576) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="50px" height="50px" viewBox="0 0 50 50" enable-background="new 0 0 50 50" xml:space="preserve">
6<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M22.5,10.5c3,2,7,5,7,7c0,3-4,8-4,10c0,3,1,3,1,5h5l2-2l2,2v4
7 c-1,0-3-2-5-2c-3,0-5,1-8,1c-1,3-2,7-2,10h-5c1-1,3-3,3-4c1-5,1-11,1-18l-1-1c-1,1-1.75,2.88-2.75,2.88c0,0-0.25-0.63-0.25-1.63
8 c4-4,2-8.25,2-13.25c0-1,0.25-2.5,0.38-5.38L22.5,5.5C23.12,6.5,22.5,8.5,22.5,10.5z"/>
9<polygon fill-rule="evenodd" clip-rule="evenodd" fill="#333333" stroke="#333333" stroke-linecap="round" stroke-linejoin="round" points="
10 25,20 25.25,16.75 26.5,17.88 "/>
11</svg>
  
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14576) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="50px" height="50px" viewBox="0 0 50 50" enable-background="new 0 0 50 50" xml:space="preserve">
6<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M20.5,7.5c1,1,1,3,1,4c10,4,8,6,8,14c0,2,6,9,10,13c-1,2-2,4-4,5
7 c1.62-8.88-8.75-13.88-12-15c-1,1-1,0-1,2c0,3,2,5,3,7c-1,1-3,2-6,2c0-1,2-1,2-4c0-2-4-4-4-6c0-3,3-4,5-6c-3-8-8-2-11-6h6
8 c0-1,1,0,1-3c0-2-1-1-2-2l1-5H20.5z"/>
9</svg>
  
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14576) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="50px" height="50px" viewBox="0 0 50 50" enable-background="new 0 0 50 50" xml:space="preserve">
6<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M20.5,12.5c0.67,0.4,0.4,1.9,1.75,2.25s1.05-0.38,1.5-0.37
7 c4.971,0,10.95-0.88,11.75,7.12c-1-2-3-4-5-5l-4,1c1,2,4,4,5,7c1,1,1,4,1,6c3,3,8-1,11,6c-2.88-0.82-4.25-2.62-12.75-2.75
8 c-1.561-0.02-2.34-1.561-3.75-1.87c-3.42-0.76-4.67-0.38-5.5-0.38c-3,0-8,7-11,7c-2,0-3-1-3-2c4,2,8-4,9-7c2-1,5-1,8-3c-2-4-6-5-8-3
9 l-6-6l2-2c1,1,1,2,1,4c1,0,4.12,0.38,6.12-0.62L16.5,17.5v-5H20.5z"/>
10</svg>
port/json.py
(0 / 33)
  
1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program; if not, write to the Free Software
13# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14
15"""
16Unify usage of simplejson in Python 2.5/2.6
17
18In Python 2.5 it imports simplejson module, in 2.6 native json module.
19
20Usage:
21
22 import port.json as json
23
24 # and using regular simplejson interface with module json
25 json.dumps([])
26
27"""
28
29try:
30 from json import *
31 dumps
32except (ImportError, NameError):
33 from simplejson import *
  
1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program; if not, write to the Free Software
13# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14
15"""gtk.gdk.Pixbuf extensions"""
16
17import os
18import cStringIO
19import tempfile
20import gtk
21
22def to_file(pixbuf):
23 """Convert pixbuf object to file object"""
24
25 def push(pixbuf, buffer):
26 buffer.write(pixbuf)
27
28 buffer = cStringIO.StringIO()
29 pixbuf.save_to_callback(push, 'png', user_data=buffer)
30 buffer.seek(0)
31
32 return buffer
33
34def to_str(pixbuf):
35 """Convert pixbuf object to string"""
36 return to_file(pixbuf).getvalue()
37
38def from_str(str):
39 """Convert string to pixbuf object"""
40
41 file_d, path = tempfile.mkstemp()
42
43 file_o = os.fdopen(file_d, 'w')
44 file_o.write(str)
45 file_o.close()
46
47 out = gtk.gdk.pixbuf_new_from_file(path)
48 os.unlink(path)
49
50 return out
  
1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program; if not, write to the Free Software
13# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14
15import gtk
16
17from sugar.graphics.icon import Icon
18
19class ScrollButton(gtk.ToolButton):
20 def __init__(self, icon_name):
21 gtk.ToolButton.__init__(self)
22
23 icon = Icon(icon_name = icon_name,
24 icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR)
25 # The alignment is a hack to work around gtk.ToolButton code
26 # that sets the icon_size when the icon_widget is a gtk.Image
27 alignment = gtk.Alignment(0.5, 0.5)
28 alignment.add(icon)
29 self.set_icon_widget(alignment)
30
31class ScrolledBox(gtk.EventBox):
32 def __init__(self, orientation, arrows_policy = gtk.POLICY_AUTOMATIC):
33 gtk.EventBox.__init__(self)
34 self.orientation = orientation
35 self._viewport = None
36 self._abox = None
37 self._aviewport = None
38 self._aviewport_sig = None
39 self._arrows_policy = arrows_policy
40 self._left = None
41 self._right = None
42
43 if orientation == gtk.ORIENTATION_HORIZONTAL:
44 box = gtk.HBox()
45 else:
46 box = gtk.VBox()
47 if self._arrows_policy == gtk.POLICY_AUTOMATIC:
48 box.connect("size-allocate", self._box_allocate_cb)
49 self.add(box)
50
51 if self._arrows_policy != gtk.POLICY_NEVER:
52 if orientation == gtk.ORIENTATION_HORIZONTAL:
53 self._left = ScrollButton('go-left')
54 else:
55 self._left = ScrollButton('go-up')
56 self._left.connect('clicked', self._scroll_cb, 'left')
57 box.pack_start(self._left, False, False, 0)
58
59 self._scrolled = gtk.ScrolledWindow()
60 if orientation == gtk.ORIENTATION_HORIZONTAL:
61 self._scrolled.set_policy(arrows_policy, gtk.POLICY_NEVER)
62 else:
63 self._scrolled.set_policy(gtk.POLICY_NEVER, arrows_policy)
64 self._scrolled.connect('scroll-event', self._scroll_event_cb)
65 box.pack_start(self._scrolled, True, True, 0)
66
67 if orientation == gtk.ORIENTATION_HORIZONTAL:
68 self._adj = self._scrolled.get_hadjustment()
69 else:
70 self._adj = self._scrolled.get_vadjustment()
71 self._adj.connect('changed', self._scroll_changed_cb)
72 self._adj.connect('value-changed', self._scroll_changed_cb)
73
74 if self._arrows_policy != gtk.POLICY_NEVER:
75 if orientation == gtk.ORIENTATION_HORIZONTAL:
76 self._right = ScrollButton('go-right')
77 else:
78 self._right = ScrollButton('go-down')
79 self._right.connect('clicked', self._scroll_cb, 'right')
80 box.pack_start(self._right, False, False, 0)
81
82 def modify_fg(self, state, bg):
83 gtk.EventBox.modify_fg(self, state, bg)
84 self._viewport.get_parent().modify_fg(state, bg)
85
86 def modify_bg(self, state, bg):
87 gtk.EventBox.modify_bg(self, state, bg)
88 self._viewport.get_parent().modify_bg(state, bg)
89
90 def set_viewport(self, widget):
91 if widget == self._viewport: return
92 if self._viewport and self._aviewport_sig:
93 self._viewport.disconnect(self._aviewport_sig)
94 self._viewport = widget
95
96 if self._arrows_policy == gtk.POLICY_AUTOMATIC:
97 self._aviewport_sig = self._viewport.connect('size-allocate',
98 self._viewport_allocate_cb)
99
100 self._scrolled.add_with_viewport(widget)
101
102 def get_viewport_allocation(self):
103 alloc = self._scrolled.get_allocation()
104 alloc.x -= self._adj.get_value()
105 return alloc
106
107 def get_adjustment(self):
108 return self._adj
109
110 def _box_allocate_cb(self, w, a):
111 self._abox = a
112 self._update_arrows()
113
114 def _viewport_allocate_cb(self, w, a):
115 self._aviewport = a
116 self._update_arrows()
117
118 def _update_arrows(self):
119 if not self._abox or not self._aviewport: return
120
121 if self.orientation == gtk.ORIENTATION_HORIZONTAL:
122 show_flag = self._abox.width < self._aviewport.width
123 else:
124 show_flag = self._abox.height < self._aviewport.height
125
126 if show_flag:
127 self._left.show()
128 self._right.show()
129 else:
130 self._left.hide()
131 self._right.hide()
132
133 def _scroll_event_cb(self, widget, event):
134 if self.orientation == gtk.ORIENTATION_HORIZONTAL:
135 if event.direction == gtk.gdk.SCROLL_UP:
136 event.direction = gtk.gdk.SCROLL_LEFT
137 if event.direction == gtk.gdk.SCROLL_DOWN:
138 event.direction = gtk.gdk.SCROLL_RIGHT
139 else:
140 if event.direction == gtk.gdk.SCROLL_LEFT:
141 event.direction = gtk.gdk.SCROLL_UP
142 if event.direction == gtk.gdk.SCROLL_RIGHT:
143 event.direction = gtk.gdk.SCROLL_DOWN
144 return False
145
146 def _scroll_cb(self, widget, data):
147 if data == 'left':
148 val = max(self._adj.get_property('lower'), self._adj.get_value()
149 - self._adj.get_property('page_increment'))
150 else:
151 val = min(self._adj.get_property('upper')
152 - self._adj.get_property('page_size'),
153 self._adj.get_value()
154 + self._adj.get_property('page_increment'))
155
156 self._adj.set_value(val)
157
158 def _scroll_changed_cb(self, widget):
159 val = self._adj.get_value()
160 if self._left:
161 if val == 0:
162 self._left.set_sensitive(False)
163 else:
164 self._left.set_sensitive(True)
165
166 if self._right:
167 if val >= self._adj.get_property('upper') - \
168 self._adj.get_property('page_size'):
169 self._right.set_sensitive(False)
170 else:
171 self._right.set_sensitive(True)
172
173class HScrolledBox(ScrolledBox):
174 def __init__(self, *args):
175 ScrolledBox.__init__(self, gtk.ORIENTATION_HORIZONTAL, *args)
176
177class VScrolledBox(ScrolledBox):
178 def __init__(self, *args):
179 ScrolledBox.__init__(self, gtk.ORIENTATION_VERTICAL, *args)
  
1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program; if not, write to the Free Software
13# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14
15"""Simplify tarfile module usage"""
16
17import os
18import time
19import tarfile
20import cStringIO
21import gtk
22import zipfile
23import tempfile
24import shutil
25
26import port.pixbuf as pixbuf
27
28class TarballError(Exception):
29 """Base Tarball exception."""
30 pass
31
32class BadDataTypeError(TarballError):
33 """Exception for unsupported data type in read/write methods."""
34 pass
35
36class Tarball:
37 """
38 Wrap standart tarfile module to simplify read/write operations with
39 most popular data types.
40
41 In read mode Tarball can load zip files as well.
42
43 Supprted types:
44
45 * string
46 * gtk.gdk.Pixbuf
47
48 Write usage:
49
50 # create Tarball object
51 # to see all supported modes use
52 # http://docs.python.org/library/tarfile.html#tarfile.open
53 tar = Tarball(tarfile, 'w')
54
55 # write string to file in tarball
56 tar.write('name within tarball', 'string to write')
57
58 # write pixbuf to file in tarball
59 tar.write('name within tarball', pixbuf_object)
60
61 # save and close tarball file
62 tar.close()
63
64 Read usage:
65
66 # create Tarball object
67 tar = Tarball(tarfile)
68
69 # read content of file in tarball to string
70 str_content = tar.read('name within tarball')
71
72 # read content of file in tarball to pixbuf object
73 pixbuf_content = tar.read_pixbuf('name within tarball')
74 """
75
76 def __init__(self, name=None, mode='r', mtime=None):
77 if not mode.startswith('r') or tarfile.is_tarfile(name):
78 self.__tar = tarfile.TarFile(name=name, mode=mode)
79 else:
80 # convert for tar
81
82 if not zipfile.is_zipfile(name):
83 raise tarfile.ReadError()
84
85 try:
86 tmp_dir = tempfile.mkdtemp()
87 tmp_fd, tmp_name = tempfile.mkstemp()
88 tmp_fo = os.fdopen(tmp_fd, 'w')
89
90 zip = zipfile.ZipFile(name)
91 zip.extractall(tmp_dir)
92
93 tar = tarfile.TarFile(fileobj=tmp_fo, mode='w')
94 tar.add(tmp_dir, arcname='')
95 tar.close()
96
97 self.__tar = tarfile.TarFile(name=tmp_name, mode=mode)
98 finally:
99 tmp_fo.close()
100 os.unlink(tmp_name)
101 shutil.rmtree(tmp_dir)
102
103 if mtime:
104 self.mtime = mtime
105 else:
106 self.mtime = time.time()
107
108 def close(self):
109 """Save(if 'r' mode was given) and close tarball file."""
110 self.__tar.close()
111
112 def getnames(self):
113 """Return names of members sorted by creation order."""
114 return self.__tar.getnames()
115
116 def read(self, arcname):
117 """Returns sring with content of given file from tarball."""
118 file_o = self.__tar.extractfile(arcname.encode('utf8'))
119 if not file_o:
120 return None
121 out = file_o.read()
122 file_o.close()
123 return out
124
125 def read_pixbuf(self, arcname):
126 """Returns pixbuf object of given file from tarball."""
127 return pixbuf.from_str(self.read(arcname))
128
129 def write(self, arcname, data, mode=0644):
130 """
131 Stores given object to file in tarball.
132 Raises BadDataTypeError exception If data type isn't supported.
133 """
134 info = tarfile.TarInfo(arcname.encode('utf8'))
135 info.mode = mode
136 info.mtime = self.mtime
137
138 if isinstance(data, str):
139 self.__write_str(info, data)
140 elif isinstance(data, gtk.gdk.Pixbuf):
141 self.__write_pixbuf(info, data)
142 else:
143 raise BadDataTypeError()
144
145 def __write_str(self, info, data):
146 info.size = len(data)
147 self.__tar.addfile(info, cStringIO.StringIO(data))
148
149 def __write_pixbuf(self, info, data):
150 buffer = pixbuf.to_file(data)
151 buffer.seek(0, os.SEEK_END)
152 info.size = buffer.tell()
153 buffer.seek(0)
154 self.__tar.addfile(info, buffer)
  
1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program; if not, write to the Free Software
13# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14
15import os
16import gtk
17
18from sugar.graphics import style
19
20class TempoSlider(gtk.HBox):
21 def __init__(self, min_value, max_value):
22 gtk.HBox.__init__(self)
23
24 self._pixbuf = [None] * 8
25 self._image = gtk.Image()
26 self._image.show()
27
28 # used to store tempo updates while the slider is active
29 self._delayed = 0
30 self._active = False
31
32 self.adjustment = gtk.Adjustment(min_value, min_value, max_value,
33 (max_value - min_value) / 8, (max_value - min_value) / 8, 0)
34 self._adjustment_h = self.adjustment.connect('value-changed',
35 self._changed_cb)
36
37 slider = gtk.HScale(adjustment = self.adjustment)
38 slider.show()
39 slider.set_draw_value(False)
40 slider.connect("button-press-event", self._press_cb)
41 slider.connect("button-release-event", self._release_cb)
42
43 self.pack_start(slider, True, True)
44 self.pack_end(self._image, False, False)
45
46 def set_value(self, tempo, quiet = False):
47 if self._active:
48 self._delayed = tempo
49 elif quiet:
50 self.adjustment.handler_block(self._adjustment_h)
51 self.adjustment.set_value(tempo)
52 self._update(tempo)
53 self.adjustment.handler_unblock(self._adjustment_h)
54 else:
55 self.adjustment.set_value(tempo)
56
57 def _changed_cb(self, widget):
58 self._update(widget.get_value())
59
60 def _update(self, tempo):
61 def map_range(value, ilower, iupper, olower, oupper):
62 if value == iupper:
63 return oupper
64 return olower + int((oupper-olower+1) * (value-ilower) /
65 float(iupper-ilower))
66
67 img = map_range(tempo, self.adjustment.lower,
68 self.adjustment.upper, 0, 7)
69
70 if not self._pixbuf[img]:
71 self._pixbuf[img] = gtk.gdk.pixbuf_new_from_file_at_size(
72 os.path.join(os.path.dirname(__file__), 'images',
73 'tempo' + str(img+1) + '.svg'),
74 style.STANDARD_ICON_SIZE, style.STANDARD_ICON_SIZE)
75
76 self._image.set_from_pixbuf(self._pixbuf[img])
77
78 def _press_cb(self, widget, event):
79 self._active = True
80
81 def _release_cb(self, widget, event):
82 self._active = False
83 if self._delayed != 0:
84 self.set_value(self._delayed, True)
85 self._delayed = 0