Sat, 25 Sep 2021 18:08:10 +0200
Extended the supported file type specific signals in the two 'Find' related widgets.
--- a/eric7/UI/FindFileWidget.py Sat Sep 25 18:07:20 2021 +0200 +++ b/eric7/UI/FindFileWidget.py Sat Sep 25 18:08:10 2021 +0200 @@ -10,8 +10,8 @@ import os import re -from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QPoint -from PyQt6.QtGui import QCursor +from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QPoint, QUrl +from PyQt6.QtGui import QCursor, QDesktopServices, QImageReader from PyQt6.QtWidgets import ( QWidget, QApplication, QMenu, QTreeWidgetItem, QComboBox ) @@ -42,10 +42,19 @@ @signal sourceFile(str, int, str, int, int) emitted to open a source file at a specificline @signal designerFile(str) emitted to open a Qt-Designer file + @signal linguistFile(str) emitted to open a Qt-Linguist (*.ts) file + @signal trpreview([str]) emitted to preview Qt-Linguist (*.qm) files + @signal pixmapFile(str) emitted to open a pixmap file + @signal svgFile(str) emitted to open a SVG file + @signal umlFile(str) emitted to open an eric UML file """ - # TODO: add more signals sourceFile = pyqtSignal(str, int, str, int, int) designerFile = pyqtSignal(str) + linguistFile = pyqtSignal(str) + trpreview = pyqtSignal(list) + pixmapFile = pyqtSignal(str) + svgFile = pyqtSignal(str) + umlFile = pyqtSignal(str) lineRole = Qt.ItemDataRole.UserRole + 1 startRole = Qt.ItemDataRole.UserRole + 2 @@ -87,7 +96,7 @@ self.findProgressLabel.setMaximumWidth(550) self.searchHistory = Preferences.toList( - Preferences.Prefs.settings.value( + Preferences.getSettings().value( "FindFileWidget/SearchHistory")) self.findtextCombo.lineEdit().setClearButtonEnabled(True) self.findtextCombo.lineEdit().returnPressed.connect(self.__doSearch) @@ -96,7 +105,7 @@ self.findtextCombo.setEditText("") self.replaceHistory = Preferences.toList( - Preferences.Prefs.settings.value( + Preferences.getSettings().value( "FindFileWidget/ReplaceHistory")) self.replacetextCombo.lineEdit().setClearButtonEnabled(True) self.replacetextCombo.lineEdit().returnPressed.connect(self.__doSearch) @@ -105,13 +114,13 @@ self.replacetextCombo.setEditText("") self.dirHistory = Preferences.toList( - Preferences.Prefs.settings.value( + Preferences.getSettings().value( "FindFileWidget/DirectoryHistory")) self.dirPicker.addItems(self.dirHistory) self.dirPicker.setText("") self.excludeHiddenCheckBox.setChecked(Preferences.toBool( - Preferences.Prefs.settings.value( + Preferences.getSettings().value( "FindFileWidget/ExcludeHidden", True) )) @@ -534,10 +543,10 @@ self.searchHistory.insert(0, ct) self.findtextCombo.clear() self.findtextCombo.addItems(self.searchHistory) - Preferences.Prefs.settings.setValue( + Preferences.getSettings().setValue( "FindFileWidget/SearchHistory", self.searchHistory[:30]) - Preferences.Prefs.settings.setValue( + Preferences.getSettings().setValue( "FindFileWidget/ExcludeHidden", self.excludeHiddenCheckBox.isChecked()) @@ -560,7 +569,7 @@ self.dirPicker.clear() self.dirPicker.addItems(self.dirHistory) self.dirPicker.setText(self.dirHistory[0]) - Preferences.Prefs.settings.setValue( + Preferences.getSettings().setValue( "FindFileWidget/DirectoryHistory", self.dirHistory[:30]) @@ -582,7 +591,7 @@ self.findProgressLabel.setPath(file) fn = ( - os.path.join(self.project.ppath, file) + os.path.join(self.project.getProjectPath(), file) if self.projectButton.isChecked() else file ) @@ -652,8 +661,7 @@ """ Private slot to handle the double click on a file item. - It emits the signal sourceFile or designerFile depending on the file - extension. + It emits a signal depending on the file extension. @param itm the double clicked tree item @type QTreeWidgetItem @@ -671,11 +679,30 @@ start = 0 end = 0 - fn = os.path.join(self.project.ppath, file) if self.project else file - if fn.endswith('.ui'): - self.designerFile.emit(fn) + fileName = ( + os.path.join(self.project.getProjectPath(), file) + if self.project.isOpen() else + file + ) + fileExt = os.path.splitext(fileName)[1] + + if fileExt == ".ui": + self.designerFile.emit(fileName) + elif fileExt == ".ts": + self.linguistFile.emit(fileName) + elif fileExt == ".qm": + self.trpreview.emit([fileName]) + elif fileExt in (".egj", ".e5g"): + self.umlFile.emit(fileName) + elif fileExt == ".svg": + self.svgFile.emit(fileName) + elif fileExt[1:] in QImageReader.supportedImageFormats(): + self.pixmapFile.emit(fileName) else: - self.sourceFile.emit(fn, line, "", start, end) + if Utilities.MimeTypes.isTextFile(fileName): + self.sourceFile.emit(fileName, line, "", start, end) + else: + QDesktopServices.openUrl(QUrl(fileName)) def __getFileList(self, path, filterRe, excludeHiddenDirs=False, excludeHiddenFiles=False): @@ -743,7 +770,7 @@ self.findProgressLabel.setPath(file) if self.projectButton.isChecked(): - fn = os.path.join(self.project.ppath, file) + fn = os.path.join(self.project.getProjectPath(), file) else: fn = file
--- a/eric7/UI/FindLocationWidget.py Sat Sep 25 18:07:20 2021 +0200 +++ b/eric7/UI/FindLocationWidget.py Sat Sep 25 18:08:10 2021 +0200 @@ -10,7 +10,8 @@ import os import sys -from PyQt6.QtCore import pyqtSignal, pyqtSlot +from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl +from PyQt6.QtGui import QDesktopServices, QImageReader from PyQt6.QtWidgets import ( QWidget, QHeaderView, QApplication, QTreeWidgetItem ) @@ -34,9 +35,19 @@ @signal sourceFile(str) emitted to open a file in the editor @signal designerFile(str) emitted to open a Qt-Designer file + @signal linguistFile(str) emitted to open a Qt-Linguist (*.ts) file + @signal trpreview([str]) emitted to preview Qt-Linguist (*.qm) files + @signal pixmapFile(str) emitted to open a pixmap file + @signal svgFile(str) emitted to open a SVG file + @signal umlFile(str) emitted to open an eric UML file """ sourceFile = pyqtSignal(str) designerFile = pyqtSignal(str) + linguistFile = pyqtSignal(str) + trpreview = pyqtSignal(list) + pixmapFile = pyqtSignal(str) + svgFile = pyqtSignal(str) + umlFile = pyqtSignal(str) def __init__(self, project, parent=None): """ @@ -67,7 +78,9 @@ self.openButton.setIcon(UI.PixmapCache.getIcon("open")) self.openButton.clicked.connect(self.__openFile) - self.project = project + self.__project = project + self.__project.projectOpened.connect(self.__projectOpened) + self.__project.projectClosed.connect(self.__projectClosed) self.extsepLabel.setText(os.extsep) self.__shouldStop = False @@ -87,8 +100,7 @@ """ Private slot to open a file. - It emits the signal sourceFile or designerFile depending on the - file extension. + It emits a signal depending on the file extension. @param itm item to be opened @type QTreeWidgetItem @@ -98,14 +110,26 @@ if itm is not None: fileName = itm.text(0) filePath = itm.text(1) + fileExt = os.path.splitext(fileName)[1] + fullName = os.path.join(filePath, fileName) - # TODO: add more extensions and use mimetype - # - *.ts, *.qm->*.ts - # Utilities.MimeTypes.isTextFile(filename) - if fileName.endswith('.ui'): - self.designerFile.emit(os.path.join(filePath, fileName)) + if fileExt == ".ui": + self.designerFile.emit(fullName) + elif fileExt == ".ts": + self.linguistFile.emit(fullName) + elif fileExt == ".qm": + self.trpreview.emit([fullName]) + elif fileExt in (".egj", ".e5g"): + self.umlFile.emit(fullName) + elif fileExt == ".svg": + self.svgFile.emit(fullName) + elif fileExt[1:] in QImageReader.supportedImageFormats(): + self.pixmapFile.emit(fullName) else: - self.sourceFile.emit(os.path.join(filePath, fileName)) + if Utilities.MimeTypes.isTextFile(fullName): + self.sourceFile.emit(fullName) + else: + QDesktopServices.openUrl(QUrl(fullName)) @pyqtSlot() def __searchFile(self): @@ -135,7 +159,7 @@ ): searchPaths.append(self.searchDirPicker.text()) if self.projectCheckBox.isChecked(): - searchPaths.append(self.project.ppath) + searchPaths.append(self.__project.getProjectPath()) if self.syspathCheckBox.isChecked(): searchPaths.extend(sys.path) @@ -164,8 +188,11 @@ del locations self.stopButton.setEnabled(False) + self.fileList.sortItems(self.fileList.sortColumn(), + Qt.SortOrder.AscendingOrder) self.fileList.header().resizeSections( QHeaderView.ResizeMode.ResizeToContents) + self.fileList.header().resizeSection(0, self.width() // 2) self.fileList.header().setStretchLastSection(True) self.findStatusLabel.setText(self.tr( @@ -230,16 +257,25 @@ self.openButton.setEnabled(current is not None) @pyqtSlot() + def __projectOpened(self): + """ + Private slot to handle a project being opened. + """ + self.projectCheckBox.setEnabled(True) + self.projectCheckBox.setChecked(True) + + @pyqtSlot() + def __projectClosed(self): + """ + Private slot to handle a project being closed. + """ + self.projectCheckBox.setEnabled(False) + self.projectCheckBox.setChecked(False) + + @pyqtSlot() def activate(self): """ Public slot to enable/disable the project checkbox. """ - if self.project and self.project.isOpen(): - self.projectCheckBox.setEnabled(True) - self.projectCheckBox.setChecked(True) - else: - self.projectCheckBox.setEnabled(False) - self.projectCheckBox.setChecked(False) - self.fileNameEdit.selectAll() self.fileNameEdit.setFocus()
--- a/eric7/UI/UserInterface.py Sat Sep 25 18:07:20 2021 +0200 +++ b/eric7/UI/UserInterface.py Sat Sep 25 18:08:10 2021 +0200 @@ -952,6 +952,11 @@ self.__findFileWidget.sourceFile.connect( self.viewmanager.openSourceFile) self.__findFileWidget.designerFile.connect(self.__designer) + self.__findFileWidget.linguistFile.connect(self.__linguist) + self.__findFileWidget.trpreview.connect(self.__TRPreviewer) + self.__findFileWidget.pixmapFile.connect(self.__showPixmap) + self.__findFileWidget.svgFile.connect(self.__showSvg) + self.__findFileWidget.umlFile.connect(self.__showUml) # Create the find location (file) widget from .FindLocationWidget import FindLocationWidget @@ -959,6 +964,11 @@ self.__findLocationWidget.sourceFile.connect( self.viewmanager.openSourceFile) self.__findLocationWidget.designerFile.connect(self.__designer) + self.__findLocationWidget.linguistFile.connect(self.__linguist) + self.__findLocationWidget.trpreview.connect(self.__TRPreviewer) + self.__findLocationWidget.pixmapFile.connect(self.__showPixmap) + self.__findLocationWidget.svgFile.connect(self.__showSvg) + self.__findLocationWidget.umlFile.connect(self.__showUml) # Create the VCS Status widget from VCS.StatusWidget import StatusWidget @@ -5470,8 +5480,8 @@ ).format(viewer)) @pyqtSlot() - @pyqtSlot(str) - @pyqtSlot(str, bool) + @pyqtSlot(list) + @pyqtSlot(list, bool) def __TRPreviewer(self, fileNames=None, ignore=False): """ Private slot to start the Translation Previewer executable.