author Nicolas Chauvat <>
Mon, 23 Jun 2008 13:42:22 +0200
changeset 6 6aad8b499e86
parent 0 7710b138d4eb
permissions -rw-r--r--
fix reST markup

# Copyright (c) 2004 LOGILAB S.A. (Paris, FRANCE).
# --
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""Basic plugin for pychecker

__revision__ = '$Id:,v 1.3 2004-12-22 11:00:18 arthur Exp $'

import commands
import gobject
import gtk
from import ConfigurableListWindow
from oobrother.plugins import AbstractPlugIn
from oobrother.sysutils import PathNormalizerMixIn

class PycheckerPlugin(AbstractPlugIn):
    """a plugin for text file, propo"""
    name = 'pychecker'
    mimetypes = 'text/x-python',

    def __init__(self):
        AbstractPlugIn.__init__(self, config_file='pychecker.ini')
        self.pychecker_window = PycheckerReportWindow()

    def set_application(self, appl):
        """set the application (on registration)"""
        AbstractPlugIn.set_application(self, appl)
        self.pychecker_window.editor = self.appl.editor

    def get_actions(self, thefile):
        """return actions provided by this plugin for the give file"""
        return [('pychecker', self.pycheck),]

    def pycheck(self, menuitem, thefile):
        """ execute pychecker """ 

    def subconfiguration(self):
        """return subconfiguration objects if any"""
        return [self.pychecker_window]

class PycheckerReportWindow(PathNormalizerMixIn, ConfigurableListWindow):
    """display pychecker report in a 3 columns list (configurable)"""
    name = 'pychecker'

    def __init__(self):
        ConfigurableListWindow.__init__(self, 'pychecker.ini',
                                        (gobject.TYPE_STRING, # type
                                         gobject.TYPE_INT, # path
                                         gobject.TYPE_STRING, # message
                                        ('File', 'Line', 'Message'),
        self.init_columns(self.cfg['columns'], (0, 0, 0))
        self.editor = None # will be set later, I promise
        self.treeview.connect('button-press-event', self.cb_button_pressed)

    def pycheck(self, thefile):
        """check the given wrapped package using checkpackage in a safe
        self.set_title('pychecker: %s' % thefile.abspath)
        output = commands.getoutput("pychecker %s" % thefile.abspath)
        for line in output.splitlines():
            file =  ''
            line_no = 0
                file, line_no, message = line.split(':', 2)
            except ValueError:
                message = line
            self.append_line((file, int(line_no), message))

    def cb_button_pressed(self, treeview, event):
        """open file on the corresponding line on double click
        # left click
        if event.button == 1:
            # double_click
            if event.type == gtk.gdk._2BUTTON_PRESS:
                file_path, lineno, _ = self.get_selected()
      , lineno)

def register(registry):
    """register plugins from this module to the plugins registry"""