forked from andreikop/qutepart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.py
executable file
·106 lines (77 loc) · 3.28 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
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
103
104
105
106
#!/usr/bin/env python
import sys
import os
import logging
import argparse
import sip
sip.setapi('QString', 2)
from PyQt4.QtGui import QApplication, QMainWindow
def _parseCommandLine():
parser = argparse.ArgumentParser(description='Qutepart test application')
parser.add_argument('-b, --binary', action='store_true', dest='binary',
help='Use binary parser. Do ./setup.py build before using this flag')
parser.add_argument('-d, --debug', action='store_true', dest='debug', help='Enable debug output')
parser.add_argument('-q, --quit', action='store_true', dest='quit', help='Quit just after start')
parser.add_argument('file', help='File to open')
return parser.parse_args()
def _fixSysPath(binaryQutepart):
executablePath = os.path.abspath(__file__)
if executablePath.startswith('/home'): # if executed from the sources
qutepartDir = os.path.dirname(executablePath)
sys.path.insert(0, qutepartDir) # do not import installed modules
if binaryQutepart:
sys.path.insert(0, qutepartDir + '/build/lib.linux-i686-2.7/') # use built modules
sys.path.insert(0, qutepartDir + '/build/lib.linux-x86_64-2.7/') # use built modules
def main():
ns = _parseCommandLine()
_fixSysPath(ns.binary)
import qutepart # after correct sys.path has been set
with open(ns.file) as file:
text = unicode(file.read(), 'utf8')
if ns.debug:
logging.getLogger('qutepart').setLevel(logging.DEBUG)
app = QApplication(sys.argv)
window = QMainWindow()
qpart = qutepart.Qutepart()
window.setCentralWidget(qpart)
firstLine = text.splitlines()[0] if text else None
qpart.detectSyntax(sourceFilePath=ns.file, firstLine=firstLine)
qpart.lineLengthEdge = 20
qpart.indentUseTabs = True
qpart.text = text
qpart.setWindowTitle(ns.file)
menu = {'Bookmarks': ('toggleBookmarkAction',
'nextBookmarkAction',
'prevBookmarkAction'),
'Navigation':('scrollUpAction',
'scrollDownAction',
'selectAndScrollUpAction',
'selectAndScrollDownAction',
),
'Edit' : ('decreaseIndentAction',
'autoIndentLineAction',
'moveLineUpAction',
'moveLineDownAction',
'deleteLineAction',
'copyLineAction',
'pasteLineAction',
'cutLineAction',
'duplicateLineAction',
'invokeCompletionAction',
'indentWithSpaceAction',
'unIndentWithSpaceAction'
)
}
for k, v in menu.items():
menuObject = window.menuBar().addMenu(k)
for actionName in v:
menuObject.addAction(getattr(qpart, actionName))
qpart.userWarning.connect(lambda text: window.statusBar().showMessage(text, 3000))
window.resize(800, 600)
window.show()
from PyQt4.QtCore import QTimer
if ns.quit:
QTimer.singleShot(0, app.quit)
return app.exec_()
if __name__ == '__main__':
main()