[go: up one dir, main page]

Menu

[r18]: / gEcrit / bin / configClass.py  Maximize  Restore  History

Download this file

323 lines (268 with data), 11.6 kB

  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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import os
from TinyFeatures import *
from SyntaxHighlight import *
class ConfigNanny:
def __init__(self):
self.DefaultConfigDict = {
"Autosave": False,
"Autosave Interval": 200,
"StatusBar": True,
"ActLog": True,
"LineNumbers": False,
"Font": "Arial",
"FontSize": "12",
"SyntaxHighlight": True,
"IndentSize": 4,
"Whitespace": False,
"IndetationGuides": False,
"Autoindentation": True,
"BackSpaceUnindent": False,
"UseTabs": False,
"CarretWidth": 7,
"FoldMarks": False,
"SourceBrowser": False,
"TabWidth": 8,
"EdgeLine": False,
"EdgeColumn": 80,
"BashShell": False,
"PythonShell": False,
"OSPath": "/bin/bash",
"PyPath": "/usr/bin/python",
"SpellCheck": False,
"SpellSuggestions": False,
"FileTree": False,
"DefaultText": "",
"DefaultTextAct": False,
"RecentFiles":[],
"BraceComp":False
}
self.HOMEDIR = os.path.expanduser('~')
self.ReadConfig()
def GetOption(self, option):
try:
return (self.ConfigDict)[option]
except:
return (self.DefaultConfigDict)[option]
def ChangeOption(self, option, val, IdRange=0):
TempConfigDict = self.ConfigDict
(self.DefaultConfigDict)[option]
TempConfigDict[option] = val
NewConfig = open(self.HOMEDIR + "/.gEcrit.conf", "w")
NewConfig.write(str(TempConfigDict))
NewConfig.close()
self.ToggleFeature(0, option, val, IdRange)
self.ReadConfig()
def ReadConfig(self):
try:
ConfigFile = open(self.HOMEDIR + "/.gEcrit.conf", "r")
self.ConfigDict = eval(ConfigFile.read())
return self.ConfigDict
except:
self.ConfigDict = self.DefaultConfigDict
ConfigFile = open(self.HOMEDIR + "/.gEcrit.conf", "w")
ConfigFile.write(str(self.DefaultConfigDict))
ConfigFile.close()
return self.ConfigDict
def ToggleFeature(self, event, feature, val, IdRange):
if feature == "IndentSize":
for id in IdRange:
item = wx.FindWindowById(id)
item.SetIndent(val)
elif feature == "IndetationGuides":
for id in IdRange:
item = wx.FindWindowById(id)
item.SetIndentationGuides(val)
elif feature == "BackSpaceUnindent":
for id in IdRange:
item = wx.FindWindowById(id)
item.SetBackSpaceUnIndents(val)
elif feature == "Whitespace":
for id in IdRange:
item = wx.FindWindowById(id)
item.SetViewWhiteSpace(val)
elif feature == "UseTabs":
for id in IdRange:
item = wx.FindWindowById(id)
item.SetUseTabs(val)
elif feature == "CarretWidth":
for id in IdRange:
item = wx.FindWindowById(id)
item.SetCaretWidth(val)
elif feature == "IndentSize":
for id in IdRange:
item = wx.FindWindowById(id)
item.SetTabWidth(val)
elif feature == "LineNumbers":
for id in IdRange:
item = wx.FindWindowById(id)
if val == True:
item.SetMarginWidth(1, 45)
else:
item.SetMarginWidth(1, 1)
elif feature == "FoldMarks":
for id in IdRange:
item = wx.FindWindowById(id)
if val == True:
item.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL)
item.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS)
item.SetMarginSensitive(2, True)
item.SetMarginWidth(2, 12)
elif val == False:
item.SetMarginWidth(2, 1)
elif feature == "SyntaxHighlight":
if val == False:
for id in IdRange:
item = wx.FindWindowById(id)
item.StyleClearAll()
elif val == True:
for id in IdRange:
SyntCol.ActivateSyntaxHighLight(id)
elif feature == "StatusBar":
item = wx.FindWindowById(999)
if val == True:
item.Show(True)
else:
item.Hide()
elif feature == "TabWidth":
for id in IdRange:
item = wx.FindWindowById(id)
item.SetTabWidth(val)
elif feature == "EdgeLine":
if val == False:
for id in IdRange:
item = wx.FindWindowById(id)
item.SetEdgeMode(wx.stc.STC_EDGE_NONE)
else:
for id in IdRange:
item = wx.FindWindowById(id)
item.SetEdgeMode(wx.stc.STC_EDGE_LINE)
elif feature == "EdgeColumn":
for id in IdRange:
item = wx.FindWindowById(id)
item.SetEdgeColumn(val)
elif feature == "SourceBrowser":
counter = 0
if val == True:
for id in IdRange:
item = wx.FindWindowById(2000 + id)
nb = wx.FindWindowById(4003 + id)
if self.GetOption("SourceBrowser") and not self.GetOption("FileTree"):
item.parent.GetParent().GetParent().GetParent().SplitVertically(item.GetParent().GetParent().GetParent(),
wx.FindWindowById(1001 + id))
nb.AddPage(item.GetParent(), "Source Browser")
counter += 1
else:
for id in IdRange:
item = wx.FindWindowById(2000 + id)
nb = wx.FindWindowById(4003 + id)
if not self.GetOption("SourceBrowser") and not self.GetOption("FileTree"):
item.parent.GetParent().GetParent().GetParent().Unsplit(item.GetParent().GetParent().GetParent())
nb.RemovePage(self.GetTab("Source Browser", nb))
counter += 1
elif feature == "FileTree":
counter = 0
if val == True:
for id in IdRange:
item = wx.FindWindowById(5000 + id)
nb = wx.FindWindowById(4003 + id)
if self.GetOption("FileTree") and not self.GetOption("SourceBrowser"):
item.parent.GetParent().GetParent().GetParent().SplitVertically(item.GetParent().GetParent().GetParent(),
wx.FindWindowById(1001 + id))
nb.AddPage(item.GetParent(), "File Browser")
counter += 1
else:
for id in IdRange:
item = wx.FindWindowById(5000 + id)
nb = wx.FindWindowById(4003 + id)
if not self.GetOption("FileTree") and not self.GetOption("SourceBrowser"):
item.parent.GetParent().GetParent().GetParent().Unsplit(item.GetParent().GetParent().GetParent())
nb.RemovePage(self.GetTab("File Browser", nb))
counter += 1
elif feature in ["PythonShell", "BashShell"]:
item = wx.FindWindowById(4002)
OSShell = wx.FindWindowById(4000)
PyShell = wx.FindWindowById(4001)
Nb_Panel = wx.FindWindowById(998)
if not self.GetOption("PythonShell"):
try:
PyShell.OnClose(0)
item.RemovePage(self.GetTab("Python", item))
except:
pass
if not self.GetOption("BashShell") and feature == \
"BashShell":
OSShell.OnClose(0)
item.RemovePage(self.GetTab("OS Shell", item))
if not self.GetOption("PythonShell") and not self.GetOption("BashShell"):
item.GetParent().GetParent().Unsplit(item.GetParent())
else:
if self.GetOption("PythonShell") and feature == \
"PythonShell":
PyShell.OnRun(0, self.GetOption("PyPath"))
item.AddPage(PyShell.parent, "Python")
PyShell.GetParent().Fit()
if self.GetOption("BashShell") and feature == \
"BashShell":
OSShell.OnRun(0, self.GetOption("OSPath"))
item.AddPage(OSShell.parent, "OS Shell")
OSShell.GetParent().Fit()
item.GetParent().GetParent().SplitHorizontally(Nb_Panel,
item.GetParent())
item.GetParent().GetParent().Refresh()
elif feature == "EdgeLine":
if val:
for id in IdRange:
wx.FindWindowById(id).SetEdgeMode(wx.stc.STC_EDGE_LINE)
else:
for id in IdRange:
wx.FindWindowById(id).SetEdgeMode(wx.stc.STC_EDGE_NONE)
elif feature == "BraceComp":
if val:
for id in IdRange:
curr_doc = wx.FindWindowById(id)
curr_doc.Bind(wx.stc.EVT_STC_CHARADDED,curr_doc.OnCompBrace)
if not val:
for id in IdRange:
curr_doc = wx.FindWindowById(id)
curr_doc.Bind(wx.stc.EVT_STC_CHARADDED,None)
def GetTab(self, tab_name, notebook):
end = notebook.GetPageCount()
selectedtabText = ""
for i in range(end):
selectedtabText = notebook.GetPageText(i)
if tab_name == selectedtabText:
return i
None
return -1
None
def ApplyIDEConfig(self, text_id, file_ext):
cur_doc = wx.FindWindowById(text_id)
if self.GetOption("SyntaxHighlight") and file_ext == "py":
SyntCol.ActivateSyntaxHighLight(text_id)
if self.GetOption("Autoindentation"):
cur_doc.SetIndent(self.GetOption("IndentSize"))
cur_doc.SetIndentationGuides(self.GetOption("IndetationGuides"))
cur_doc.SetBackSpaceUnIndents(self.GetOption("BackSpaceUnindent"))
cur_doc.SetViewWhiteSpace(self.GetOption("Whitespace"))
cur_doc.SetUseTabs(self.GetOption("UseTabs"))
cur_doc.SetCaretWidth(self.GetOption("CarretWidth"))
cur_doc.SetTabWidth(self.GetOption("IndentSize"))
cur_doc.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
if self.GetOption("LineNumbers"):
cur_doc.SetMarginWidth(1, 45)
else:
cur_doc.SetMarginWidth(1, 1)
if self.GetOption("FoldMarks"):
cur_doc.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL)
cur_doc.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS)
cur_doc.SetMarginSensitive(2, True)
cur_doc.SetMarginWidth(2, 12)
cur_doc.SetTabWidth(self.GetOption("TabWidth"))
if self.GetOption("EdgeLine"):
cur_doc.SetEdgeColumn(self.GetOption("EdgeColumn"))
cur_doc.SetEdgeMode(wx.stc.STC_EDGE_LINE)
cur_doc.SetEdgeColour(SyntCol.ReadColorFile("EdgeLine"))
Config = ConfigNanny()