/
editor.py
executable file
·56 lines (38 loc) · 1.3 KB
/
editor.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
#!/usr/bin/env python
import sys
if not '-p' in sys.argv:
sys.path.insert(0, 'build/lib.linux-x86_64-2.6/')
import sip
sip.setapi('QString', 2)
from PyQt4.QtGui import QApplication, QFont, QPlainTextEdit, QSyntaxHighlighter, \
QTextCharFormat, QTextBlockUserData
from qutepart.syntax.highlighter import SyntaxHighlighter
from qutepart.syntax.syntax import SyntaxManager
def main():
args = [arg for arg in sys.argv \
if not arg.startswith('-')]
if len(args) != 2:
print 'Usage:\n\t%s FILE' % sys.argv[0]
filePath = args[1]
try:
syntax = SyntaxManager().getSyntaxBySourceFileName(filePath, SyntaxHighlighter.formatConverterFunction)
except KeyError:
print 'No syntax for', filePath
return
print 'Using syntax', syntax.name
with open(filePath) as file:
text = unicode(file.read(), 'utf8')
app = QApplication(sys.argv)
pte = QPlainTextEdit()
pte.setPlainText(text)
pte.setWindowTitle(filePath)
pte.setFont(QFont("Monospace"))
hl = SyntaxHighlighter(syntax, pte.document())
pte.resize(800, 600)
pte.show()
from PyQt4.QtCore import QTimer
if '-q' in sys.argv:
QTimer.singleShot(0, app.quit)
return app.exec_()
if __name__ == '__main__':
main()