--- a/UI/LogView.py Mon Apr 30 10:25:49 2012 +0200 +++ b/UI/LogView.py Mon Apr 30 19:19:17 2012 +0200 @@ -8,15 +8,74 @@ """ from PyQt4.QtCore import Qt -from PyQt4.QtGui import QTextEdit, QBrush, QApplication, QMenu, QTextCursor +from PyQt4.QtGui import QTextEdit, QBrush, QApplication, QMenu, QTextCursor, QWidget, \ + QHBoxLayout, QTextDocument from E5Gui.E5Application import e5App +from .SearchWidget import SearchWidget + import UI.PixmapCache import Preferences -class LogViewer(QTextEdit): +class LogViewer(QWidget): + """ + Class implementing the containing widget for the log viewer. + """ + def __init__(self, parent=None): + """ + Constructor + + @param parent reference to the parent widget (QWidget) + """ + super().__init__(parent) + + self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) + + self.__logViewer = LogViewerEdit(self) + self.__searchWidget = SearchWidget(self.__logViewer, self) + self.__searchWidget.hide() + + self.__layout = QHBoxLayout(self) + self.__layout.addWidget(self.__logViewer) + self.__layout.addWidget(self.__searchWidget) + + self.__searchWidget.searchNext.connect(self.__logViewer.searchNext) + self.__searchWidget.searchPrevious.connect(self.__logViewer.searchPrev) + + def appendToStdout(self, txt): + """ + Public slot to appand text to the "stdout" tab. + + @param txt text to be appended (string) + """ + self.__logViewer.appendToStdout(txt) + + def appendToStderr(self, txt): + """ + Public slot to appand text to the "stderr" tab. + + @param txt text to be appended (string) + """ + self.__logViewer.appendToStderr(txt) + + def preferencesChanged(self): + """ + Public slot to handle a change of the preferences. + """ + self.__logViewer.preferencesChanged() + + def showFind(self, txt=""): + """ + Public method to display the search widget. + + @param txt text to be shown in the combo (string) + """ + self.__searchWidget.showFind() + + +class LogViewerEdit(QTextEdit): """ Class providing a specialized text edit for displaying logging information. """ @@ -31,13 +90,16 @@ self.setLineWrapMode(QTextEdit.NoWrap) self.setReadOnly(True) - self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) + self.__mainWindow = parent + self.__lastSearch = () # create the context menu self.__menu = QMenu(self) self.__menu.addAction(self.trUtf8('Clear'), self.clear) self.__menu.addAction(self.trUtf8('Copy'), self.copy) self.__menu.addSeparator() + self.__menu.addAction(self.trUtf8('Find'), self.__find) + self.__menu.addSeparator() self.__menu.addAction(self.trUtf8('Select All'), self.selectAll) self.__menu.addSeparator() self.__menu.addAction(self.trUtf8("Configure..."), self.__configure) @@ -104,3 +166,64 @@ Private method to open the configuration dialog. """ e5App().getObject("UserInterface").showPreferences("interfacePage") + + def __find(self): + """ + Private slot to show the find widget. + """ + txt = self.textCursor().selectedText() + self.__mainWindow.showFind(txt) + + def searchNext(self, txt, caseSensitive, wholeWord): + """ + Public method to search the next occurrence of the given text. + """ + self.__lastSearch = (txt, caseSensitive, wholeWord) + flags = QTextDocument.FindFlags() + if caseSensitive: + flags |= QTextDocument.FindCaseSensitively + if wholeWord: + flags |= QTextDocument.FindWholeWords + self.find(txt, flags) + + def searchPrev(self, txt, caseSensitive, wholeWord): + """ + Public method to search the previous occurrence of the given text. + """ + self.__lastSearch = (txt, caseSensitive, wholeWord) + flags = QTextDocument.FindFlags(QTextDocument.FindBackward) + if caseSensitive: + flags |= QTextDocument.FindCaseSensitively + if wholeWord: + flags |= QTextDocument.FindWholeWords + self.find(txt, flags) + + def keyPressEvent(self, evt): + """ + Protected method handling key press events. + + @param evt key press event (QKeyEvent) + """ + if evt.modifiers() == Qt.ControlModifier: + if evt.key() == Qt.Key_F: + self.__find() + evt.accept() + return + elif evt.key() == Qt.Key_C: + self.copy() + evt.accept() + return + elif evt.key() == Qt.Key_A: + self.selectAll() + evt.accept() + return + elif evt.modifiers() == Qt.NoModifier: + if evt.key() == Qt.Key_F3 and self.__lastSearch: + self.searchNext(*self.__lastSearch) + evt.accept() + return + elif evt.modifiers() == Qt.ShiftModifier and self.__lastSearch: + if evt.key() == Qt.Key_F3 and self.__lastSearch: + self.searchPrev(*self.__lastSearch) + evt.accept() + return