UI/Browser.py

changeset 5011
4085e2348621
parent 4651
7f3f276d3bf3
child 5389
9b1c800daff3
equal deleted inserted replaced
5009:8b1ca3c1da22 5011:4085e2348621
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import os 12 import os
13 13
14 from PyQt5.QtCore import QModelIndex, pyqtSignal, QUrl, Qt, qVersion, \ 14 from PyQt5.QtCore import QModelIndex, pyqtSignal, QUrl, Qt, qVersion, \
15 QCoreApplication, QItemSelectionModel 15 QCoreApplication, QItemSelectionModel, QElapsedTimer
16 from PyQt5.QtGui import QDesktopServices 16 from PyQt5.QtGui import QDesktopServices
17 from PyQt5.QtWidgets import QTreeView, QApplication, QMenu, QAbstractItemView 17 from PyQt5.QtWidgets import QTreeView, QApplication, QMenu, QAbstractItemView
18 18
19 from E5Gui.E5Application import e5App 19 from E5Gui.E5Application import e5App
20 from E5Gui import E5FileDialog, E5MessageBox 20 from E5Gui import E5FileDialog, E5MessageBox
138 )) 138 ))
139 139
140 self.__createPopupMenus() 140 self.__createPopupMenus()
141 141
142 self._init() # perform common initialization tasks 142 self._init() # perform common initialization tasks
143
144 self._keyboardSearchString = ""
145 self._keyboardSearchTimer = QElapsedTimer()
146 self._keyboardSearchTimer.invalidate()
143 147
144 def _init(self): 148 def _init(self):
145 """ 149 """
146 Protected method to perform initialization tasks common to this 150 Protected method to perform initialization tasks common to this
147 base class and all derived classes. 151 base class and all derived classes.
727 e5App().getObject("UserInterface")\ 731 e5App().getObject("UserInterface")\
728 .showPreferences("debuggerGeneralPage") 732 .showPreferences("debuggerGeneralPage")
729 elif self.__embeddedBrowser == 2: 733 elif self.__embeddedBrowser == 2:
730 e5App().getObject("UserInterface")\ 734 e5App().getObject("UserInterface")\
731 .showPreferences("projectBrowserPage") 735 .showPreferences("projectBrowserPage")
736
737 def keyboardSearch(self, search):
738 """
739 Public function to search the tree via the keyboard.
740
741 @param search the character entered via the keyboard
742 @type str
743 """
744 if self.model().rowCount() == 0:
745 return
746
747 if self.currentIndex().isValid():
748 startIndex = self.currentIndex()
749 else:
750 startIndex = self.model().index(0, 0)
751
752 keyboardSearchTimeWasValid = self._keyboardSearchTimer.isValid()
753 keyboardSearchTimeElapsed = self._keyboardSearchTimer.restart()
754 if not search or not keyboardSearchTimeWasValid or \
755 keyboardSearchTimeElapsed > \
756 QApplication.keyboardInputInterval():
757 self._keyboardSearchString = search.lower()
758 else:
759 self._keyboardSearchString += search.lower()
760
761 index = startIndex
762 found = False
763 while True:
764 name = self.model().data(index)
765 if name.lower().startswith(self._keyboardSearchString) and \
766 self._keyboardSearchType(self.model().item(index)):
767 found = True
768 break
769
770 index = self.indexBelow(index)
771 if not index.isValid():
772 index = self.model().index(0, 0)
773 if index == startIndex:
774 break
775
776 if found:
777 self.setCurrentIndex(index)
778
779 def _keyboardSearchType(self, item):
780 """
781 Protected method to check, if the item is of the correct type.
782
783 @param item reference to the item
784 @type BrowserItem
785 @return flag indicating a correct type
786 @rtype bool
787 """
788 return isinstance(
789 item, (BrowserDirectoryItem, BrowserFileItem, BrowserSysPathItem))

eric ide

mercurial