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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PySide.QtCore import *
from PySide.QtGui import *
import ScintillaConstants as sci
sys.path.append("../..")
from bin import ScintillaEditPy
txtInit = "int main(int argc, char **argv) {\n" \
" // Start up the gnome\n" \
" gnome_init(\"stest\", \"1.0\", argc, argv);\n}\n";
keywords = \
"and and_eq asm auto bitand bitor bool break " \
"case catch char class compl const const_cast continue " \
"default delete do double dynamic_cast else enum explicit export extern false float for " \
"friend goto if inline int long mutable namespace new not not_eq " \
"operator or or_eq private protected public " \
"register reinterpret_cast return short signed sizeof static static_cast struct switch " \
"template this throw true try typedef typeid typename union unsigned using " \
"virtual void volatile wchar_t while xor xor_eq";
def uriDropped():
print "uriDropped"
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.resize(460,300)
# Create widgets
self.edit = ScintillaEditPy.ScintillaEdit(self)
self.edit.uriDropped.connect(uriDropped)
self.edit.command.connect(self.receive_command)
self.edit.notify.connect(self.receive_notification)
self.edit.styleClearAll()
self.edit.setMarginWidthN(0, 35)
self.edit.setScrollWidth(200)
self.edit.setScrollWidthTracking(1)
self.edit.setLexer(sci.SCLEX_CPP)
self.edit.styleSetFore(sci.SCE_C_COMMENT, 0x008000)
self.edit.styleSetFore(sci.SCE_C_COMMENTLINE, 0x008000)
self.edit.styleSetFore(sci.SCE_C_COMMENTDOC, 0x008040)
self.edit.styleSetItalic(sci.SCE_C_COMMENTDOC, 1)
self.edit.styleSetFore(sci.SCE_C_NUMBER, 0x808000)
self.edit.styleSetFore(sci.SCE_C_WORD, 0x800000)
self.edit.styleSetBold(sci.SCE_C_WORD, True)
self.edit.styleSetFore(sci.SCE_C_STRING, 0x800080)
self.edit.styleSetFore(sci.SCE_C_PREPROCESSOR, 0x008080)
self.edit.styleSetBold(sci.SCE_C_OPERATOR, True)
self.edit.setMultipleSelection(1)
self.edit.setVirtualSpaceOptions(
sci.SCVS_RECTANGULARSELECTION | sci.SCVS_USERACCESSIBLE)
self.edit.setAdditionalSelectionTyping(1)
self.edit.styleSetFore(sci.STYLE_INDENTGUIDE, 0x808080)
self.edit.setIndentationGuides(sci.SC_IV_LOOKBOTH)
self.edit.setKeyWords(0, keywords)
self.edit.addText(len(txtInit), txtInit)
self.edit.setSel(1,10)
retriever = str(self.edit.getLine(1))
print(type(retriever), len(retriever))
print('[' + retriever + ']')
someText = str(self.edit.textRange(2,5))
print(len(someText), '[' + someText + ']')
someText = self.edit.getCurLine(100)
print(len(someText), '[' + someText + ']')
someText = self.edit.styleFont(1)
print(len(someText), '[' + someText + ']')
someText = self.edit.getSelText()
print(len(someText), '[' + someText + ']')
someText = self.edit.tag(1)
print(len(someText), '[' + someText + ']')
someText = self.edit.autoCCurrentText()
print(len(someText), '[' + someText + ']')
someText = self.edit.annotationText(1)
print(len(someText), '[' + someText + ']')
someText = self.edit.annotationStyles(1)
print(len(someText), '[' + someText + ']')
someText = self.edit.describeKeyWordSets()
print(len(someText), '[' + someText + ']')
someText = self.edit.propertyNames()
print(len(someText), '[' + someText + ']')
self.edit.setProperty("fold", "1")
someText = self.edit.property("fold")
print(len(someText), '[' + someText + ']')
someText = self.edit.propertyExpanded("fold")
print(len(someText), '[' + someText + ']')
someText = self.edit.lexerLanguage()
print(len(someText), '[' + someText + ']')
someText = self.edit.describeProperty("styling.within.preprocessor")
print(len(someText), '[' + someText + ']')
xx = self.edit.findText(0, "main", 0, 25)
print(type(xx), xx)
print("isBold", self.edit.styleBold(sci.SCE_C_WORD))
# Retrieve the document and write into it
doc = self.edit.get_doc()
doc.insert_string(40, "***")
stars = doc.get_char_range(40,3)
assert stars == "***"
# Create a new independent document and attach it to the editor
doc = ScintillaEditPy.ScintillaDocument()
doc.insert_string(0, "/***/\nif(a)\n")
self.edit.set_doc(doc)
self.edit.setLexer(sci.SCLEX_CPP)
def Call(self, message, wParam=0, lParam=0):
return self.edit.send(message, wParam, lParam)
def resizeEvent(self, e):
self.edit.resize(e.size().width(), e.size().height())
def receive_command(self, wParam, lParam):
# Show underline at start when focussed
notifyCode = wParam >> 16
if (notifyCode == sci.SCEN_SETFOCUS) or (notifyCode == sci.SCEN_KILLFOCUS):
self.edit.setIndicatorCurrent(sci.INDIC_CONTAINER);
self.edit.indicatorClearRange(0, self.edit.length())
if notifyCode == sci.SCEN_SETFOCUS:
self.edit.indicatorFillRange(0, 2);
def receive_notification(self, scn):
if scn.nmhdr.code == sci.SCN_CHARADDED:
print "Char %02X" % scn.ch
elif scn.nmhdr.code == sci.SCN_SAVEPOINTREACHED:
print "Saved"
elif scn.nmhdr.code == sci.SCN_SAVEPOINTLEFT:
print "Unsaved"
elif scn.nmhdr.code == sci.SCN_MODIFIED:
print "Modified"
elif scn.nmhdr.code == sci.SCN_UPDATEUI:
print "Update UI"
elif scn.nmhdr.code == sci.SCN_PAINTED:
#print "Painted"
pass
else:
print "Notification", scn.nmhdr.code
pass
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the form
form = Form()
form.show()
# Run the main Qt loop
sys.exit(app.exec_())
|