RefactoringRope/MatchesDialog.py

Sun, 30 Jan 2011 19:19:40 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 30 Jan 2011 19:19:40 +0100
changeset 20
83b71483e198
parent 2
fc72a5b922a6
child 21
46236998ad5f
permissions
-rw-r--r--

Made the code PEP-8 compliant.

# -*- coding: utf-8 -*-

# Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to show matching references/definitions.
"""

from PyQt4.QtCore import pyqtSlot, Qt
from PyQt4.QtGui import QDialog, QTreeWidgetItem, QDialogButtonBox, \
    QHeaderView

from E5Gui.E5Application import e5App

from Ui_MatchesDialog import Ui_MatchesDialog


class MatchesDialog(QDialog, Ui_MatchesDialog):
    """
    Class implementing a dialog to show matching references/definitions.
    """
    def __init__(self, ui, showConfidence, parent=None, name=None):
        """
        Constructor
        
        @param ui reference to the UI object
        @param showConfidence flag indicating the display of the
            confidence column (boolean)
        @param parent parent of this dialog (QWidget)
        @param name name of this dialog (string)
        """
        QDialog.__init__(self, parent)
        if name:
            self.setObjectName(name)
        self.setupUi(self)
        
        self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
        
        self.ui = ui
        self.__showConfidence = showConfidence
        
        if not self.__showConfidence:
            self.matchesList.setColumnHidden(2, True)
        self.matchesList.header().setSortIndicator(0, Qt.AscendingOrder)
    
    def __resort(self):
        """
        Private method to resort the tree.
        """
        self.matchesList.sortItems(self.matchesList.sortColumn(),
            self.matchesList.header().sortIndicatorOrder())
    
    def __resizeColumns(self):
        """
        Private method to resize the list columns.
        """
        self.matchesList.header().resizeSections(QHeaderView.ResizeToContents)
        self.matchesList.header().setStretchLastSection(True)
    
    @pyqtSlot(QTreeWidgetItem, int)
    def on_matchesList_itemActivated(self, item, column):
        """
        Private slot to handle the itemActivated signal of the list.
        """
        lineno = int(item.text(1))
        fn = item.text(0)
        e5App().getObject("ViewManager").openSourceFile(fn, lineno)
    
    def addEntry(self, resource, lineno, unsure=False):
        """
        Public slot to add an entry to the list.
        
        @param resource reference to the resource object
            (rope.base.resources.Resource)
        @param lineno linenumber of the match (integer)
        @param unsure flag indicating an unsure match (boolean)
        """
        if unsure:
            conf = 50
        else:
            conf = 100
        itm = QTreeWidgetItem(self.matchesList,
            [resource.real_path,
             " {0:5d}".format(lineno),
             " {0:5d}%".format(conf)])
        itm.setTextAlignment(1, Qt.AlignRight)
        itm.setTextAlignment(2, Qt.AlignRight)
        self.__resort()
        self.__resizeColumns()

eric ide

mercurial