Commit 9dd16b34 authored by Steven M. Gava's avatar Steven M. Gava

further config system work

parent 0bd292f0
...@@ -67,7 +67,7 @@ class ColorDelegator(Delegator): ...@@ -67,7 +67,7 @@ class ColorDelegator(Delegator):
"hit": idleConf.GetHighlight(theme, "hit"), "hit": idleConf.GetHighlight(theme, "hit"),
} }
print tagdefs if DEBUG: print 'tagdefs',tagdefs
def insert(self, index, chars, tags=None): def insert(self, index, chars, tags=None):
index = self.index(index) index = self.index(index)
......
...@@ -25,8 +25,23 @@ class ConfigDialog(Toplevel): ...@@ -25,8 +25,23 @@ class ConfigDialog(Toplevel):
self.configure(borderwidth=5) self.configure(borderwidth=5)
self.geometry("+%d+%d" % (parent.winfo_rootx()+20, self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
parent.winfo_rooty()+30)) parent.winfo_rooty()+30))
#self.LoadConfig() #Theme Elements. Each theme element key is it's display name.
#The first value of the tuple is the sample area tag name.
#The second value is the display name list sort index.
#The third value indicates whether the element can have a foreground
#or background colour or both.
self.themeElements={'Normal Text':('normal','00','both'),
'Python Keywords':('keyword','01','both'),
'Python Definitions':('definition','02','both'),
'Python Comments':('comment','03','both'),
'Python Strings':('string','04','both'),
'Selected Text':('selected','05','both'),
'Found Text':('found','06','both'),
'Cursor':('cursor','07','fg'),
'Error Background':('error','08','bg'),
'Shell Foreground':('shfg','09','fg'),
'Shell Stdout Foreground':('shstdout','10','fg'),
'Shell Stderr Foreground':('shstderr','11','fg')}
self.CreateWidgets() self.CreateWidgets()
self.resizable(height=FALSE,width=FALSE) self.resizable(height=FALSE,width=FALSE)
self.ChangePage() self.ChangePage()
...@@ -43,10 +58,7 @@ class ConfigDialog(Toplevel): ...@@ -43,10 +58,7 @@ class ConfigDialog(Toplevel):
self.bind('<Alt-h>',self.ChangePageBinding) self.bind('<Alt-h>',self.ChangePageBinding)
self.bind('<Alt-k>',self.ChangePageBinding) self.bind('<Alt-k>',self.ChangePageBinding)
self.bind('<Alt-g>',self.ChangePageBinding) self.bind('<Alt-g>',self.ChangePageBinding)
#self.LoadOptMenuHighlightTarget()
self.LoadConfigs() self.LoadConfigs()
self.wait_window() self.wait_window()
def Cancel(self): def Cancel(self):
...@@ -93,11 +105,11 @@ class ConfigDialog(Toplevel): ...@@ -93,11 +105,11 @@ class ConfigDialog(Toplevel):
pos=pos+1 pos=pos+1
def SetThemeType(self): def SetThemeType(self):
if self.themeType.get()==0: if self.themeBuiltin.get():
self.optMenuThemeBuiltin.config(state=NORMAL) self.optMenuThemeBuiltin.config(state=NORMAL)
self.optMenuThemeCustom.config(state=DISABLED) self.optMenuThemeCustom.config(state=DISABLED)
self.buttonDeleteCustomTheme.config(state=DISABLED) self.buttonDeleteCustomTheme.config(state=DISABLED)
elif self.themeType.get()==1: else:
self.optMenuThemeBuiltin.config(state=DISABLED) self.optMenuThemeBuiltin.config(state=DISABLED)
self.optMenuThemeCustom.config(state=NORMAL) self.optMenuThemeCustom.config(state=NORMAL)
self.buttonDeleteCustomTheme.config(state=NORMAL) self.buttonDeleteCustomTheme.config(state=NORMAL)
...@@ -113,18 +125,17 @@ class ConfigDialog(Toplevel): ...@@ -113,18 +125,17 @@ class ConfigDialog(Toplevel):
self.buttonDeleteCustomKeys.config(state=NORMAL) self.buttonDeleteCustomKeys.config(state=NORMAL)
def GetColour(self): def GetColour(self):
target=self.highlightTarget.get()
rgbTuplet, colourString = tkColorChooser.askcolor(parent=self, rgbTuplet, colourString = tkColorChooser.askcolor(parent=self,
title='Pick new colour for : '+self.highlightTarget.get(), title='Pick new colour for : '+target,
initialcolor=self.workingTestColours['Foo-Bg'])#._root() initialcolor=self.frameColourSet.cget('bg'))
if colourString: #user didn't cancel if colourString: #user didn't cancel
self.workingTestColours['Foo-Bg']=colourString self.frameColourSet.config(bg=colourString)#set sample
self.frameColourSet.config(bg=self.workingTestColours['Foo-Bg']) if self.fgHilite.get(): plane='foreground'
self.labelTestSample.config(bg=self.workingTestColours['Foo-Bg']) else: plane='background'
self.frameHighlightSample.config(bg=self.workingTestColours['Foo-Bg']) apply(self.textHighlightSample.tag_config,
self.frameColourSet.update() #redraw after dialog (self.themeElements[target][0],),{plane:colourString})
self.frameHighlightSample.update() #redraw after dialog
self.labelTestSample.update()
def SetFontSampleBinding(self,event): def SetFontSampleBinding(self,event):
self.SetFontSample() self.SetFontSample()
...@@ -136,21 +147,19 @@ class ConfigDialog(Toplevel): ...@@ -136,21 +147,19 @@ class ConfigDialog(Toplevel):
self.SetHighlightTarget() self.SetHighlightTarget()
def SetHighlightTarget(self): def SetHighlightTarget(self):
if self.highlightTarget.get() in ('Cursor','Error Background'): colourPlane=self.themeElements[self.highlightTarget.get()][2]
#only bg colour selection is possible if colourPlane == 'bg':
self.radioFg.config(state=DISABLED) self.radioFg.config(state=DISABLED)
self.radioBg.config(state=DISABLED) self.radioBg.config(state=DISABLED)
self.fgHilite.set(0) self.fgHilite.set(0)
elif self.highlightTarget.get() in ('Shell Foreground', elif colourPlane == 'fg':
'Shell Stdout Foreground','Shell Stderr Foreground'):
#fg and font style selection possible
self.radioFg.config(state=DISABLED) self.radioFg.config(state=DISABLED)
self.radioBg.config(state=DISABLED) self.radioBg.config(state=DISABLED)
self.fgHilite.set(1) self.fgHilite.set(1)
else: #full fg/bg and font style selection possible elif colourPlane == 'both':
self.radioFg.config(state=NORMAL) self.radioFg.config(state=NORMAL)
self.radioBg.config(state=NORMAL) self.radioBg.config(state=NORMAL)
self.fgHilite.set(1) #default to setting foreground properties self.fgHilite.set(1) #default to setting foreground attribute
def CreateWidgets(self): def CreateWidgets(self):
self.framePages = Frame(self) self.framePages = Frame(self)
...@@ -291,7 +300,7 @@ class ConfigDialog(Toplevel): ...@@ -291,7 +300,7 @@ class ConfigDialog(Toplevel):
self.fgHilite=IntVar() self.fgHilite=IntVar()
self.colour=StringVar() self.colour=StringVar()
self.fontName=StringVar() self.fontName=StringVar()
self.themeType=IntVar() self.themeBuiltin=IntVar()
self.highlightTarget=StringVar() self.highlightTarget=StringVar()
self.highlightTarget.trace_variable('w',self.SetHighlightTargetBinding) self.highlightTarget.trace_variable('w',self.SetHighlightTargetBinding)
##widget creation ##widget creation
...@@ -307,95 +316,41 @@ class ConfigDialog(Toplevel): ...@@ -307,95 +316,41 @@ class ConfigDialog(Toplevel):
text=self.textHighlightSample text=self.textHighlightSample
text.bind('<Double-Button-1>',lambda e: 'break') text.bind('<Double-Button-1>',lambda e: 'break')
text.bind('<B1-Motion>',lambda e: 'break') text.bind('<B1-Motion>',lambda e: 'break')
text.insert(END,'#you can click in here','comment') textAndTags=(('#you can click in here','comment'),('\n','normal'),
text.insert(END,'\n') ('#to choose items','comment'),('\n','normal'),('def','keyword'),
text.insert(END,'#to choose items','comment') (' ','normal'),('func','definition'),('(param):','normal'),
text.insert(END,'\n') ('\n ','normal'),('"""string"""','string'),('\n var0 = ','normal'),
text.insert(END,'def','keyword') ("'string'",'string'),('\n var1 = ','normal'),("'selected'",'selected'),('\n var2 = ','normal'),
text.insert(END,' ') ("'found'",'found'),('\n\n','normal'),(' error ','error'),
text.insert(END,'func','definition') ('cursor |','cursor'),('\n ','normal'),('shell','shfg'),(' ','normal'),('stdout','shstdout'),(' ','normal'),
text.insert(END,'(param):') ('stderr','shstderr'))
text.insert(END,'\n ') for txTa in textAndTags:
text.insert(END,'"""string"""','string') text.insert(END,txTa[0],txTa[1])
text.insert(END,'\n var0 = ') for element in self.themeElements.keys():
text.insert(END,"'string'",'string') text.tag_bind(self.themeElements[element][0],'<ButtonPress-1>',
text.insert(END,'\n var1 = ') lambda event,elem=element: event.widget.winfo_toplevel()
text.insert(END,"'selected'",'selected') .highlightTarget.set(elem))
text.insert(END,'\n var2 = ')
text.insert(END,"'found'",'found')
text.insert(END,'\n\n')
text.insert(END,' error ','error')
text.insert(END,'cursor |','cursor')
text.insert(END,'\n ')
text.insert(END,'shell','shell')
text.insert(END,' ')
text.insert(END,'stdout','shellstdout')
text.insert(END,' ')
text.insert(END,'stderr','shellstderr')
text.tag_add('normal',1.0,END)
text.tag_lower('normal')
text.tag_bind('normal','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Normal Text'))
text.tag_bind('comment','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Python Comments'))
text.tag_bind('keyword','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Python Keywords'))
text.tag_bind('definition','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Python Definitions'))
text.tag_bind('string','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Python Strings'))
text.tag_bind('selected','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Selected Text'))
text.tag_bind('found','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Found Text'))
text.tag_bind('error','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Error Background'))
text.tag_bind('cursor','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Cursor'))
text.tag_bind('shell','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Shell Foreground'))
text.tag_bind('shellstdout','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Shell Stdout Foreground'))
text.tag_bind('shellstderr','<ButtonPress-1>',
lambda e: e.widget.winfo_toplevel().highlightTarget.set(
'Shell Stderr Foreground'))
text.config(state=DISABLED) text.config(state=DISABLED)
self.frameColourSet=Frame(frameCustom,relief=SOLID,borderwidth=1) self.frameColourSet=Frame(frameCustom,relief=SOLID,borderwidth=1)
frameFgBg=Frame(frameCustom) frameFgBg=Frame(frameCustom)
labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting') labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting')
buttonSetColour=Button(self.frameColourSet,text='Choose Colour for :', buttonSetColour=Button(self.frameColourSet,text='Choose Colour for :',
command=self.GetColour) command=self.GetColour,highlightthickness=0)
self.optMenuHighlightTarget=DynOptionMenu(self.frameColourSet, self.optMenuHighlightTarget=DynOptionMenu(self.frameColourSet,
self.highlightTarget,None)#,command=self.SetHighlightTargetBinding self.highlightTarget,None,highlightthickness=0)#,command=self.SetHighlightTargetBinding
self.radioFg=Radiobutton(frameFgBg,variable=self.fgHilite, self.radioFg=Radiobutton(frameFgBg,variable=self.fgHilite,
value=1,text='Foreground')#,command=self.SetFgBg value=1,text='Foreground')#,command=self.SetFgBg
self.radioBg=Radiobutton(frameFgBg,variable=self.fgHilite, self.radioBg=Radiobutton(frameFgBg,variable=self.fgHilite,
value=0,text='Background')#,command=self.SetFgBg value=0,text='Background')#,command=self.SetFgBg
self.fgHilite.set(1) self.fgHilite.set(1)
#self.labelFontTypeTitle=Label(frameFontSet,text='Font Style :')
#self.checkFontBold=Checkbutton(frameFontSet,variable=self.fontBold,
# onvalue='Bold',offvalue='',text='Bold')
#self.checkFontItalic=Checkbutton(frameFontSet,variable=self.fontItalic,
# onvalue='Italic',offvalue='',text='Italic')
buttonSaveCustomTheme=Button(frameCustom, buttonSaveCustomTheme=Button(frameCustom,
text='Save as a Custom Theme') text='Save as a Custom Theme')
#frameTheme #frameTheme
labelThemeTitle=Label(frameTheme,text='Select a Highlighting Theme') labelThemeTitle=Label(frameTheme,text='Select a Highlighting Theme')
labelTypeTitle=Label(frameTheme,text='Select : ') labelTypeTitle=Label(frameTheme,text='Select : ')
self.radioThemeBuiltin=Radiobutton(frameTheme,variable=self.themeType, self.radioThemeBuiltin=Radiobutton(frameTheme,variable=self.themeBuiltin,
value=0,command=self.SetThemeType,text='a Built-in Theme') value=0,command=self.SetThemeType,text='a Built-in Theme')
self.radioThemeCustom=Radiobutton(frameTheme,variable=self.themeType, self.radioThemeCustom=Radiobutton(frameTheme,variable=self.themeBuiltin,
value=1,command=self.SetThemeType,text='a Custom Theme') value=1,command=self.SetThemeType,text='a Custom Theme')
self.optMenuThemeBuiltin=DynOptionMenu(frameTheme, self.optMenuThemeBuiltin=DynOptionMenu(frameTheme,
self.builtinTheme,None,command=None) self.builtinTheme,None,command=None)
...@@ -412,8 +367,8 @@ class ConfigDialog(Toplevel): ...@@ -412,8 +367,8 @@ class ConfigDialog(Toplevel):
frameFgBg.pack(side=TOP,padx=5,pady=0) frameFgBg.pack(side=TOP,padx=5,pady=0)
self.textHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE, self.textHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,
fill=BOTH) fill=BOTH)
buttonSetColour.pack(side=TOP,expand=TRUE,fill=X,padx=5,pady=3) buttonSetColour.pack(side=TOP,expand=TRUE,fill=X,padx=8,pady=4)
self.optMenuHighlightTarget.pack(side=TOP,expand=TRUE,fill=X,padx=5,pady=3) self.optMenuHighlightTarget.pack(side=TOP,expand=TRUE,fill=X,padx=8,pady=3)
self.radioFg.pack(side=LEFT,anchor=E) self.radioFg.pack(side=LEFT,anchor=E)
self.radioBg.pack(side=RIGHT,anchor=W) self.radioBg.pack(side=RIGHT,anchor=W)
buttonSaveCustomTheme.pack(side=BOTTOM,fill=X,padx=5,pady=5) buttonSaveCustomTheme.pack(side=BOTTOM,fill=X,padx=5,pady=5)
...@@ -579,6 +534,9 @@ class ConfigDialog(Toplevel): ...@@ -579,6 +534,9 @@ class ConfigDialog(Toplevel):
return frame return frame
def PaintThemeSample(self):
pass
def LoadFontCfg(self): def LoadFontCfg(self):
##base editor font selection list ##base editor font selection list
fonts=list(tkFont.families(self)) fonts=list(tkFont.families(self))
...@@ -611,13 +569,13 @@ class ConfigDialog(Toplevel): ...@@ -611,13 +569,13 @@ class ConfigDialog(Toplevel):
self.spaceNum.set(spaceNum) self.spaceNum.set(spaceNum)
self.tabCols.set(tabCols) self.tabCols.set(tabCols)
def LoadThemeLists(self): def LoadThemeCfg(self):
##current theme type radiobutton ##current theme type radiobutton
self.themeType.set(idleConf.GetOption('main','Theme','user',type='int')) self.themeBuiltin.set(idleConf.GetOption('main','Theme','user',type='int'))
##currently set theme ##currently set theme
currentOption=idleConf.GetOption('main','Theme','name') currentOption=idleConf.GetOption('main','Theme','name')
##load available theme option menus ##load available theme option menus
if self.themeType.get() == 0: #default theme selected if self.themeBuiltin.get(): #default theme selected
itemList=idleConf.GetSectionList('default','highlight') itemList=idleConf.GetSectionList('default','highlight')
self.optMenuThemeBuiltin.SetMenu(itemList,currentOption) self.optMenuThemeBuiltin.SetMenu(itemList,currentOption)
itemList=idleConf.GetSectionList('user','highlight') itemList=idleConf.GetSectionList('user','highlight')
...@@ -626,20 +584,24 @@ class ConfigDialog(Toplevel): ...@@ -626,20 +584,24 @@ class ConfigDialog(Toplevel):
self.customTheme.set('- no custom themes -') self.customTheme.set('- no custom themes -')
else: else:
self.optMenuThemeCustom.SetMenu(itemList,itemList[0]) self.optMenuThemeCustom.SetMenu(itemList,itemList[0])
elif self.themeType.get() == 1: #user theme selected else: #user theme selected
itemList=idleConf.GetSectionList('user','highlight') itemList=idleConf.GetSectionList('user','highlight')
self.optMenuThemeCustom.SetMenu(itemList,currentOption) self.optMenuThemeCustom.SetMenu(itemList,currentOption)
itemList=idleConf.GetSectionList('default','highlight') itemList=idleConf.GetSectionList('default','highlight')
self.optMenuThemeBuiltin.SetMenu(itemList,itemList[0]) self.optMenuThemeBuiltin.SetMenu(itemList,itemList[0])
self.SetThemeType() self.SetThemeType()
##load theme element option menu ##load theme element option menu
elements=('Normal Text','Python Keywords','Python Definitions', themeNames=self.themeElements.keys()
'Python Comments','Python Strings','Selected Text', themeNames.sort(self.__ThemeNameIndexCompare)
'Found Text','Cursor','Error Background','Shell Foreground', self.optMenuHighlightTarget.SetMenu(themeNames,themeNames[0])
'Shell Stdout Foreground','Shell Stderr Foreground') self.PaintThemeSample()
self.optMenuHighlightTarget.SetMenu(elements,elements[0])
def __ThemeNameIndexCompare(self,a,b):
if self.themeElements[a][1]<self.themeElements[b][1]: return -1
elif self.themeElements[a][1]==self.themeElements[b][1]: return 0
else: return 1
def LoadKeyLists(self): def LoadKeyCfg(self):
##current keys type radiobutton ##current keys type radiobutton
self.keysType.set(idleConf.GetOption('main','Keys','user',type='int')) self.keysType.set(idleConf.GetOption('main','Keys','user',type='int'))
##currently set keys ##currently set keys
...@@ -671,9 +633,9 @@ class ConfigDialog(Toplevel): ...@@ -671,9 +633,9 @@ class ConfigDialog(Toplevel):
self.LoadFontCfg() self.LoadFontCfg()
self.LoadTabCfg() self.LoadTabCfg()
### highlighting page ### highlighting page
self.LoadThemeLists() self.LoadThemeCfg()
### keys page ### keys page
self.LoadKeyLists() self.LoadKeyCfg()
### help page ### help page
### general page ### general page
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment