Ticket #2479: 0004-make-AbiWordActivity-pep8-complaint.patch

File 0004-make-AbiWordActivity-pep8-complaint.patch, 13.5 KB (added by godiard, 13 years ago)
  • AbiWordActivity.py

    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 
    5353
    5454logger = logging.getLogger('write-activity')
    5555
    56 class AbiWordActivity (activity.Activity):
    5756
    58     def __init__ (self, handle):
    59         activity.Activity.__init__ (self, handle)
     57class AbiWordActivity(activity.Activity):
     58
     59    def __init__(self, handle):
     60        activity.Activity.__init__(self, handle)
    6061
    6162        # abiword uses the current directory for all its file dialogs
    6263        os.chdir(os.path.expanduser('~'))
    class AbiWordActivity (activity.Activity): 
    173174        self.abiword_canvas.connect_after('map-event', self.__map_event_cb)
    174175        self.abiword_canvas.show()
    175176
    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)
    177179
    178180    def _image_selected(self, button):
    179181        self._insert_toolbar.props.page.enable_table_button(False)
    class AbiWordActivity (activity.Activity): 
    195197    def __zoom_cb(self, abi, zoom):
    196198        abi.disconnect(self._zoom_handler)
    197199
    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
    199202        # looks like original #1121 issue is already not reproducible in
    200203        # environments like fc13 but we still need it for older ones
     204
    201205        def size_allocate_cb(abi, alloc):
     206
    202207            def idle_cb():
    203208                zoom = abi.get_zoom_percentage()
    204209                abi.set_zoom_percentage(zoom)
     210
    205211            gobject.idle_add(idle_cb)
    206212        abi.connect('size-allocate', size_allocate_cb)
    207213
    class AbiWordActivity (activity.Activity): 
    209215        logger.debug('__map_event_cb')
    210216
    211217        # 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')
    214220        self.abiword_canvas.invoke_cmd(
    215221                'com.abisource.abiword.loadbindings.fromURI',
    216222                keybindings_file, 0, 0)
    217223
    218224        # 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)
    220226
    221227        # we only do per-word selections (when using the mouse)
    222228        self.abiword_canvas.set_word_selections(True)
    class AbiWordActivity (activity.Activity): 
    240246            # we are joining the activity
    241247            logger.debug("We are joining an activity")
    242248            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)
    244251            self._shared_activity.connect('buddy-left', self._buddy_left_cb)
    245252            if self.get_shared():
    246 #                # oh, OK, we've already joined
     253                # oh, OK, we've already joined
    247254                self._joined_cb()
    248255        else:
    249256            # we are creating the activity
    class AbiWordActivity (activity.Activity): 
    260267                                     gtk.gdk.INTERP_BILINEAR)
    261268
    262269        preview_data = []
     270
    263271        def save_func(buf, data):
    264272            data.append(buf)
    265273
    class AbiWordActivity (activity.Activity): 
    279287        logger.debug('This is my activity: offering a tube...')
    280288        id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(
    281289            "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))
    284292
    285293    def _setup(self):
    286294        logger.debug("_setup()")
    class AbiWordActivity (activity.Activity): 
    289297            logger.error('Failed to share or join activity')
    290298            return
    291299
    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()
    293302
    294303        # Work out what our room is called and whether we have Tubes already
    295304        room = None
    class AbiWordActivity (activity.Activity): 
    319328
    320329        # Make sure we have a Tubes channel - PS doesn't yet provide one
    321330        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,
    324335                telepathy.HANDLE_TYPE_ROOM, room, True)
    325336            logger.debug("Got our tubes negotiation channel")
    326337
    class AbiWordActivity (activity.Activity): 
    359370        if (type == telepathy.TUBE_TYPE_DBUS and
    360371            service == "com.abisource.abiword.abicollab"):
    361372            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)
    363375
    364376            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)
    367381            for i, struct in enumerate(contacts):
    368382                #print 'mapping i',i
    369383                handle, path = struct
    class AbiWordActivity (activity.Activity): 
    373387                    break
    374388
    375389            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')
    377392            else:
    378393                # 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)
    380396                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)
    383402                    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)
    386408                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',
    391417                self._on_dbus_names_changed)
    392418
    393419            # 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',
    395422                self._on_members_changed)
    396423
    397424    def _on_dbus_names_changed(self, tube_id, added, removed):
    398425        logger.debug('_on_dbus_names_changed')
    399426#        if tube_id == self.tube_id:
    400427        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)
    403433            self.participants[handle] = bus_name
    404434
    405435#            if handle == self.self_handle:
    class AbiWordActivity (activity.Activity): 
    411441
    412442# HACK: doesn't work yet, bad morgs!
    413443#        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)
    415446#            bus_name = self.participants.pop(handle, None)
    416447
    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):
    418450        logger.debug("_on_members_changed")
    419451        for handle in removed:
    420452            bus_name = self.participants.pop(handle, None)
    class AbiWordActivity (activity.Activity): 
    425457
    426458            logger.debug('removed handle: %d, with dbus name: %s', handle,
    427459                         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)
    429463
    430     def _buddy_joined_cb (self, activity, buddy):
     464    def _buddy_joined_cb(self, activity, buddy):
    431465        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)
    433469
    434     def _buddy_left_cb (self, activity, buddy):
     470    def _buddy_left_cb(self, activity, buddy):
    435471        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)
    437475
    438476    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'])
    440479
    441480        if self.metadata['mime_type'] in ['text/plain', 'text/csv']:
    442481            logging.debug('Opening file in text mode')
    443482            self.abiword_canvas.load_file('file://' + file_path, 'text/plain')
    444483        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
    446487
    447488    def write_file(self, file_path):
    448489        logging.debug('AbiWordActivity.write_file')
    class AbiWordActivity (activity.Activity): 
    466507
    467508        self.metadata['mime_type'] = actual_mimetype
    468509
    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]
    470513        self.abiword_canvas.save('file://' + file_path, actual_mimetype, '')
    471514
    472515    def _change_file_ext(self, file_name, extension):