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