UI/FindFileNameDialog.py

branch
Py2 comp.
changeset 2791
a9577f248f04
parent 2677
3d4277929fb3
parent 2754
2b3a46d8905b
child 3057
10516539f238
equal deleted inserted replaced
2790:6686a3326df8 2791:a9577f248f04
56 self.buttonBox.addButton(self.trUtf8("Stop"), QDialogButtonBox.ActionRole) 56 self.buttonBox.addButton(self.trUtf8("Stop"), QDialogButtonBox.ActionRole)
57 self.stopButton.setToolTip(self.trUtf8("Press to stop the search")) 57 self.stopButton.setToolTip(self.trUtf8("Press to stop the search"))
58 self.stopButton.setEnabled(False) 58 self.stopButton.setEnabled(False)
59 self.buttonBox.button(QDialogButtonBox.Open).setToolTip( 59 self.buttonBox.button(QDialogButtonBox.Open).setToolTip(
60 self.trUtf8("Opens the selected file")) 60 self.trUtf8("Opens the selected file"))
61 self.buttonBox.button(QDialogButtonBox.Open).setEnabled(False)
61 62
62 self.project = project 63 self.project = project
63 self.extsepLabel.setText(os.extsep) 64 self.extsepLabel.setText(os.extsep)
64 65
65 self.shouldStop = False 66 self.shouldStop = False
73 if button == self.stopButton: 74 if button == self.stopButton:
74 self.shouldStop = True 75 self.shouldStop = True
75 elif button == self.buttonBox.button(QDialogButtonBox.Open): 76 elif button == self.buttonBox.button(QDialogButtonBox.Open):
76 self.__openFile() 77 self.__openFile()
77 78
78 def __openFile(self): 79 def __openFile(self, itm=None):
79 """ 80 """
80 Private slot to open a file. 81 Private slot to open a file.
81 82
82 It emits the signal 83 It emits the signal sourceFile or designerFile depending on the
83 sourceFile or designerFile depending on the file extension. 84 file extension.
84 """ 85
85 itm = self.fileList.currentItem() 86 @param itm item to be opened (QTreeWidgetItem)
86 fileName = itm.text(0) 87 """
87 filePath = itm.text(1) 88 if itm is None:
88 89 itm = self.fileList.currentItem()
89 if fileName.endswith('.ui'): 90 if itm is not None:
90 self.designerFile.emit(os.path.join(filePath, fileName)) 91 fileName = itm.text(0)
91 else: 92 filePath = itm.text(1)
92 self.sourceFile.emit(os.path.join(filePath, fileName)) 93
94 if fileName.endswith('.ui'):
95 self.designerFile.emit(os.path.join(filePath, fileName))
96 else:
97 self.sourceFile.emit(os.path.join(filePath, fileName))
93 98
94 def __searchFile(self): 99 def __searchFile(self):
95 """ 100 """
96 Private slot to handle the search. 101 Private slot to handle the search.
97 """ 102 """
102 fileExt = self.fileExtEdit.text() 107 fileExt = self.fileExtEdit.text()
103 if not fileExt and Utilities.isWindowsPlatform(): 108 if not fileExt and Utilities.isWindowsPlatform():
104 self.fileList.clear() 109 self.fileList.clear()
105 return 110 return
106 111
107 patternFormat = fileExt and "{0}{1}{2}*" or "{0}*{1}{2}" 112 patternFormat = fileExt and "{0}{1}{2}" or "{0}*{1}{2}"
108 fileNamePattern = patternFormat.format(fileName, os.extsep, 113 fileNamePattern = patternFormat.format(fileName, os.extsep,
109 fileExt and fileExt or '*') 114 fileExt and fileExt or '*')
110 115
111 searchPaths = [] 116 searchPaths = []
112 if self.searchDirCheckBox.isChecked() and \ 117 if self.searchDirCheckBox.isChecked() and \
140 locations[fn] = [fp] 145 locations[fn] = [fp]
141 QTreeWidgetItem(self.fileList, [fn, fp]) 146 QTreeWidgetItem(self.fileList, [fn, fp])
142 QApplication.processEvents() 147 QApplication.processEvents()
143 148
144 del locations 149 del locations
145 self.buttonBox.button(QDialogButtonBox.Open).setEnabled(found)
146 self.stopButton.setEnabled(False) 150 self.stopButton.setEnabled(False)
147 self.fileList.header().resizeSections(QHeaderView.ResizeToContents) 151 self.fileList.header().resizeSections(QHeaderView.ResizeToContents)
148 self.fileList.header().setStretchLastSection(True) 152 self.fileList.header().setStretchLastSection(True)
153
154 if found:
155 self.fileList.setCurrentItem(self.fileList.topLevelItem(0))
149 156
150 def checkStop(self): 157 def checkStop(self):
151 """ 158 """
152 Public method to check, if the search should be stopped. 159 Public method to check, if the search should be stopped.
153 160
224 231
225 def on_fileList_itemActivated(self, itm, column): 232 def on_fileList_itemActivated(self, itm, column):
226 """ 233 """
227 Private slot to handle the double click on a file item. 234 Private slot to handle the double click on a file item.
228 235
229 It emits the signal 236 It emits the signal sourceFile or designerFile depending on the
230 sourceFile or designerFile depending on the file extension. 237 file extension.
231 238
232 @param itm the double clicked listview item (QTreeWidgetItem) 239 @param itm the double clicked listview item (QTreeWidgetItem)
233 @param column column that was double clicked (integer) (ignored) 240 @param column column that was double clicked (integer) (ignored)
234 """ 241 """
235 self.__openFile() 242 self.__openFile(itm)
243
244 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
245 def on_fileList_currentItemChanged(self, current, previous):
246 """
247 Private slot handling a change of the current item.
248
249 @param current current item (QTreeWidgetItem)
250 @param previous prevoius current item (QTreeWidgetItem)
251 """
252 self.buttonBox.button(QDialogButtonBox.Open).setEnabled(current is not None)
236 253
237 def show(self): 254 def show(self):
238 """ 255 """
239 Overwritten method to enable/disable the project checkbox. 256 Overwritten method to enable/disable the project checkbox.
240 """ 257 """

eric ide

mercurial