more work to support new config system

This commit is contained in:
Steven M. Gava 2001-11-03 05:07:28 +00:00
parent dedbe255d3
commit e16d94b77e
3 changed files with 121 additions and 87 deletions

View File

@ -4,7 +4,7 @@ import re
import keyword import keyword
from Tkinter import * from Tkinter import *
from Delegator import Delegator from Delegator import Delegator
from IdleConf import idleconf from configHandler import idleConf
#$ event <<toggle-auto-coloring>> #$ event <<toggle-auto-coloring>>
#$ win <Control-slash> #$ win <Control-slash>
@ -53,19 +53,21 @@ class ColorDelegator(Delegator):
apply(self.tag_configure, (tag,), cnf) apply(self.tag_configure, (tag,), cnf)
self.tag_raise('sel') self.tag_raise('sel')
cconf = idleconf.getsection('Colors') theme = idleConf.GetOption('main','Theme','name')
tagdefs = { tagdefs = {
"COMMENT": cconf.getcolor("comment"), "COMMENT": idleConf.GetHighlight(theme, "comment"),
"KEYWORD": cconf.getcolor("keyword"), "KEYWORD": idleConf.GetHighlight(theme, "keyword"),
"STRING": cconf.getcolor("string"), "STRING": idleConf.GetHighlight(theme, "string"),
"DEFINITION": cconf.getcolor("definition"), "DEFINITION": idleConf.GetHighlight(theme, "definition"),
"SYNC": cconf.getcolor("sync"), "SYNC": idleConf.GetHighlight(theme, "sync"),
"TODO": cconf.getcolor("todo"), "TODO": idleConf.GetHighlight(theme, "todo"),
"BREAK": cconf.getcolor("break"), "BREAK": idleConf.GetHighlight(theme, "break"),
# The following is used by ReplaceDialog: # The following is used by ReplaceDialog:
"hit": cconf.getcolor("hit"), "hit": idleConf.GetHighlight(theme, "hit"),
} }
print tagdefs
def insert(self, index, chars, tags=None): def insert(self, index, chars, tags=None):
index = self.index(index) index = self.index(index)

View File

@ -112,16 +112,6 @@ class ConfigDialog(Toplevel):
self.optMenuKeysCustom.config(state=NORMAL) self.optMenuKeysCustom.config(state=NORMAL)
self.buttonDeleteCustomKeys.config(state=NORMAL) self.buttonDeleteCustomKeys.config(state=NORMAL)
def SetFgBg(self):
if self.fgHilite.get()==0:
self.labelFontTypeTitle.config(state=DISABLED)
self.checkFontBold.config(state=DISABLED)
self.checkFontItalic.config(state=DISABLED)
elif self.fgHilite.get()==1:
self.labelFontTypeTitle.config(state=NORMAL)
self.checkFontBold.config(state=NORMAL)
self.checkFontItalic.config(state=NORMAL)
def GetColour(self): def GetColour(self):
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 : '+self.highlightTarget.get(),
@ -142,7 +132,7 @@ class ConfigDialog(Toplevel):
self.editFont.config(size=self.fontSize.get(),weight=NORMAL, self.editFont.config(size=self.fontSize.get(),weight=NORMAL,
family=self.listFontName.get(self.listFontName.curselection()[0])) family=self.listFontName.get(self.listFontName.curselection()[0]))
def SetHighlightTargetBinding(self,event): def SetHighlightTargetBinding(self,*args):
self.SetHighlightTarget() self.SetHighlightTarget()
def SetHighlightTarget(self): def SetHighlightTarget(self):
@ -151,19 +141,16 @@ class ConfigDialog(Toplevel):
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)
self.SetFgBg()
elif self.highlightTarget.get() in ('Shell Foreground', elif self.highlightTarget.get() in ('Shell Foreground',
'Shell Stdout Foreground','Shell Stderr Foreground'): 'Shell Stdout Foreground','Shell Stderr Foreground'):
#fg and font style selection possible #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)
self.SetFgBg()
else: #full fg/bg and font style selection possible else: #full fg/bg and font style selection possible
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 properties
self.SetFgBg()
def CreateWidgets(self): def CreateWidgets(self):
self.framePages = Frame(self) self.framePages = Frame(self)
@ -216,6 +203,7 @@ class ConfigDialog(Toplevel):
def CreatePageFontTab(self): def CreatePageFontTab(self):
#tkVars #tkVars
self.fontSize=StringVar() self.fontSize=StringVar()
self.fontBold=StringVar()
self.spaceNum=IntVar() self.spaceNum=IntVar()
self.tabCols=IntVar() self.tabCols=IntVar()
self.indentType=IntVar() self.indentType=IntVar()
@ -229,7 +217,7 @@ class ConfigDialog(Toplevel):
#frameFont #frameFont
labelFontTitle=Label(frameFont,text='Set Base Editor Font') labelFontTitle=Label(frameFont,text='Set Base Editor Font')
frameFontName=Frame(frameFont) frameFontName=Frame(frameFont)
frameFontSize=Frame(frameFontName) frameFontParam=Frame(frameFont)
labelFontNameTitle=Label(frameFontName,justify=LEFT, labelFontNameTitle=Label(frameFontName,justify=LEFT,
text='Font :') text='Font :')
self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE, self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE,
@ -238,9 +226,11 @@ class ConfigDialog(Toplevel):
scrollFont=Scrollbar(frameFontName) scrollFont=Scrollbar(frameFontName)
scrollFont.config(command=self.listFontName.yview) scrollFont.config(command=self.listFontName.yview)
self.listFontName.config(yscrollcommand=scrollFont.set) self.listFontName.config(yscrollcommand=scrollFont.set)
labelFontSizeTitle=Label(frameFontSize,text='Size :') labelFontSizeTitle=Label(frameFontParam,text='Size :')
self.optMenuFontSize=DynOptionMenu(frameFontSize,self.fontSize,None, self.optMenuFontSize=DynOptionMenu(frameFontParam,self.fontSize,None,
command=self.SetFontSampleBinding) command=self.SetFontSampleBinding)
checkFontBold=Checkbutton(frameFontParam,variable=self.fontBold,
onvalue='Bold',offvalue='',text='Bold')
frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1) frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1)
self.labelFontSample=Label(frameFontSample, self.labelFontSample=Label(frameFontSample,
text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]', text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
@ -265,20 +255,20 @@ class ConfigDialog(Toplevel):
text='when tab key inserts tabs,\ncolumns per tab') text='when tab key inserts tabs,\ncolumns per tab')
self.scaleTabCols=Scale(frameIndentSize,variable=self.tabCols, self.scaleTabCols=Scale(frameIndentSize,variable=self.tabCols,
orient='horizontal',tickinterval=2,from_=2,to=8) orient='horizontal',tickinterval=2,from_=2,to=8)
#widget packing #widget packing
#body #body
frameFont.pack(side=LEFT,padx=5,pady=10,expand=TRUE,fill=BOTH) frameFont.pack(side=LEFT,padx=5,pady=10,expand=TRUE,fill=BOTH)
frameIndent.pack(side=LEFT,padx=5,pady=10,fill=Y) frameIndent.pack(side=LEFT,padx=5,pady=10,fill=Y)
#frameFont #frameFont
labelFontTitle.pack(side=TOP,anchor=W,padx=5,pady=5) labelFontTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
frameFontName.pack(side=TOP,padx=5,pady=5) frameFontName.pack(side=TOP,padx=5,pady=5,fill=X)
frameFontSize.pack(side=RIGHT,anchor=N,fill=X) frameFontParam.pack(side=TOP,padx=5,pady=5,fill=X)
labelFontNameTitle.pack(side=TOP,anchor=W) labelFontNameTitle.pack(side=TOP,anchor=W)
self.listFontName.pack(side=LEFT,fill=Y) self.listFontName.pack(side=LEFT,expand=TRUE,fill=X)
scrollFont.pack(side=LEFT,fill=Y) scrollFont.pack(side=LEFT,fill=Y)
labelFontSizeTitle.pack(side=TOP,anchor=W) labelFontSizeTitle.pack(side=LEFT,anchor=W)
self.optMenuFontSize.pack(side=TOP,anchor=W,fill=X) self.optMenuFontSize.pack(side=LEFT,anchor=W)
checkFontBold.pack(side=LEFT,anchor=W,padx=20)
frameFontSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) frameFontSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
self.labelFontSample.pack(expand=TRUE,fill=BOTH) self.labelFontSample.pack(expand=TRUE,fill=BOTH)
#frameIndent #frameIndent
@ -296,16 +286,14 @@ class ConfigDialog(Toplevel):
return frame return frame
def CreatePageHighlight(self): def CreatePageHighlight(self):
#tkVars
self.highlightTarget=StringVar()
self.builtinTheme=StringVar() self.builtinTheme=StringVar()
self.customTheme=StringVar() self.customTheme=StringVar()
self.fgHilite=IntVar() self.fgHilite=IntVar()
self.colour=StringVar() self.colour=StringVar()
self.fontName=StringVar() self.fontName=StringVar()
self.fontBold=StringVar()
self.fontItalic=StringVar()
self.themeType=IntVar() self.themeType=IntVar()
self.highlightTarget=StringVar()
self.highlightTarget.trace_variable('w',self.SetHighlightTargetBinding)
##widget creation ##widget creation
#body frame #body frame
frame=Frame(self.framePages,borderwidth=2,relief=RAISED) frame=Frame(self.framePages,borderwidth=2,relief=RAISED)
@ -313,39 +301,96 @@ class ConfigDialog(Toplevel):
frameCustom=Frame(frame,borderwidth=2,relief=GROOVE) frameCustom=Frame(frame,borderwidth=2,relief=GROOVE)
frameTheme=Frame(frame,borderwidth=2,relief=GROOVE) frameTheme=Frame(frame,borderwidth=2,relief=GROOVE)
#frameCustom #frameCustom
self.frameHighlightTarget=Frame(frameCustom) self.textHighlightSample=Text(frameCustom,relief=SOLID,borderwidth=1,
self.frameHighlightSample=Frame(frameCustom,relief=SOLID, font=('courier',12,''),cursor='hand2',width=10,height=10,
borderwidth=1,cursor='hand2') takefocus=FALSE,highlightthickness=0)
frameSet=Frame(frameCustom) text=self.textHighlightSample
self.frameColourSet=Frame(frameSet,relief=SOLID,borderwidth=1) text.bind('<Double-Button-1>',lambda e: 'break')
text.bind('<B1-Motion>',lambda e: 'break')
text.insert(END,'#you can click in here','comment')
text.insert(END,'\n')
text.insert(END,'#to choose items','comment')
text.insert(END,'\n')
text.insert(END,'def','keyword')
text.insert(END,' ')
text.insert(END,'func','definition')
text.insert(END,'(param):')
text.insert(END,'\n ')
text.insert(END,'"""string"""','string')
text.insert(END,'\n var0 = ')
text.insert(END,"'string'",'string')
text.insert(END,'\n var1 = ')
text.insert(END,"'selected'",'selected')
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)
self.frameColourSet=Frame(frameCustom,relief=SOLID,borderwidth=1)
frameFgBg=Frame(frameCustom) frameFgBg=Frame(frameCustom)
frameFontSet=Frame(frameSet)
labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting') labelCustomTitle=Label(frameCustom,text='Set Custom Highlighting')
labelTargetTitle=Label(self.frameHighlightTarget,text='for : ') buttonSetColour=Button(self.frameColourSet,text='Choose Colour for :',
self.optMenuHighlightTarget=DynOptionMenu(self.frameHighlightTarget, command=self.GetColour)
self.highlightTarget,None,command=self.SetHighlightTargetBinding) self.optMenuHighlightTarget=DynOptionMenu(self.frameColourSet,
self.highlightTarget,None)#,command=self.SetHighlightTargetBinding
self.radioFg=Radiobutton(frameFgBg,variable=self.fgHilite, self.radioFg=Radiobutton(frameFgBg,variable=self.fgHilite,
value=1,command=self.SetFgBg,text='Foreground') value=1,text='Foreground')#,command=self.SetFgBg
self.radioBg=Radiobutton(frameFgBg,variable=self.fgHilite, self.radioBg=Radiobutton(frameFgBg,variable=self.fgHilite,
value=0,command=self.SetFgBg,text='Background') value=0,text='Background')#,command=self.SetFgBg
self.fgHilite.set(1) self.fgHilite.set(1)
buttonSetColour=Button(self.frameColourSet,text='Choose Colour', #self.labelFontTypeTitle=Label(frameFontSet,text='Font Style :')
command=self.GetColour) #self.checkFontBold=Checkbutton(frameFontSet,variable=self.fontBold,
self.labelFontTypeTitle=Label(frameFontSet,text='Font Style :') # onvalue='Bold',offvalue='',text='Bold')
self.checkFontBold=Checkbutton(frameFontSet,variable=self.fontBold, #self.checkFontItalic=Checkbutton(frameFontSet,variable=self.fontItalic,
onvalue='Bold',offvalue='',text='Bold') # onvalue='Italic',offvalue='',text='Italic')
self.checkFontItalic=Checkbutton(frameFontSet,variable=self.fontItalic,
onvalue='Italic',offvalue='',text='Italic')
self.labelTestSample=Label(self.frameHighlightSample,justify=LEFT,font=('courier',12,''),
text='#when finished, this\n#sample area will\n#be interactive\n'+
'def Ahem(foo,bar):\n '+
'"""'+'doc hazard'+'"""'+
'\n test=foo\n text=bar\n return')
buttonSaveCustomTheme=Button(frameCustom, buttonSaveCustomTheme=Button(frameCustom,
text='Save as a Custom Theme') text='Save as a Custom Theme')
#frameTheme #frameTheme
#frameDivider=Frame(frameTheme,relief=SUNKEN,borderwidth=1,
# width=2,height=10)
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.themeType,
@ -356,33 +401,23 @@ class ConfigDialog(Toplevel):
self.builtinTheme,None,command=None) self.builtinTheme,None,command=None)
self.optMenuThemeCustom=DynOptionMenu(frameTheme, self.optMenuThemeCustom=DynOptionMenu(frameTheme,
self.customTheme,None,command=None) self.customTheme,None,command=None)
# self.themeType.set(0)
self.buttonDeleteCustomTheme=Button(frameTheme,text='Delete Custom Theme') self.buttonDeleteCustomTheme=Button(frameTheme,text='Delete Custom Theme')
# self.SetThemeType()
##widget packing ##widget packing
#body #body
frameCustom.pack(side=LEFT,padx=5,pady=10,expand=TRUE,fill=BOTH) frameCustom.pack(side=LEFT,padx=5,pady=10,expand=TRUE,fill=BOTH)
frameTheme.pack(side=LEFT,padx=5,pady=10,fill=Y) frameTheme.pack(side=LEFT,padx=5,pady=10,fill=Y)
#frameCustom #frameCustom
labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5) labelCustomTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
self.frameHighlightTarget.pack(side=TOP,padx=5,pady=5,fill=X) self.frameColourSet.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=X)
frameFgBg.pack(side=TOP,padx=5,pady=0) frameFgBg.pack(side=TOP,padx=5,pady=0)
self.frameHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) self.textHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,
frameSet.pack(side=TOP,fill=X) fill=BOTH)
self.frameColourSet.pack(side=LEFT,padx=5,pady=5,fill=BOTH) buttonSetColour.pack(side=TOP,expand=TRUE,fill=X,padx=5,pady=3)
frameFontSet.pack(side=RIGHT,padx=5,pady=5,anchor=W) self.optMenuHighlightTarget.pack(side=TOP,expand=TRUE,fill=X,padx=5,pady=3)
labelTargetTitle.pack(side=LEFT,anchor=E)
self.optMenuHighlightTarget.pack(side=RIGHT,anchor=W,expand=TRUE,fill=X)
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)
buttonSetColour.pack(expand=TRUE,fill=BOTH,padx=10,pady=10)
self.labelFontTypeTitle.pack(side=TOP,anchor=W)
self.checkFontBold.pack(side=LEFT,anchor=W,pady=2)
self.checkFontItalic.pack(side=RIGHT,anchor=W)
self.labelTestSample.pack(anchor=CENTER,expand=TRUE,fill=BOTH)
buttonSaveCustomTheme.pack(side=BOTTOM,fill=X,padx=5,pady=5) buttonSaveCustomTheme.pack(side=BOTTOM,fill=X,padx=5,pady=5)
#frameTheme #frameTheme
#frameDivider.pack(side=LEFT,fill=Y,padx=5,pady=5)
labelThemeTitle.pack(side=TOP,anchor=W,padx=5,pady=5) labelThemeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
labelTypeTitle.pack(side=TOP,anchor=W,padx=5,pady=5) labelTypeTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
self.radioThemeBuiltin.pack(side=TOP,anchor=W,padx=5) self.radioThemeBuiltin.pack(side=TOP,anchor=W,padx=5)
@ -600,7 +635,7 @@ class ConfigDialog(Toplevel):
##load theme element option menu ##load theme element option menu
elements=('Normal Text','Python Keywords','Python Definitions', elements=('Normal Text','Python Keywords','Python Definitions',
'Python Comments','Python Strings','Selected Text', 'Python Comments','Python Strings','Selected Text',
'Search Hits','Cursor','Error Background','Shell Foreground', 'Found Text','Cursor','Error Background','Shell Foreground',
'Shell Stdout Foreground','Shell Stderr Foreground') 'Shell Stdout Foreground','Shell Stderr Foreground')
self.optMenuHighlightTarget.SetMenu(elements,elements[0]) self.optMenuHighlightTarget.SetMenu(elements,elements[0])

View File

@ -49,14 +49,6 @@ class IdleConfParser(ConfigParser):
else: #return a default value else: #return a default value
return [] return []
def GetHighlight(self, theme, element):
fore = self.Get(theme, element + "-foreground")
back = self.Get(theme, element + "-background")
style = self.Ge(theme, element + "-fontStyle", default='')
return {"fg": fore,
"bg": back,
"fStyle": style}
def Load(self): def Load(self):
""" """
Load the configuration file from disk Load the configuration file from disk
@ -160,7 +152,12 @@ class IdleConf:
return cfgParser.sections() return cfgParser.sections()
def GetHighlight(self, theme, element):
fore = self.GetOption('highlight', theme, element + "-foreground")
back = self.GetOption('highlight', theme, element + "-background")
return {"foreground": fore,
"background": back}
def GetTheme(self, name=None): def GetTheme(self, name=None):
""" """
Gets the requested theme or returns a final fallback theme in case Gets the requested theme or returns a final fallback theme in case