RefactoringRope/MatchesDialog.py

changeset 2
fc72a5b922a6
child 20
83b71483e198
equal deleted inserted replaced
1:9f687137a929 2:fc72a5b922a6
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to show matching references/definitions.
8 """
9
10 from PyQt4.QtCore import pyqtSlot, Qt
11 from PyQt4.QtGui import QDialog, QTreeWidgetItem, QDialogButtonBox, \
12 QHeaderView
13
14 from E5Gui.E5Application import e5App
15
16 from Ui_MatchesDialog import Ui_MatchesDialog
17
18 class MatchesDialog(QDialog, Ui_MatchesDialog):
19 """
20 Class implementing a dialog to show matching references/definitions.
21 """
22 def __init__(self, ui, showConfidence, parent = None, name = None):
23 """
24 Constructor
25
26 @param ui reference to the UI object
27 @param showConfidence flag indicating the display of the
28 confidence column (boolean)
29 @param parent parent of this dialog (QWidget)
30 @param name name of this dialog (string)
31 """
32 QDialog.__init__(self, parent)
33 if name:
34 self.setObjectName(name)
35 self.setupUi(self)
36
37 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
38
39 self.ui = ui
40 self.__showConfidence = showConfidence
41
42 if not self.__showConfidence:
43 self.matchesList.setColumnHidden(2, True)
44 self.matchesList.header().setSortIndicator(0, Qt.AscendingOrder)
45
46 def __resort(self):
47 """
48 Private method to resort the tree.
49 """
50 self.matchesList.sortItems(self.matchesList.sortColumn(),
51 self.matchesList.header().sortIndicatorOrder())
52
53 def __resizeColumns(self):
54 """
55 Private method to resize the list columns.
56 """
57 self.matchesList.header().resizeSections(QHeaderView.ResizeToContents)
58 self.matchesList.header().setStretchLastSection(True)
59
60 @pyqtSlot(QTreeWidgetItem, int)
61 def on_matchesList_itemActivated(self, item, column):
62 """
63 Private slot to handle the itemActivated signal of the list.
64 """
65 lineno = int(item.text(1))
66 fn = item.text(0)
67 e5App().getObject("ViewManager").openSourceFile(fn, lineno)
68
69 def addEntry(self, resource, lineno, unsure=False):
70 """
71 Public slot to add an entry to the list.
72
73 @param resource reference to the resource object
74 (rope.base.resources.Resource)
75 @param lineno linenumber of the match (integer)
76 @param unsure flag indicating an unsure match (boolean)
77 """
78 if unsure:
79 conf = 50
80 else:
81 conf = 100
82 itm = QTreeWidgetItem(self.matchesList,
83 [resource.real_path,
84 " {0:5d}".format(lineno),
85 " {0:5d}%".format(conf)])
86 itm.setTextAlignment(1, Qt.AlignRight)
87 itm.setTextAlignment(2, Qt.AlignRight)
88 self.__resort()
89 self.__resizeColumns()

eric ide

mercurial