import wx, os
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"}
self.HOMEDIR= os.path.expanduser('~')
self.SyntCol = SyntaxColorizer()
self.ReadConfig()
def GetOption(self,option):
try:
return self.ConfigDict[option]
except:
return self.DefaultConfigDict[option]
def ChangeOption(self,option, val,IdRange):
TempConfigDict = self.ConfigDict
#~ try:
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()
#~ except:
#~ ConfigDict = self.DefaultConfigDict
#~ ConfigFile = open(self.HOMEDIR+"/.gEcrit.conf","w")
#~ ConfigFile.write(str(self.DefaultConfigDict))
#~ ConfigFile.close()
#~ 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.SetMarginType(0,wx.stc.STC_MARGIN_NUMBER)
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:
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)
item.GetParent().GetParent().SplitVertically(item.GetParent(), wx.FindWindowById(997))
counter +=1
else:
for id in IdRange:
item = wx.FindWindowById(2000+id)
item.GetParent().GetParent().Unsplit(item.GetParent())
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":
# try:
OSShell.OnClose(0)
item.RemovePage(self.GetTab("OS Shell",item))
# except: pass
if not self.GetOption("PythonShell") and not self.GetOption("BashShell"):
#item.Hide()
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")
if self.GetOption("BashShell") and feature == "BashShell":
OSShell.OnRun(0,self.GetOption("OSPath"))
item.AddPage(OSShell.parent,"OS Shell")
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)
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;
return -1;
def ApplyIDEConfig(self,text_id, file_ext):
CurrentWidget = wx.FindWindowById(text_id)
if self.GetOption("SyntaxHighlight") and file_ext =="py":
self.SyntCol.ActivateSyntaxHighLight(text_id)
if self.GetOption("Autoindentation"):
CurrentWidget.SetIndent(self.GetOption("IndentSize"))
CurrentWidget.SetIndentationGuides(self.GetOption("IndetationGuides"))
CurrentWidget.SetBackSpaceUnIndents(self.GetOption("BackSpaceUnindent"))
CurrentWidget.SetViewWhiteSpace(self.GetOption("Whitespace"))
CurrentWidget.SetUseTabs(self.GetOption("UseTabs"))
CurrentWidget.SetCaretWidth(self.GetOption("CarretWidth"))
CurrentWidget.SetTabWidth(self.GetOption("IndentSize"))
CurrentWidget.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
if self.GetOption("LineNumbers"):
CurrentWidget.SetMarginWidth(1,45)
else:
CurrentWidget.SetMarginWidth(1,1)
if self.GetOption("FoldMarks"):
CurrentWidget.SetMarginType(2, wx.stc.STC_MARGIN_SYMBOL)
CurrentWidget.SetMarginMask(2, wx.stc.STC_MASK_FOLDERS)
CurrentWidget.SetMarginSensitive(2, True)
CurrentWidget.SetMarginWidth(2, 12)
CurrentWidget.SetTabWidth(self.GetOption("TabWidth"))
if self.GetOption("EdgeLine"):
CurrentWidget.SetEdgeColumn(self.GetOption("EdgeColumn"))
CurrentWidget.SetEdgeMode(wx.stc.STC_EDGE_LINE)
CurrentWidget.SetEdgeColour(self.SyntCol.ReadColorFile("EdgeLine"))