-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_iface_files.py
235 lines (177 loc) · 7.02 KB
/
make_iface_files.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!python3
'''Create api and hta files from scintilla.iface file.
The json file created is cached data, collected by use of Face.py.
'''
import html, importlib, json, os, sys
import scintilla.scripts.Face as Face
import common
settings = common.settings
# Make iface.api.
settings['make_api'] = False
# Make iface.hta.
settings['make_hta'] = True
def make_api():
'''Make an api file.'''
with open('iface.json') as r:
dic = json.load(r)
api = []
for name, feature in dic.items():
if feature['FeatureType'] in ('get', 'fun', 'set'):
calltip = [feature['FeatureType'], name]
# To match SciTE Lua doc.
if feature['Param1Name'] == 'length':
if feature['Param2Type'] == 'string':
feature['Param1Type'] = ''
feature['Param1Name'] = ''
elif feature['Param2Type'] == 'stringresult':
feature['Param1Type'] = ''
feature['Param1Name'] = ''
feature['Param2Type'] = ''
feature['Param2Name'] = ''
parameters = '{Param1Type} {Param1Name}, {Param2Type} {Param2Name}' \
.format_map(feature).strip()
if parameters.startswith(',') or parameters.endswith(','):
parameters = parameters.replace(',', '').strip()
calltip.append(parameters)
comment = '\\n '.join(feature['Comment']).rstrip()
calltip.append(comment)
calltip.append(feature['ReturnType'])
api.append(calltip)
api.sort()
# Build a combined list of lines sorted for write.
lines = []
for item in api:
if item[0] == 'fun':
line = '{1}({2}) {3}'.format(*item)
lines.append('editor:' + line)
lines.append('output:' + line)
elif item[0] in ('get', 'set'):
line = '{1}(-) {0}[{2}]\\n {3}'.format(*item)
lines.append('editor.' + line)
lines.append('output.' + line)
lines.sort()
with open('iface.api', 'w') as w:
for line in lines:
w.write(line + '\n')
def make_hta():
'''Make an hta file with SciTE functions, getters and setters.'''
head = ('<!DOCTYPE html>\n'
'<html>\n\n'
'<head>\n'
' <meta charset="utf-8">\n'
' <style>\n'
' body {background: #383838}\n'
' h1 {color: lightblue; background: #444444; padding: 2px}\n'
' pre {border: 1px solid grey; padding: 10px; background-color: #FBFBFB}\n'
' table {color: #CCCCCC; background: #333333}\n'
' table, th, tr, td {border: #555555 solid 1px; border-collapse: collapse}\n'
' th {color: #FFFFFF; background: #000000}\n'
' p {color: #CCCCCC}\n'
' i {padding: 0px 15px}\n'
' .s0 {color: white}\n'
' .s1 {color: lightgreen}\n'
' .s2 {color: red}\n'
' </style>\n'
'</head>\n\n'
'<body>\n'
' <h1># Scintilla IFace Functions, Getters And Setters</h1>\n\n'
' <p><b>Colors:</b> <i>Basics</i> | <i class="s1">Provisional</i> |'
' <i class="s2">Deprecated</i> | <i class="s0">No parameters</i></p>\n\n'
' <table>\n'
' <tr>'
'<th>FType</th>'
'<th>Name</th>'
'<th>Comment</th>'
'<th>ReturnType</th>'
'<th>Param1Type</th>'
'<th>Param1Name</th>'
'<th>Param2Type</th>'
'<th>Param2Name</th>'
'<th>Category</th>'
'<th>Value</th>'
'</tr>')
foot = ' </table>\n\n</body>\n\n</html>'
with open('iface.json') as r:
dic = json.load(r)
with open('iface.hta', 'w') as w:
w.write(head + '\n')
for name, data in dic.items():
# Get the functions, getters and setters.
if data['FeatureType'] in ('fun', 'get', 'set'):
data['Comment'] = [html.escape(item) for item in data['Comment']]
data['Comment'] = ' '.join(data['Comment'])
if data['ReturnType'] == 'void':
data['ReturnType'] = ''
# Style rows that are Provisional and Deprecated.
if data['Category'] == 'Basics':
data['Category'] = ''
style = ''
elif data['Category'] == 'Provisional':
style = ' class="s1"'
elif data['Category'] == 'Deprecated':
style = ' class="s2"'
else:
style = ''
# Style rows that have no arguments and return value.
if not style:
style = ''
for item in ('ReturnType', 'Param1Type', 'Param1Name',
'Param2Type', 'Param2Name'):
if data[item] != '':
break
else:
style = ' class="s0"'
# Write the current row.
w.write((' <tr' + style + '>'
'<td>{FeatureType}</td>'
'<td>' + name + '</td>'
'<td>{Comment}</td>'
'<td>{ReturnType}</td>'
'<td>{Param1Type}</td>'
'<td>{Param1Name}</td>'
'<td>{Param2Type}</td>'
'<td>{Param2Name}</td>'
'<td>{Category}</td>'
'<td>{Value}</td>'
'</tr>\n').format_map(data))
# End the html with a footer.
w.write(foot + '\n')
def make_json(scintilla_iface_file, all_features=True):
'''Make a json file with iface data.'''
face = Face.Face()
face.ReadFromFile(scintilla_iface_file)
if all_features:
dic = face.features
else:
dic = {}
for name, feature in face.features.items():
if feature['FeatureType'] in ('fun', 'get', 'set'):
dic[name] = feature
with open('iface.json', 'w') as w:
json.dump(dic, w, indent=4, sort_keys=True)
if __name__ == '__main__':
# Set output path.
output = settings['output']
if not os.path.isdir(output):
os.makedirs(output)
# Get initial directory, then change directory to output.
initial_dir = os.getcwd()
os.chdir(output)
print('output:')
# Make iface.json if not exist.
if not os.path.isfile('iface.json'):
print(' iface.json')
file = os.path.join(initial_dir, 'scintilla',
'include', 'Scintilla.iface')
make_json(file, False)
# Make iface.api.
if settings['make_api']:
make_api()
if os.path.isfile('iface.api'):
print(' iface.api')
# Make iface.hta.
if settings['make_hta']:
make_hta()
if os.path.isfile('iface.hta'):
print(' iface.hta')
print('done')