src/eric7/Project/QuickFindFileDialog.py

Wed, 20 Dec 2023 19:28:22 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 20 Dec 2023 19:28:22 +0100
branch
eric7
changeset 10430
e440aaf179ce
parent 10069
435cc5875135
child 10439
21c28b0f9e41
permissions
-rw-r--r--

Converted some source code documentation to the new style.

4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9531
diff changeset
3 # Copyright (c) 2004 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a quick search for files.
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 This is basically the FindFileNameDialog modified to support faster
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 interactions.
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import os
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
15 from PyQt6.QtCore import QEvent, Qt, pyqtSignal, pyqtSlot
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
16 from PyQt6.QtWidgets import (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
17 QApplication,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
18 QDialogButtonBox,
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
19 QHeaderView,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
20 QTreeWidgetItem,
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
21 QWidget,
7265
0665c4d509c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
22 )
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 from .Ui_QuickFindFile import Ui_QuickFindFile
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 class QuickFindFileDialog(QWidget, Ui_QuickFindFile):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Class implementing the Quick Find File by Name Dialog.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
30
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 This dialog provides a slightly more streamlined behaviour
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 than the standard FindFileNameDialog in that it tries to
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 match any name in the project against (fragmentary) bits of
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 file names.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
35
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @signal sourceFile(str) emitted to open a file in the editor
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @signal designerFile(str) emitted to open a Qt-Designer file
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @signal linguistFile(str) emitted to open a Qt translation file
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
40
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 sourceFile = pyqtSignal(str)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 designerFile = pyqtSignal(str)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 linguistFile = pyqtSignal(str)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
44
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 def __init__(self, project, parent=None):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
48
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param project reference to the project object
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @type Project
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @param parent parent widget of this dialog
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 @type QWidget
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8205
diff changeset
54 super().__init__(parent)
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.setupUi(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.fileList.headerItem().setText(self.fileList.columnCount(), "")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58 self.fileNameEdit.returnPressed.connect(self.on_fileNameEdit_returnPressed)
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.installEventFilter(self)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.stopButton = self.buttonBox.addButton(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
62 self.tr("Stop"), QDialogButtonBox.ButtonRole.ActionRole
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63 )
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.project = project
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
65
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 def eventFilter(self, source, event):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 Public method to handle event for another object.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @param source object to handle events for
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @type QObject
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @param event event to handle
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 @type QEvent
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 @return flag indicating that the event was handled
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 @rtype bool
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7988
diff changeset
77 if event.type() == QEvent.Type.KeyPress:
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 # Anywhere in the dialog, make hitting escape cancel it
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7988
diff changeset
79 if event.key() == Qt.Key.Key_Escape:
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 # Anywhere in the dialog, make hitting up/down choose next item
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 # Note: This doesn't really do anything, as other than the text
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 # input there's nothing that doesn't handle up/down already.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
85 elif event.key() == Qt.Key.Key_Up or event.key() == Qt.Key.Key_Down:
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 current = self.fileList.currentItem()
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 index = self.fileList.indexOfTopLevelItem(current)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7988
diff changeset
88 if event.key() == Qt.Key.Key_Up:
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 if index != 0:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.fileList.setCurrentItem(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91 self.fileList.topLevelItem(index - 1)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
92 )
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 else:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if index < (self.fileList.topLevelItemCount() - 1):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.fileList.setCurrentItem(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
96 self.fileList.topLevelItem(index + 1)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
97 )
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 return QWidget.eventFilter(self, source, event)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 def on_buttonBox_clicked(self, button):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 Private slot called by a button of the button box clicked.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
103
10430
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
104 @param button button that was clicked
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
105 @type QAbstractButton
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 if button == self.stopButton:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 self.shouldStop = True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
109 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Open):
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.__openFile()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
111
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 def __openFile(self, itm=None):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 Private slot to open a file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
115
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 It emits the signal sourceFile or designerFile depending on the
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 file extension.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
118
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @param itm item to be opened
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 @type QTreeWidgetItem
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 @return flag indicating a file was opened
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @rtype bool
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 if itm is None:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 itm = self.fileList.currentItem()
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 if itm is not None:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 filePath = itm.text(1)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 fileName = itm.text(0)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 fullPath = os.path.join(self.project.ppath, filePath, fileName)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
130
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
131 if fullPath.endswith(".ui"):
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.designerFile.emit(fullPath)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133 elif fullPath.endswith((".ts", ".qm")):
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self.linguistFile.emit(fullPath)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 else:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 self.sourceFile.emit(fullPath)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
138
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
140
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 def __generateLocations(self):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 Private method to generate a set of locations that can be searched.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
144
7988
c4c17121eff8 Updated source code documentation with the new tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
145 @yield set of files in our project
c4c17121eff8 Updated source code documentation with the new tags.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
146 @ytype str
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
9516
0f023e61a9b5 Continued refactoring of the project browser related code in order to extract some as plugins later on.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9514
diff changeset
148 for fileCategory in self.project.getFileCategories():
0f023e61a9b5 Continued refactoring of the project browser related code in order to extract some as plugins later on.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9514
diff changeset
149 entries = self.project.getProjectData(dataKey=fileCategory, default=[])
8205
4a0f1f896341 Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
150 yield from entries[:]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
151
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 def __sortedMatches(self, items, searchTerm):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 Private method to find the subset of items which match a search term.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
155
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 @param items list of items to be scanned for the search term
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @type list of str
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 @param searchTerm search term to be searched for
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 @type str
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 @return sorted subset of items which match searchTerm in
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 relevance order (i.e. the most likely match first)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 @rtype list of tuple of bool, int and str
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 fragments = searchTerm.split()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
165
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 possible = [
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 # matches, in_order, file name
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 ]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
169
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 for entry in items:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 count = 0
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 match_order = []
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 for fragment in fragments:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 index = entry.find(fragment)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 if index == -1:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 # try case-insensitive match
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 index = entry.lower().find(fragment.lower())
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 if index != -1:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 count += 1
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 match_order.append(index)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 if count:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 record = (count, match_order == sorted(match_order), entry)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 if possible and count < possible[0][0]:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 # ignore...
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 continue
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 elif possible and count > possible[0][0]:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 # better than all previous matches, discard them and
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 # keep this
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 del possible[:]
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 possible.append(record)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
191
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 ordered = []
9786
f94b530722af Corrected some code style and formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
193 for _, in_order, name in possible:
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 try:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 age = os.stat(os.path.join(self.project.ppath, name)).st_mtime
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
196 except OSError:
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 # skipping, because it doesn't appear to exist...
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 continue
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
199 ordered.append(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
200 (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
201 in_order, # we want closer match first
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
202 -age, # then approximately "most recently edited"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
203 name,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
204 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
205 )
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 ordered.sort()
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 return ordered
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 def __searchFile(self):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 Private slot to handle the search.
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 fileName = self.fileNameEdit.text().strip()
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 if not fileName:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 self.fileList.clear()
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
217
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 ordered = self.__sortedMatches(self.__generateLocations(), fileName)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
219
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 found = False
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 self.fileList.clear()
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 locations = {}
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223
6188
5a6ae3be31e6 Fixed some loop related coding issues detected by the extended code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
224 for _in_order, _age, name in ordered:
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 found = True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
226 QTreeWidgetItem(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
227 self.fileList, [os.path.basename(name), os.path.dirname(name)]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
228 )
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 QApplication.processEvents()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
230
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 del locations
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 self.stopButton.setEnabled(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
233 self.fileList.header().resizeSections(QHeaderView.ResizeMode.ResizeToContents)
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 self.fileList.header().setStretchLastSection(True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
235
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 if found:
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 self.fileList.setCurrentItem(self.fileList.topLevelItem(0))
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238
10069
435cc5875135 Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
239 @pyqtSlot(str)
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 def on_fileNameEdit_textChanged(self, text):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 Private slot to handle the textChanged signal of the file name edit.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
243
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 @param text (ignored)
10430
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
245 @type str
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 self.__searchFile()
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248
10069
435cc5875135 Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
249 @pyqtSlot()
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 def on_fileNameEdit_returnPressed(self):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 Private slot to handle enter being pressed on the file name edit box.
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 if self.__openFile():
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 self.close()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
256
10069
435cc5875135 Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
257 @pyqtSlot(QTreeWidgetItem, int)
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 def on_fileList_itemActivated(self, itm, column):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 Private slot to handle the double click on a file item.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
261
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 It emits the signal sourceFile or designerFile depending on the
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 file extension.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
264
10430
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
265 @param itm the double clicked listview item
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
266 @type QTreeWidgetItem
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
267 @param column column that was double clicked
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
268 @type int
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 self.__openFile(itm)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
271
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 def on_fileList_currentItemChanged(self, current, previous):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 Private slot handling a change of the current item.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
276
10430
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
277 @param current current item
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
278 @type QTreeWidgetItem
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
279 @param previous prevoius current item
e440aaf179ce Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
280 @type QTreeWidgetItem
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 """
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7988
diff changeset
282 self.buttonBox.button(QDialogButtonBox.StandardButton.Open).setEnabled(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
283 current is not None
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284 )
4985
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 def show(self):
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 Public method to enable/disable the project checkbox.
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 """
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 self.fileNameEdit.selectAll()
03ac1a030529 Added a dialog to quickly search for files in the list of project files (thanks to Mike C. Fletcher for contributing the majority of this code).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 self.fileNameEdit.setFocus()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
292
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8205
diff changeset
293 super().show()

eric ide

mercurial