-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpychmindex.py
61 lines (43 loc) · 1.68 KB
/
pychmindex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
# vim: set fileencoding=utf-8 :
" Provides the index panel. "
from PyQt4 import QtCore
from treeview import AbstractTreeView
from Ui_panelindex import Ui_PanelIndex
class PyChmIndexView(AbstractTreeView, Ui_PanelIndex ):
" Implements the index panel. "
def __init__(self, mainwin=None, parent=None):
AbstractTreeView.__init__(self, parent)
self.connect(self.text,
QtCore.SIGNAL('textChanged(const QString&)'),
self.onTextChanged)
self.connect(self.text,
QtCore.SIGNAL('returnPressed()'),
self.onReturnPressed)
self.mainwin = mainwin
if mainwin.currentView:
chmfile = mainwin.currentView.chmfile
if chmfile and chmfile.index :
self.loadIndex(chmfile.index)
self.lastitem = None
def onTabSwitched(self):
" Update the index panel to fit with current file "
self.clear()
if self.mainwin.currentView:
chmfile = self.mainwin.currentView.chmfile
self.loadIndex(chmfile.index)
def clear(self):
" Clear current contents of index panel"
AbstractTreeView.clear(self)
self.text.clear()
loadIndex = AbstractTreeView.loadData
def onTextChanged(self, text):
" Search the index at real time"
items = self.tree.findItems(text, QtCore.Qt.MatchStartsWith)
if items:
item = items[0]
self.tree.setCurrentItem(item)
self.tree.scrollToItem(item)
def onReturnPressed(self):
" What to do when user press Enter in the input field?"
raise NotImplementedError("")