From 328a762d4d495ddfc7c9c51c8687aacc1a253c1d Mon Sep 17 00:00:00 2001
From: Gonzalo Odiard <godiard@sugarlabs.org>
Date: Tue, 26 Oct 2010 09:01:50 -0300
Subject: [PATCH 4/8] make AbiWordActivity pep8 complaint
---
AbiWordActivity.py | 125 +++++++++++++++++++++++++++++++++++-----------------
1 files changed, 84 insertions(+), 41 deletions(-)
diff --git a/AbiWordActivity.py b/AbiWordActivity.py
index 5275a2c..555f76a 100644
a
|
b
|
from widgets import ExportButton |
53 | 53 | |
54 | 54 | logger = logging.getLogger('write-activity') |
55 | 55 | |
56 | | class AbiWordActivity (activity.Activity): |
57 | 56 | |
58 | | def __init__ (self, handle): |
59 | | activity.Activity.__init__ (self, handle) |
| 57 | class AbiWordActivity(activity.Activity): |
| 58 | |
| 59 | def __init__(self, handle): |
| 60 | activity.Activity.__init__(self, handle) |
60 | 61 | |
61 | 62 | # abiword uses the current directory for all its file dialogs |
62 | 63 | os.chdir(os.path.expanduser('~')) |
… |
… |
class AbiWordActivity (activity.Activity): |
173 | 174 | self.abiword_canvas.connect_after('map-event', self.__map_event_cb) |
174 | 175 | self.abiword_canvas.show() |
175 | 176 | |
176 | | self._zoom_handler = self.abiword_canvas.connect("zoom", self.__zoom_cb) |
| 177 | self._zoom_handler = self.abiword_canvas.connect('zoom', |
| 178 | self.__zoom_cb) |
177 | 179 | |
178 | 180 | def _image_selected(self, button): |
179 | 181 | self._insert_toolbar.props.page.enable_table_button(False) |
… |
… |
class AbiWordActivity (activity.Activity): |
195 | 197 | def __zoom_cb(self, abi, zoom): |
196 | 198 | abi.disconnect(self._zoom_handler) |
197 | 199 | |
198 | | # XXX workarond code to redraw abi document on every resize, see #1121 |
| 200 | # XXX workarond code to redraw abi document on every resize, |
| 201 | # see #1121 |
199 | 202 | # looks like original #1121 issue is already not reproducible in |
200 | 203 | # environments like fc13 but we still need it for older ones |
| 204 | |
201 | 205 | def size_allocate_cb(abi, alloc): |
| 206 | |
202 | 207 | def idle_cb(): |
203 | 208 | zoom = abi.get_zoom_percentage() |
204 | 209 | abi.set_zoom_percentage(zoom) |
| 210 | |
205 | 211 | gobject.idle_add(idle_cb) |
206 | 212 | abi.connect('size-allocate', size_allocate_cb) |
207 | 213 | |
… |
… |
class AbiWordActivity (activity.Activity): |
209 | 215 | logger.debug('__map_event_cb') |
210 | 216 | |
211 | 217 | # set custom keybindings for Write |
212 | | logger.debug("Loading keybindings") |
213 | | keybindings_file = os.path.join( get_bundle_path(), "keybindings.xml" ) |
| 218 | logger.debug('Loading keybindings') |
| 219 | keybindings_file = os.path.join(get_bundle_path(), 'keybindings.xml') |
214 | 220 | self.abiword_canvas.invoke_cmd( |
215 | 221 | 'com.abisource.abiword.loadbindings.fromURI', |
216 | 222 | keybindings_file, 0, 0) |
217 | 223 | |
218 | 224 | # no ugly borders please |
219 | | self.abiword_canvas.set_property("shadow-type", gtk.SHADOW_NONE) |
| 225 | self.abiword_canvas.set_property('shadow-type', gtk.SHADOW_NONE) |
220 | 226 | |
221 | 227 | # we only do per-word selections (when using the mouse) |
222 | 228 | self.abiword_canvas.set_word_selections(True) |
… |
… |
class AbiWordActivity (activity.Activity): |
240 | 246 | # we are joining the activity |
241 | 247 | logger.debug("We are joining an activity") |
242 | 248 | self.connect('joined', self._joined_cb) |
243 | | self._shared_activity.connect('buddy-joined', self._buddy_joined_cb) |
| 249 | self._shared_activity.connect('buddy-joined', |
| 250 | self._buddy_joined_cb) |
244 | 251 | self._shared_activity.connect('buddy-left', self._buddy_left_cb) |
245 | 252 | if self.get_shared(): |
246 | | # # oh, OK, we've already joined |
| 253 | # oh, OK, we've already joined |
247 | 254 | self._joined_cb() |
248 | 255 | else: |
249 | 256 | # we are creating the activity |
… |
… |
class AbiWordActivity (activity.Activity): |
260 | 267 | gtk.gdk.INTERP_BILINEAR) |
261 | 268 | |
262 | 269 | preview_data = [] |
| 270 | |
263 | 271 | def save_func(buf, data): |
264 | 272 | data.append(buf) |
265 | 273 | |
… |
… |
class AbiWordActivity (activity.Activity): |
279 | 287 | logger.debug('This is my activity: offering a tube...') |
280 | 288 | id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube( |
281 | 289 | "com.abisource.abiword.abicollab", {}) |
282 | | logger.debug('Tube address: %s', self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusTubeAddress(id)) |
283 | | |
| 290 | logger.debug('Tube address: %s', \ |
| 291 | self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusTubeAddress(id)) |
284 | 292 | |
285 | 293 | def _setup(self): |
286 | 294 | logger.debug("_setup()") |
… |
… |
class AbiWordActivity (activity.Activity): |
289 | 297 | logger.error('Failed to share or join activity') |
290 | 298 | return |
291 | 299 | |
292 | | bus_name, conn_path, channel_paths = self._shared_activity.get_channels() |
| 300 | bus_name, conn_path, channel_paths = \ |
| 301 | self._shared_activity.get_channels() |
293 | 302 | |
294 | 303 | # Work out what our room is called and whether we have Tubes already |
295 | 304 | room = None |
… |
… |
class AbiWordActivity (activity.Activity): |
319 | 328 | |
320 | 329 | # Make sure we have a Tubes channel - PS doesn't yet provide one |
321 | 330 | if tubes_chan is None: |
322 | | logger.debug("Didn't find our Tubes negotation channel, requesting one...") |
323 | | tubes_chan = self.conn.request_channel(telepathy.CHANNEL_TYPE_TUBES, |
| 331 | logger.debug("Didn't find our Tubes negotation channel, " + |
| 332 | "requesting one...") |
| 333 | tubes_chan = \ |
| 334 | self.conn.request_channel(telepathy.CHANNEL_TYPE_TUBES, |
324 | 335 | telepathy.HANDLE_TYPE_ROOM, room, True) |
325 | 336 | logger.debug("Got our tubes negotiation channel") |
326 | 337 | |
… |
… |
class AbiWordActivity (activity.Activity): |
359 | 370 | if (type == telepathy.TUBE_TYPE_DBUS and |
360 | 371 | service == "com.abisource.abiword.abicollab"): |
361 | 372 | if state == telepathy.TUBE_STATE_LOCAL_PENDING: |
362 | | self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id) |
| 373 | tube = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES] |
| 374 | tube.AcceptDBusTube(id) |
363 | 375 | |
364 | 376 | initiator_path = None |
365 | | contacts = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusNames(id) |
366 | | #print 'dbus contact mapping',self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusNames(id) |
| 377 | contacts = \ |
| 378 | self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusNames(id) |
| 379 | # print 'dbus contact mapping', |
| 380 | # self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusNames(id) |
367 | 381 | for i, struct in enumerate(contacts): |
368 | 382 | #print 'mapping i',i |
369 | 383 | handle, path = struct |
… |
… |
class AbiWordActivity (activity.Activity): |
373 | 387 | break |
374 | 388 | |
375 | 389 | if initiator_path is None: |
376 | | logger.error('Unable to get the dbus path of the tube initiator') |
| 390 | logger.error('Unable to get the dbus path ' + |
| 391 | 'of the tube initiator') |
377 | 392 | else: |
378 | 393 | # pass this tube to abicollab |
379 | | address = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusTubeAddress(id) |
| 394 | tube = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES] |
| 395 | address = tube.GetDBusTubeAddress(id) |
380 | 396 | if self.joined: |
381 | | logger.debug('Passing tube address to abicollab (join): %s', address) |
382 | | self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.joinTube', address, 0, 0) |
| 397 | logger.debug('Passing tube address to abicollab ' + |
| 398 | '(join): %s', address) |
| 399 | self.abiword_canvas.invoke_cmd( \ |
| 400 | 'com.abisource.abiword.abicollab.olpc.joinTube', |
| 401 | address, 0, 0) |
383 | 402 | if initiator_path is not None: |
384 | | logger.debug('Adding the initiator to the session: %s', initiator_path) |
385 | | self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyJoined', initiator_path, 0, 0) |
| 403 | logger.debug('Adding the initiator ' + |
| 404 | 'to the session: %s', initiator_path) |
| 405 | self.abiword_canvas.invoke_cmd( \ |
| 406 | 'com.abisource.abiword.abicollab.olpc.buddyJoined', |
| 407 | initiator_path, 0, 0) |
386 | 408 | else: |
387 | | logger.debug('Passing tube address to abicollab (offer): %s', address) |
388 | | self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.offerTube', address, 0, 0) |
389 | | |
390 | | self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('DBusNamesChanged', |
| 409 | logger.debug('Passing tube address to abicollab ' + |
| 410 | '(offer): %s', address) |
| 411 | self.abiword_canvas.invoke_cmd( \ |
| 412 | 'com.abisource.abiword.abicollab.olpc.offerTube', |
| 413 | address, 0, 0) |
| 414 | |
| 415 | self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal( \ |
| 416 | 'DBusNamesChanged', |
391 | 417 | self._on_dbus_names_changed) |
392 | 418 | |
393 | 419 | # HACK, as DBusNamesChanged doesn't fire on buddies leaving |
394 | | self.tubes_chan[telepathy.CHANNEL_INTERFACE_GROUP].connect_to_signal('MembersChanged', |
| 420 | tube = self.tubes_chan[telepathy.CHANNEL_INTERFACE_GROUP] |
| 421 | tube.connect_to_signal('MembersChanged', |
395 | 422 | self._on_members_changed) |
396 | 423 | |
397 | 424 | def _on_dbus_names_changed(self, tube_id, added, removed): |
398 | 425 | logger.debug('_on_dbus_names_changed') |
399 | 426 | # if tube_id == self.tube_id: |
400 | 427 | for handle, bus_name in added: |
401 | | logger.debug('added handle: %s, with dbus_name: %s', handle, bus_name) |
402 | | self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyJoined', bus_name, 0, 0) |
| 428 | logger.debug('added handle: %s, with dbus_name: %s', |
| 429 | handle, bus_name) |
| 430 | self.abiword_canvas.invoke_cmd( \ |
| 431 | 'com.abisource.abiword.abicollab.olpc.buddyJoined', |
| 432 | bus_name, 0, 0) |
403 | 433 | self.participants[handle] = bus_name |
404 | 434 | |
405 | 435 | # if handle == self.self_handle: |
… |
… |
class AbiWordActivity (activity.Activity): |
411 | 441 | |
412 | 442 | # HACK: doesn't work yet, bad morgs! |
413 | 443 | # for handle in removed: |
414 | | # logger.debug('removed handle: %s, with dbus name: %s', handle, bus_name) |
| 444 | # logger.debug('removed handle: %s, with dbus name: %s', |
| 445 | # handle, bus_name) |
415 | 446 | # bus_name = self.participants.pop(handle, None) |
416 | 447 | |
417 | | def _on_members_changed(self, message, added, removed, local_pending, remote_pending, actor, reason): |
| 448 | def _on_members_changed(self, message, added, removed, local_pending, |
| 449 | remote_pending, actor, reason): |
418 | 450 | logger.debug("_on_members_changed") |
419 | 451 | for handle in removed: |
420 | 452 | bus_name = self.participants.pop(handle, None) |
… |
… |
class AbiWordActivity (activity.Activity): |
425 | 457 | |
426 | 458 | logger.debug('removed handle: %d, with dbus name: %s', handle, |
427 | 459 | bus_name) |
428 | | self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyLeft', bus_name, 0, 0) |
| 460 | self.abiword_canvas.invoke_cmd( \ |
| 461 | 'com.abisource.abiword.abicollab.olpc.buddyLeft', |
| 462 | bus_name, 0, 0) |
429 | 463 | |
430 | | def _buddy_joined_cb (self, activity, buddy): |
| 464 | def _buddy_joined_cb(self, activity, buddy): |
431 | 465 | logger.debug('buddy joined with object path: %s', buddy.object_path()) |
432 | | # self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyJoined', buddy.object_path(), 0, 0) |
| 466 | # self.abiword_canvas.invoke_cmd( |
| 467 | # 'com.abisource.abiword.abicollab.olpc.buddyJoined', |
| 468 | # buddy.object_path(), 0, 0) |
433 | 469 | |
434 | | def _buddy_left_cb (self, activity, buddy): |
| 470 | def _buddy_left_cb(self, activity, buddy): |
435 | 471 | logger.debug('buddy left with object path: %s', buddy.object_path()) |
436 | | #self.abiword_canvas.invoke_cmd('com.abisource.abiword.abicollab.olpc.buddyLeft', self.participants[buddy.object_path()], 0, 0) |
| 472 | # self.abiword_canvas.invoke_cmd( |
| 473 | # 'com.abisource.abiword.abicollab.olpc.buddyLeft', |
| 474 | # self.participants[buddy.object_path()], 0, 0) |
437 | 475 | |
438 | 476 | def read_file(self, file_path): |
439 | | logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', file_path, self.metadata['mime_type']) |
| 477 | logging.debug('AbiWordActivity.read_file: %s, mimetype: %s', |
| 478 | file_path, self.metadata['mime_type']) |
440 | 479 | |
441 | 480 | if self.metadata['mime_type'] in ['text/plain', 'text/csv']: |
442 | 481 | logging.debug('Opening file in text mode') |
443 | 482 | self.abiword_canvas.load_file('file://' + file_path, 'text/plain') |
444 | 483 | else: |
445 | | self.abiword_canvas.load_file('file://' + file_path, '') # we pass no mime/file type, let libabiword autodetect it, so we can handle multiple file formats |
| 484 | self.abiword_canvas.load_file('file://' + file_path, '') |
| 485 | # we pass no mime/file type, let libabiword autodetect it, |
| 486 | # so we can handle multiple file formats |
446 | 487 | |
447 | 488 | def write_file(self, file_path): |
448 | 489 | logging.debug('AbiWordActivity.write_file') |
… |
… |
class AbiWordActivity (activity.Activity): |
466 | 507 | |
467 | 508 | self.metadata['mime_type'] = actual_mimetype |
468 | 509 | |
469 | | self.metadata['fulltext'] = self.abiword_canvas.get_content(extension_or_mimetype=".txt")[:3000] |
| 510 | self.metadata['fulltext'] = \ |
| 511 | self.abiword_canvas.get_content(extension_or_mimetype=".txt")\ |
| 512 | [:3000] |
470 | 513 | self.abiword_canvas.save('file://' + file_path, actual_mimetype, '') |
471 | 514 | |
472 | 515 | def _change_file_ext(self, file_name, extension): |