forked from smathot/QProgEdit
/
example.py
102 lines (73 loc) · 2.73 KB
/
example.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
This file is part of QProgEdit.
QProgEdit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QProgEdit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QProgEdit. If not, see <http://www.gnu.org/licenses/>.
"""
import sip
sip.setapi('QString', 1)
import os
import sys
from PyQt4 import QtGui, QtCore
from QProgEdit import QTabManager, validate
def cursorRowChanged(index, rowFrom, rowTo):
print(u'curorRowChanged(): %d, %d, %d' % (index, rowFrom, rowTo))
def focusLost(index):
print(u'focusOut(): %s' % index)
def focusReceived(index):
print(u'focusReceived(): %s' % index)
def handlerButtonClicked(index):
print(u'handlerButtonClicked(): %s' % index)
def activateSymbolTree(treeWidgetItem):
treeWidgetItem.activate()
def main():
"""Runs a simple QProgEdit demonstration."""
validate.addPythonBuiltins(['builtin_var'])
app = QtGui.QApplication(sys.argv)
treeWidgetItem1 = QtGui.QTreeWidgetItem([u'Tab 1'])
treeWidgetItem3 = QtGui.QTreeWidgetItem([u'Tab 3'])
symbolTree = QtGui.QTreeWidget()
symbolTree.addTopLevelItem(treeWidgetItem1)
symbolTree.addTopLevelItem(treeWidgetItem3)
symbolTree.itemActivated.connect(activateSymbolTree)
tabManager = QTabManager(handlerButtonText=u'apply')
tabManager.setWindowIcon(QtGui.QIcon.fromTheme(u'accessories-text-editor'))
tabManager.setWindowTitle(u'QProgEdit')
tabManager.resize(800, 600)
tabManager.cursorRowChanged.connect(cursorRowChanged)
tabManager.focusLost.connect(focusLost)
tabManager.focusReceived.connect(focusReceived)
tabManager.handlerButtonClicked.connect(handlerButtonClicked)
tab = tabManager.addTab(u'Tab 1')
tab.setLang(u'Python')
tab.setSymbolTree(treeWidgetItem1)
tab.setText(open(__file__).read())
print tab.symbols()
tab = tabManager.addTab(u'Tab 2')
tab.setText(u'Some plain text')
tab = tabManager.addTab(u'Tab 3')
tab.setLang(u'Python')
tab.setSymbolTree(treeWidgetItem3)
if os.path.exists(u'content.txt'):
tab.setText(open(u'content.txt').read().decode(u'utf-8'))
print tab.symbols()
layout = QtGui.QHBoxLayout()
layout.addWidget(symbolTree)
layout.addWidget(tabManager)
container = QtGui.QWidget()
container.setLayout(layout)
container.show()
res = app.exec_()
open(u'content.txt', u'w').write(tab.text().encode(u'utf-8'))
sys.exit(res)
if __name__ == '__main__':
main()