2003-01-10 16:13:57 -04:00
|
|
|
"""IDLE Configuration Dialog: support user customization of IDLE by GUI
|
|
|
|
|
|
|
|
Customize font faces, sizes, and colorization attributes. Set indentation
|
|
|
|
defaults. Customize keybindings. Colorization and keybindings can be
|
|
|
|
saved as user defined sets. Select startup options including shell/editor
|
|
|
|
and default window size. Define additional help sources.
|
|
|
|
|
|
|
|
Note that tab width in IDLE is currently fixed at eight due to Tk issues.
|
2005-01-30 23:34:26 -04:00
|
|
|
Refer to comments in EditorWindow autoindent code for details.
|
2003-01-10 16:13:57 -04:00
|
|
|
|
2001-07-31 03:59:02 -03:00
|
|
|
"""
|
2008-05-20 04:13:37 -03:00
|
|
|
from Tkinter import *
|
|
|
|
import tkMessageBox, tkColorChooser, tkFont
|
2001-07-31 03:59:02 -03:00
|
|
|
|
2010-04-02 04:24:52 -03:00
|
|
|
from idlelib.configHandler import idleConf
|
|
|
|
from idlelib.dynOptionMenuWidget import DynOptionMenu
|
|
|
|
from idlelib.keybindingDialog import GetKeysDialog
|
|
|
|
from idlelib.configSectionNameDialog import GetCfgSectionNameDialog
|
|
|
|
from idlelib.configHelpSourceEdit import GetHelpSourceDialog
|
2014-10-22 21:15:12 -03:00
|
|
|
from idlelib.tabbedpages import TabbedPageSet
|
2010-04-02 04:24:52 -03:00
|
|
|
from idlelib import macosxSupport
|
2001-07-31 03:59:02 -03:00
|
|
|
class ConfigDialog(Toplevel):
|
2005-01-30 23:34:26 -04:00
|
|
|
|
2014-10-17 02:31:29 -03:00
|
|
|
def __init__(self, parent, title='', _htest=False, _utest=False):
|
2014-05-29 02:46:16 -03:00
|
|
|
"""
|
|
|
|
_htest - bool, change box location when running htest
|
2014-07-15 00:07:21 -03:00
|
|
|
_utest - bool, don't wait_window when running unittest
|
2014-05-29 02:46:16 -03:00
|
|
|
"""
|
2001-07-31 07:46:53 -03:00
|
|
|
Toplevel.__init__(self, parent)
|
2014-07-30 20:24:26 -03:00
|
|
|
self.parent = parent
|
2014-08-04 00:02:53 -03:00
|
|
|
if _htest:
|
|
|
|
parent.instance_dict = {}
|
2007-10-04 00:11:12 -03:00
|
|
|
self.wm_withdraw()
|
|
|
|
|
2001-07-31 07:46:53 -03:00
|
|
|
self.configure(borderwidth=5)
|
2014-10-17 02:31:29 -03:00
|
|
|
self.title(title or 'IDLE Preferences')
|
2014-08-04 00:02:53 -03:00
|
|
|
self.geometry(
|
|
|
|
"+%d+%d" % (parent.winfo_rootx() + 20,
|
|
|
|
parent.winfo_rooty() + (30 if not _htest else 150)))
|
2005-07-22 18:49:32 -03:00
|
|
|
#Theme Elements. Each theme element key is its display name.
|
2001-11-03 10:54:25 -04:00
|
|
|
#The first value of the tuple is the sample area tag name.
|
2002-12-31 12:03:23 -04:00
|
|
|
#The second value is the display name list sort index.
|
2014-08-04 00:02:53 -03:00
|
|
|
self.themeElements={
|
|
|
|
'Normal Text':('normal', '00'),
|
|
|
|
'Python Keywords':('keyword', '01'),
|
|
|
|
'Python Definitions':('definition', '02'),
|
2004-03-08 14:15:31 -04:00
|
|
|
'Python Builtins':('builtin', '03'),
|
2014-08-04 00:02:53 -03:00
|
|
|
'Python Comments':('comment', '04'),
|
|
|
|
'Python Strings':('string', '05'),
|
|
|
|
'Selected Text':('hilite', '06'),
|
|
|
|
'Found Text':('hit', '07'),
|
|
|
|
'Cursor':('cursor', '08'),
|
|
|
|
'Error Text':('error', '09'),
|
|
|
|
'Shell Normal Text':('console', '10'),
|
|
|
|
'Shell Stdout Text':('stdout', '11'),
|
|
|
|
'Shell Stderr Text':('stderr', '12'),
|
2004-03-08 14:15:31 -04:00
|
|
|
}
|
2002-01-31 21:33:36 -04:00
|
|
|
self.ResetChangedItems() #load initial values in changed items dict
|
2001-07-31 07:46:53 -03:00
|
|
|
self.CreateWidgets()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.resizable(height=FALSE, width=FALSE)
|
2001-07-31 07:46:53 -03:00
|
|
|
self.transient(parent)
|
|
|
|
self.grab_set()
|
|
|
|
self.protocol("WM_DELETE_WINDOW", self.Cancel)
|
2001-12-05 03:54:07 -04:00
|
|
|
self.tabPages.focus_set()
|
2001-07-31 07:46:53 -03:00
|
|
|
#key bindings for this dialog
|
2014-08-04 00:02:53 -03:00
|
|
|
#self.bind('<Escape>', self.Cancel) #dismiss dialog, no save
|
|
|
|
#self.bind('<Alt-a>', self.Apply) #apply changes, save
|
|
|
|
#self.bind('<F1>', self.Help) #context help
|
2001-10-23 07:42:12 -03:00
|
|
|
self.LoadConfigs()
|
2002-12-31 12:03:23 -04:00
|
|
|
self.AttachVarCallbacks() #avoid callbacks during LoadConfigs
|
2007-10-04 00:11:12 -03:00
|
|
|
|
2014-07-15 00:07:21 -03:00
|
|
|
if not _utest:
|
|
|
|
self.wm_deiconify()
|
|
|
|
self.wait_window()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-07-31 07:46:53 -03:00
|
|
|
def CreateWidgets(self):
|
2007-10-29 23:38:54 -03:00
|
|
|
self.tabPages = TabbedPageSet(self,
|
2014-08-04 00:02:53 -03:00
|
|
|
page_names=['Fonts/Tabs', 'Highlighting', 'Keys', 'General'])
|
2014-10-08 21:29:05 -03:00
|
|
|
self.tabPages.pack(side=TOP, expand=TRUE, fill=BOTH)
|
|
|
|
self.CreatePageFontTab()
|
|
|
|
self.CreatePageHighlight()
|
|
|
|
self.CreatePageKeys()
|
|
|
|
self.CreatePageGeneral()
|
|
|
|
self.create_action_buttons().pack(side=BOTTOM)
|
|
|
|
def create_action_buttons(self):
|
2014-03-28 00:47:04 -03:00
|
|
|
if macosxSupport.isAquaTk():
|
2009-03-04 17:35:05 -04:00
|
|
|
# Changing the default padding on OSX results in unreadable
|
|
|
|
# text in the buttons
|
2014-08-04 00:02:53 -03:00
|
|
|
paddingArgs = {}
|
2009-03-04 17:35:05 -04:00
|
|
|
else:
|
2014-08-04 00:02:53 -03:00
|
|
|
paddingArgs = {'padx':6, 'pady':3}
|
2014-10-22 21:15:12 -03:00
|
|
|
outer = Frame(self, pady=2)
|
|
|
|
buttons = Frame(outer, pady=2)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.buttonOk = Button(
|
2014-10-22 21:15:12 -03:00
|
|
|
buttons, text='Ok', command=self.Ok,
|
2014-10-08 21:29:05 -03:00
|
|
|
takefocus=FALSE, **paddingArgs)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.buttonApply = Button(
|
2014-10-22 21:15:12 -03:00
|
|
|
buttons, text='Apply', command=self.Apply,
|
2014-10-08 21:29:05 -03:00
|
|
|
takefocus=FALSE, **paddingArgs)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.buttonCancel = Button(
|
2014-10-22 21:15:12 -03:00
|
|
|
buttons, text='Cancel', command=self.Cancel,
|
2014-10-08 21:29:05 -03:00
|
|
|
takefocus=FALSE, **paddingArgs)
|
2014-10-22 21:15:12 -03:00
|
|
|
self.buttonOk.pack(side=LEFT, padx=5)
|
|
|
|
self.buttonApply.pack(side=LEFT, padx=5)
|
|
|
|
self.buttonCancel.pack(side=LEFT, padx=5)
|
2014-10-08 21:29:05 -03:00
|
|
|
# Comment out Help button creation and packing until implement self.Help
|
|
|
|
## self.buttonHelp = Button(
|
2014-10-22 21:15:12 -03:00
|
|
|
## buttons, text='Help', command=self.Help,
|
2014-10-08 21:29:05 -03:00
|
|
|
## takefocus=FALSE, **paddingArgs)
|
2014-08-04 00:02:53 -03:00
|
|
|
## self.buttonHelp.pack(side=RIGHT, padx=5)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-10-22 21:15:12 -03:00
|
|
|
# add space above buttons
|
|
|
|
Frame(outer, height=2, borderwidth=0).pack(side=TOP)
|
|
|
|
buttons.pack(side=BOTTOM)
|
|
|
|
return outer
|
2001-08-04 10:58:22 -03:00
|
|
|
def CreatePageFontTab(self):
|
2014-07-30 20:24:26 -03:00
|
|
|
parent = self.parent
|
|
|
|
self.fontSize = StringVar(parent)
|
|
|
|
self.fontBold = BooleanVar(parent)
|
|
|
|
self.fontName = StringVar(parent)
|
|
|
|
self.spaceNum = IntVar(parent)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.editFont = tkFont.Font(parent, ('courier', 10, 'normal'))
|
2014-07-30 20:24:26 -03:00
|
|
|
|
2001-08-05 05:00:28 -03:00
|
|
|
##widget creation
|
|
|
|
#body frame
|
2014-08-04 00:02:53 -03:00
|
|
|
frame = self.tabPages.pages['Fonts/Tabs'].frame
|
2001-08-05 05:00:28 -03:00
|
|
|
#body section frames
|
2014-08-04 00:02:53 -03:00
|
|
|
frameFont = LabelFrame(
|
|
|
|
frame, borderwidth=2, relief=GROOVE, text=' Base Editor Font ')
|
|
|
|
frameIndent = LabelFrame(
|
|
|
|
frame, borderwidth=2, relief=GROOVE, text=' Indentation Width ')
|
2001-08-05 05:00:28 -03:00
|
|
|
#frameFont
|
2014-08-04 00:02:53 -03:00
|
|
|
frameFontName = Frame(frameFont)
|
|
|
|
frameFontParam = Frame(frameFont)
|
|
|
|
labelFontNameTitle = Label(
|
|
|
|
frameFontName, justify=LEFT, text='Font Face :')
|
|
|
|
self.listFontName = Listbox(
|
|
|
|
frameFontName, height=5, takefocus=FALSE, exportselection=FALSE)
|
|
|
|
self.listFontName.bind(
|
|
|
|
'<ButtonRelease-1>', self.OnListFontButtonRelease)
|
|
|
|
scrollFont = Scrollbar(frameFontName)
|
2001-08-11 12:48:13 -03:00
|
|
|
scrollFont.config(command=self.listFontName.yview)
|
|
|
|
self.listFontName.config(yscrollcommand=scrollFont.set)
|
2014-08-04 00:02:53 -03:00
|
|
|
labelFontSizeTitle = Label(frameFontParam, text='Size :')
|
|
|
|
self.optMenuFontSize = DynOptionMenu(
|
|
|
|
frameFontParam, self.fontSize, None, command=self.SetFontSample)
|
|
|
|
checkFontBold = Checkbutton(
|
|
|
|
frameFontParam, variable=self.fontBold, onvalue=1,
|
|
|
|
offvalue=0, text='Bold', command=self.SetFontSample)
|
|
|
|
frameFontSample = Frame(frameFont, relief=SOLID, borderwidth=1)
|
|
|
|
self.labelFontSample = Label(
|
|
|
|
frameFontSample, justify=LEFT, font=self.editFont,
|
|
|
|
text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]')
|
2001-08-05 05:00:28 -03:00
|
|
|
#frameIndent
|
2014-08-04 00:02:53 -03:00
|
|
|
frameIndentSize = Frame(frameIndent)
|
|
|
|
labelSpaceNumTitle = Label(
|
|
|
|
frameIndentSize, justify=LEFT,
|
|
|
|
text='Python Standard: 4 Spaces!')
|
|
|
|
self.scaleSpaceNum = Scale(
|
|
|
|
frameIndentSize, variable=self.spaceNum,
|
|
|
|
orient='horizontal', tickinterval=2, from_=2, to=16)
|
2014-07-30 20:24:26 -03:00
|
|
|
|
2001-08-05 05:00:28 -03:00
|
|
|
#widget packing
|
|
|
|
#body
|
2014-08-04 00:02:53 -03:00
|
|
|
frameFont.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
|
|
|
frameIndent.pack(side=LEFT, padx=5, pady=5, fill=Y)
|
2001-08-05 05:00:28 -03:00
|
|
|
#frameFont
|
2014-08-04 00:02:53 -03:00
|
|
|
frameFontName.pack(side=TOP, padx=5, pady=5, fill=X)
|
|
|
|
frameFontParam.pack(side=TOP, padx=5, pady=5, fill=X)
|
|
|
|
labelFontNameTitle.pack(side=TOP, anchor=W)
|
|
|
|
self.listFontName.pack(side=LEFT, expand=TRUE, fill=X)
|
|
|
|
scrollFont.pack(side=LEFT, fill=Y)
|
|
|
|
labelFontSizeTitle.pack(side=LEFT, anchor=W)
|
|
|
|
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)
|
|
|
|
self.labelFontSample.pack(expand=TRUE, fill=BOTH)
|
2001-08-05 05:00:28 -03:00
|
|
|
#frameIndent
|
2014-08-04 00:02:53 -03:00
|
|
|
frameIndentSize.pack(side=TOP, fill=X)
|
|
|
|
labelSpaceNumTitle.pack(side=TOP, anchor=W, padx=5)
|
|
|
|
self.scaleSpaceNum.pack(side=TOP, padx=5, fill=X)
|
2001-08-03 01:43:44 -03:00
|
|
|
return frame
|
|
|
|
|
|
|
|
def CreatePageHighlight(self):
|
2014-07-30 20:24:26 -03:00
|
|
|
parent = self.parent
|
|
|
|
self.builtinTheme = StringVar(parent)
|
|
|
|
self.customTheme = StringVar(parent)
|
|
|
|
self.fgHilite = BooleanVar(parent)
|
|
|
|
self.colour = StringVar(parent)
|
|
|
|
self.fontName = StringVar(parent)
|
|
|
|
self.themeIsBuiltin = BooleanVar(parent)
|
|
|
|
self.highlightTarget = StringVar(parent)
|
|
|
|
|
2001-08-03 01:43:44 -03:00
|
|
|
##widget creation
|
|
|
|
#body frame
|
2014-08-04 00:02:53 -03:00
|
|
|
frame = self.tabPages.pages['Highlighting'].frame
|
2001-08-03 01:43:44 -03:00
|
|
|
#body section frames
|
2014-08-04 00:02:53 -03:00
|
|
|
frameCustom = LabelFrame(frame, borderwidth=2, relief=GROOVE,
|
|
|
|
text=' Custom Highlighting ')
|
|
|
|
frameTheme = LabelFrame(frame, borderwidth=2, relief=GROOVE,
|
|
|
|
text=' Highlighting Theme ')
|
2001-08-03 01:43:44 -03:00
|
|
|
#frameCustom
|
2014-08-04 00:02:53 -03:00
|
|
|
self.textHighlightSample=Text(
|
|
|
|
frameCustom, relief=SOLID, borderwidth=1,
|
|
|
|
font=('courier', 12, ''), cursor='hand2', width=21, height=11,
|
|
|
|
takefocus=FALSE, highlightthickness=0, wrap=NONE)
|
2001-11-03 01:07:28 -04:00
|
|
|
text=self.textHighlightSample
|
2014-08-04 00:02:53 -03:00
|
|
|
text.bind('<Double-Button-1>', lambda e: 'break')
|
|
|
|
text.bind('<B1-Motion>', lambda e: 'break')
|
|
|
|
textAndTags=(
|
|
|
|
('#you can click here', 'comment'), ('\n', 'normal'),
|
|
|
|
('#to choose items', 'comment'), ('\n', 'normal'),
|
|
|
|
('def', 'keyword'), (' ', 'normal'),
|
|
|
|
('func', 'definition'), ('(param):\n ', 'normal'),
|
|
|
|
('"""string"""', 'string'), ('\n var0 = ', 'normal'),
|
|
|
|
("'string'", 'string'), ('\n var1 = ', 'normal'),
|
|
|
|
("'selected'", 'hilite'), ('\n var2 = ', 'normal'),
|
|
|
|
("'found'", 'hit'), ('\n var3 = ', 'normal'),
|
|
|
|
('list', 'builtin'), ('(', 'normal'),
|
|
|
|
('None', 'builtin'), (')\n\n', 'normal'),
|
|
|
|
(' error ', 'error'), (' ', 'normal'),
|
|
|
|
('cursor |', 'cursor'), ('\n ', 'normal'),
|
|
|
|
('shell', 'console'), (' ', 'normal'),
|
|
|
|
('stdout', 'stdout'), (' ', 'normal'),
|
|
|
|
('stderr', 'stderr'), ('\n', 'normal'))
|
2001-11-03 10:54:25 -04:00
|
|
|
for txTa in textAndTags:
|
2014-08-04 00:02:53 -03:00
|
|
|
text.insert(END, txTa[0], txTa[1])
|
2014-07-27 05:07:18 -03:00
|
|
|
for element in self.themeElements:
|
2014-08-04 00:02:53 -03:00
|
|
|
def tem(event, elem=element):
|
|
|
|
event.widget.winfo_toplevel().highlightTarget.set(elem)
|
|
|
|
text.tag_bind(
|
|
|
|
self.themeElements[element][0], '<ButtonPress-1>', tem)
|
2001-11-03 01:07:28 -04:00
|
|
|
text.config(state=DISABLED)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.frameColourSet = Frame(frameCustom, relief=SOLID, borderwidth=1)
|
|
|
|
frameFgBg = Frame(frameCustom)
|
|
|
|
buttonSetColour = Button(
|
|
|
|
self.frameColourSet, text='Choose Colour for :',
|
|
|
|
command=self.GetColour, highlightthickness=0)
|
|
|
|
self.optMenuHighlightTarget = DynOptionMenu(
|
|
|
|
self.frameColourSet, self.highlightTarget, None,
|
|
|
|
highlightthickness=0) #, command=self.SetHighlightTargetBinding
|
|
|
|
self.radioFg = Radiobutton(
|
|
|
|
frameFgBg, variable=self.fgHilite, value=1,
|
|
|
|
text='Foreground', command=self.SetColourSampleBinding)
|
|
|
|
self.radioBg=Radiobutton(
|
|
|
|
frameFgBg, variable=self.fgHilite, value=0,
|
|
|
|
text='Background', command=self.SetColourSampleBinding)
|
2001-10-29 07:19:46 -04:00
|
|
|
self.fgHilite.set(1)
|
2014-08-04 00:02:53 -03:00
|
|
|
buttonSaveCustomTheme = Button(
|
|
|
|
frameCustom, text='Save as New Custom Theme',
|
|
|
|
command=self.SaveAsNewTheme)
|
2001-08-03 01:43:44 -03:00
|
|
|
#frameTheme
|
2014-08-04 00:02:53 -03:00
|
|
|
labelTypeTitle = Label(frameTheme, text='Select : ')
|
|
|
|
self.radioThemeBuiltin = Radiobutton(
|
|
|
|
frameTheme, variable=self.themeIsBuiltin, value=1,
|
|
|
|
command=self.SetThemeType, text='a Built-in Theme')
|
|
|
|
self.radioThemeCustom = Radiobutton(
|
|
|
|
frameTheme, variable=self.themeIsBuiltin, value=0,
|
|
|
|
command=self.SetThemeType, text='a Custom Theme')
|
|
|
|
self.optMenuThemeBuiltin = DynOptionMenu(
|
|
|
|
frameTheme, self.builtinTheme, None, command=None)
|
|
|
|
self.optMenuThemeCustom=DynOptionMenu(
|
|
|
|
frameTheme, self.customTheme, None, command=None)
|
|
|
|
self.buttonDeleteCustomTheme=Button(
|
|
|
|
frameTheme, text='Delete Custom Theme',
|
2002-02-17 21:43:11 -04:00
|
|
|
command=self.DeleteCustomTheme)
|
2014-07-30 20:24:26 -03:00
|
|
|
|
2001-08-03 01:43:44 -03:00
|
|
|
##widget packing
|
|
|
|
#body
|
2014-08-04 00:02:53 -03:00
|
|
|
frameCustom.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
|
|
|
frameTheme.pack(side=LEFT, padx=5, pady=5, fill=Y)
|
2001-08-03 01:43:44 -03:00
|
|
|
#frameCustom
|
2014-08-04 00:02:53 -03:00
|
|
|
self.frameColourSet.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=X)
|
|
|
|
frameFgBg.pack(side=TOP, padx=5, pady=0)
|
|
|
|
self.textHighlightSample.pack(
|
|
|
|
side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
|
|
|
buttonSetColour.pack(side=TOP, expand=TRUE, fill=X, padx=8, pady=4)
|
|
|
|
self.optMenuHighlightTarget.pack(
|
|
|
|
side=TOP, expand=TRUE, fill=X, padx=8, pady=3)
|
|
|
|
self.radioFg.pack(side=LEFT, anchor=E)
|
|
|
|
self.radioBg.pack(side=RIGHT, anchor=W)
|
|
|
|
buttonSaveCustomTheme.pack(side=BOTTOM, fill=X, padx=5, pady=5)
|
2001-08-03 01:43:44 -03:00
|
|
|
#frameTheme
|
2014-08-04 00:02:53 -03:00
|
|
|
labelTypeTitle.pack(side=TOP, anchor=W, padx=5, pady=5)
|
|
|
|
self.radioThemeBuiltin.pack(side=TOP, anchor=W, padx=5)
|
|
|
|
self.radioThemeCustom.pack(side=TOP, anchor=W, padx=5, pady=2)
|
|
|
|
self.optMenuThemeBuiltin.pack(side=TOP, fill=X, padx=5, pady=5)
|
|
|
|
self.optMenuThemeCustom.pack(side=TOP, fill=X, anchor=W, padx=5, pady=5)
|
|
|
|
self.buttonDeleteCustomTheme.pack(side=TOP, fill=X, padx=5, pady=5)
|
2001-08-03 01:43:44 -03:00
|
|
|
return frame
|
|
|
|
|
|
|
|
def CreatePageKeys(self):
|
2014-07-30 20:24:26 -03:00
|
|
|
parent = self.parent
|
|
|
|
self.bindingTarget = StringVar(parent)
|
|
|
|
self.builtinKeys = StringVar(parent)
|
|
|
|
self.customKeys = StringVar(parent)
|
|
|
|
self.keysAreBuiltin = BooleanVar(parent)
|
|
|
|
self.keyBinding = StringVar(parent)
|
|
|
|
|
2001-08-04 10:58:22 -03:00
|
|
|
##widget creation
|
|
|
|
#body frame
|
2014-08-04 00:02:53 -03:00
|
|
|
frame = self.tabPages.pages['Keys'].frame
|
2001-08-04 10:58:22 -03:00
|
|
|
#body section frames
|
2014-08-04 00:02:53 -03:00
|
|
|
frameCustom = LabelFrame(
|
|
|
|
frame, borderwidth=2, relief=GROOVE,
|
|
|
|
text=' Custom Key Bindings ')
|
|
|
|
frameKeySets = LabelFrame(
|
|
|
|
frame, borderwidth=2, relief=GROOVE, text=' Key Set ')
|
2001-08-04 10:58:22 -03:00
|
|
|
#frameCustom
|
2014-08-04 00:02:53 -03:00
|
|
|
frameTarget = Frame(frameCustom)
|
|
|
|
labelTargetTitle = Label(frameTarget, text='Action - Key(s)')
|
|
|
|
scrollTargetY = Scrollbar(frameTarget)
|
|
|
|
scrollTargetX = Scrollbar(frameTarget, orient=HORIZONTAL)
|
|
|
|
self.listBindings = Listbox(
|
|
|
|
frameTarget, takefocus=FALSE, exportselection=FALSE)
|
|
|
|
self.listBindings.bind('<ButtonRelease-1>', self.KeyBindingSelected)
|
2002-01-18 20:29:54 -04:00
|
|
|
scrollTargetY.config(command=self.listBindings.yview)
|
|
|
|
scrollTargetX.config(command=self.listBindings.xview)
|
|
|
|
self.listBindings.config(yscrollcommand=scrollTargetY.set)
|
|
|
|
self.listBindings.config(xscrollcommand=scrollTargetX.set)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.buttonNewKeys = Button(
|
|
|
|
frameCustom, text='Get New Keys for Selection',
|
|
|
|
command=self.GetNewKeys, state=DISABLED)
|
2001-08-04 10:58:22 -03:00
|
|
|
#frameKeySets
|
2007-12-28 00:18:01 -04:00
|
|
|
frames = [Frame(frameKeySets, padx=2, pady=2, borderwidth=0)
|
|
|
|
for i in range(2)]
|
2014-08-04 00:02:53 -03:00
|
|
|
self.radioKeysBuiltin = Radiobutton(
|
|
|
|
frames[0], variable=self.keysAreBuiltin, value=1,
|
|
|
|
command=self.SetKeysType, text='Use a Built-in Key Set')
|
|
|
|
self.radioKeysCustom = Radiobutton(
|
|
|
|
frames[0], variable=self.keysAreBuiltin, value=0,
|
|
|
|
command=self.SetKeysType, text='Use a Custom Key Set')
|
|
|
|
self.optMenuKeysBuiltin = DynOptionMenu(
|
|
|
|
frames[0], self.builtinKeys, None, command=None)
|
|
|
|
self.optMenuKeysCustom = DynOptionMenu(
|
|
|
|
frames[0], self.customKeys, None, command=None)
|
|
|
|
self.buttonDeleteCustomKeys = Button(
|
|
|
|
frames[1], text='Delete Custom Key Set',
|
2002-02-17 21:43:11 -04:00
|
|
|
command=self.DeleteCustomKeys)
|
2014-08-04 00:02:53 -03:00
|
|
|
buttonSaveCustomKeys = Button(
|
|
|
|
frames[1], text='Save as New Custom Key Set',
|
|
|
|
command=self.SaveAsNewKeySet)
|
2014-07-30 20:24:26 -03:00
|
|
|
|
2001-08-04 10:58:22 -03:00
|
|
|
##widget packing
|
|
|
|
#body
|
2014-08-04 00:02:53 -03:00
|
|
|
frameCustom.pack(side=BOTTOM, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
|
|
|
frameKeySets.pack(side=BOTTOM, padx=5, pady=5, fill=BOTH)
|
2001-08-04 10:58:22 -03:00
|
|
|
#frameCustom
|
2014-08-04 00:02:53 -03:00
|
|
|
self.buttonNewKeys.pack(side=BOTTOM, fill=X, padx=5, pady=5)
|
|
|
|
frameTarget.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
2002-01-18 20:29:54 -04:00
|
|
|
#frame target
|
2014-08-04 00:02:53 -03:00
|
|
|
frameTarget.columnconfigure(0, weight=1)
|
|
|
|
frameTarget.rowconfigure(1, weight=1)
|
|
|
|
labelTargetTitle.grid(row=0, column=0, columnspan=2, sticky=W)
|
|
|
|
self.listBindings.grid(row=1, column=0, sticky=NSEW)
|
|
|
|
scrollTargetY.grid(row=1, column=1, sticky=NS)
|
|
|
|
scrollTargetX.grid(row=2, column=0, sticky=EW)
|
2001-08-04 10:58:22 -03:00
|
|
|
#frameKeySets
|
2007-12-28 00:18:01 -04:00
|
|
|
self.radioKeysBuiltin.grid(row=0, column=0, sticky=W+NS)
|
|
|
|
self.radioKeysCustom.grid(row=1, column=0, sticky=W+NS)
|
|
|
|
self.optMenuKeysBuiltin.grid(row=0, column=1, sticky=NSEW)
|
|
|
|
self.optMenuKeysCustom.grid(row=1, column=1, sticky=NSEW)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.buttonDeleteCustomKeys.pack(side=LEFT, fill=X, expand=True, padx=2)
|
|
|
|
buttonSaveCustomKeys.pack(side=LEFT, fill=X, expand=True, padx=2)
|
2007-12-28 00:18:01 -04:00
|
|
|
frames[0].pack(side=TOP, fill=BOTH, expand=True)
|
|
|
|
frames[1].pack(side=TOP, fill=X, expand=True, pady=2)
|
2001-08-03 01:43:44 -03:00
|
|
|
return frame
|
|
|
|
|
|
|
|
def CreatePageGeneral(self):
|
2014-07-30 20:24:26 -03:00
|
|
|
parent = self.parent
|
|
|
|
self.winWidth = StringVar(parent)
|
|
|
|
self.winHeight = StringVar(parent)
|
|
|
|
self.startupEdit = IntVar(parent)
|
|
|
|
self.autoSave = IntVar(parent)
|
|
|
|
self.encoding = StringVar(parent)
|
|
|
|
self.userHelpBrowser = BooleanVar(parent)
|
|
|
|
self.helpBrowser = StringVar(parent)
|
|
|
|
|
2001-08-07 00:28:25 -03:00
|
|
|
#widget creation
|
|
|
|
#body
|
2014-08-04 00:02:53 -03:00
|
|
|
frame = self.tabPages.pages['General'].frame
|
2002-12-31 12:03:23 -04:00
|
|
|
#body section frames
|
2014-08-04 00:02:53 -03:00
|
|
|
frameRun = LabelFrame(frame, borderwidth=2, relief=GROOVE,
|
|
|
|
text=' Startup Preferences ')
|
|
|
|
frameSave = LabelFrame(frame, borderwidth=2, relief=GROOVE,
|
|
|
|
text=' Autosave Preferences ')
|
|
|
|
frameWinSize = Frame(frame, borderwidth=2, relief=GROOVE)
|
|
|
|
frameEncoding = Frame(frame, borderwidth=2, relief=GROOVE)
|
|
|
|
frameHelp = LabelFrame(frame, borderwidth=2, relief=GROOVE,
|
|
|
|
text=' Additional Help Sources ')
|
2001-08-07 00:28:25 -03:00
|
|
|
#frameRun
|
2014-08-04 00:02:53 -03:00
|
|
|
labelRunChoiceTitle = Label(frameRun, text='At Startup')
|
|
|
|
radioStartupEdit = Radiobutton(
|
|
|
|
frameRun, variable=self.startupEdit, value=1,
|
|
|
|
command=self.SetKeysType, text="Open Edit Window")
|
|
|
|
radioStartupShell = Radiobutton(
|
|
|
|
frameRun, variable=self.startupEdit, value=0,
|
|
|
|
command=self.SetKeysType, text='Open Shell Window')
|
2003-05-26 03:23:10 -03:00
|
|
|
#frameSave
|
2014-08-04 00:02:53 -03:00
|
|
|
labelRunSaveTitle = Label(frameSave, text='At Start of Run (F5) ')
|
|
|
|
radioSaveAsk = Radiobutton(
|
|
|
|
frameSave, variable=self.autoSave, value=0,
|
|
|
|
command=self.SetKeysType, text="Prompt to Save")
|
|
|
|
radioSaveAuto = Radiobutton(
|
|
|
|
frameSave, variable=self.autoSave, value=1,
|
|
|
|
command=self.SetKeysType, text='No Prompt')
|
2001-08-07 00:28:25 -03:00
|
|
|
#frameWinSize
|
2014-08-04 00:02:53 -03:00
|
|
|
labelWinSizeTitle = Label(
|
|
|
|
frameWinSize, text='Initial Window Size (in characters)')
|
|
|
|
labelWinWidthTitle = Label(frameWinSize, text='Width')
|
|
|
|
entryWinWidth = Entry(
|
|
|
|
frameWinSize, textvariable=self.winWidth, width=3)
|
|
|
|
labelWinHeightTitle = Label(frameWinSize, text='Height')
|
|
|
|
entryWinHeight = Entry(
|
|
|
|
frameWinSize, textvariable=self.winHeight, width=3)
|
2003-05-09 21:49:56 -03:00
|
|
|
#frameEncoding
|
2014-08-04 00:02:53 -03:00
|
|
|
labelEncodingTitle = Label(
|
|
|
|
frameEncoding, text="Default Source Encoding")
|
|
|
|
radioEncLocale = Radiobutton(
|
|
|
|
frameEncoding, variable=self.encoding,
|
|
|
|
value="locale", text="Locale-defined")
|
|
|
|
radioEncUTF8 = Radiobutton(
|
|
|
|
frameEncoding, variable=self.encoding,
|
|
|
|
value="utf-8", text="UTF-8")
|
|
|
|
radioEncNone = Radiobutton(
|
|
|
|
frameEncoding, variable=self.encoding,
|
|
|
|
value="none", text="None")
|
2002-02-05 00:52:32 -04:00
|
|
|
#frameHelp
|
2014-08-04 00:02:53 -03:00
|
|
|
frameHelpList = Frame(frameHelp)
|
|
|
|
frameHelpListButtons = Frame(frameHelpList)
|
|
|
|
scrollHelpList = Scrollbar(frameHelpList)
|
|
|
|
self.listHelp = Listbox(
|
|
|
|
frameHelpList, height=5, takefocus=FALSE,
|
2002-02-05 00:52:32 -04:00
|
|
|
exportselection=FALSE)
|
|
|
|
scrollHelpList.config(command=self.listHelp.yview)
|
|
|
|
self.listHelp.config(yscrollcommand=scrollHelpList.set)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.listHelp.bind('<ButtonRelease-1>', self.HelpSourceSelected)
|
|
|
|
self.buttonHelpListEdit = Button(
|
|
|
|
frameHelpListButtons, text='Edit', state=DISABLED,
|
|
|
|
width=8, command=self.HelpListItemEdit)
|
|
|
|
self.buttonHelpListAdd = Button(
|
|
|
|
frameHelpListButtons, text='Add',
|
|
|
|
width=8, command=self.HelpListItemAdd)
|
|
|
|
self.buttonHelpListRemove = Button(
|
|
|
|
frameHelpListButtons, text='Remove', state=DISABLED,
|
|
|
|
width=8, command=self.HelpListItemRemove)
|
2014-07-30 20:24:26 -03:00
|
|
|
|
2001-08-07 00:28:25 -03:00
|
|
|
#widget packing
|
|
|
|
#body
|
2014-08-04 00:02:53 -03:00
|
|
|
frameRun.pack(side=TOP, padx=5, pady=5, fill=X)
|
|
|
|
frameSave.pack(side=TOP, padx=5, pady=5, fill=X)
|
|
|
|
frameWinSize.pack(side=TOP, padx=5, pady=5, fill=X)
|
|
|
|
frameEncoding.pack(side=TOP, padx=5, pady=5, fill=X)
|
|
|
|
frameHelp.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
2001-08-07 00:28:25 -03:00
|
|
|
#frameRun
|
2014-08-04 00:02:53 -03:00
|
|
|
labelRunChoiceTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
|
|
|
|
radioStartupShell.pack(side=RIGHT, anchor=W, padx=5, pady=5)
|
|
|
|
radioStartupEdit.pack(side=RIGHT, anchor=W, padx=5, pady=5)
|
2003-05-26 03:23:10 -03:00
|
|
|
#frameSave
|
2014-08-04 00:02:53 -03:00
|
|
|
labelRunSaveTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
|
|
|
|
radioSaveAuto.pack(side=RIGHT, anchor=W, padx=5, pady=5)
|
|
|
|
radioSaveAsk.pack(side=RIGHT, anchor=W, padx=5, pady=5)
|
2001-08-07 00:28:25 -03:00
|
|
|
#frameWinSize
|
2014-08-04 00:02:53 -03:00
|
|
|
labelWinSizeTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
|
|
|
|
entryWinHeight.pack(side=RIGHT, anchor=E, padx=10, pady=5)
|
|
|
|
labelWinHeightTitle.pack(side=RIGHT, anchor=E, pady=5)
|
|
|
|
entryWinWidth.pack(side=RIGHT, anchor=E, padx=10, pady=5)
|
|
|
|
labelWinWidthTitle.pack(side=RIGHT, anchor=E, pady=5)
|
2003-05-09 21:49:56 -03:00
|
|
|
#frameEncoding
|
2014-08-04 00:02:53 -03:00
|
|
|
labelEncodingTitle.pack(side=LEFT, anchor=W, padx=5, pady=5)
|
|
|
|
radioEncNone.pack(side=RIGHT, anchor=E, pady=5)
|
|
|
|
radioEncUTF8.pack(side=RIGHT, anchor=E, pady=5)
|
|
|
|
radioEncLocale.pack(side=RIGHT, anchor=E, pady=5)
|
2002-02-05 00:52:32 -04:00
|
|
|
#frameHelp
|
2014-08-04 00:02:53 -03:00
|
|
|
frameHelpListButtons.pack(side=RIGHT, padx=5, pady=5, fill=Y)
|
|
|
|
frameHelpList.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
|
|
|
scrollHelpList.pack(side=RIGHT, anchor=W, fill=Y)
|
|
|
|
self.listHelp.pack(side=LEFT, anchor=E, expand=TRUE, fill=BOTH)
|
|
|
|
self.buttonHelpListEdit.pack(side=TOP, anchor=W, pady=5)
|
|
|
|
self.buttonHelpListAdd.pack(side=TOP, anchor=W)
|
|
|
|
self.buttonHelpListRemove.pack(side=TOP, anchor=W, pady=5)
|
2001-08-03 01:43:44 -03:00
|
|
|
return frame
|
|
|
|
|
2002-01-22 01:56:40 -04:00
|
|
|
def AttachVarCallbacks(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
self.fontSize.trace_variable('w', self.VarChanged_fontSize)
|
|
|
|
self.fontName.trace_variable('w', self.VarChanged_fontName)
|
|
|
|
self.fontBold.trace_variable('w', self.VarChanged_fontBold)
|
|
|
|
self.spaceNum.trace_variable('w', self.VarChanged_spaceNum)
|
|
|
|
self.colour.trace_variable('w', self.VarChanged_colour)
|
|
|
|
self.builtinTheme.trace_variable('w', self.VarChanged_builtinTheme)
|
|
|
|
self.customTheme.trace_variable('w', self.VarChanged_customTheme)
|
|
|
|
self.themeIsBuiltin.trace_variable('w', self.VarChanged_themeIsBuiltin)
|
|
|
|
self.highlightTarget.trace_variable('w', self.VarChanged_highlightTarget)
|
|
|
|
self.keyBinding.trace_variable('w', self.VarChanged_keyBinding)
|
|
|
|
self.builtinKeys.trace_variable('w', self.VarChanged_builtinKeys)
|
|
|
|
self.customKeys.trace_variable('w', self.VarChanged_customKeys)
|
|
|
|
self.keysAreBuiltin.trace_variable('w', self.VarChanged_keysAreBuiltin)
|
|
|
|
self.winWidth.trace_variable('w', self.VarChanged_winWidth)
|
|
|
|
self.winHeight.trace_variable('w', self.VarChanged_winHeight)
|
|
|
|
self.startupEdit.trace_variable('w', self.VarChanged_startupEdit)
|
|
|
|
self.autoSave.trace_variable('w', self.VarChanged_autoSave)
|
|
|
|
self.encoding.trace_variable('w', self.VarChanged_encoding)
|
|
|
|
|
|
|
|
def VarChanged_fontSize(self, *params):
|
|
|
|
value = self.fontSize.get()
|
|
|
|
self.AddChangedItem('main', 'EditorWindow', 'font-size', value)
|
|
|
|
|
|
|
|
def VarChanged_fontName(self, *params):
|
|
|
|
value = self.fontName.get()
|
|
|
|
self.AddChangedItem('main', 'EditorWindow', 'font', value)
|
|
|
|
|
|
|
|
def VarChanged_fontBold(self, *params):
|
|
|
|
value = self.fontBold.get()
|
|
|
|
self.AddChangedItem('main', 'EditorWindow', 'font-bold', value)
|
|
|
|
|
|
|
|
def VarChanged_spaceNum(self, *params):
|
|
|
|
value = self.spaceNum.get()
|
|
|
|
self.AddChangedItem('main', 'Indent', 'num-spaces', value)
|
|
|
|
|
|
|
|
def VarChanged_colour(self, *params):
|
2002-02-10 22:20:53 -04:00
|
|
|
self.OnNewColourSet()
|
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_builtinTheme(self, *params):
|
|
|
|
value = self.builtinTheme.get()
|
|
|
|
self.AddChangedItem('main', 'Theme', 'name', value)
|
2002-02-10 22:20:53 -04:00
|
|
|
self.PaintThemeSample()
|
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_customTheme(self, *params):
|
|
|
|
value = self.customTheme.get()
|
2002-02-17 21:43:11 -04:00
|
|
|
if value != '- no custom themes -':
|
2014-08-04 00:02:53 -03:00
|
|
|
self.AddChangedItem('main', 'Theme', 'name', value)
|
2002-02-17 21:43:11 -04:00
|
|
|
self.PaintThemeSample()
|
2002-02-10 22:20:53 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_themeIsBuiltin(self, *params):
|
|
|
|
value = self.themeIsBuiltin.get()
|
|
|
|
self.AddChangedItem('main', 'Theme', 'default', value)
|
2002-03-04 20:25:58 -04:00
|
|
|
if value:
|
|
|
|
self.VarChanged_builtinTheme()
|
|
|
|
else:
|
|
|
|
self.VarChanged_customTheme()
|
2002-02-10 22:20:53 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_highlightTarget(self, *params):
|
2002-02-10 22:20:53 -04:00
|
|
|
self.SetHighlightTarget()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_keyBinding(self, *params):
|
|
|
|
value = self.keyBinding.get()
|
|
|
|
keySet = self.customKeys.get()
|
|
|
|
event = self.listBindings.get(ANCHOR).split()[0]
|
2002-01-31 21:33:36 -04:00
|
|
|
if idleConf.IsCoreBinding(event):
|
|
|
|
#this is a core keybinding
|
2014-08-04 00:02:53 -03:00
|
|
|
self.AddChangedItem('keys', keySet, event, value)
|
2002-01-31 21:33:36 -04:00
|
|
|
else: #this is an extension key binding
|
2014-08-04 00:02:53 -03:00
|
|
|
extName = idleConf.GetExtnNameForEvent(event)
|
|
|
|
extKeybindSection = extName + '_cfgBindings'
|
|
|
|
self.AddChangedItem('extensions', extKeybindSection, event, value)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_builtinKeys(self, *params):
|
|
|
|
value = self.builtinKeys.get()
|
|
|
|
self.AddChangedItem('main', 'Keys', 'name', value)
|
2002-02-10 22:20:53 -04:00
|
|
|
self.LoadKeysList(value)
|
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_customKeys(self, *params):
|
|
|
|
value = self.customKeys.get()
|
2002-02-17 21:43:11 -04:00
|
|
|
if value != '- no custom keys -':
|
2014-08-04 00:02:53 -03:00
|
|
|
self.AddChangedItem('main', 'Keys', 'name', value)
|
2002-02-17 21:43:11 -04:00
|
|
|
self.LoadKeysList(value)
|
2002-02-10 22:20:53 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_keysAreBuiltin(self, *params):
|
|
|
|
value = self.keysAreBuiltin.get()
|
|
|
|
self.AddChangedItem('main', 'Keys', 'default', value)
|
2002-12-31 12:03:23 -04:00
|
|
|
if value:
|
2002-03-04 20:25:58 -04:00
|
|
|
self.VarChanged_builtinKeys()
|
2002-02-10 22:20:53 -04:00
|
|
|
else:
|
2002-03-04 20:25:58 -04:00
|
|
|
self.VarChanged_customKeys()
|
2002-02-10 22:20:53 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_winWidth(self, *params):
|
|
|
|
value = self.winWidth.get()
|
|
|
|
self.AddChangedItem('main', 'EditorWindow', 'width', value)
|
2002-01-22 01:56:40 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_winHeight(self, *params):
|
|
|
|
value = self.winHeight.get()
|
|
|
|
self.AddChangedItem('main', 'EditorWindow', 'height', value)
|
2002-01-22 01:56:40 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_startupEdit(self, *params):
|
|
|
|
value = self.startupEdit.get()
|
|
|
|
self.AddChangedItem('main', 'General', 'editor-on-startup', value)
|
2002-01-22 01:56:40 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_autoSave(self, *params):
|
|
|
|
value = self.autoSave.get()
|
|
|
|
self.AddChangedItem('main', 'General', 'autosave', value)
|
2003-05-26 03:23:10 -03:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def VarChanged_encoding(self, *params):
|
|
|
|
value = self.encoding.get()
|
|
|
|
self.AddChangedItem('main', 'EditorWindow', 'encoding', value)
|
2003-05-09 21:49:56 -03:00
|
|
|
|
2002-01-31 21:33:36 -04:00
|
|
|
def ResetChangedItems(self):
|
2002-03-02 03:16:21 -04:00
|
|
|
#When any config item is changed in this dialog, an entry
|
2002-12-31 12:03:23 -04:00
|
|
|
#should be made in the relevant section (config type) of this
|
|
|
|
#dictionary. The key should be the config file section name and the
|
2002-01-31 21:33:36 -04:00
|
|
|
#value a dictionary, whose key:value pairs are item=value pairs for
|
|
|
|
#that config file section.
|
2014-08-04 00:02:53 -03:00
|
|
|
self.changedItems = {'main':{}, 'highlight':{}, 'keys':{},
|
|
|
|
'extensions':{}}
|
2002-01-31 21:33:36 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def AddChangedItem(self, typ, section, item, value):
|
|
|
|
value = str(value) #make sure we use a string
|
|
|
|
if section not in self.changedItems[typ]:
|
|
|
|
self.changedItems[typ][section] = {}
|
|
|
|
self.changedItems[typ][section][item] = value
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-21 02:38:21 -04:00
|
|
|
def GetDefaultItems(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
dItems={'main':{}, 'highlight':{}, 'keys':{}, 'extensions':{}}
|
2014-07-27 05:07:18 -03:00
|
|
|
for configType in dItems:
|
2014-08-04 00:02:53 -03:00
|
|
|
sections = idleConf.GetSectionList('default', configType)
|
2002-01-21 02:38:21 -04:00
|
|
|
for section in sections:
|
2014-08-04 00:02:53 -03:00
|
|
|
dItems[configType][section] = {}
|
|
|
|
options = idleConf.defaultCfg[configType].GetOptionList(section)
|
2002-12-31 12:03:23 -04:00
|
|
|
for option in options:
|
2014-08-04 00:02:53 -03:00
|
|
|
dItems[configType][section][option] = (
|
|
|
|
idleConf.defaultCfg[configType].Get(section, option))
|
2002-01-21 02:38:21 -04:00
|
|
|
return dItems
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-21 02:38:21 -04:00
|
|
|
def SetThemeType(self):
|
|
|
|
if self.themeIsBuiltin.get():
|
|
|
|
self.optMenuThemeBuiltin.config(state=NORMAL)
|
|
|
|
self.optMenuThemeCustom.config(state=DISABLED)
|
|
|
|
self.buttonDeleteCustomTheme.config(state=DISABLED)
|
|
|
|
else:
|
|
|
|
self.optMenuThemeBuiltin.config(state=DISABLED)
|
2002-01-24 02:02:50 -04:00
|
|
|
self.radioThemeCustom.config(state=NORMAL)
|
2002-01-21 02:38:21 -04:00
|
|
|
self.optMenuThemeCustom.config(state=NORMAL)
|
|
|
|
self.buttonDeleteCustomTheme.config(state=NORMAL)
|
|
|
|
|
|
|
|
def SetKeysType(self):
|
2002-02-10 22:20:53 -04:00
|
|
|
if self.keysAreBuiltin.get():
|
2002-01-21 02:38:21 -04:00
|
|
|
self.optMenuKeysBuiltin.config(state=NORMAL)
|
|
|
|
self.optMenuKeysCustom.config(state=DISABLED)
|
|
|
|
self.buttonDeleteCustomKeys.config(state=DISABLED)
|
|
|
|
else:
|
|
|
|
self.optMenuKeysBuiltin.config(state=DISABLED)
|
2002-01-24 02:02:50 -04:00
|
|
|
self.radioKeysCustom.config(state=NORMAL)
|
2002-01-21 02:38:21 -04:00
|
|
|
self.optMenuKeysCustom.config(state=NORMAL)
|
|
|
|
self.buttonDeleteCustomKeys.config(state=NORMAL)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-24 02:02:50 -04:00
|
|
|
def GetNewKeys(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
listIndex = self.listBindings.index(ANCHOR)
|
|
|
|
binding = self.listBindings.get(listIndex)
|
|
|
|
bindName = binding.split()[0] #first part, up to first space
|
2002-12-31 12:03:23 -04:00
|
|
|
if self.keysAreBuiltin.get():
|
2014-08-04 00:02:53 -03:00
|
|
|
currentKeySetName = self.builtinKeys.get()
|
2002-12-31 12:03:23 -04:00
|
|
|
else:
|
2014-08-04 00:02:53 -03:00
|
|
|
currentKeySetName = self.customKeys.get()
|
|
|
|
currentBindings = idleConf.GetCurrentKeySet()
|
2014-07-27 05:07:18 -03:00
|
|
|
if currentKeySetName in self.changedItems['keys']: #unsaved changes
|
2014-08-04 00:02:53 -03:00
|
|
|
keySetChanges = self.changedItems['keys'][currentKeySetName]
|
2014-07-27 05:07:18 -03:00
|
|
|
for event in keySetChanges:
|
2014-08-04 00:02:53 -03:00
|
|
|
currentBindings[event] = keySetChanges[event].split()
|
|
|
|
currentKeySequences = currentBindings.values()
|
|
|
|
newKeys = GetKeysDialog(self, 'Get New Keys', bindName,
|
2002-02-05 00:52:32 -04:00
|
|
|
currentKeySequences).result
|
|
|
|
if newKeys: #new keys were specified
|
2002-02-10 22:20:53 -04:00
|
|
|
if self.keysAreBuiltin.get(): #current key set is a built-in
|
2014-08-04 00:02:53 -03:00
|
|
|
message = ('Your changes will be saved as a new Custom Key Set.'
|
|
|
|
' Enter a name for your new Custom Key Set below.')
|
|
|
|
newKeySet = self.GetNewKeysName(message)
|
2002-02-05 00:52:32 -04:00
|
|
|
if not newKeySet: #user cancelled custom key set creation
|
2002-01-24 02:02:50 -04:00
|
|
|
self.listBindings.select_set(listIndex)
|
|
|
|
self.listBindings.select_anchor(listIndex)
|
|
|
|
return
|
2002-12-31 12:03:23 -04:00
|
|
|
else: #create new custom key set based on previously active key set
|
|
|
|
self.CreateNewKeySet(newKeySet)
|
2002-01-24 02:02:50 -04:00
|
|
|
self.listBindings.delete(listIndex)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.listBindings.insert(listIndex, bindName+' - '+newKeys)
|
2002-01-24 02:02:50 -04:00
|
|
|
self.listBindings.select_set(listIndex)
|
|
|
|
self.listBindings.select_anchor(listIndex)
|
2002-02-10 22:20:53 -04:00
|
|
|
self.keyBinding.set(newKeys)
|
2002-01-24 02:02:50 -04:00
|
|
|
else:
|
|
|
|
self.listBindings.select_set(listIndex)
|
|
|
|
self.listBindings.select_anchor(listIndex)
|
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def GetNewKeysName(self, message):
|
|
|
|
usedNames = (idleConf.GetSectionList('user', 'keys') +
|
|
|
|
idleConf.GetSectionList('default', 'keys'))
|
|
|
|
newKeySet = GetCfgSectionNameDialog(
|
|
|
|
self, 'New Custom Key Set', message, usedNames).result
|
2002-02-05 00:52:32 -04:00
|
|
|
return newKeySet
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-02-05 00:52:32 -04:00
|
|
|
def SaveAsNewKeySet(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
newKeysName = self.GetNewKeysName('New Key Set Name:')
|
2002-02-05 00:52:32 -04:00
|
|
|
if newKeysName:
|
|
|
|
self.CreateNewKeySet(newKeysName)
|
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def KeyBindingSelected(self, event):
|
2002-01-24 02:02:50 -04:00
|
|
|
self.buttonNewKeys.config(state=NORMAL)
|
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def CreateNewKeySet(self, newKeySetName):
|
2002-01-24 02:02:50 -04:00
|
|
|
#creates new custom key set based on the previously active key set,
|
|
|
|
#and makes the new key set active
|
2002-12-31 12:03:23 -04:00
|
|
|
if self.keysAreBuiltin.get():
|
2014-08-04 00:02:53 -03:00
|
|
|
prevKeySetName = self.builtinKeys.get()
|
2002-12-31 12:03:23 -04:00
|
|
|
else:
|
2014-08-04 00:02:53 -03:00
|
|
|
prevKeySetName = self.customKeys.get()
|
|
|
|
prevKeys = idleConf.GetCoreKeys(prevKeySetName)
|
|
|
|
newKeys = {}
|
2014-07-27 05:07:18 -03:00
|
|
|
for event in prevKeys: #add key set to changed items
|
2014-08-04 00:02:53 -03:00
|
|
|
eventName = event[2:-2] #trim off the angle brackets
|
|
|
|
binding = ' '.join(prevKeys[event])
|
|
|
|
newKeys[eventName] = binding
|
2002-02-10 22:20:53 -04:00
|
|
|
#handle any unsaved changes to prev key set
|
2014-07-27 05:07:18 -03:00
|
|
|
if prevKeySetName in self.changedItems['keys']:
|
2014-08-04 00:02:53 -03:00
|
|
|
keySetChanges = self.changedItems['keys'][prevKeySetName]
|
2014-07-27 05:07:18 -03:00
|
|
|
for event in keySetChanges:
|
2014-08-04 00:02:53 -03:00
|
|
|
newKeys[event] = keySetChanges[event]
|
2002-02-10 22:20:53 -04:00
|
|
|
#save the new theme
|
2014-08-04 00:02:53 -03:00
|
|
|
self.SaveNewKeySet(newKeySetName, newKeys)
|
2002-01-24 02:02:50 -04:00
|
|
|
#change gui over to the new key set
|
2014-08-04 00:02:53 -03:00
|
|
|
customKeyList = idleConf.GetSectionList('user', 'keys')
|
2002-01-24 02:02:50 -04:00
|
|
|
customKeyList.sort()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuKeysCustom.SetMenu(customKeyList, newKeySetName)
|
2002-02-10 22:20:53 -04:00
|
|
|
self.keysAreBuiltin.set(0)
|
2002-01-24 02:02:50 -04:00
|
|
|
self.SetKeysType()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def LoadKeysList(self, keySetName):
|
|
|
|
reselect = 0
|
|
|
|
newKeySet = 0
|
2002-02-10 22:20:53 -04:00
|
|
|
if self.listBindings.curselection():
|
2014-08-04 00:02:53 -03:00
|
|
|
reselect = 1
|
|
|
|
listIndex = self.listBindings.index(ANCHOR)
|
|
|
|
keySet = idleConf.GetKeySet(keySetName)
|
|
|
|
bindNames = keySet.keys()
|
2002-02-10 22:20:53 -04:00
|
|
|
bindNames.sort()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.listBindings.delete(0, END)
|
2002-12-31 12:03:23 -04:00
|
|
|
for bindName in bindNames:
|
2014-08-04 00:02:53 -03:00
|
|
|
key = ' '.join(keySet[bindName]) #make key(s) into a string
|
|
|
|
bindName = bindName[2:-2] #trim off the angle brackets
|
2014-07-27 05:07:18 -03:00
|
|
|
if keySetName in self.changedItems['keys']:
|
2002-02-10 22:20:53 -04:00
|
|
|
#handle any unsaved changes to this key set
|
2014-07-27 05:07:18 -03:00
|
|
|
if bindName in self.changedItems['keys'][keySetName]:
|
2014-08-04 00:02:53 -03:00
|
|
|
key = self.changedItems['keys'][keySetName][bindName]
|
2002-02-10 22:20:53 -04:00
|
|
|
self.listBindings.insert(END, bindName+' - '+key)
|
|
|
|
if reselect:
|
|
|
|
self.listBindings.see(listIndex)
|
|
|
|
self.listBindings.select_set(listIndex)
|
|
|
|
self.listBindings.select_anchor(listIndex)
|
|
|
|
|
2002-02-17 21:43:11 -04:00
|
|
|
def DeleteCustomKeys(self):
|
|
|
|
keySetName=self.customKeys.get()
|
2014-08-04 00:02:53 -03:00
|
|
|
delmsg = 'Are you sure you wish to delete the key set %r ?'
|
|
|
|
if not tkMessageBox.askyesno(
|
|
|
|
'Delete Key Set', delmsg % keySetName, parent=self):
|
2002-02-17 21:43:11 -04:00
|
|
|
return
|
|
|
|
#remove key set from config
|
|
|
|
idleConf.userCfg['keys'].remove_section(keySetName)
|
2009-10-09 19:15:50 -03:00
|
|
|
if keySetName in self.changedItems['keys']:
|
2002-02-17 21:43:11 -04:00
|
|
|
del(self.changedItems['keys'][keySetName])
|
|
|
|
#write changes
|
|
|
|
idleConf.userCfg['keys'].Save()
|
|
|
|
#reload user key set list
|
2014-08-04 00:02:53 -03:00
|
|
|
itemList = idleConf.GetSectionList('user', 'keys')
|
2002-02-17 21:43:11 -04:00
|
|
|
itemList.sort()
|
|
|
|
if not itemList:
|
|
|
|
self.radioKeysCustom.config(state=DISABLED)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuKeysCustom.SetMenu(itemList, '- no custom keys -')
|
2002-02-17 21:43:11 -04:00
|
|
|
else:
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuKeysCustom.SetMenu(itemList, itemList[0])
|
2002-02-17 21:43:11 -04:00
|
|
|
#revert to default key set
|
2014-08-04 00:02:53 -03:00
|
|
|
self.keysAreBuiltin.set(idleConf.defaultCfg['main'].Get('Keys', 'default'))
|
|
|
|
self.builtinKeys.set(idleConf.defaultCfg['main'].Get('Keys', 'name'))
|
2002-02-17 21:43:11 -04:00
|
|
|
#user can't back out of these changes, they must be applied now
|
|
|
|
self.Apply()
|
|
|
|
self.SetKeysType()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-02-17 21:43:11 -04:00
|
|
|
def DeleteCustomTheme(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
themeName = self.customTheme.get()
|
|
|
|
delmsg = 'Are you sure you wish to delete the theme %r ?'
|
|
|
|
if not tkMessageBox.askyesno(
|
|
|
|
'Delete Theme', delmsg % themeName, parent=self):
|
2002-02-17 21:43:11 -04:00
|
|
|
return
|
|
|
|
#remove theme from config
|
|
|
|
idleConf.userCfg['highlight'].remove_section(themeName)
|
2009-10-09 19:15:50 -03:00
|
|
|
if themeName in self.changedItems['highlight']:
|
2002-02-17 21:43:11 -04:00
|
|
|
del(self.changedItems['highlight'][themeName])
|
|
|
|
#write changes
|
|
|
|
idleConf.userCfg['highlight'].Save()
|
|
|
|
#reload user theme list
|
2014-08-04 00:02:53 -03:00
|
|
|
itemList = idleConf.GetSectionList('user', 'highlight')
|
2002-02-17 21:43:11 -04:00
|
|
|
itemList.sort()
|
|
|
|
if not itemList:
|
|
|
|
self.radioThemeCustom.config(state=DISABLED)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuThemeCustom.SetMenu(itemList, '- no custom themes -')
|
2002-02-17 21:43:11 -04:00
|
|
|
else:
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuThemeCustom.SetMenu(itemList, itemList[0])
|
2002-02-17 21:43:11 -04:00
|
|
|
#revert to default theme
|
2014-08-04 00:02:53 -03:00
|
|
|
self.themeIsBuiltin.set(idleConf.defaultCfg['main'].Get('Theme', 'default'))
|
|
|
|
self.builtinTheme.set(idleConf.defaultCfg['main'].Get('Theme', 'name'))
|
2002-02-17 21:43:11 -04:00
|
|
|
#user can't back out of these changes, they must be applied now
|
|
|
|
self.Apply()
|
|
|
|
self.SetThemeType()
|
|
|
|
|
2002-01-21 02:38:21 -04:00
|
|
|
def GetColour(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
target = self.highlightTarget.get()
|
|
|
|
prevColour = self.frameColourSet.cget('bg')
|
|
|
|
rgbTuplet, colourString = tkColorChooser.askcolor(
|
|
|
|
parent=self, title='Pick new colour for : '+target,
|
|
|
|
initialcolor=prevColour)
|
|
|
|
if colourString and (colourString != prevColour):
|
2002-02-10 22:20:53 -04:00
|
|
|
#user didn't cancel, and they chose a new colour
|
2014-08-04 00:02:53 -03:00
|
|
|
if self.themeIsBuiltin.get(): #current theme is a built-in
|
|
|
|
message = ('Your changes will be saved as a new Custom Theme. '
|
|
|
|
'Enter a name for your new Custom Theme below.')
|
|
|
|
newTheme = self.GetNewThemeName(message)
|
|
|
|
if not newTheme: #user cancelled custom theme creation
|
2002-01-24 02:02:50 -04:00
|
|
|
return
|
2014-08-04 00:02:53 -03:00
|
|
|
else: #create new custom theme based on previously active theme
|
2002-12-31 12:03:23 -04:00
|
|
|
self.CreateNewTheme(newTheme)
|
2002-02-10 22:20:53 -04:00
|
|
|
self.colour.set(colourString)
|
2014-08-04 00:02:53 -03:00
|
|
|
else: #current theme is user defined
|
2002-02-10 22:20:53 -04:00
|
|
|
self.colour.set(colourString)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-02-10 22:20:53 -04:00
|
|
|
def OnNewColourSet(self):
|
|
|
|
newColour=self.colour.get()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.frameColourSet.config(bg=newColour) #set sample
|
|
|
|
plane ='foreground' if self.fgHilite.get() else 'background'
|
|
|
|
sampleElement = self.themeElements[self.highlightTarget.get()][0]
|
2003-07-09 15:48:24 -03:00
|
|
|
self.textHighlightSample.tag_config(sampleElement, **{plane:newColour})
|
2014-08-04 00:02:53 -03:00
|
|
|
theme = self.customTheme.get()
|
|
|
|
themeElement = sampleElement + '-' + plane
|
|
|
|
self.AddChangedItem('highlight', theme, themeElement, newColour)
|
|
|
|
|
|
|
|
def GetNewThemeName(self, message):
|
|
|
|
usedNames = (idleConf.GetSectionList('user', 'highlight') +
|
|
|
|
idleConf.GetSectionList('default', 'highlight'))
|
|
|
|
newTheme = GetCfgSectionNameDialog(
|
|
|
|
self, 'New Custom Theme', message, usedNames).result
|
2002-02-05 00:52:32 -04:00
|
|
|
return newTheme
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-02-05 00:52:32 -04:00
|
|
|
def SaveAsNewTheme(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
newThemeName = self.GetNewThemeName('New Theme Name:')
|
2002-02-05 00:52:32 -04:00
|
|
|
if newThemeName:
|
|
|
|
self.CreateNewTheme(newThemeName)
|
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def CreateNewTheme(self, newThemeName):
|
2002-01-24 02:02:50 -04:00
|
|
|
#creates new custom theme based on the previously active theme,
|
|
|
|
#and makes the new theme active
|
2002-12-31 12:03:23 -04:00
|
|
|
if self.themeIsBuiltin.get():
|
2014-08-04 00:02:53 -03:00
|
|
|
themeType = 'default'
|
|
|
|
themeName = self.builtinTheme.get()
|
2002-12-31 12:03:23 -04:00
|
|
|
else:
|
2014-08-04 00:02:53 -03:00
|
|
|
themeType = 'user'
|
|
|
|
themeName = self.customTheme.get()
|
|
|
|
newTheme = idleConf.GetThemeDict(themeType, themeName)
|
2002-02-10 22:20:53 -04:00
|
|
|
#apply any of the old theme's unsaved changes to the new theme
|
2014-07-27 05:07:18 -03:00
|
|
|
if themeName in self.changedItems['highlight']:
|
2014-08-04 00:02:53 -03:00
|
|
|
themeChanges = self.changedItems['highlight'][themeName]
|
2014-07-27 05:07:18 -03:00
|
|
|
for element in themeChanges:
|
2014-08-04 00:02:53 -03:00
|
|
|
newTheme[element] = themeChanges[element]
|
2002-02-10 22:20:53 -04:00
|
|
|
#save the new theme
|
2014-08-04 00:02:53 -03:00
|
|
|
self.SaveNewTheme(newThemeName, newTheme)
|
2002-01-24 02:02:50 -04:00
|
|
|
#change gui over to the new theme
|
2014-08-04 00:02:53 -03:00
|
|
|
customThemeList = idleConf.GetSectionList('user', 'highlight')
|
2002-01-24 02:02:50 -04:00
|
|
|
customThemeList.sort()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuThemeCustom.SetMenu(customThemeList, newThemeName)
|
2002-01-24 02:02:50 -04:00
|
|
|
self.themeIsBuiltin.set(0)
|
|
|
|
self.SetThemeType()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def OnListFontButtonRelease(self, event):
|
2003-05-26 17:35:53 -03:00
|
|
|
font = self.listFontName.get(ANCHOR)
|
|
|
|
self.fontName.set(font.lower())
|
2002-01-21 02:38:21 -04:00
|
|
|
self.SetFontSample()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def SetFontSample(self, event=None):
|
|
|
|
fontName = self.fontName.get()
|
|
|
|
fontWeight = tkFont.BOLD if self.fontBold.get() else tkFont.NORMAL
|
2012-10-22 19:13:01 -03:00
|
|
|
newFont = (fontName, self.fontSize.get(), fontWeight)
|
|
|
|
self.labelFontSample.config(font=newFont)
|
|
|
|
self.textHighlightSample.configure(font=newFont)
|
2002-01-21 02:38:21 -04:00
|
|
|
|
|
|
|
def SetHighlightTarget(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
if self.highlightTarget.get() == 'Cursor': #bg not possible
|
2002-01-21 02:38:21 -04:00
|
|
|
self.radioFg.config(state=DISABLED)
|
|
|
|
self.radioBg.config(state=DISABLED)
|
|
|
|
self.fgHilite.set(1)
|
2014-08-04 00:02:53 -03:00
|
|
|
else: #both fg and bg can be set
|
2002-01-21 02:38:21 -04:00
|
|
|
self.radioFg.config(state=NORMAL)
|
|
|
|
self.radioBg.config(state=NORMAL)
|
|
|
|
self.fgHilite.set(1)
|
|
|
|
self.SetColourSample()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def SetColourSampleBinding(self, *args):
|
2002-01-21 02:38:21 -04:00
|
|
|
self.SetColourSample()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-21 02:38:21 -04:00
|
|
|
def SetColourSample(self):
|
|
|
|
#set the colour smaple area
|
2014-08-04 00:02:53 -03:00
|
|
|
tag = self.themeElements[self.highlightTarget.get()][0]
|
|
|
|
plane = 'foreground' if self.fgHilite.get() else 'background'
|
|
|
|
colour = self.textHighlightSample.tag_cget(tag, plane)
|
2002-01-21 02:38:21 -04:00
|
|
|
self.frameColourSet.config(bg=colour)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-11-03 10:54:25 -04:00
|
|
|
def PaintThemeSample(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
if self.themeIsBuiltin.get(): #a default theme
|
|
|
|
theme = self.builtinTheme.get()
|
|
|
|
else: #a user theme
|
|
|
|
theme = self.customTheme.get()
|
2014-07-27 05:07:18 -03:00
|
|
|
for elementTitle in self.themeElements:
|
2014-08-04 00:02:53 -03:00
|
|
|
element = self.themeElements[elementTitle][0]
|
|
|
|
colours = idleConf.GetHighlight(theme, element)
|
|
|
|
if element == 'cursor': #cursor sample needs special painting
|
|
|
|
colours['background'] = idleConf.GetHighlight(
|
|
|
|
theme, 'normal', fgBg='bg')
|
2002-02-10 22:20:53 -04:00
|
|
|
#handle any unsaved changes to this theme
|
2014-07-27 05:07:18 -03:00
|
|
|
if theme in self.changedItems['highlight']:
|
2014-08-04 00:02:53 -03:00
|
|
|
themeDict = self.changedItems['highlight'][theme]
|
|
|
|
if element + '-foreground' in themeDict:
|
|
|
|
colours['foreground'] = themeDict[element + '-foreground']
|
|
|
|
if element + '-background' in themeDict:
|
|
|
|
colours['background'] = themeDict[element + '-background']
|
2003-07-09 15:48:24 -03:00
|
|
|
self.textHighlightSample.tag_config(element, **colours)
|
2002-02-10 22:20:53 -04:00
|
|
|
self.SetColourSample()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def HelpSourceSelected(self, event):
|
2002-02-05 00:52:32 -04:00
|
|
|
self.SetHelpListButtonStates()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-02-05 00:52:32 -04:00
|
|
|
def SetHelpListButtonStates(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
if self.listHelp.size() < 1: #no entries in list
|
2002-02-05 00:52:32 -04:00
|
|
|
self.buttonHelpListEdit.config(state=DISABLED)
|
|
|
|
self.buttonHelpListRemove.config(state=DISABLED)
|
|
|
|
else: #there are some entries
|
2014-08-04 00:02:53 -03:00
|
|
|
if self.listHelp.curselection(): #there currently is a selection
|
2002-02-05 00:52:32 -04:00
|
|
|
self.buttonHelpListEdit.config(state=NORMAL)
|
|
|
|
self.buttonHelpListRemove.config(state=NORMAL)
|
|
|
|
else: #there currently is not a selection
|
|
|
|
self.buttonHelpListEdit.config(state=DISABLED)
|
|
|
|
self.buttonHelpListRemove.config(state=DISABLED)
|
|
|
|
|
|
|
|
def HelpListItemAdd(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
helpSource = GetHelpSourceDialog(self, 'New Help Source').result
|
2002-02-05 00:52:32 -04:00
|
|
|
if helpSource:
|
2014-08-04 00:02:53 -03:00
|
|
|
self.userHelpList.append((helpSource[0], helpSource[1]))
|
|
|
|
self.listHelp.insert(END, helpSource[0])
|
2002-02-05 00:52:32 -04:00
|
|
|
self.UpdateUserHelpChangedItems()
|
|
|
|
self.SetHelpListButtonStates()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-02-05 00:52:32 -04:00
|
|
|
def HelpListItemEdit(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
itemIndex = self.listHelp.index(ANCHOR)
|
|
|
|
helpSource = self.userHelpList[itemIndex]
|
|
|
|
newHelpSource = GetHelpSourceDialog(
|
|
|
|
self, 'Edit Help Source', menuItem=helpSource[0],
|
|
|
|
filePath=helpSource[1]).result
|
|
|
|
if (not newHelpSource) or (newHelpSource == helpSource):
|
2002-02-05 00:52:32 -04:00
|
|
|
return #no changes
|
2014-08-04 00:02:53 -03:00
|
|
|
self.userHelpList[itemIndex] = newHelpSource
|
2002-02-05 00:52:32 -04:00
|
|
|
self.listHelp.delete(itemIndex)
|
2014-08-04 00:02:53 -03:00
|
|
|
self.listHelp.insert(itemIndex, newHelpSource[0])
|
2002-02-05 00:52:32 -04:00
|
|
|
self.UpdateUserHelpChangedItems()
|
|
|
|
self.SetHelpListButtonStates()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-02-05 00:52:32 -04:00
|
|
|
def HelpListItemRemove(self):
|
2014-08-04 00:02:53 -03:00
|
|
|
itemIndex = self.listHelp.index(ANCHOR)
|
2002-02-05 00:52:32 -04:00
|
|
|
del(self.userHelpList[itemIndex])
|
|
|
|
self.listHelp.delete(itemIndex)
|
|
|
|
self.UpdateUserHelpChangedItems()
|
|
|
|
self.SetHelpListButtonStates()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-02-05 00:52:32 -04:00
|
|
|
def UpdateUserHelpChangedItems(self):
|
2003-01-14 18:03:31 -04:00
|
|
|
"Clear and rebuild the HelpFiles section in self.changedItems"
|
|
|
|
self.changedItems['main']['HelpFiles'] = {}
|
2014-08-04 00:02:53 -03:00
|
|
|
for num in range(1, len(self.userHelpList) + 1):
|
|
|
|
self.AddChangedItem(
|
|
|
|
'main', 'HelpFiles', str(num),
|
2014-07-27 05:07:18 -03:00
|
|
|
';'.join(self.userHelpList[num-1][:2]))
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-10-23 07:42:12 -03:00
|
|
|
def LoadFontCfg(self):
|
|
|
|
##base editor font selection list
|
2014-08-04 00:02:53 -03:00
|
|
|
fonts = list(tkFont.families(self))
|
2001-09-24 06:43:17 -03:00
|
|
|
fonts.sort()
|
|
|
|
for font in fonts:
|
2014-08-04 00:02:53 -03:00
|
|
|
self.listFontName.insert(END, font)
|
|
|
|
configuredFont = idleConf.GetOption(
|
|
|
|
'main', 'EditorWindow', 'font', default='courier')
|
2003-05-26 17:35:53 -03:00
|
|
|
lc_configuredFont = configuredFont.lower()
|
|
|
|
self.fontName.set(lc_configuredFont)
|
|
|
|
lc_fonts = [s.lower() for s in fonts]
|
|
|
|
if lc_configuredFont in lc_fonts:
|
|
|
|
currentFontIndex = lc_fonts.index(lc_configuredFont)
|
2001-10-23 07:42:12 -03:00
|
|
|
self.listFontName.see(currentFontIndex)
|
|
|
|
self.listFontName.select_set(currentFontIndex)
|
2002-01-22 01:56:40 -04:00
|
|
|
self.listFontName.select_anchor(currentFontIndex)
|
2001-10-23 07:42:12 -03:00
|
|
|
##font size dropdown
|
2014-08-04 00:02:53 -03:00
|
|
|
fontSize = idleConf.GetOption(
|
|
|
|
'main', 'EditorWindow', 'font-size', type='int', default='10')
|
|
|
|
self.optMenuFontSize.SetMenu(('7', '8', '9', '10', '11', '12', '13',
|
|
|
|
'14', '16', '18', '20', '22'), fontSize )
|
2002-01-22 01:56:40 -04:00
|
|
|
##fontWeight
|
2014-08-04 00:02:53 -03:00
|
|
|
self.fontBold.set(idleConf.GetOption(
|
|
|
|
'main', 'EditorWindow', 'font-bold', default=0, type='bool'))
|
2002-12-31 12:03:23 -04:00
|
|
|
##font sample
|
2001-10-23 07:42:12 -03:00
|
|
|
self.SetFontSample()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-10-23 07:42:12 -03:00
|
|
|
def LoadTabCfg(self):
|
|
|
|
##indent sizes
|
2014-08-04 00:02:53 -03:00
|
|
|
spaceNum = idleConf.GetOption(
|
|
|
|
'main', 'Indent', 'num-spaces', default=4, type='int')
|
2001-10-23 07:42:12 -03:00
|
|
|
self.spaceNum.set(spaceNum)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-11-03 10:54:25 -04:00
|
|
|
def LoadThemeCfg(self):
|
2001-10-29 04:05:34 -04:00
|
|
|
##current theme type radiobutton
|
2014-08-04 00:02:53 -03:00
|
|
|
self.themeIsBuiltin.set(idleConf.GetOption(
|
|
|
|
'main', 'Theme', 'default', type='bool', default=1))
|
2001-10-29 04:05:34 -04:00
|
|
|
##currently set theme
|
2014-08-04 00:02:53 -03:00
|
|
|
currentOption = idleConf.CurrentTheme()
|
2001-10-29 07:19:46 -04:00
|
|
|
##load available theme option menus
|
2001-11-04 07:53:10 -04:00
|
|
|
if self.themeIsBuiltin.get(): #default theme selected
|
2014-08-04 00:02:53 -03:00
|
|
|
itemList = idleConf.GetSectionList('default', 'highlight')
|
2002-01-24 02:02:50 -04:00
|
|
|
itemList.sort()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuThemeBuiltin.SetMenu(itemList, currentOption)
|
|
|
|
itemList = idleConf.GetSectionList('user', 'highlight')
|
2002-01-24 02:02:50 -04:00
|
|
|
itemList.sort()
|
2001-10-29 04:05:34 -04:00
|
|
|
if not itemList:
|
|
|
|
self.radioThemeCustom.config(state=DISABLED)
|
2002-12-31 12:03:23 -04:00
|
|
|
self.customTheme.set('- no custom themes -')
|
2001-10-29 04:05:34 -04:00
|
|
|
else:
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuThemeCustom.SetMenu(itemList, itemList[0])
|
2001-11-03 10:54:25 -04:00
|
|
|
else: #user theme selected
|
2014-08-04 00:02:53 -03:00
|
|
|
itemList = idleConf.GetSectionList('user', 'highlight')
|
2002-01-24 02:02:50 -04:00
|
|
|
itemList.sort()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuThemeCustom.SetMenu(itemList, currentOption)
|
|
|
|
itemList = idleConf.GetSectionList('default', 'highlight')
|
2002-01-24 02:02:50 -04:00
|
|
|
itemList.sort()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuThemeBuiltin.SetMenu(itemList, itemList[0])
|
2001-10-29 07:19:46 -04:00
|
|
|
self.SetThemeType()
|
|
|
|
##load theme element option menu
|
2014-08-04 00:02:53 -03:00
|
|
|
themeNames = self.themeElements.keys()
|
2010-04-02 05:15:26 -03:00
|
|
|
themeNames.sort(key=lambda x: self.themeElements[x][1])
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuHighlightTarget.SetMenu(themeNames, themeNames[0])
|
2001-11-03 10:54:25 -04:00
|
|
|
self.PaintThemeSample()
|
2002-01-04 03:53:06 -04:00
|
|
|
self.SetHighlightTarget()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-11-03 10:54:25 -04:00
|
|
|
def LoadKeyCfg(self):
|
2001-10-29 04:05:34 -04:00
|
|
|
##current keys type radiobutton
|
2014-08-04 00:02:53 -03:00
|
|
|
self.keysAreBuiltin.set(idleConf.GetOption(
|
|
|
|
'main', 'Keys', 'default', type='bool', default=1))
|
2001-10-29 04:05:34 -04:00
|
|
|
##currently set keys
|
2014-08-04 00:02:53 -03:00
|
|
|
currentOption = idleConf.CurrentKeys()
|
2001-10-29 07:19:46 -04:00
|
|
|
##load available keyset option menus
|
2002-02-10 22:20:53 -04:00
|
|
|
if self.keysAreBuiltin.get(): #default theme selected
|
2014-08-04 00:02:53 -03:00
|
|
|
itemList = idleConf.GetSectionList('default', 'keys')
|
2002-01-24 02:02:50 -04:00
|
|
|
itemList.sort()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuKeysBuiltin.SetMenu(itemList, currentOption)
|
|
|
|
itemList = idleConf.GetSectionList('user', 'keys')
|
2002-01-24 02:02:50 -04:00
|
|
|
itemList.sort()
|
2001-10-29 04:05:34 -04:00
|
|
|
if not itemList:
|
2002-12-31 12:03:23 -04:00
|
|
|
self.radioKeysCustom.config(state=DISABLED)
|
|
|
|
self.customKeys.set('- no custom keys -')
|
2001-10-29 04:05:34 -04:00
|
|
|
else:
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuKeysCustom.SetMenu(itemList, itemList[0])
|
2002-01-31 21:33:36 -04:00
|
|
|
else: #user key set selected
|
2014-08-04 00:02:53 -03:00
|
|
|
itemList = idleConf.GetSectionList('user', 'keys')
|
2002-01-24 02:02:50 -04:00
|
|
|
itemList.sort()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuKeysCustom.SetMenu(itemList, currentOption)
|
|
|
|
itemList = idleConf.GetSectionList('default', 'keys')
|
2002-01-24 02:02:50 -04:00
|
|
|
itemList.sort()
|
2014-08-04 00:02:53 -03:00
|
|
|
self.optMenuKeysBuiltin.SetMenu(itemList, itemList[0])
|
2002-12-31 12:03:23 -04:00
|
|
|
self.SetKeysType()
|
2002-01-18 20:29:54 -04:00
|
|
|
##load keyset element list
|
2014-08-04 00:02:53 -03:00
|
|
|
keySetName = idleConf.CurrentKeys()
|
2002-02-10 22:20:53 -04:00
|
|
|
self.LoadKeysList(keySetName)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-18 20:29:54 -04:00
|
|
|
def LoadGeneralCfg(self):
|
2002-01-21 02:38:21 -04:00
|
|
|
#startup state
|
2014-08-04 00:02:53 -03:00
|
|
|
self.startupEdit.set(idleConf.GetOption(
|
|
|
|
'main', 'General', 'editor-on-startup', default=1, type='bool'))
|
2003-05-26 03:23:10 -03:00
|
|
|
#autosave state
|
2014-08-04 00:02:53 -03:00
|
|
|
self.autoSave.set(idleConf.GetOption(
|
|
|
|
'main', 'General', 'autosave', default=0, type='bool'))
|
2002-01-18 20:29:54 -04:00
|
|
|
#initial window size
|
2014-08-04 00:02:53 -03:00
|
|
|
self.winWidth.set(idleConf.GetOption(
|
|
|
|
'main', 'EditorWindow', 'width', type='int'))
|
|
|
|
self.winHeight.set(idleConf.GetOption(
|
|
|
|
'main', 'EditorWindow', 'height', type='int'))
|
2003-05-09 21:49:56 -03:00
|
|
|
# default source encoding
|
2014-08-04 00:02:53 -03:00
|
|
|
self.encoding.set(idleConf.GetOption(
|
|
|
|
'main', 'EditorWindow', 'encoding', default='none'))
|
2003-01-14 18:03:31 -04:00
|
|
|
# additional help sources
|
|
|
|
self.userHelpList = idleConf.GetAllExtraHelpSourcesList()
|
2002-02-05 00:52:32 -04:00
|
|
|
for helpItem in self.userHelpList:
|
2014-08-04 00:02:53 -03:00
|
|
|
self.listHelp.insert(END, helpItem[0])
|
2002-02-05 00:52:32 -04:00
|
|
|
self.SetHelpListButtonStates()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-10-23 07:42:12 -03:00
|
|
|
def LoadConfigs(self):
|
|
|
|
"""
|
|
|
|
load configuration from default and user config files and populate
|
|
|
|
the widgets on the config dialog pages.
|
|
|
|
"""
|
|
|
|
### fonts / tabs page
|
2002-12-31 12:03:23 -04:00
|
|
|
self.LoadFontCfg()
|
|
|
|
self.LoadTabCfg()
|
2001-10-23 07:42:12 -03:00
|
|
|
### highlighting page
|
2001-11-03 10:54:25 -04:00
|
|
|
self.LoadThemeCfg()
|
2001-10-23 07:42:12 -03:00
|
|
|
### keys page
|
2001-11-03 10:54:25 -04:00
|
|
|
self.LoadKeyCfg()
|
2001-10-23 07:42:12 -03:00
|
|
|
### general page
|
2002-01-18 20:29:54 -04:00
|
|
|
self.LoadGeneralCfg()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def SaveNewKeySet(self, keySetName, keySet):
|
2002-02-10 22:20:53 -04:00
|
|
|
"""
|
|
|
|
save a newly created core key set.
|
|
|
|
keySetName - string, the name of the new key set
|
|
|
|
keySet - dictionary containing the new key set
|
|
|
|
"""
|
|
|
|
if not idleConf.userCfg['keys'].has_section(keySetName):
|
|
|
|
idleConf.userCfg['keys'].add_section(keySetName)
|
2014-07-27 05:07:18 -03:00
|
|
|
for event in keySet:
|
2014-08-04 00:02:53 -03:00
|
|
|
value = keySet[event]
|
|
|
|
idleConf.userCfg['keys'].SetOption(keySetName, event, value)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def SaveNewTheme(self, themeName, theme):
|
2002-02-10 22:20:53 -04:00
|
|
|
"""
|
|
|
|
save a newly created theme.
|
|
|
|
themeName - string, the name of the new theme
|
|
|
|
theme - dictionary containing the new theme
|
|
|
|
"""
|
|
|
|
if not idleConf.userCfg['highlight'].has_section(themeName):
|
|
|
|
idleConf.userCfg['highlight'].add_section(themeName)
|
2014-07-27 05:07:18 -03:00
|
|
|
for element in theme:
|
2014-08-04 00:02:53 -03:00
|
|
|
value = theme[element]
|
|
|
|
idleConf.userCfg['highlight'].SetOption(themeName, element, value)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2014-08-04 00:02:53 -03:00
|
|
|
def SetUserValue(self, configType, section, item, value):
|
|
|
|
if idleConf.defaultCfg[configType].has_option(section, item):
|
|
|
|
if idleConf.defaultCfg[configType].Get(section, item) == value:
|
2002-01-29 04:35:29 -04:00
|
|
|
#the setting equals a default setting, remove it from user cfg
|
2014-08-04 00:02:53 -03:00
|
|
|
return idleConf.userCfg[configType].RemoveOption(section, item)
|
2002-01-29 04:35:29 -04:00
|
|
|
#if we got here set the option
|
2014-08-04 00:02:53 -03:00
|
|
|
return idleConf.userCfg[configType].SetOption(section, item, value)
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-02-10 22:20:53 -04:00
|
|
|
def SaveAllChangedConfigs(self):
|
2003-01-10 16:13:57 -04:00
|
|
|
"Save configuration changes to the user config file."
|
2002-03-26 22:25:44 -04:00
|
|
|
idleConf.userCfg['main'].Save()
|
2014-07-27 05:07:18 -03:00
|
|
|
for configType in self.changedItems:
|
2003-01-10 16:13:57 -04:00
|
|
|
cfgTypeHasChanges = False
|
2014-07-27 05:07:18 -03:00
|
|
|
for section in self.changedItems[configType]:
|
2003-01-10 16:13:57 -04:00
|
|
|
if section == 'HelpFiles':
|
|
|
|
#this section gets completely replaced
|
|
|
|
idleConf.userCfg['main'].remove_section('HelpFiles')
|
2003-01-14 18:03:31 -04:00
|
|
|
cfgTypeHasChanges = True
|
2014-07-27 05:07:18 -03:00
|
|
|
for item in self.changedItems[configType][section]:
|
2003-01-10 16:13:57 -04:00
|
|
|
value = self.changedItems[configType][section][item]
|
2014-08-04 00:02:53 -03:00
|
|
|
if self.SetUserValue(configType, section, item, value):
|
2003-01-10 16:13:57 -04:00
|
|
|
cfgTypeHasChanges = True
|
2002-12-31 12:03:23 -04:00
|
|
|
if cfgTypeHasChanges:
|
|
|
|
idleConf.userCfg[configType].Save()
|
2004-11-16 17:28:36 -04:00
|
|
|
for configType in ['keys', 'highlight']:
|
|
|
|
# save these even if unchanged!
|
|
|
|
idleConf.userCfg[configType].Save()
|
2002-01-31 21:33:36 -04:00
|
|
|
self.ResetChangedItems() #clear the changed items dict
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2005-11-18 18:05:48 -04:00
|
|
|
def DeactivateCurrentConfig(self):
|
|
|
|
#Before a config is saved, some cleanup of current
|
|
|
|
#config must be done - remove the previous keybindings
|
2014-08-04 00:02:53 -03:00
|
|
|
winInstances = self.parent.instance_dict
|
2005-11-18 18:05:48 -04:00
|
|
|
for instance in winInstances:
|
|
|
|
instance.RemoveKeybindings()
|
|
|
|
|
2002-02-17 21:43:11 -04:00
|
|
|
def ActivateConfigChanges(self):
|
2005-01-30 23:34:26 -04:00
|
|
|
"Dynamically apply configuration changes"
|
2014-07-27 05:07:18 -03:00
|
|
|
winInstances = self.parent.instance_dict.keys()
|
2002-03-02 03:16:21 -04:00
|
|
|
for instance in winInstances:
|
|
|
|
instance.ResetColorizer()
|
2002-03-11 20:21:56 -04:00
|
|
|
instance.ResetFont()
|
2005-01-30 23:34:26 -04:00
|
|
|
instance.set_notabs_indentwidth()
|
2005-11-18 18:05:48 -04:00
|
|
|
instance.ApplyKeybindings()
|
2003-01-14 18:03:31 -04:00
|
|
|
instance.reset_help_menu_entries()
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2002-01-21 02:38:21 -04:00
|
|
|
def Cancel(self):
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
def Ok(self):
|
|
|
|
self.Apply()
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
def Apply(self):
|
2005-11-18 18:05:48 -04:00
|
|
|
self.DeactivateCurrentConfig()
|
2002-02-10 22:20:53 -04:00
|
|
|
self.SaveAllChangedConfigs()
|
2002-02-17 21:43:11 -04:00
|
|
|
self.ActivateConfigChanges()
|
2002-01-21 02:38:21 -04:00
|
|
|
|
|
|
|
def Help(self):
|
2001-09-24 06:43:17 -03:00
|
|
|
pass
|
|
|
|
|
2014-10-22 21:15:12 -03:00
|
|
|
class VerticalScrolledFrame(Frame):
|
|
|
|
"""A pure Tkinter vertically scrollable frame.
|
|
|
|
|
|
|
|
* Use the 'interior' attribute to place widgets inside the scrollable frame
|
|
|
|
* Construct and pack/place/grid normally
|
|
|
|
* This frame only allows vertical scrolling
|
|
|
|
"""
|
|
|
|
def __init__(self, parent, *args, **kw):
|
|
|
|
Frame.__init__(self, parent, *args, **kw)
|
|
|
|
|
|
|
|
# create a canvas object and a vertical scrollbar for scrolling it
|
|
|
|
vscrollbar = Scrollbar(self, orient=VERTICAL)
|
|
|
|
vscrollbar.pack(fill=Y, side=RIGHT, expand=FALSE)
|
|
|
|
canvas = Canvas(self, bd=0, highlightthickness=0,
|
|
|
|
yscrollcommand=vscrollbar.set)
|
|
|
|
canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
|
|
|
|
vscrollbar.config(command=canvas.yview)
|
|
|
|
|
|
|
|
# reset the view
|
|
|
|
canvas.xview_moveto(0)
|
|
|
|
canvas.yview_moveto(0)
|
|
|
|
|
|
|
|
# create a frame inside the canvas which will be scrolled with it
|
|
|
|
self.interior = interior = Frame(canvas)
|
|
|
|
interior_id = canvas.create_window(0, 0, window=interior, anchor=NW)
|
|
|
|
|
|
|
|
# track changes to the canvas and frame width and sync them,
|
|
|
|
# also updating the scrollbar
|
|
|
|
def _configure_interior(event):
|
|
|
|
# update the scrollbars to match the size of the inner frame
|
|
|
|
size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
|
|
|
|
canvas.config(scrollregion="0 0 %s %s" % size)
|
|
|
|
if interior.winfo_reqwidth() != canvas.winfo_width():
|
|
|
|
# update the canvas's width to fit the inner frame
|
|
|
|
canvas.config(width=interior.winfo_reqwidth())
|
|
|
|
interior.bind('<Configure>', _configure_interior)
|
|
|
|
|
|
|
|
def _configure_canvas(event):
|
|
|
|
if interior.winfo_reqwidth() != canvas.winfo_width():
|
|
|
|
# update the inner frame's width to fill the canvas
|
|
|
|
canvas.itemconfigure(interior_id, width=canvas.winfo_width())
|
|
|
|
canvas.bind('<Configure>', _configure_canvas)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
def is_int(s):
|
|
|
|
"Return 's is blank or represents an int'"
|
|
|
|
if not s:
|
|
|
|
return True
|
|
|
|
try:
|
|
|
|
int(s)
|
|
|
|
return True
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# TODO:
|
|
|
|
# * Revert to default(s)? Per option or per extension?
|
|
|
|
# * List options in their original order (possible??)
|
|
|
|
class ConfigExtensionsDialog(Toplevel):
|
|
|
|
"""A dialog for configuring IDLE extensions.
|
|
|
|
|
|
|
|
This dialog is generic - it works for any and all IDLE extensions.
|
|
|
|
|
|
|
|
IDLE extensions save their configuration options using idleConf.
|
|
|
|
ConfigExtensionsDialog reads the current configuration using idleConf,
|
|
|
|
supplies a GUI interface to change the configuration values, and saves the
|
|
|
|
changes using idleConf.
|
|
|
|
|
|
|
|
Not all changes take effect immediately - some may require restarting IDLE.
|
|
|
|
This depends on each extension's implementation.
|
|
|
|
|
|
|
|
All values are treated as text, and it is up to the user to supply
|
|
|
|
reasonable values. The only exception to this are the 'enable*' options,
|
|
|
|
which are boolean, and can be toggled with an True/False button.
|
|
|
|
"""
|
|
|
|
def __init__(self, parent, title=None, _htest=False):
|
|
|
|
Toplevel.__init__(self, parent)
|
|
|
|
self.wm_withdraw()
|
|
|
|
|
|
|
|
self.configure(borderwidth=5)
|
|
|
|
self.geometry(
|
|
|
|
"+%d+%d" % (parent.winfo_rootx() + 20,
|
|
|
|
parent.winfo_rooty() + (30 if not _htest else 150)))
|
|
|
|
self.wm_title(title or 'IDLE Extensions Configuration')
|
|
|
|
|
|
|
|
self.defaultCfg = idleConf.defaultCfg['extensions']
|
|
|
|
self.userCfg = idleConf.userCfg['extensions']
|
|
|
|
self.is_int = self.register(is_int)
|
|
|
|
self.load_extensions()
|
|
|
|
self.create_widgets()
|
|
|
|
|
|
|
|
self.resizable(height=FALSE, width=FALSE) # don't allow resizing yet
|
|
|
|
self.transient(parent)
|
|
|
|
self.protocol("WM_DELETE_WINDOW", self.Cancel)
|
|
|
|
self.tabbed_page_set.focus_set()
|
|
|
|
# wait for window to be generated
|
|
|
|
self.update()
|
|
|
|
# set current width as the minimum width
|
|
|
|
self.wm_minsize(self.winfo_width(), 1)
|
|
|
|
# now allow resizing
|
|
|
|
self.resizable(height=TRUE, width=TRUE)
|
|
|
|
|
|
|
|
self.wm_deiconify()
|
|
|
|
if not _htest:
|
|
|
|
self.grab_set()
|
|
|
|
self.wait_window()
|
|
|
|
|
|
|
|
def load_extensions(self):
|
|
|
|
"Fill self.extensions with data from the default and user configs."
|
|
|
|
self.extensions = {}
|
|
|
|
for ext_name in idleConf.GetExtensions(active_only=False):
|
|
|
|
self.extensions[ext_name] = []
|
|
|
|
|
|
|
|
for ext_name in self.extensions:
|
|
|
|
opt_list = sorted(self.defaultCfg.GetOptionList(ext_name))
|
|
|
|
|
|
|
|
# bring 'enable' options to the beginning of the list
|
|
|
|
enables = [opt_name for opt_name in opt_list
|
|
|
|
if opt_name.startswith('enable')]
|
|
|
|
for opt_name in enables:
|
|
|
|
opt_list.remove(opt_name)
|
|
|
|
opt_list = enables + opt_list
|
|
|
|
|
|
|
|
for opt_name in opt_list:
|
|
|
|
def_str = self.defaultCfg.Get(
|
|
|
|
ext_name, opt_name, raw=True)
|
|
|
|
try:
|
|
|
|
def_obj = {'True':True, 'False':False}[def_str]
|
|
|
|
opt_type = 'bool'
|
|
|
|
except KeyError:
|
|
|
|
try:
|
|
|
|
def_obj = int(def_str)
|
|
|
|
opt_type = 'int'
|
|
|
|
except ValueError:
|
|
|
|
def_obj = def_str
|
|
|
|
opt_type = None
|
|
|
|
try:
|
|
|
|
value = self.userCfg.Get(
|
|
|
|
ext_name, opt_name, type=opt_type, raw=True,
|
|
|
|
default=def_obj)
|
|
|
|
except ValueError: # Need this until .Get fixed
|
|
|
|
value = def_obj # bad values overwritten by entry
|
|
|
|
var = StringVar(self)
|
|
|
|
var.set(str(value))
|
|
|
|
|
|
|
|
self.extensions[ext_name].append({'name': opt_name,
|
|
|
|
'type': opt_type,
|
|
|
|
'default': def_str,
|
|
|
|
'value': value,
|
|
|
|
'var': var,
|
|
|
|
})
|
|
|
|
|
|
|
|
def create_widgets(self):
|
|
|
|
"""Create the dialog's widgets."""
|
|
|
|
self.rowconfigure(0, weight=1)
|
|
|
|
self.rowconfigure(1, weight=0)
|
|
|
|
self.columnconfigure(0, weight=1)
|
|
|
|
|
|
|
|
# create the tabbed pages
|
|
|
|
self.tabbed_page_set = TabbedPageSet(
|
|
|
|
self, page_names=self.extensions.keys(),
|
|
|
|
n_rows=None, max_tabs_per_row=5,
|
|
|
|
page_class=TabbedPageSet.PageRemove)
|
|
|
|
self.tabbed_page_set.grid(row=0, column=0, sticky=NSEW)
|
|
|
|
for ext_name in self.extensions:
|
|
|
|
self.create_tab_page(ext_name)
|
|
|
|
|
|
|
|
self.create_action_buttons().grid(row=1)
|
|
|
|
|
|
|
|
create_action_buttons = ConfigDialog.create_action_buttons.im_func
|
|
|
|
|
|
|
|
def create_tab_page(self, ext_name):
|
|
|
|
"""Create the page for an extension."""
|
|
|
|
|
|
|
|
page = LabelFrame(self.tabbed_page_set.pages[ext_name].frame,
|
|
|
|
border=2, padx=2, relief=GROOVE,
|
|
|
|
text=' %s ' % ext_name)
|
|
|
|
page.pack(fill=BOTH, expand=True, padx=12, pady=2)
|
|
|
|
|
|
|
|
# create the scrollable frame which will contain the entries
|
|
|
|
scrolled_frame = VerticalScrolledFrame(page, pady=2, height=250)
|
|
|
|
scrolled_frame.pack(side=BOTTOM, fill=BOTH, expand=TRUE)
|
|
|
|
entry_area = scrolled_frame.interior
|
|
|
|
entry_area.columnconfigure(0, weight=0)
|
|
|
|
entry_area.columnconfigure(1, weight=1)
|
|
|
|
|
|
|
|
# create an entry for each configuration option
|
|
|
|
for row, opt in enumerate(self.extensions[ext_name]):
|
|
|
|
# create a row with a label and entry/checkbutton
|
|
|
|
label = Label(entry_area, text=opt['name'])
|
|
|
|
label.grid(row=row, column=0, sticky=NW)
|
|
|
|
var = opt['var']
|
|
|
|
if opt['type'] == 'bool':
|
|
|
|
Checkbutton(entry_area, textvariable=var, variable=var,
|
|
|
|
onvalue='True', offvalue='False',
|
|
|
|
indicatoron=FALSE, selectcolor='', width=8
|
|
|
|
).grid(row=row, column=1, sticky=W, padx=7)
|
|
|
|
elif opt['type'] == 'int':
|
|
|
|
Entry(entry_area, textvariable=var, validate='key',
|
|
|
|
validatecommand=(self.is_int, '%P')
|
|
|
|
).grid(row=row, column=1, sticky=NSEW, padx=7)
|
|
|
|
|
|
|
|
else:
|
|
|
|
Entry(entry_area, textvariable=var
|
|
|
|
).grid(row=row, column=1, sticky=NSEW, padx=7)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
Ok = ConfigDialog.Ok.im_func
|
|
|
|
|
|
|
|
def Apply(self):
|
|
|
|
self.save_all_changed_configs()
|
|
|
|
pass
|
|
|
|
|
|
|
|
Cancel = ConfigDialog.Cancel.im_func
|
|
|
|
|
|
|
|
def Help(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def set_user_value(self, section, opt):
|
|
|
|
name = opt['name']
|
|
|
|
default = opt['default']
|
|
|
|
value = opt['var'].get().strip() or default
|
|
|
|
opt['var'].set(value)
|
|
|
|
# if self.defaultCfg.has_section(section):
|
|
|
|
# Currently, always true; if not, indent to return
|
|
|
|
if (value == default):
|
|
|
|
return self.userCfg.RemoveOption(section, name)
|
|
|
|
# set the option
|
|
|
|
return self.userCfg.SetOption(section, name, value)
|
|
|
|
|
|
|
|
def save_all_changed_configs(self):
|
|
|
|
"""Save configuration changes to the user config file."""
|
|
|
|
has_changes = False
|
|
|
|
for ext_name in self.extensions:
|
|
|
|
options = self.extensions[ext_name]
|
|
|
|
for opt in options:
|
|
|
|
if self.set_user_value(ext_name, opt):
|
|
|
|
has_changes = True
|
|
|
|
if has_changes:
|
|
|
|
self.userCfg.Save()
|
|
|
|
|
|
|
|
|
2001-07-31 03:59:02 -03:00
|
|
|
if __name__ == '__main__':
|
2014-07-15 00:07:21 -03:00
|
|
|
import unittest
|
|
|
|
unittest.main('idlelib.idle_test.test_configdialog',
|
|
|
|
verbosity=2, exit=False)
|
2014-05-29 02:46:16 -03:00
|
|
|
from idlelib.idle_test.htest import run
|
2014-10-22 21:15:12 -03:00
|
|
|
run(ConfigDialog, ConfigExtensionsDialog)
|