[Python-checkins] r64000 - in sandbox/trunk/ttk-gsoc/src: idlelib/AutoCompleteWindow.py idlelib/CallTipWindow.py idlelib/Debugger.py idlelib/EditorWindow.py idlelib/GrepDialog.py idlelib/IOBinding.py idlelib/MultiStatusBar.py idlelib/PyShell.py idlelib/ReplaceDialog.py idlelib/ScrolledList.py idlelib/SearchDialog.py idlelib/SearchDialogBase.py idlelib/ToolTip.py idlelib/TreeWidget.py idlelib/aboutDialog.py idlelib/config-main.def idlelib/configDialog.py idlelib/configHelpSourceEdit.py idlelib/configSectionNameDialog.py idlelib/dynOptionMenuWidget.py idlelib/keybindingDialog.py idlelib/stylist.py idlelib/tabbedpages.py idlelib/tabbedpages_new.py idlelib/tabbedpages_old.py idlelib/textView.py idlelib_ttk.diff
guilherme.polo
python-checkins at python.org
Sat Jun 7 00:16:58 CEST 2008
Author: guilherme.polo
Date: Sat Jun 7 00:16:57 2008
New Revision: 64000
Log:
Merged the large idlelib diff into my idlelib branch and removed the old idlelib_ttk.diff
Added:
sandbox/trunk/ttk-gsoc/src/idlelib/stylist.py
sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages_new.py
sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages_old.py
Removed:
sandbox/trunk/ttk-gsoc/src/idlelib_ttk.diff
Modified:
sandbox/trunk/ttk-gsoc/src/idlelib/AutoCompleteWindow.py
sandbox/trunk/ttk-gsoc/src/idlelib/CallTipWindow.py
sandbox/trunk/ttk-gsoc/src/idlelib/Debugger.py
sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py
sandbox/trunk/ttk-gsoc/src/idlelib/GrepDialog.py
sandbox/trunk/ttk-gsoc/src/idlelib/IOBinding.py
sandbox/trunk/ttk-gsoc/src/idlelib/MultiStatusBar.py
sandbox/trunk/ttk-gsoc/src/idlelib/PyShell.py
sandbox/trunk/ttk-gsoc/src/idlelib/ReplaceDialog.py
sandbox/trunk/ttk-gsoc/src/idlelib/ScrolledList.py
sandbox/trunk/ttk-gsoc/src/idlelib/SearchDialog.py
sandbox/trunk/ttk-gsoc/src/idlelib/SearchDialogBase.py
sandbox/trunk/ttk-gsoc/src/idlelib/ToolTip.py
sandbox/trunk/ttk-gsoc/src/idlelib/TreeWidget.py
sandbox/trunk/ttk-gsoc/src/idlelib/aboutDialog.py
sandbox/trunk/ttk-gsoc/src/idlelib/config-main.def
sandbox/trunk/ttk-gsoc/src/idlelib/configDialog.py
sandbox/trunk/ttk-gsoc/src/idlelib/configHelpSourceEdit.py
sandbox/trunk/ttk-gsoc/src/idlelib/configSectionNameDialog.py
sandbox/trunk/ttk-gsoc/src/idlelib/dynOptionMenuWidget.py
sandbox/trunk/ttk-gsoc/src/idlelib/keybindingDialog.py
sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages.py
sandbox/trunk/ttk-gsoc/src/idlelib/textView.py
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/AutoCompleteWindow.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/AutoCompleteWindow.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/AutoCompleteWindow.py Sat Jun 7 00:16:57 2008
@@ -4,6 +4,10 @@
from Tkinter import *
from MultiCall import MC_SHIFT
import AutoComplete
+from idlelib.configHandler import idleConf
+
+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
+ from ttk import *
HIDE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-hide>>"
HIDE_SEQUENCES = ("<FocusOut>", "<ButtonPress>")
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/CallTipWindow.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/CallTipWindow.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/CallTipWindow.py Sat Jun 7 00:16:57 2008
@@ -5,6 +5,10 @@
"""
from Tkinter import *
+from idlelib.configHandler import idleConf
+
+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
+ from ttk import *
HIDE_VIRTUAL_EVENT_NAME = "<<calltipwindow-hide>>"
HIDE_SEQUENCES = ("<Key-Escape>", "<FocusOut>")
@@ -163,6 +167,8 @@
def calltip_hide(self, event):
self.calltip.hidetip()
+# XXX Bugged test
+
def main():
# Test code
c=container()
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/Debugger.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/Debugger.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/Debugger.py Sat Jun 7 00:16:57 2008
@@ -4,8 +4,11 @@
from Tkinter import *
from WindowList import ListedToplevel
from ScrolledList import ScrolledList
+from configHandler import idleConf
import macosxSupport
+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
+ from ttk import Scrollbar, Button, Radiobutton
class Idb(bdb.Bdb):
@@ -155,6 +158,7 @@
self.show_locals()
if self.vglobals.get():
self.show_globals()
+ #
def interaction(self, message, frame, info=None):
self.frame = frame
@@ -413,6 +417,7 @@
height = 20*len(dict) # XXX 20 == observed height of Entry widget
self.master = master
self.title = title
+
import repr
self.repr = repr.Repr()
self.repr.maxstring = 60
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py Sat Jun 7 00:16:57 2008
@@ -19,6 +19,10 @@
import aboutDialog, textView, configDialog
import macosxSupport
+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
+ from ttk import Scrollbar
+
+
# The default tab setting for a Text widget, in average-width characters.
TK_TABWIDTH_DEFAULT = 8
@@ -365,7 +369,7 @@
self.menudict = menudict = {}
for name, label in self.menu_specs:
underline, label = prepstr(label)
- menudict[name] = menu = Menu(mbar, name=name)
+ menudict[name] = menu = Menu(mbar, name=name, tearoff=0)
mbar.add_cascade(label=label, menu=menu, underline=underline)
if sys.platform == 'darwin' and '.framework' in sys.executable:
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/GrepDialog.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/GrepDialog.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/GrepDialog.py Sat Jun 7 00:16:57 2008
@@ -4,6 +4,10 @@
from Tkinter import *
import SearchEngine
from SearchDialogBase import SearchDialogBase
+from idlelib.configHandler import idleConf
+
+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
+ from ttk import *
def grep(text, io=None, flist=None):
root = text._root()
@@ -15,10 +19,10 @@
dialog.open(text, searchphrase, io)
class GrepDialog(SearchDialogBase):
-
title = "Find in Files Dialog"
icon = "Grep"
needwrapbutton = 0
+ bottom_btns = [("Search Files", 'default_command', 1)]
def __init__(self, root, engine, flist):
SearchDialogBase.__init__(self, root, engine)
@@ -40,20 +44,18 @@
def create_entries(self):
SearchDialogBase.create_entries(self)
- self.globent = self.make_entry("In files:", self.globvar)
+ self.globent = self.make_entry("In files", self.globvar)
def create_other_buttons(self):
f = self.make_frame()
- btn = Checkbutton(f, anchor="w",
- variable=self.recvar,
+ btn = Checkbutton(f, variable=self.recvar,
text="Recurse down subdirectories")
btn.pack(side="top", fill="both")
- btn.select()
+ btn.invoke()
def create_command_buttons(self):
SearchDialogBase.create_command_buttons(self)
- self.make_button("Search Files", self.default_command, 1)
def default_command(self, event=None):
prog = self.engine.getprog()
@@ -126,8 +128,3 @@
for subdir in subdirs:
list.extend(self.findfiles(subdir, base, rec))
return list
-
- def close(self, event=None):
- if self.top:
- self.top.grab_release()
- self.top.withdraw()
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/IOBinding.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/IOBinding.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/IOBinding.py Sat Jun 7 00:16:57 2008
@@ -18,6 +18,9 @@
from configHandler import idleConf
+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
+ from ttk import *
+
try:
from codecs import BOM_UTF8
except ImportError:
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/MultiStatusBar.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/MultiStatusBar.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/MultiStatusBar.py Sat Jun 7 00:16:57 2008
@@ -1,4 +1,8 @@
from Tkinter import *
+from idlelib.configHandler import idleConf
+
+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
+ from ttk import Frame, Label
class MultiStatusBar(Frame):
@@ -10,7 +14,7 @@
def set_label(self, name, text='', side=LEFT):
if not self.labels.has_key(name):
- label = Label(self, bd=1, relief=SUNKEN, anchor=W)
+ label = Label(self, relief=SUNKEN, anchor=W)
label.pack(side=side)
self.labels[name] = label
else:
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/PyShell.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/PyShell.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/PyShell.py Sat Jun 7 00:16:57 2008
@@ -22,14 +22,26 @@
print>>sys.__stderr__, "** IDLE can't import Tkinter. " \
"Your Python may not be configured for Tk. **"
sys.exit(1)
+try:
+ from ttk import *
+ TTK = 1
+except ImportError:
+ print >> sys.stderr, "** IDLE can't import ttk."
+ TTK = 0
+
import tkMessageBox
+from configHandler import idleConf
+
+# store ttk availability
+idleConf.SetOption('main', 'General', 'use-ttk', str(TTK))
+idleConf.SaveUserCfgFiles()
+
from EditorWindow import EditorWindow, fixwordbreaks
from FileList import FileList
from ColorDelegator import ColorDelegator
from UndoDelegator import UndoDelegator
from OutputWindow import OutputWindow
-from configHandler import idleConf
import idlever
import rpc
@@ -1381,6 +1393,19 @@
# start editor and/or shell windows:
root = Tk(className="Idle")
+ if TTK:
+ # create base styles used along idle files
+ style = Style()
+
+ x = style.map('.')
+ r = {'background': []}
+ for sspec in x['background']:
+ if 'active' in sspec[:-1]:
+ r['background'].append(('!disabled', sspec[-1]))
+ break
+ style.map('RootColor.TFrame', **r)
+ # end styles
+
fixwordbreaks(root)
root.withdraw()
flist = PyShellFileList(root)
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/ReplaceDialog.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/ReplaceDialog.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/ReplaceDialog.py Sat Jun 7 00:16:57 2008
@@ -11,9 +11,12 @@
dialog.open(text)
class ReplaceDialog(SearchDialogBase):
-
title = "Replace Dialog"
icon = "Replace"
+ bottom_btns = [("Find", 'find_it'),
+ ("Replace", 'replace_it'),
+ ("Replace+Find", 'default_command', 1),
+ ("Replace All", 'replace_all')]
def __init__(self, root, engine):
SearchDialogBase.__init__(self, root, engine)
@@ -36,14 +39,10 @@
def create_entries(self):
SearchDialogBase.create_entries(self)
- self.replent = self.make_entry("Replace with:", self.replvar)
+ self.replent = self.make_entry("Replace with", self.replvar)
def create_command_buttons(self):
SearchDialogBase.create_command_buttons(self)
- self.make_button("Find", self.find_it)
- self.make_button("Replace", self.replace_it)
- self.make_button("Replace+Find", self.default_command, 1)
- self.make_button("Replace All", self.replace_all)
def find_it(self, event=None):
self.do_find(0)
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/ScrolledList.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/ScrolledList.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/ScrolledList.py Sat Jun 7 00:16:57 2008
@@ -1,4 +1,8 @@
from Tkinter import *
+from idlelib.configHandler import idleConf
+
+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
+ from ttk import *
class ScrolledList:
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/SearchDialog.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/SearchDialog.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/SearchDialog.py Sat Jun 7 00:16:57 2008
@@ -21,10 +21,10 @@
return _setup(text).find_selection(text)
class SearchDialog(SearchDialogBase):
+ bottom_btns = [("Find", 'default_command', 1)]
def create_widgets(self):
- f = SearchDialogBase.create_widgets(self)
- self.make_button("Find", self.default_command, 1)
+ SearchDialogBase.create_widgets(self)
def default_command(self, event=None):
if not self.engine.getprog():
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/SearchDialogBase.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/SearchDialogBase.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/SearchDialogBase.py Sat Jun 7 00:16:57 2008
@@ -1,35 +1,40 @@
from Tkinter import *
+from idlelib.configHandler import idleConf
+
+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
+ from ttk import *
class SearchDialogBase:
title = "Search Dialog"
icon = "Search"
needwrapbutton = 1
+ bottom_btns = None
def __init__(self, root, engine):
self.root = root
self.engine = engine
- self.top = None
+ self.ttop = None
def open(self, text, searchphrase=None):
self.text = text
- if not self.top:
+ if not self.ttop:
self.create_widgets()
else:
- self.top.deiconify()
- self.top.tkraise()
+ self.ttop.deiconify()
+ self.ttop.tkraise()
if searchphrase:
- self.ent.delete(0,"end")
- self.ent.insert("end",searchphrase)
+ self.ent.delete(0, "end")
+ self.ent.insert("end", searchphrase)
self.ent.focus_set()
self.ent.selection_range(0, "end")
self.ent.icursor(0)
- self.top.grab_set()
+ self.ttop.grab_set()
def close(self, event=None):
- if self.top:
- self.top.grab_release()
- self.top.withdraw()
+ if self.ttop:
+ self.ttop.grab_release()
+ self.ttop.withdraw()
def create_widgets(self):
top = Toplevel(self.root)
@@ -38,103 +43,96 @@
top.protocol("WM_DELETE_WINDOW", self.close)
top.wm_title(self.title)
top.wm_iconname(self.icon)
- self.top = top
+ top.resizable(height=FALSE,width=FALSE)
+ self.ttop = top
+ self.top = Frame(top)
self.row = 0
- self.top.grid_columnconfigure(0, pad=2, weight=0)
- self.top.grid_columnconfigure(1, pad=2, minsize=100, weight=100)
+ self.top.grid(sticky='news')
self.create_entries()
self.create_option_buttons()
self.create_other_buttons()
- return self.create_command_buttons()
+ self.create_command_buttons()
+
def make_entry(self, label, var):
l = Label(self.top, text=label)
- l.grid(row=self.row, column=0, sticky="nw")
+ l.grid(row=self.row, column=0, sticky="ne", padx=6, pady=6)
e = Entry(self.top, textvariable=var, exportselection=0)
- e.grid(row=self.row, column=1, sticky="nwe")
+ e.grid(row=self.row, column=1, sticky="nwe", padx=6, pady=6)
self.row = self.row + 1
return e
def make_frame(self,labeltext=None):
if labeltext:
l = Label(self.top, text=labeltext)
- l.grid(row=self.row, column=0, sticky="nw")
+ l.grid(row=self.row, column=0, sticky="ne", padx=6, pady=6)
f = Frame(self.top)
- f.grid(row=self.row, column=1, columnspan=1, sticky="nwe")
+ f.grid(row=self.row, column=1, columnspan=1, sticky="nwe",
+ padx=6, pady=6 if labeltext else 0)
self.row = self.row + 1
return f
- def make_button(self, label, command, isdef=0):
- b = Button(self.buttonframe,
- text=label, command=command,
- default=isdef and "active" or "normal")
- cols,rows=self.buttonframe.grid_size()
- b.grid(pady=1,row=rows,column=0,sticky="ew")
- self.buttonframe.grid(rowspan=rows+1)
- return b
-
def create_entries(self):
- self.ent = self.make_entry("Find:", self.engine.patvar)
+ self.ent = self.make_entry("Find", self.engine.patvar)
def create_option_buttons(self):
f = self.make_frame("Options")
- btn = Checkbutton(f, anchor="w",
- variable=self.engine.revar,
- text="Regular expression")
+ btn = Checkbutton(f, variable=self.engine.revar,
+ text="Regular expression")
btn.pack(side="left", fill="both")
if self.engine.isre():
- btn.select()
+ btn.invoke()
- btn = Checkbutton(f, anchor="w",
- variable=self.engine.casevar,
- text="Match case")
+ btn = Checkbutton(f, variable=self.engine.casevar, text="Match case")
btn.pack(side="left", fill="both")
if self.engine.iscase():
- btn.select()
+ btn.invoke()
- btn = Checkbutton(f, anchor="w",
- variable=self.engine.wordvar,
- text="Whole word")
+ btn = Checkbutton(f, variable=self.engine.wordvar, text="Whole word")
btn.pack(side="left", fill="both")
if self.engine.isword():
- btn.select()
+ btn.invoke()
if self.needwrapbutton:
- btn = Checkbutton(f, anchor="w",
- variable=self.engine.wrapvar,
- text="Wrap around")
+ btn = Checkbutton(f, variable=self.engine.wrapvar,
+ text="Wrap around")
btn.pack(side="left", fill="both")
if self.engine.iswrap():
- btn.select()
+ btn.invoke()
def create_other_buttons(self):
f = self.make_frame("Direction")
- #lbl = Label(f, text="Direction: ")
- #lbl.pack(side="left")
-
- btn = Radiobutton(f, anchor="w",
- variable=self.engine.backvar, value=1,
- text="Up")
- btn.pack(side="left", fill="both")
+ btn = Radiobutton(f, variable=self.engine.backvar, value=1, text="Up")
+ btn.pack(side="left")
if self.engine.isback():
- btn.select()
+ btn.invoke()
- btn = Radiobutton(f, anchor="w",
- variable=self.engine.backvar, value=0,
- text="Down")
- btn.pack(side="left", fill="both")
+ btn = Radiobutton(f, variable=self.engine.backvar, value=0, text="Down")
+ btn.pack(side="left")
if not self.engine.isback():
- btn.select()
+ btn.invoke()
def create_command_buttons(self):
- #
- # place button frame on the right
- f = self.buttonframe = Frame(self.top)
- f.grid(row=0,column=2,padx=2,pady=2,ipadx=2,ipady=2)
+ self.bottom_btns = self.bottom_btns or []
+ f = Frame(self.top)
+ f.grid(row=self.row, column=0, columnspan=len(self.bottom_btns) + 1,
+ pady=6)
- b = self.make_button("close", self.close)
- b.lower()
+ column = 0
+ b = Button(f, text="Close", command=self.close)
+ b.grid(row=self.row, column=column, padx=6, pady=6)
+ column += 1
+
+ btns = {}
+ for tbtn in self.bottom_btns:
+ opts = {'text': tbtn[0], 'command': getattr(self, tbtn[1])}
+ if len(tbtn) == 3:
+ opts['default'] = tbtn[2] and 'active' or 'normal'
+
+ btns[opts['text']] = Button(f, **opts).grid(row=self.row, padx=6,
+ pady=6, column=column)
+ column += 1
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/ToolTip.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/ToolTip.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/ToolTip.py Sat Jun 7 00:16:57 2008
@@ -3,7 +3,8 @@
# may be useful for some purposes in (or almost in ;) the current project scope
# Ideas gleaned from PySol
-from Tkinter import *
+from Tkinter import END, Listbox, Tk, Toplevel
+from ttk import Button, Label
class ToolTipBase:
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/TreeWidget.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/TreeWidget.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/TreeWidget.py Sat Jun 7 00:16:57 2008
@@ -21,6 +21,12 @@
import ZoomHeight
from configHandler import idleConf
+from idlelib.configHandler import idleConf
+
+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
+if TTK:
+ from ttk import *
+
ICONDIR = "Icons"
# Look for Icons subdirectory in the same directory as this module
@@ -248,7 +254,9 @@
label = self.label
except AttributeError:
# padding carefully selected (on Windows) to match Entry widget:
- self.label = Label(self.canvas, text=text, bd=0, padx=2, pady=2)
+ self.label = Label(self.canvas, text=text)
+ if not TTK:
+ self.label.configure(bd=0, padx=2, pady=2)
theme = idleConf.GetOption('main','Theme','name')
if self.selected:
self.label.configure(idleConf.GetHighlight(theme, 'hilite'))
@@ -451,6 +459,8 @@
# Testing functions
+# XXX Can't run these tests
+
def test():
import PyShell
root = Toplevel(PyShell.root)
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/aboutDialog.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/aboutDialog.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/aboutDialog.py Sat Jun 7 00:16:57 2008
@@ -1,13 +1,17 @@
-"""About Dialog for IDLE
-
-"""
-
+"""About Dialog for IDLE"""
from Tkinter import *
import os
import os.path
import textView
import idlever
+from idlelib.stylist import PoorManStyle
+from idlelib.configHandler import idleConf
+
+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
+if TTK:
+ from ttk import *
+
class AboutDialog(Toplevel):
"""Modal about dialog for idle
@@ -15,10 +19,13 @@
def __init__(self,parent,title):
Toplevel.__init__(self, parent)
self.configure(borderwidth=5)
+
self.geometry("+%d+%d" % (parent.winfo_rootx()+30,
parent.winfo_rooty()+30))
self.bg = "#707070"
self.fg = "#ffffff"
+
+ self.SetupStyles()
self.CreateWidgets()
self.resizable(height=FALSE, width=FALSE)
self.title(title)
@@ -31,40 +38,44 @@
self.bind('<Escape>',self.Ok) #dismiss dialog
self.wait_window()
+ def SetupStyles(self):
+ if TTK:
+ style = Style(self.master)
+ style.configure('Color.TLabel', foreground=self.fg,
+ background=self.bg)
+ style.configure('Color.TFrame', background=self.bg)
+ self.ttkstyle = style
+ self.style = lambda w, style: w.configure(style=style)
+ else:
+ self.style = PoorManStyle(self,
+ styles={'Color.TLabel': {'fg': self.fg, 'bg': self.bg},
+ 'Color.TFrame': {'bg': self.bg}}).style_it
+
def CreateWidgets(self):
frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
frameButtons = Frame(self)
- frameButtons.pack(side=BOTTOM, fill=X)
+ frameButtons.pack(side=BOTTOM, pady=3)
frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
- self.buttonOk = Button(frameButtons, text='Close',
- command=self.Ok)
- self.buttonOk.pack(padx=5, pady=5)
- #self.picture = Image('photo', data=self.pictureData)
- frameBg = Frame(frameMain, bg=self.bg)
+ self.buttonOk = Button(frameButtons, text='Close', command=self.Ok)
+ self.buttonOk.pack()
+ frameBg = Frame(frameMain)
frameBg.pack(expand=TRUE, fill=BOTH)
- labelTitle = Label(frameBg, text='IDLE', fg=self.fg, bg=self.bg,
- font=('courier', 24, 'bold'))
+ labelTitle = Label(frameBg, text='IDLE', font=('courier', 24, 'bold'))
labelTitle.grid(row=0, column=0, sticky=W, padx=10, pady=10)
- #labelPicture = Label(frameBg, text='[picture]')
- #image=self.picture, bg=self.bg)
- #labelPicture.grid(row=1, column=1, sticky=W, rowspan=2,
- # padx=0, pady=3)
byline = "Python's Integrated DeveLopment Environment" + 5*'\n'
- labelDesc = Label(frameBg, text=byline, justify=LEFT,
- fg=self.fg, bg=self.bg)
+ labelDesc = Label(frameBg, text=byline, justify=LEFT)
labelDesc.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
labelEmail = Label(frameBg, text='email: idle-dev at python.org',
- justify=LEFT, fg=self.fg, bg=self.bg)
+ justify=LEFT)
labelEmail.grid(row=6, column=0, columnspan=2,
sticky=W, padx=10, pady=0)
labelWWW = Label(frameBg, text='www: http://www.python.org/idle/',
- justify=LEFT, fg=self.fg, bg=self.bg)
+ justify=LEFT)
labelWWW.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
- Frame(frameBg, borderwidth=1, relief=SUNKEN,
- height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
- columnspan=3, padx=5, pady=5)
+ fbg = Frame(frameBg, borderwidth=1, relief=SUNKEN, height=2)
+ fbg.grid(row=8, column=0, sticky=EW, columnspan=3, padx=5, pady=5)
labelPythonVer = Label(frameBg, text='Python version: ' + \
- sys.version.split()[0], fg=self.fg, bg=self.bg)
+ sys.version.split()[0])
labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0)
# handle weird tk version num in windoze python >= 1.6 (?!?)
tkVer = repr(TkVersion).split('.')
@@ -72,44 +83,50 @@
if tkVer[len(tkVer)-1] == '':
tkVer[len(tkVer)-1] = '0'
tkVer = '.'.join(tkVer)
- labelTkVer = Label(frameBg, text='Tk version: '+
- tkVer, fg=self.fg, bg=self.bg)
+ labelTkVer = Label(frameBg, text='Tk version: '+ tkVer)
labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
- py_button_f = Frame(frameBg, bg=self.bg)
+ py_button_f = Frame(frameBg)
py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW)
buttonLicense = Button(py_button_f, text='License', width=8,
- highlightbackground=self.bg,
command=self.ShowLicense)
buttonLicense.pack(side=LEFT, padx=10, pady=10)
buttonCopyright = Button(py_button_f, text='Copyright', width=8,
- highlightbackground=self.bg,
command=self.ShowCopyright)
buttonCopyright.pack(side=LEFT, padx=10, pady=10)
buttonCredits = Button(py_button_f, text='Credits', width=8,
- highlightbackground=self.bg,
command=self.ShowPythonCredits)
buttonCredits.pack(side=LEFT, padx=10, pady=10)
- Frame(frameBg, borderwidth=1, relief=SUNKEN,
- height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
- columnspan=3, padx=5, pady=5)
- idle_v = Label(frameBg, text='IDLE version: ' + idlever.IDLE_VERSION,
- fg=self.fg, bg=self.bg)
+ fbg2 = Frame(frameBg, borderwidth=1, relief=SUNKEN, height=2)
+ fbg2.grid(row=11, column=0, sticky=EW, columnspan=3, padx=5, pady=5)
+ idle_v = Label(frameBg, text='IDLE version: ' + idlever.IDLE_VERSION)
idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0)
- idle_button_f = Frame(frameBg, bg=self.bg)
+ idle_button_f = Frame(frameBg)
idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW)
idle_about_b = Button(idle_button_f, text='README', width=8,
- highlightbackground=self.bg,
command=self.ShowIDLEAbout)
idle_about_b.pack(side=LEFT, padx=10, pady=10)
idle_news_b = Button(idle_button_f, text='NEWS', width=8,
- highlightbackground=self.bg,
command=self.ShowIDLENEWS)
idle_news_b.pack(side=LEFT, padx=10, pady=10)
idle_credits_b = Button(idle_button_f, text='Credits', width=8,
- highlightbackground=self.bg,
command=self.ShowIDLECredits)
idle_credits_b.pack(side=LEFT, padx=10, pady=10)
+ s = self.style
+ s(frameButtons, 'RootColor.TFrame')
+ s(frameBg, 'Color.TFrame')
+ s(labelTitle, 'Color.TLabel')
+ s(labelDesc, 'Color.TLabel')
+ s(labelEmail, 'Color.TLabel')
+ s(labelWWW, 'Color.TLabel')
+ s(fbg, 'Color.TFrame')
+ s(labelPythonVer, 'Color.TLabel')
+ s(labelTkVer, 'Color.TLabel')
+ s(py_button_f, 'Color.TFrame')
+ s(fbg2, 'Color.TFrame')
+ s(idle_v, 'Color.TLabel')
+ s(idle_button_f, 'Color.TFrame')
+
def ShowLicense(self):
self.display_printer_text('About - License', license)
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/config-main.def
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/config-main.def (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/config-main.def Sat Jun 7 00:16:57 2008
@@ -49,6 +49,7 @@
print-command-posix=lpr %s
print-command-win=start /min notepad /p %s
delete-exitfunc= 1
+use-ttk=0
[EditorWindow]
width= 80
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/configDialog.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/configDialog.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/configDialog.py Sat Jun 7 00:16:57 2008
@@ -7,7 +7,6 @@
Note that tab width in IDLE is currently fixed at eight due to Tk issues.
Refer to comments in EditorWindow autoindent code for details.
-
"""
from Tkinter import *
import tkMessageBox, tkColorChooser, tkFont
@@ -19,6 +18,11 @@
from keybindingDialog import GetKeysDialog
from configSectionNameDialog import GetCfgSectionNameDialog
from configHelpSourceEdit import GetHelpSourceDialog
+from stylist import PoorManStyle
+
+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
+if TTK:
+ from ttk import *
class ConfigDialog(Toplevel):
@@ -47,6 +51,7 @@
'Shell Stderr Text':('stderr','12'),
}
self.ResetChangedItems() #load initial values in changed items dict
+ self.SetupStyles()
self.CreateWidgets()
self.resizable(height=FALSE,width=FALSE)
self.transient(parent)
@@ -64,32 +69,52 @@
self.wm_deiconify()
self.wait_window()
+ def SetupStyles(self):
+ if TTK:
+ style = Style(self.master)
+ style.configure('S.TButton', padding=[6, 3])
+ style.configure('S2.TFrame', padding=2)
+ style.configure('Color.TFrame', background='blue')
+ self.ttkstyle = style
+ self.style = lambda w, style: w.configure(style=style)
+ else:
+ self.ttkstyle = PoorManStyle(self, styles={
+ 'S.TButton': {'pady': 6, 'padx': 3},
+ 'S2.TFrame': {'padx': 2, 'pady': 2}
+ }, cfgstyles={'Color.TFrame': 'frameColourSet'})
+ self.style = self.ttkstyle.style_it
+
def CreateWidgets(self):
self.tabPages = TabbedPageSet(self,
page_names=['Fonts/Tabs','Highlighting','Keys','General'])
- frameActionButtons = Frame(self,pady=2)
+ frameActionButtons = Frame(self)
#action buttons
self.buttonHelp = Button(frameActionButtons,text='Help',
- command=self.Help,takefocus=FALSE,
- padx=6,pady=3)
- self.buttonOk = Button(frameActionButtons,text='Ok',
- command=self.Ok,takefocus=FALSE,
- padx=6,pady=3)
- self.buttonApply = Button(frameActionButtons,text='Apply',
- command=self.Apply,takefocus=FALSE,
- padx=6,pady=3)
- self.buttonCancel = Button(frameActionButtons,text='Cancel',
- command=self.Cancel,takefocus=FALSE,
- padx=6,pady=3)
+ command=self.Help, takefocus=FALSE)
+ self.buttonOk = Button(frameActionButtons, text='Ok',
+ command=self.Ok, takefocus=FALSE)
+ self.buttonApply = Button(frameActionButtons, text='Apply',
+ command=self.Apply, takefocus=FALSE)
+ self.buttonCancel = Button(frameActionButtons, text='Cancel',
+ command=self.Cancel, takefocus=FALSE)
+
+ # Apply styles
+ s = self.style
+ s(frameActionButtons, 'RootColor.TFrame')
+ s(self.buttonHelp, 'S.TButton')
+ s(self.buttonOk, 'S.TButton')
+ s(self.buttonApply, 'S.TButton')
+ s(self.buttonCancel, 'S.TButton')
+
self.CreatePageFontTab()
self.CreatePageHighlight()
self.CreatePageKeys()
self.CreatePageGeneral()
- self.buttonHelp.pack(side=RIGHT,padx=5)
- self.buttonOk.pack(side=LEFT,padx=5)
- self.buttonApply.pack(side=LEFT,padx=5)
- self.buttonCancel.pack(side=LEFT,padx=5)
- frameActionButtons.pack(side=BOTTOM)
+ self.buttonHelp.pack(side=LEFT, pady=6)
+ self.buttonApply.pack(side=RIGHT, pady=6)
+ self.buttonOk.pack(side=RIGHT, padx=6, pady=6)
+ self.buttonCancel.pack(side=RIGHT, pady=6)
+ frameActionButtons.pack(side=BOTTOM, fill=X, expand=TRUE)
Frame(self, height=2, borderwidth=0).pack(side=BOTTOM)
self.tabPages.pack(side=TOP,expand=TRUE,fill=BOTH)
@@ -127,14 +152,11 @@
frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1)
self.labelFontSample=Label(frameFontSample,
text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
- justify=LEFT,font=self.editFont)
+ justify=LEFT, font=self.editFont)
#frameIndent
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)
#widget packing
#body
frameFont.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
@@ -149,11 +171,20 @@
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)
+ self.labelFontSample.pack(expand=1, fill=Y)
#frameIndent
frameIndentSize.pack(side=TOP,fill=X)
- labelSpaceNumTitle.pack(side=TOP,anchor=W,padx=5)
- self.scaleSpaceNum.pack(side=TOP,padx=5,fill=X)
+ labelSpaceNumTitle.pack(side=TOP, anchor=W, padx=5, pady=6)
+
+ if TTK:
+ self.scaleSpaceNum = LabeledScale(frameIndentSize, self.spaceNum,
+ from_=2, to=16, padding=2)
+ else:
+ self.scaleSpaceNum=Scale(frameIndentSize, variable=self.spaceNum,
+ orient='horizontal', from_=2, to=16, tickinterval=2)
+
+ self.scaleSpaceNum.pack(side=TOP, padx=5, fill=X)
+
return frame
def CreatePageHighlight(self):
@@ -174,7 +205,7 @@
text=' Highlighting Theme ')
#frameCustom
self.textHighlightSample=Text(frameCustom,relief=SOLID,borderwidth=1,
- font=('courier',12,''),cursor='hand2',width=21,height=10,
+ font=('courier',12,''), cursor='hand2', width=21, height=11,
takefocus=FALSE,highlightthickness=0,wrap=NONE)
text=self.textHighlightSample
text.bind('<Double-Button-1>',lambda e: 'break')
@@ -197,12 +228,15 @@
lambda event,elem=element: event.widget.winfo_toplevel()
.highlightTarget.set(elem))
text.config(state=DISABLED)
- self.frameColourSet=Frame(frameCustom,relief=SOLID,borderwidth=1)
+
+ self.frameColourSet=Frame(frameCustom, relief=SOLID, borderwidth=1)
+ self.style(self.frameColourSet, 'Color.TFrame')
+
frameFgBg=Frame(frameCustom)
buttonSetColour=Button(self.frameColourSet,text='Choose Colour for :',
- command=self.GetColour,highlightthickness=0)
+ command=self.GetColour) # XXX
self.optMenuHighlightTarget=DynOptionMenu(self.frameColourSet,
- self.highlightTarget,None,highlightthickness=0)#,command=self.SetHighlightTargetBinding
+ self.highlightTarget, None) # XXX
self.radioFg=Radiobutton(frameFgBg,variable=self.fgHilite,
value=1,text='Foreground',command=self.SetColourSampleBinding)
self.radioBg=Radiobutton(frameFgBg,variable=self.fgHilite,
@@ -275,8 +309,11 @@
self.buttonNewKeys=Button(frameCustom,text='Get New Keys for Selection',
command=self.GetNewKeys,state=DISABLED)
#frameKeySets
- frames = [Frame(frameKeySets, padx=2, pady=2, borderwidth=0)
- for i in range(2)]
+ frames = []
+ for i in range(2):
+ f = Frame(frameKeySets, borderwidth=0)
+ self.style(f, 'S2.TFrame')
+ frames.append(f)
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,
@@ -748,14 +785,14 @@
def GetColour(self):
target=self.highlightTarget.get()
- prevColour=self.frameColourSet.cget('bg')
+ prevColour = self.ttkstyle.configure('Color.TFrame', 'background')
rgbTuplet, colourString = tkColorChooser.askcolor(parent=self,
title='Pick new colour for : '+target,initialcolor=prevColour)
if colourString and (colourString!=prevColour):
#user didn't cancel, and they chose a new colour
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.')
+ 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
return
@@ -767,7 +804,7 @@
def OnNewColourSet(self):
newColour=self.colour.get()
- self.frameColourSet.config(bg=newColour)#set sample
+ self.ttkstyle.configure('Color.TFrame', background=newColour)
if self.fgHilite.get(): plane='foreground'
else: plane='background'
sampleElement=self.themeElements[self.highlightTarget.get()][0]
@@ -777,6 +814,7 @@
self.AddChangedItem('highlight',theme,themeElement,newColour)
def GetNewThemeName(self,message):
+ # XXX idle bug here
usedNames=(idleConf.GetSectionList('user','highlight')+
idleConf.GetSectionList('default','highlight'))
newTheme=GetCfgSectionNameDialog(self,'New Custom Theme',
@@ -846,7 +884,7 @@
if self.fgHilite.get(): plane='foreground'
else: plane='background'
colour=self.textHighlightSample.tag_cget(tag,plane)
- self.frameColourSet.config(bg=colour)
+ self.ttkstyle.configure('Color.TFrame', background=colour)
def PaintThemeSample(self):
if self.themeIsBuiltin.get(): #a default theme
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/configHelpSourceEdit.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/configHelpSourceEdit.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/configHelpSourceEdit.py Sat Jun 7 00:16:57 2008
@@ -1,12 +1,16 @@
"Dialog to specify or edit the parameters for a user configured help source."
-
import os
import sys
-
from Tkinter import *
import tkMessageBox
import tkFileDialog
+from idlelib.configHandler import idleConf
+
+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
+if TTK:
+ from ttk import *
+
class GetHelpSourceDialog(Toplevel):
def __init__(self, parent, title, menuItem='', filePath=''):
"""Get menu entry and url/ local file location for Additional Help
@@ -25,6 +29,7 @@
self.protocol("WM_DELETE_WINDOW", self.Cancel)
self.parent = parent
self.result = None
+
self.CreateWidgets()
self.menu.set(menuItem)
self.path.set(filePath)
@@ -46,32 +51,35 @@
self.path = StringVar(self)
self.fontSize = StringVar(self)
self.frameMain = Frame(self, borderwidth=2, relief=GROOVE)
- self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
labelMenu = Label(self.frameMain, anchor=W, justify=LEFT,
- text='Menu Item:')
- self.entryMenu = Entry(self.frameMain, textvariable=self.menu,
- width=30)
- self.entryMenu.focus_set()
+ text='Menu Item:')
+ self.entryMenu = Entry(self.frameMain, textvariable=self.menu)
labelPath = Label(self.frameMain, anchor=W, justify=LEFT,
- text='Help File Path: Enter URL or browse for file')
+ text='Help File Path: Enter URL or browse for file')
self.entryPath = Entry(self.frameMain, textvariable=self.path,
- width=40)
+ width=30)
+ browseButton = Button(self.frameMain, text='Browse', width=8,
+ command=self.browseFile)
+ frameButtons = Frame(self)
+ self.buttonOk = Button(frameButtons, text='OK', width=8,
+ default=ACTIVE, command=self.Ok)
+ self.buttonCancel = Button(frameButtons, text='Cancel', width=8,
+ command=self.Cancel)
+
self.entryMenu.focus_set()
+
+ self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
labelMenu.pack(anchor=W, padx=5, pady=3)
- self.entryMenu.pack(anchor=W, padx=5, pady=3)
+ self.entryMenu.pack(anchor=W, padx=5, pady=3, fill=X)
labelPath.pack(anchor=W, padx=5, pady=3)
- self.entryPath.pack(anchor=W, padx=5, pady=3)
- browseButton = Button(self.frameMain, text='Browse', width=8,
- command=self.browseFile)
- browseButton.pack(pady=3)
- frameButtons = Frame(self)
+ self.entryPath.pack(anchor=W, padx=5, pady=3, side=LEFT, fill=X)
+ browseButton.pack(pady=3, padx=5, side=RIGHT)
frameButtons.pack(side=BOTTOM, fill=X)
- self.buttonOk = Button(frameButtons, text='OK',
- width=8, default=ACTIVE, command=self.Ok)
- self.buttonOk.grid(row=0, column=0, padx=5,pady=5)
- self.buttonCancel = Button(frameButtons, text='Cancel',
- width=8, command=self.Cancel)
- self.buttonCancel.grid(row=0, column=1, padx=5, pady=5)
+ self.buttonOk.pack(pady=5, side=RIGHT)
+ self.buttonCancel.pack(padx=5, pady=5, side=RIGHT)
+
+ if TTK:
+ frameButtons['style'] = 'RootColor.TFrame'
def browseFile(self):
filetypes = [
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/configSectionNameDialog.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/configSectionNameDialog.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/configSectionNameDialog.py Sat Jun 7 00:16:57 2008
@@ -5,93 +5,106 @@
from Tkinter import *
import tkMessageBox
+from idlelib.configHandler import idleConf
+
+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
+if TTK:
+ from ttk import *
+
class GetCfgSectionNameDialog(Toplevel):
- def __init__(self,parent,title,message,usedNames):
+ def __init__(self, parent, title, message, usedNames):
"""
message - string, informational message to display
usedNames - list, list of names already in use for validity check
"""
Toplevel.__init__(self, parent)
self.configure(borderwidth=5)
- self.resizable(height=FALSE,width=FALSE)
+ self.resizable(height=FALSE, width=FALSE)
self.title(title)
self.transient(parent)
self.grab_set()
self.protocol("WM_DELETE_WINDOW", self.Cancel)
self.parent = parent
- self.message=message
- self.usedNames=usedNames
- self.result=''
+ self.message = message
+ self.usedNames = usedNames
+ self.result = ''
self.CreateWidgets()
self.withdraw() #hide while setting geometry
self.update_idletasks()
- #needs to be done here so that the winfo_reqwidth is valid
- self.messageInfo.config(width=self.frameMain.winfo_reqwidth())
self.geometry("+%d+%d" %
- ((parent.winfo_rootx()+((parent.winfo_width()/2)
- -(self.winfo_reqwidth()/2)),
- parent.winfo_rooty()+((parent.winfo_height()/2)
- -(self.winfo_reqheight()/2)) )) ) #centre dialog over parent
+ ((parent.winfo_rootx() + ((parent.winfo_width() / 2)
+ - (self.winfo_reqwidth() / 2)),
+ parent.winfo_rooty() + ((parent.winfo_height() / 2)
+ - (self.winfo_reqheight() / 2)) )) ) #centre dialog over parent
self.deiconify() #geometry set, unhide
self.wait_window()
def CreateWidgets(self):
- self.name=StringVar(self)
- self.fontSize=StringVar(self)
- self.frameMain = Frame(self,borderwidth=2,relief=SUNKEN)
- self.frameMain.pack(side=TOP,expand=TRUE,fill=BOTH)
- self.messageInfo=Message(self.frameMain,anchor=W,justify=LEFT,padx=5,pady=5,
- text=self.message)#,aspect=200)
- entryName=Entry(self.frameMain,textvariable=self.name,width=30)
+ self.name = StringVar(self)
+ self.fontSize = StringVar(self)
+ self.frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
+ self.messageInfo = Label(self.frameMain, text=self.message)
+ entryName = Entry(self.frameMain, textvariable=self.name, width=30)
+ frameButtons = Frame(self)
+ self.buttonOk = Button(frameButtons, text='Ok', command=self.Ok)
+ self.buttonCancel = Button(frameButtons, text='Cancel',
+ command=self.Cancel)
+
entryName.focus_set()
- self.messageInfo.pack(padx=5,pady=5)#,expand=TRUE,fill=BOTH)
- entryName.pack(padx=5,pady=5)
- frameButtons=Frame(self)
- frameButtons.pack(side=BOTTOM,fill=X)
- self.buttonOk = Button(frameButtons,text='Ok',
- width=8,command=self.Ok)
- self.buttonOk.grid(row=0,column=0,padx=5,pady=5)
- self.buttonCancel = Button(frameButtons,text='Cancel',
- width=8,command=self.Cancel)
- self.buttonCancel.grid(row=0,column=1,padx=5,pady=5)
+
+ self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
+ self.messageInfo.pack(padx=5, pady=5)
+ entryName.pack(padx=5, pady=5)
+ frameButtons.pack(side=BOTTOM, fill=X)
+ self.buttonOk.pack(padx=1, pady=5, side=RIGHT)
+ self.buttonCancel.pack(pady=5, padx=5, side=RIGHT)
+
+ if TTK:
+ self.messageInfo['padding'] = 5
+ frameButtons['style'] = 'RootColor.TFrame'
+ else:
+ self.messageInfo.configure(padx=5, pady=5)
def NameOk(self):
#simple validity check for a sensible
#ConfigParser file section name
- nameOk=1
- name=self.name.get()
+ nameOk = 1
+ name = self.name.get()
name.strip()
+
if not name: #no name specified
tkMessageBox.showerror(title='Name Error',
- message='No name specified.', parent=self)
- nameOk=0
- elif len(name)>30: #name too long
+ message='No name specified.', parent=self)
+ nameOk = 0
+ elif len(name) > 30: #name too long
tkMessageBox.showerror(title='Name Error',
- message='Name too long. It should be no more than '+
- '30 characters.', parent=self)
+ message=('Name too long. It should be no more than '
+ '30 characters.'), parent=self)
nameOk=0
elif name in self.usedNames:
tkMessageBox.showerror(title='Name Error',
message='This name is already in use.', parent=self)
nameOk=0
+
return nameOk
def Ok(self, event=None):
if self.NameOk():
- self.result=self.name.get().strip()
+ self.result = self.name.get().strip()
self.destroy()
def Cancel(self, event=None):
- self.result=''
+ self.result = ''
self.destroy()
if __name__ == '__main__':
#test the dialog
- root=Tk()
def run():
- keySeq=''
- dlg=GetCfgSectionNameDialog(root,'Get Name',
- 'The information here should need to be word wrapped. Test.')
+ keySeq = ''
+ dlg = GetCfgSectionNameDialog(root, 'Get Name',
+ 'The information here should need to be word wrapped. Test.')
print dlg.result
- Button(root,text='Dialog',command=run).pack()
+
+ root=Tk()
+ Button(root, text='Dialog', command=run).pack()
root.mainloop()
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/dynOptionMenuWidget.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/dynOptionMenuWidget.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/dynOptionMenuWidget.py Sat Jun 7 00:16:57 2008
@@ -2,34 +2,41 @@
OptionMenu widget modified to allow dynamic menu reconfiguration
and setting of highlightthickness
"""
-from Tkinter import OptionMenu
+from Tkinter import OptionMenu, Menu
from Tkinter import _setit
import copy
+from configHandler import idleConf
+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
+if TTK:
+ from ttk import *
+
class DynOptionMenu(OptionMenu):
- """
- unlike OptionMenu, our kwargs can include highlightthickness
- """
+ """Unlike OptionMenu, our kwargs can include highlightthickness"""
def __init__(self, master, variable, value, *values, **kwargs):
#get a copy of kwargs before OptionMenu.__init__ munges them
kwargsCopy=copy.copy(kwargs)
if 'highlightthickness' in kwargs.keys():
del(kwargs['highlightthickness'])
+ self.command=kwargs.get('command')
+ self.variable=variable
+
OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
self.config(highlightthickness=kwargsCopy.get('highlightthickness'))
- #self.menu=self['menu']
- self.variable=variable
- self.command=kwargs.get('command')
- def SetMenu(self,valueList,value=None):
+ def SetMenu(self, valueList, value=None):
"""
clear and reload the menu with a new set of options.
valueList - list of new options
value - initial value to set the optionmenu's menubutton to
"""
- self['menu'].delete(0,'end')
- for item in valueList:
- self['menu'].add_command(label=item,
+ if TTK:
+ self.set_menu(value, *valueList)
+ else:
+ menu = self['menu']
+ menu.delete(0,'end')
+ for item in valueList:
+ menu.add_command(label=item,
command=_setit(self.variable,item,self.command))
- if value:
- self.variable.set(value)
+ if value:
+ self.variable.set(value)
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/keybindingDialog.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/keybindingDialog.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/keybindingDialog.py Sat Jun 7 00:16:57 2008
@@ -5,6 +5,12 @@
import tkMessageBox
import string
+from idlelib.configHandler import idleConf
+
+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
+if TTK:
+ from ttk import *
+
class GetKeysDialog(Toplevel):
def __init__(self,parent,title,action,currentKeySequences):
"""
@@ -124,6 +130,9 @@
"separated by a space, eg., <Alt-v> <Meta-v>." )
labelHelpAdvanced.grid(row=0,column=0,sticky=NSEW)
+ if TTK:
+ frameButtons['style'] = 'RootColor.TFrame'
+
def SetModifiersForPlatform(self):
"""Determine list of names of key modifiers for this platform.
Added: sandbox/trunk/ttk-gsoc/src/idlelib/stylist.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/stylist.py Sat Jun 7 00:16:57 2008
@@ -0,0 +1,29 @@
+from configHandler import idleConf
+
+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
+
+class PoorManStyle(object):
+ def __init__(self, parent, styles=None, cfgstyles=None):
+ self.parent = parent
+ self.cfgstyles = cfgstyles
+ self.styles = styles
+
+ def configure(self, style, lookup=None, background=None):
+ if style not in self.cfgstyles: # passed wrong style probably
+ return
+
+ widget = getattr(self.parent, self.cfgstyles[style])
+ if lookup:
+ return widget.cget('bg')
+
+ widget.configure(bg=background)
+
+ def style_it(self, w, style):
+ if TTK:
+ w['style'] = style
+ return
+
+ if not style in self.styles: # may not need to be styled
+ return
+
+ w.configure(**self.styles[style])
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages.py Sat Jun 7 00:16:57 2008
@@ -1,490 +1,4 @@
-"""An implementation of tabbed pages using only standard Tkinter.
-
-Originally developed for use in IDLE. Based on tabpage.py.
-
-Classes exported:
-TabbedPageSet -- A Tkinter implementation of a tabbed-page widget.
-TabSet -- A widget containing tabs (buttons) in one or more rows.
-
-"""
-from Tkinter import *
-
-class InvalidNameError(Exception): pass
-class AlreadyExistsError(Exception): pass
-
-
-class TabSet(Frame):
- """A widget containing tabs (buttons) in one or more rows.
-
- Only one tab may be selected at a time.
-
- """
- def __init__(self, page_set, select_command,
- tabs=None, n_rows=1, max_tabs_per_row=5,
- expand_tabs=False, **kw):
- """Constructor arguments:
-
- select_command -- A callable which will be called when a tab is
- selected. It is called with the name of the selected tab as an
- argument.
-
- tabs -- A list of strings, the names of the tabs. Should be specified in
- the desired tab order. The first tab will be the default and first
- active tab. If tabs is None or empty, the TabSet will be initialized
- empty.
-
- n_rows -- Number of rows of tabs to be shown. If n_rows <= 0 or is
- None, then the number of rows will be decided by TabSet. See
- _arrange_tabs() for details.
-
- max_tabs_per_row -- Used for deciding how many rows of tabs are needed,
- when the number of rows is not constant. See _arrange_tabs() for
- details.
-
- """
- Frame.__init__(self, page_set, **kw)
- self.select_command = select_command
- self.n_rows = n_rows
- self.max_tabs_per_row = max_tabs_per_row
- self.expand_tabs = expand_tabs
- self.page_set = page_set
-
- self._tabs = {}
- self._tab2row = {}
- if tabs:
- self._tab_names = list(tabs)
- else:
- self._tab_names = []
- self._selected_tab = None
- self._tab_rows = []
-
- self.padding_frame = Frame(self, height=2,
- borderwidth=0, relief=FLAT,
- background=self.cget('background'))
- self.padding_frame.pack(side=TOP, fill=X, expand=False)
-
- self._arrange_tabs()
-
- def add_tab(self, tab_name):
- """Add a new tab with the name given in tab_name."""
- if not tab_name:
- raise InvalidNameError("Invalid Tab name: '%s'" % tab_name)
- if tab_name in self._tab_names:
- raise AlreadyExistsError("Tab named '%s' already exists" %tab_name)
-
- self._tab_names.append(tab_name)
- self._arrange_tabs()
-
- def remove_tab(self, tab_name):
- """Remove the tab named <tab_name>"""
- if not tab_name in self._tab_names:
- raise KeyError("No such Tab: '%s" % page_name)
-
- self._tab_names.remove(tab_name)
- self._arrange_tabs()
-
- def set_selected_tab(self, tab_name):
- """Show the tab named <tab_name> as the selected one"""
- if tab_name == self._selected_tab:
- return
- if tab_name is not None and tab_name not in self._tabs:
- raise KeyError("No such Tab: '%s" % page_name)
-
- # deselect the current selected tab
- if self._selected_tab is not None:
- self._tabs[self._selected_tab].set_normal()
- self._selected_tab = None
-
- if tab_name is not None:
- # activate the tab named tab_name
- self._selected_tab = tab_name
- tab = self._tabs[tab_name]
- tab.set_selected()
- # move the tab row with the selected tab to the bottom
- tab_row = self._tab2row[tab]
- tab_row.pack_forget()
- tab_row.pack(side=TOP, fill=X, expand=0)
-
- def _add_tab_row(self, tab_names, expand_tabs):
- if not tab_names:
- return
-
- tab_row = Frame(self)
- tab_row.pack(side=TOP, fill=X, expand=0)
- self._tab_rows.append(tab_row)
-
- for tab_name in tab_names:
- tab = TabSet.TabButton(tab_name, self.select_command,
- tab_row, self)
- if expand_tabs:
- tab.pack(side=LEFT, fill=X, expand=True)
- else:
- tab.pack(side=LEFT)
- self._tabs[tab_name] = tab
- self._tab2row[tab] = tab_row
-
- # tab is the last one created in the above loop
- tab.is_last_in_row = True
-
- def _reset_tab_rows(self):
- while self._tab_rows:
- tab_row = self._tab_rows.pop()
- tab_row.destroy()
- self._tab2row = {}
-
- def _arrange_tabs(self):
- """
- Arrange the tabs in rows, in the order in which they were added.
-
- If n_rows >= 1, this will be the number of rows used. Otherwise the
- number of rows will be calculated according to the number of tabs and
- max_tabs_per_row. In this case, the number of rows may change when
- adding/removing tabs.
-
- """
- # remove all tabs and rows
- for tab_name in self._tabs.keys():
- self._tabs.pop(tab_name).destroy()
- self._reset_tab_rows()
-
- if not self._tab_names:
- return
-
- if self.n_rows is not None and self.n_rows > 0:
- n_rows = self.n_rows
- else:
- # calculate the required number of rows
- n_rows = (len(self._tab_names) - 1) // self.max_tabs_per_row + 1
-
- # not expanding the tabs with more than one row is very ugly
- expand_tabs = self.expand_tabs or n_rows > 1
- i = 0 # index in self._tab_names
- for row_index in xrange(n_rows):
- # calculate required number of tabs in this row
- n_tabs = (len(self._tab_names) - i - 1) // (n_rows - row_index) + 1
- tab_names = self._tab_names[i:i + n_tabs]
- i += n_tabs
- self._add_tab_row(tab_names, expand_tabs)
-
- # re-select selected tab so it is properly displayed
- selected = self._selected_tab
- self.set_selected_tab(None)
- if selected in self._tab_names:
- self.set_selected_tab(selected)
-
- class TabButton(Frame):
- """A simple tab-like widget."""
-
- bw = 2 # borderwidth
-
- def __init__(self, name, select_command, tab_row, tab_set):
- """Constructor arguments:
-
- name -- The tab's name, which will appear in its button.
-
- select_command -- The command to be called upon selection of the
- tab. It is called with the tab's name as an argument.
-
- """
- Frame.__init__(self, tab_row, borderwidth=self.bw, relief=RAISED)
-
- self.name = name
- self.select_command = select_command
- self.tab_set = tab_set
- self.is_last_in_row = False
-
- self.button = Radiobutton(
- self, text=name, command=self._select_event,
- padx=5, pady=1, takefocus=FALSE, indicatoron=FALSE,
- highlightthickness=0, selectcolor='', borderwidth=0)
- self.button.pack(side=LEFT, fill=X, expand=True)
-
- self._init_masks()
- self.set_normal()
-
- def _select_event(self, *args):
- """Event handler for tab selection.
-
- With TabbedPageSet, this calls TabbedPageSet.change_page, so that
- selecting a tab changes the page.
-
- Note that this does -not- call set_selected -- it will be called by
- TabSet.set_selected_tab, which should be called when whatever the
- tabs are related to changes.
-
- """
- self.select_command(self.name)
- return
-
- def set_selected(self):
- """Assume selected look"""
- self._place_masks(selected=True)
-
- def set_normal(self):
- """Assume normal look"""
- self._place_masks(selected=False)
-
- def _init_masks(self):
- page_set = self.tab_set.page_set
- background = page_set.pages_frame.cget('background')
- # mask replaces the middle of the border with the background color
- self.mask = Frame(page_set, borderwidth=0, relief=FLAT,
- background=background)
- # mskl replaces the bottom-left corner of the border with a normal
- # left border
- self.mskl = Frame(page_set, borderwidth=0, relief=FLAT,
- background=background)
- self.mskl.ml = Frame(self.mskl, borderwidth=self.bw,
- relief=RAISED)
- self.mskl.ml.place(x=0, y=-self.bw,
- width=2*self.bw, height=self.bw*4)
- # mskr replaces the bottom-right corner of the border with a normal
- # right border
- self.mskr = Frame(page_set, borderwidth=0, relief=FLAT,
- background=background)
- self.mskr.mr = Frame(self.mskr, borderwidth=self.bw,
- relief=RAISED)
-
- def _place_masks(self, selected=False):
- height = self.bw
- if selected:
- height += self.bw
-
- self.mask.place(in_=self,
- relx=0.0, x=0,
- rely=1.0, y=0,
- relwidth=1.0, width=0,
- relheight=0.0, height=height)
-
- self.mskl.place(in_=self,
- relx=0.0, x=-self.bw,
- rely=1.0, y=0,
- relwidth=0.0, width=self.bw,
- relheight=0.0, height=height)
-
- page_set = self.tab_set.page_set
- if selected and ((not self.is_last_in_row) or
- (self.winfo_rootx() + self.winfo_width() <
- page_set.winfo_rootx() + page_set.winfo_width())
- ):
- # for a selected tab, if its rightmost edge isn't on the
- # rightmost edge of the page set, the right mask should be one
- # borderwidth shorter (vertically)
- height -= self.bw
-
- self.mskr.place(in_=self,
- relx=1.0, x=0,
- rely=1.0, y=0,
- relwidth=0.0, width=self.bw,
- relheight=0.0, height=height)
-
- self.mskr.mr.place(x=-self.bw, y=-self.bw,
- width=2*self.bw, height=height + self.bw*2)
-
- # finally, lower the tab set so that all of the frames we just
- # placed hide it
- self.tab_set.lower()
-
-class TabbedPageSet(Frame):
- """A Tkinter tabbed-pane widget.
-
- Constains set of 'pages' (or 'panes') with tabs above for selecting which
- page is displayed. Only one page will be displayed at a time.
-
- Pages may be accessed through the 'pages' attribute, which is a dictionary
- of pages, using the name given as the key. A page is an instance of a
- subclass of Tk's Frame widget.
-
- The page widgets will be created (and destroyed when required) by the
- TabbedPageSet. Do not call the page's pack/place/grid/destroy methods.
-
- Pages may be added or removed at any time using the add_page() and
- remove_page() methods.
-
- """
- class Page(object):
- """Abstract base class for TabbedPageSet's pages.
-
- Subclasses must override the _show() and _hide() methods.
-
- """
- uses_grid = False
-
- def __init__(self, page_set):
- self.frame = Frame(page_set, borderwidth=2, relief=RAISED)
-
- def _show(self):
- raise NotImplementedError
-
- def _hide(self):
- raise NotImplementedError
-
- class PageRemove(Page):
- """Page class using the grid placement manager's "remove" mechanism."""
- uses_grid = True
-
- def _show(self):
- self.frame.grid(row=0, column=0, sticky=NSEW)
-
- def _hide(self):
- self.frame.grid_remove()
-
- class PageLift(Page):
- """Page class using the grid placement manager's "lift" mechanism."""
- uses_grid = True
-
- def __init__(self, page_set):
- super(TabbedPageSet.PageLift, self).__init__(page_set)
- self.frame.grid(row=0, column=0, sticky=NSEW)
- self.frame.lower()
-
- def _show(self):
- self.frame.lift()
-
- def _hide(self):
- self.frame.lower()
-
- class PagePackForget(Page):
- """Page class using the pack placement manager's "forget" mechanism."""
- def _show(self):
- self.frame.pack(fill=BOTH, expand=True)
-
- def _hide(self):
- self.frame.pack_forget()
-
- def __init__(self, parent, page_names=None, page_class=PageLift,
- n_rows=1, max_tabs_per_row=5, expand_tabs=False,
- **kw):
- """Constructor arguments:
-
- page_names -- A list of strings, each will be the dictionary key to a
- page's widget, and the name displayed on the page's tab. Should be
- specified in the desired page order. The first page will be the default
- and first active page. If page_names is None or empty, the
- TabbedPageSet will be initialized empty.
-
- n_rows, max_tabs_per_row -- Parameters for the TabSet which will
- manage the tabs. See TabSet's docs for details.
-
- page_class -- Pages can be shown/hidden using three mechanisms:
-
- * PageLift - All pages will be rendered one on top of the other. When
- a page is selected, it will be brought to the top, thus hiding all
- other pages. Using this method, the TabbedPageSet will not be resized
- when pages are switched. (It may still be resized when pages are
- added/removed.)
-
- * PageRemove - When a page is selected, the currently showing page is
- hidden, and the new page shown in its place. Using this method, the
- TabbedPageSet may resize when pages are changed.
-
- * PagePackForget - This mechanism uses the pack placement manager.
- When a page is shown it is packed, and when it is hidden it is
- unpacked (i.e. pack_forget). This mechanism may also cause the
- TabbedPageSet to resize when the page is changed.
-
- """
- Frame.__init__(self, parent, **kw)
-
- self.page_class = page_class
- self.pages = {}
- self._pages_order = []
- self._current_page = None
- self._default_page = None
-
- self.columnconfigure(0, weight=1)
- self.rowconfigure(1, weight=1)
-
- self.pages_frame = Frame(self)
- self.pages_frame.grid(row=1, column=0, sticky=NSEW)
- if self.page_class.uses_grid:
- self.pages_frame.columnconfigure(0, weight=1)
- self.pages_frame.rowconfigure(0, weight=1)
-
- # the order of the following commands is important
- self._tab_set = TabSet(self, self.change_page, n_rows=n_rows,
- max_tabs_per_row=max_tabs_per_row,
- expand_tabs=expand_tabs)
- if page_names:
- for name in page_names:
- self.add_page(name)
- self._tab_set.grid(row=0, column=0, sticky=NSEW)
-
- self.change_page(self._default_page)
-
- def add_page(self, page_name):
- """Add a new page with the name given in page_name."""
- if not page_name:
- raise InvalidNameError("Invalid TabPage name: '%s'" % page_name)
- if page_name in self.pages:
- raise AlreadyExistsError(
- "TabPage named '%s' already exists" % page_name)
-
- self.pages[page_name] = self.page_class(self.pages_frame)
- self._pages_order.append(page_name)
- self._tab_set.add_tab(page_name)
-
- if len(self.pages) == 1: # adding first page
- self._default_page = page_name
- self.change_page(page_name)
-
- def remove_page(self, page_name):
- """Destroy the page whose name is given in page_name."""
- if not page_name in self.pages:
- raise KeyError("No such TabPage: '%s" % page_name)
-
- self._pages_order.remove(page_name)
-
- # handle removing last remaining, default, or currently shown page
- if len(self._pages_order) > 0:
- if page_name == self._default_page:
- # set a new default page
- self._default_page = self._pages_order[0]
- else:
- self._default_page = None
-
- if page_name == self._current_page:
- self.change_page(self._default_page)
-
- self._tab_set.remove_tab(page_name)
- page = self.pages.pop(page_name)
- page.frame.destroy()
-
- def change_page(self, page_name):
- """Show the page whose name is given in page_name."""
- if self._current_page == page_name:
- return
- if page_name is not None and page_name not in self.pages:
- raise KeyError("No such TabPage: '%s'" % page_name)
-
- if self._current_page is not None:
- self.pages[self._current_page]._hide()
- self._current_page = None
-
- if page_name is not None:
- self._current_page = page_name
- self.pages[page_name]._show()
-
- self._tab_set.set_selected_tab(page_name)
-
-if __name__ == '__main__':
- # test dialog
- root=Tk()
- tabPage=TabbedPageSet(root, page_names=['Foobar','Baz'], n_rows=0,
- expand_tabs=False,
- )
- tabPage.pack(side=TOP, expand=TRUE, fill=BOTH)
- Label(tabPage.pages['Foobar'].frame, text='Foo', pady=20).pack()
- Label(tabPage.pages['Foobar'].frame, text='Bar', pady=20).pack()
- Label(tabPage.pages['Baz'].frame, text='Baz').pack()
- entryPgName=Entry(root)
- buttonAdd=Button(root, text='Add Page',
- command=lambda:tabPage.add_page(entryPgName.get()))
- buttonRemove=Button(root, text='Remove Page',
- command=lambda:tabPage.remove_page(entryPgName.get()))
- labelPgName=Label(root, text='name of page to add/remove:')
- buttonAdd.pack(padx=5, pady=5)
- buttonRemove.pack(padx=5, pady=5)
- labelPgName.pack(padx=5)
- entryPgName.pack(padx=5)
- root.mainloop()
+try:
+ from idlelib.tabbedpages_new import TabbedPageSet
+except ImportError:
+ from idlelib.tabbedpages_old import TabbedPageSet
Added: sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages_new.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages_new.py Sat Jun 7 00:16:57 2008
@@ -0,0 +1,85 @@
+"""Classes exported:
+
+TabbedPageSet -- A custom ttk.Notebook used by IDLE.
+"""
+from Tkinter import *
+from ttk import *
+
+class InvalidNameError(Exception): pass
+class AlreadyExistsError(Exception): pass
+
+class FramePage(object):
+ def __init__(self, notebook):
+ self.frame = Frame(notebook)
+
+class TabbedPageSet(Notebook):
+ """
+ Pages may be accessed through the 'pages' attribute, which is a dictionary
+ of pages, using the name given as the key. A page is an instance of a
+ subclass of ttk's Frame widget.
+
+ Pages may be added or removed at any time using the add_page() and
+ remove_page() methods.
+ """
+
+ def __init__(self, master, page_names=None, **kw):
+ """Constructor arguments:
+
+ page_names -- A list of strings, each will be the dictionary key to a
+ page's widget, and the name displayed on the page's tab. Should be
+ specified in the desired page order. The first page will be the default
+ and first active page. If page_names is None or empty, the
+ TabbedPageSet will be initialized empty.
+ """
+ Notebook.__init__(self, master, **kw)
+
+ self.pages = {}
+ for name in page_names:
+ self.add_page(name)
+
+ def add_page(self, page_name):
+ """Add a new page with the name given in page_name."""
+ if not page_name:
+ raise InvalidNameError("Invalid TabPage name: '%s'" % page_name)
+ if page_name in self.pages:
+ raise AlreadyExistsError(
+ "TabPage named '%s' already exists" % page_name)
+
+ fpage = FramePage(self)
+ self.pages[page_name] = fpage
+ self.add(fpage.frame, text=page_name, padding=6)
+
+ # workaround for bug #1878298 at tktoolkit sf bug tracker
+ self.event_generate('<Expose>')
+
+ def remove_page(self, page_name):
+ if not page_name in self.pages:
+ raise KeyError("No such TabPage: '%s" % page_name)
+
+ self.forget(self.index(self.pages[page_name].frame))
+ del self.pages[page_name]
+
+ # workaround for bug #1878298 at tktoolkit sf bug tracker
+ self.event_generate('<Expose>')
+
+if __name__ == '__main__':
+ # test dialog
+ root=Tk()
+ style = Style()
+ style.configure('C.TLabel', padding=20)
+ tabPage=TabbedPageSet(root, page_names=['Foobar','Baz'])
+ tabPage.pack(side=TOP, expand=TRUE, fill=BOTH)
+ Label(tabPage.pages['Foobar'].frame, text='Foo', style='C.TLabel').pack()
+ Label(tabPage.pages['Foobar'].frame, text='Bar', style='C.TLabel').pack()
+ Label(tabPage.pages['Baz'].frame, text='Baz').pack()
+ entryPgName=Entry(root)
+ buttonAdd=Button(root, text='Add Page',
+ command=lambda:tabPage.add_page(entryPgName.get()))
+ buttonRemove=Button(root, text='Remove Page',
+ command=lambda:tabPage.remove_page(entryPgName.get()))
+ labelPgName=Label(root, text='name of page to add/remove:')
+ buttonAdd.pack(padx=5, pady=5)
+ buttonRemove.pack(padx=5, pady=5)
+ labelPgName.pack(padx=5)
+ entryPgName.pack(padx=5)
+ root.mainloop()
Added: sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages_old.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/tabbedpages_old.py Sat Jun 7 00:16:57 2008
@@ -0,0 +1,490 @@
+"""An implementation of tabbed pages using only standard Tkinter.
+
+Originally developed for use in IDLE. Based on tabpage.py.
+
+Classes exported:
+TabbedPageSet -- A Tkinter implementation of a tabbed-page widget.
+TabSet -- A widget containing tabs (buttons) in one or more rows.
+
+"""
+from Tkinter import *
+
+class InvalidNameError(Exception): pass
+class AlreadyExistsError(Exception): pass
+
+
+class TabSet(Frame):
+ """A widget containing tabs (buttons) in one or more rows.
+
+ Only one tab may be selected at a time.
+
+ """
+ def __init__(self, page_set, select_command,
+ tabs=None, n_rows=1, max_tabs_per_row=5,
+ expand_tabs=False, **kw):
+ """Constructor arguments:
+
+ select_command -- A callable which will be called when a tab is
+ selected. It is called with the name of the selected tab as an
+ argument.
+
+ tabs -- A list of strings, the names of the tabs. Should be specified in
+ the desired tab order. The first tab will be the default and first
+ active tab. If tabs is None or empty, the TabSet will be initialized
+ empty.
+
+ n_rows -- Number of rows of tabs to be shown. If n_rows <= 0 or is
+ None, then the number of rows will be decided by TabSet. See
+ _arrange_tabs() for details.
+
+ max_tabs_per_row -- Used for deciding how many rows of tabs are needed,
+ when the number of rows is not constant. See _arrange_tabs() for
+ details.
+
+ """
+ Frame.__init__(self, page_set, **kw)
+ self.select_command = select_command
+ self.n_rows = n_rows
+ self.max_tabs_per_row = max_tabs_per_row
+ self.expand_tabs = expand_tabs
+ self.page_set = page_set
+
+ self._tabs = {}
+ self._tab2row = {}
+ if tabs:
+ self._tab_names = list(tabs)
+ else:
+ self._tab_names = []
+ self._selected_tab = None
+ self._tab_rows = []
+
+ self.padding_frame = Frame(self, height=2,
+ borderwidth=0, relief=FLAT,
+ background=self.cget('background'))
+ self.padding_frame.pack(side=TOP, fill=X, expand=False)
+
+ self._arrange_tabs()
+
+ def add_tab(self, tab_name):
+ """Add a new tab with the name given in tab_name."""
+ if not tab_name:
+ raise InvalidNameError("Invalid Tab name: '%s'" % tab_name)
+ if tab_name in self._tab_names:
+ raise AlreadyExistsError("Tab named '%s' already exists" %tab_name)
+
+ self._tab_names.append(tab_name)
+ self._arrange_tabs()
+
+ def remove_tab(self, tab_name):
+ """Remove the tab named <tab_name>"""
+ if not tab_name in self._tab_names:
+ raise KeyError("No such Tab: '%s" % page_name)
+
+ self._tab_names.remove(tab_name)
+ self._arrange_tabs()
+
+ def set_selected_tab(self, tab_name):
+ """Show the tab named <tab_name> as the selected one"""
+ if tab_name == self._selected_tab:
+ return
+ if tab_name is not None and tab_name not in self._tabs:
+ raise KeyError("No such Tab: '%s" % page_name)
+
+ # deselect the current selected tab
+ if self._selected_tab is not None:
+ self._tabs[self._selected_tab].set_normal()
+ self._selected_tab = None
+
+ if tab_name is not None:
+ # activate the tab named tab_name
+ self._selected_tab = tab_name
+ tab = self._tabs[tab_name]
+ tab.set_selected()
+ # move the tab row with the selected tab to the bottom
+ tab_row = self._tab2row[tab]
+ tab_row.pack_forget()
+ tab_row.pack(side=TOP, fill=X, expand=0)
+
+ def _add_tab_row(self, tab_names, expand_tabs):
+ if not tab_names:
+ return
+
+ tab_row = Frame(self)
+ tab_row.pack(side=TOP, fill=X, expand=0)
+ self._tab_rows.append(tab_row)
+
+ for tab_name in tab_names:
+ tab = TabSet.TabButton(tab_name, self.select_command,
+ tab_row, self)
+ if expand_tabs:
+ tab.pack(side=LEFT, fill=X, expand=True)
+ else:
+ tab.pack(side=LEFT)
+ self._tabs[tab_name] = tab
+ self._tab2row[tab] = tab_row
+
+ # tab is the last one created in the above loop
+ tab.is_last_in_row = True
+
+ def _reset_tab_rows(self):
+ while self._tab_rows:
+ tab_row = self._tab_rows.pop()
+ tab_row.destroy()
+ self._tab2row = {}
+
+ def _arrange_tabs(self):
+ """
+ Arrange the tabs in rows, in the order in which they were added.
+
+ If n_rows >= 1, this will be the number of rows used. Otherwise the
+ number of rows will be calculated according to the number of tabs and
+ max_tabs_per_row. In this case, the number of rows may change when
+ adding/removing tabs.
+
+ """
+ # remove all tabs and rows
+ while self._tabs:
+ self._tabs.popitem()[1].destroy()
+ self._reset_tab_rows()
+
+ if not self._tab_names:
+ return
+
+ if self.n_rows is not None and self.n_rows > 0:
+ n_rows = self.n_rows
+ else:
+ # calculate the required number of rows
+ n_rows = (len(self._tab_names) - 1) // self.max_tabs_per_row + 1
+
+ # not expanding the tabs with more than one row is very ugly
+ expand_tabs = self.expand_tabs or n_rows > 1
+ i = 0 # index in self._tab_names
+ for row_index in range(n_rows):
+ # calculate required number of tabs in this row
+ n_tabs = (len(self._tab_names) - i - 1) // (n_rows - row_index) + 1
+ tab_names = self._tab_names[i:i + n_tabs]
+ i += n_tabs
+ self._add_tab_row(tab_names, expand_tabs)
+
+ # re-select selected tab so it is properly displayed
+ selected = self._selected_tab
+ self.set_selected_tab(None)
+ if selected in self._tab_names:
+ self.set_selected_tab(selected)
+
+ class TabButton(Frame):
+ """A simple tab-like widget."""
+
+ bw = 2 # borderwidth
+
+ def __init__(self, name, select_command, tab_row, tab_set):
+ """Constructor arguments:
+
+ name -- The tab's name, which will appear in its button.
+
+ select_command -- The command to be called upon selection of the
+ tab. It is called with the tab's name as an argument.
+
+ """
+ Frame.__init__(self, tab_row, borderwidth=self.bw, relief=RAISED)
+
+ self.name = name
+ self.select_command = select_command
+ self.tab_set = tab_set
+ self.is_last_in_row = False
+
+ self.button = Radiobutton(
+ self, text=name, command=self._select_event,
+ padx=5, pady=1, takefocus=FALSE, indicatoron=FALSE,
+ highlightthickness=0, selectcolor='', borderwidth=0)
+ self.button.pack(side=LEFT, fill=X, expand=True)
+
+ self._init_masks()
+ self.set_normal()
+
+ def _select_event(self, *args):
+ """Event handler for tab selection.
+
+ With TabbedPageSet, this calls TabbedPageSet.change_page, so that
+ selecting a tab changes the page.
+
+ Note that this does -not- call set_selected -- it will be called by
+ TabSet.set_selected_tab, which should be called when whatever the
+ tabs are related to changes.
+
+ """
+ self.select_command(self.name)
+ return
+
+ def set_selected(self):
+ """Assume selected look"""
+ self._place_masks(selected=True)
+
+ def set_normal(self):
+ """Assume normal look"""
+ self._place_masks(selected=False)
+
+ def _init_masks(self):
+ page_set = self.tab_set.page_set
+ background = page_set.pages_frame.cget('background')
+ # mask replaces the middle of the border with the background color
+ self.mask = Frame(page_set, borderwidth=0, relief=FLAT,
+ background=background)
+ # mskl replaces the bottom-left corner of the border with a normal
+ # left border
+ self.mskl = Frame(page_set, borderwidth=0, relief=FLAT,
+ background=background)
+ self.mskl.ml = Frame(self.mskl, borderwidth=self.bw,
+ relief=RAISED)
+ self.mskl.ml.place(x=0, y=-self.bw,
+ width=2*self.bw, height=self.bw*4)
+ # mskr replaces the bottom-right corner of the border with a normal
+ # right border
+ self.mskr = Frame(page_set, borderwidth=0, relief=FLAT,
+ background=background)
+ self.mskr.mr = Frame(self.mskr, borderwidth=self.bw,
+ relief=RAISED)
+
+ def _place_masks(self, selected=False):
+ height = self.bw
+ if selected:
+ height += self.bw
+
+ self.mask.place(in_=self,
+ relx=0.0, x=0,
+ rely=1.0, y=0,
+ relwidth=1.0, width=0,
+ relheight=0.0, height=height)
+
+ self.mskl.place(in_=self,
+ relx=0.0, x=-self.bw,
+ rely=1.0, y=0,
+ relwidth=0.0, width=self.bw,
+ relheight=0.0, height=height)
+
+ page_set = self.tab_set.page_set
+ if selected and ((not self.is_last_in_row) or
+ (self.winfo_rootx() + self.winfo_width() <
+ page_set.winfo_rootx() + page_set.winfo_width())
+ ):
+ # for a selected tab, if its rightmost edge isn't on the
+ # rightmost edge of the page set, the right mask should be one
+ # borderwidth shorter (vertically)
+ height -= self.bw
+
+ self.mskr.place(in_=self,
+ relx=1.0, x=0,
+ rely=1.0, y=0,
+ relwidth=0.0, width=self.bw,
+ relheight=0.0, height=height)
+
+ self.mskr.mr.place(x=-self.bw, y=-self.bw,
+ width=2*self.bw, height=height + self.bw*2)
+
+ # finally, lower the tab set so that all of the frames we just
+ # placed hide it
+ self.tab_set.lower()
+
+class TabbedPageSet(Frame):
+ """A Tkinter tabbed-pane widget.
+
+ Constains set of 'pages' (or 'panes') with tabs above for selecting which
+ page is displayed. Only one page will be displayed at a time.
+
+ Pages may be accessed through the 'pages' attribute, which is a dictionary
+ of pages, using the name given as the key. A page is an instance of a
+ subclass of Tk's Frame widget.
+
+ The page widgets will be created (and destroyed when required) by the
+ TabbedPageSet. Do not call the page's pack/place/grid/destroy methods.
+
+ Pages may be added or removed at any time using the add_page() and
+ remove_page() methods.
+
+ """
+ class Page(object):
+ """Abstract base class for TabbedPageSet's pages.
+
+ Subclasses must override the _show() and _hide() methods.
+
+ """
+ uses_grid = False
+
+ def __init__(self, page_set):
+ self.frame = Frame(page_set, borderwidth=2, relief=RAISED)
+
+ def _show(self):
+ raise NotImplementedError
+
+ def _hide(self):
+ raise NotImplementedError
+
+ class PageRemove(Page):
+ """Page class using the grid placement manager's "remove" mechanism."""
+ uses_grid = True
+
+ def _show(self):
+ self.frame.grid(row=0, column=0, sticky=NSEW)
+
+ def _hide(self):
+ self.frame.grid_remove()
+
+ class PageLift(Page):
+ """Page class using the grid placement manager's "lift" mechanism."""
+ uses_grid = True
+
+ def __init__(self, page_set):
+ super(TabbedPageSet.PageLift, self).__init__(page_set)
+ self.frame.grid(row=0, column=0, sticky=NSEW)
+ self.frame.lower()
+
+ def _show(self):
+ self.frame.lift()
+
+ def _hide(self):
+ self.frame.lower()
+
+ class PagePackForget(Page):
+ """Page class using the pack placement manager's "forget" mechanism."""
+ def _show(self):
+ self.frame.pack(fill=BOTH, expand=True)
+
+ def _hide(self):
+ self.frame.pack_forget()
+
+ def __init__(self, parent, page_names=None, page_class=PageLift,
+ n_rows=1, max_tabs_per_row=5, expand_tabs=False,
+ **kw):
+ """Constructor arguments:
+
+ page_names -- A list of strings, each will be the dictionary key to a
+ page's widget, and the name displayed on the page's tab. Should be
+ specified in the desired page order. The first page will be the default
+ and first active page. If page_names is None or empty, the
+ TabbedPageSet will be initialized empty.
+
+ n_rows, max_tabs_per_row -- Parameters for the TabSet which will
+ manage the tabs. See TabSet's docs for details.
+
+ page_class -- Pages can be shown/hidden using three mechanisms:
+
+ * PageLift - All pages will be rendered one on top of the other. When
+ a page is selected, it will be brought to the top, thus hiding all
+ other pages. Using this method, the TabbedPageSet will not be resized
+ when pages are switched. (It may still be resized when pages are
+ added/removed.)
+
+ * PageRemove - When a page is selected, the currently showing page is
+ hidden, and the new page shown in its place. Using this method, the
+ TabbedPageSet may resize when pages are changed.
+
+ * PagePackForget - This mechanism uses the pack placement manager.
+ When a page is shown it is packed, and when it is hidden it is
+ unpacked (i.e. pack_forget). This mechanism may also cause the
+ TabbedPageSet to resize when the page is changed.
+
+ """
+ Frame.__init__(self, parent, **kw)
+
+ self.page_class = page_class
+ self.pages = {}
+ self._pages_order = []
+ self._current_page = None
+ self._default_page = None
+
+ self.columnconfigure(0, weight=1)
+ self.rowconfigure(1, weight=1)
+
+ self.pages_frame = Frame(self)
+ self.pages_frame.grid(row=1, column=0, sticky=NSEW)
+ if self.page_class.uses_grid:
+ self.pages_frame.columnconfigure(0, weight=1)
+ self.pages_frame.rowconfigure(0, weight=1)
+
+ # the order of the following commands is important
+ self._tab_set = TabSet(self, self.change_page, n_rows=n_rows,
+ max_tabs_per_row=max_tabs_per_row,
+ expand_tabs=expand_tabs)
+ if page_names:
+ for name in page_names:
+ self.add_page(name)
+ self._tab_set.grid(row=0, column=0, sticky=NSEW)
+
+ self.change_page(self._default_page)
+
+ def add_page(self, page_name):
+ """Add a new page with the name given in page_name."""
+ if not page_name:
+ raise InvalidNameError("Invalid TabPage name: '%s'" % page_name)
+ if page_name in self.pages:
+ raise AlreadyExistsError(
+ "TabPage named '%s' already exists" % page_name)
+
+ self.pages[page_name] = self.page_class(self.pages_frame)
+ self._pages_order.append(page_name)
+ self._tab_set.add_tab(page_name)
+
+ if len(self.pages) == 1: # adding first page
+ self._default_page = page_name
+ self.change_page(page_name)
+
+ def remove_page(self, page_name):
+ """Destroy the page whose name is given in page_name."""
+ if not page_name in self.pages:
+ raise KeyError("No such TabPage: '%s" % page_name)
+
+ self._pages_order.remove(page_name)
+
+ # handle removing last remaining, default, or currently shown page
+ if len(self._pages_order) > 0:
+ if page_name == self._default_page:
+ # set a new default page
+ self._default_page = self._pages_order[0]
+ else:
+ self._default_page = None
+
+ if page_name == self._current_page:
+ self.change_page(self._default_page)
+
+ self._tab_set.remove_tab(page_name)
+ page = self.pages.pop(page_name)
+ page.frame.destroy()
+
+ def change_page(self, page_name):
+ """Show the page whose name is given in page_name."""
+ if self._current_page == page_name:
+ return
+ if page_name is not None and page_name not in self.pages:
+ raise KeyError("No such TabPage: '%s'" % page_name)
+
+ if self._current_page is not None:
+ self.pages[self._current_page]._hide()
+ self._current_page = None
+
+ if page_name is not None:
+ self._current_page = page_name
+ self.pages[page_name]._show()
+
+ self._tab_set.set_selected_tab(page_name)
+
+if __name__ == '__main__':
+ # test dialog
+ root=Tk()
+ tabPage=TabbedPageSet(root, page_names=['Foobar','Baz'], n_rows=0,
+ expand_tabs=False,
+ )
+ tabPage.pack(side=TOP, expand=TRUE, fill=BOTH)
+ Label(tabPage.pages['Foobar'].frame, text='Foo', pady=20).pack()
+ Label(tabPage.pages['Foobar'].frame, text='Bar', pady=20).pack()
+ Label(tabPage.pages['Baz'].frame, text='Baz').pack()
+ entryPgName=Entry(root)
+ buttonAdd=Button(root, text='Add Page',
+ command=lambda:tabPage.add_page(entryPgName.get()))
+ buttonRemove=Button(root, text='Remove Page',
+ command=lambda:tabPage.remove_page(entryPgName.get()))
+ labelPgName=Label(root, text='name of page to add/remove:')
+ buttonAdd.pack(padx=5, pady=5)
+ buttonRemove.pack(padx=5, pady=5)
+ labelPgName.pack(padx=5)
+ entryPgName.pack(padx=5)
+ root.mainloop()
Modified: sandbox/trunk/ttk-gsoc/src/idlelib/textView.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/textView.py (original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/textView.py Sat Jun 7 00:16:57 2008
@@ -1,9 +1,12 @@
-"""Simple text browser for IDLE
+"""Simple text browser for IDLE"""
-"""
-
-from Tkinter import *
import tkMessageBox
+from Tkinter import *
+from idlelib.configHandler import idleConf
+
+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
+if TTK:
+ from ttk import *
class TextViewer(Toplevel):
"""A simple text viewer dialog for IDLE
@@ -42,17 +45,20 @@
self.buttonOk = Button(frameButtons, text='Close',
command=self.Ok, takefocus=FALSE)
self.scrollbarView = Scrollbar(frameText, orient=VERTICAL,
- takefocus=FALSE, highlightthickness=0)
- self.textView = Text(frameText, wrap=WORD, highlightthickness=0,
- fg=self.fg, bg=self.bg)
+ takefocus=FALSE)
+ self.textView = Text(frameText, wrap=WORD, fg=self.fg, bg=self.bg,
+ highlightthickness=0)
self.scrollbarView.config(command=self.textView.yview)
self.textView.config(yscrollcommand=self.scrollbarView.set)
self.buttonOk.pack()
self.scrollbarView.pack(side=RIGHT,fill=Y)
self.textView.pack(side=LEFT,expand=TRUE,fill=BOTH)
- frameButtons.pack(side=BOTTOM,fill=X)
+ frameButtons.pack(side=BOTTOM)
frameText.pack(side=TOP,expand=TRUE,fill=BOTH)
+ if TTK:
+ frameButtons['style'] = 'RootColor.TFrame'
+
def Ok(self, event=None):
self.destroy()
Deleted: sandbox/trunk/ttk-gsoc/src/idlelib_ttk.diff
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib_ttk.diff Sat Jun 7 00:16:57 2008
+++ (empty file)
@@ -1,1698 +0,0 @@
-Index: Lib/idlelib/AutoCompleteWindow.py
-===================================================================
---- Lib/idlelib/AutoCompleteWindow.py (revision 63916)
-+++ Lib/idlelib/AutoCompleteWindow.py (working copy)
-@@ -4,7 +4,11 @@
- from Tkinter import *
- from MultiCall import MC_SHIFT
- import AutoComplete
-+from idlelib.configHandler import idleConf
-
-+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
-+ from ttk import *
-+
- HIDE_VIRTUAL_EVENT_NAME = "<<autocompletewindow-hide>>"
- HIDE_SEQUENCES = ("<FocusOut>", "<ButtonPress>")
- KEYPRESS_VIRTUAL_EVENT_NAME = "<<autocompletewindow-keypress>>"
-Index: Lib/idlelib/ToolTip.py
-===================================================================
---- Lib/idlelib/ToolTip.py (revision 63916)
-+++ Lib/idlelib/ToolTip.py (working copy)
-@@ -3,7 +3,8 @@
- # may be useful for some purposes in (or almost in ;) the current project scope
- # Ideas gleaned from PySol
-
--from Tkinter import *
-+from Tkinter import END, Listbox, Tk, Toplevel
-+from ttk import Button, Label
-
- class ToolTipBase:
-
-Index: Lib/idlelib/configSectionNameDialog.py
-===================================================================
---- Lib/idlelib/configSectionNameDialog.py (revision 63916)
-+++ Lib/idlelib/configSectionNameDialog.py (working copy)
-@@ -4,7 +4,12 @@
- """
- from Tkinter import *
- import tkMessageBox
-+from idlelib.configHandler import idleConf
-
-+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
-+if TTK:
-+ from ttk import *
-+
- class GetCfgSectionNameDialog(Toplevel):
- def __init__(self,parent,title,message,usedNames):
- """
-@@ -25,8 +30,6 @@
- self.CreateWidgets()
- self.withdraw() #hide while setting geometry
- self.update_idletasks()
-- #needs to be done here so that the winfo_reqwidth is valid
-- self.messageInfo.config(width=self.frameMain.winfo_reqwidth())
- self.geometry("+%d+%d" %
- ((parent.winfo_rootx()+((parent.winfo_width()/2)
- -(self.winfo_reqwidth()/2)),
-@@ -40,11 +43,10 @@
- self.fontSize=StringVar(self)
- self.frameMain = Frame(self,borderwidth=2,relief=SUNKEN)
- self.frameMain.pack(side=TOP,expand=TRUE,fill=BOTH)
-- self.messageInfo=Message(self.frameMain,anchor=W,justify=LEFT,padx=5,pady=5,
-- text=self.message)#,aspect=200)
-+ self.messageInfo= Label(self.frameMain, text=self.message)
- entryName=Entry(self.frameMain,textvariable=self.name,width=30)
- entryName.focus_set()
-- self.messageInfo.pack(padx=5,pady=5)#,expand=TRUE,fill=BOTH)
-+ self.messageInfo.pack(padx=5,pady=5)
- entryName.pack(padx=5,pady=5)
- frameButtons=Frame(self)
- frameButtons.pack(side=BOTTOM,fill=X)
-@@ -55,6 +57,12 @@
- width=8,command=self.Cancel)
- self.buttonCancel.grid(row=0,column=1,padx=5,pady=5)
-
-+ if TTK:
-+ self.messageInfo['padding'] = 5
-+ frameButtons['style'] = 'RootColor.TFrame'
-+ else:
-+ self.messageInfo.configure(padx=5, pady=5)
-+
- def NameOk(self):
- #simple validity check for a sensible
- #ConfigParser file section name
-Index: Lib/idlelib/PyShell.py
-===================================================================
---- Lib/idlelib/PyShell.py (revision 63916)
-+++ Lib/idlelib/PyShell.py (working copy)
-@@ -22,14 +22,26 @@
- print>>sys.__stderr__, "** IDLE can't import Tkinter. " \
- "Your Python may not be configured for Tk. **"
- sys.exit(1)
-+try:
-+ from ttk import *
-+ TTK = 1
-+except ImportError:
-+ print >> sys.stderr, "** IDLE can't import ttk."
-+ TTK = 0
-+
- import tkMessageBox
-
-+from configHandler import idleConf
-+
-+# store ttk availability
-+idleConf.SetOption('main', 'General', 'use-ttk', str(TTK))
-+idleConf.SaveUserCfgFiles()
-+
- from EditorWindow import EditorWindow, fixwordbreaks
- from FileList import FileList
- from ColorDelegator import ColorDelegator
- from UndoDelegator import UndoDelegator
- from OutputWindow import OutputWindow
--from configHandler import idleConf
- import idlever
-
- import rpc
-@@ -1381,6 +1393,19 @@
- # start editor and/or shell windows:
- root = Tk(className="Idle")
-
-+ if TTK:
-+ # create base styles used along idle files
-+ style = Style()
-+
-+ x = style.map('.')
-+ r = {'background': []}
-+ for sspec in x['background']:
-+ if 'active' in sspec[:-1]:
-+ r['background'].append(('!disabled', sspec[-1]))
-+ break
-+ style.map('RootColor.TFrame', **r)
-+ # end styles
-+
- fixwordbreaks(root)
- root.withdraw()
- flist = PyShellFileList(root)
-Index: Lib/idlelib/Debugger.py
-===================================================================
---- Lib/idlelib/Debugger.py (revision 63916)
-+++ Lib/idlelib/Debugger.py (working copy)
-@@ -4,8 +4,11 @@
- from Tkinter import *
- from WindowList import ListedToplevel
- from ScrolledList import ScrolledList
-+from configHandler import idleConf
- import macosxSupport
-
-+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
-+ from ttk import Scrollbar, Button, Radiobutton
-
- class Idb(bdb.Bdb):
-
-@@ -155,6 +158,7 @@
- self.show_locals()
- if self.vglobals.get():
- self.show_globals()
-+ #
-
- def interaction(self, message, frame, info=None):
- self.frame = frame
-@@ -413,6 +417,7 @@
- height = 20*len(dict) # XXX 20 == observed height of Entry widget
- self.master = master
- self.title = title
-+
- import repr
- self.repr = repr.Repr()
- self.repr.maxstring = 60
-Index: Lib/idlelib/configDialog.py
-===================================================================
---- Lib/idlelib/configDialog.py (revision 63916)
-+++ Lib/idlelib/configDialog.py (working copy)
-@@ -7,7 +7,6 @@
-
- Note that tab width in IDLE is currently fixed at eight due to Tk issues.
- Refer to comments in EditorWindow autoindent code for details.
--
- """
- from Tkinter import *
- import tkMessageBox, tkColorChooser, tkFont
-@@ -19,7 +18,12 @@
- from keybindingDialog import GetKeysDialog
- from configSectionNameDialog import GetCfgSectionNameDialog
- from configHelpSourceEdit import GetHelpSourceDialog
-+from stylist import PoorManStyle
-
-+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
-+if TTK:
-+ from ttk import *
-+
- class ConfigDialog(Toplevel):
-
- def __init__(self,parent,title):
-@@ -47,6 +51,7 @@
- 'Shell Stderr Text':('stderr','12'),
- }
- self.ResetChangedItems() #load initial values in changed items dict
-+ self.SetupStyles()
- self.CreateWidgets()
- self.resizable(height=FALSE,width=FALSE)
- self.transient(parent)
-@@ -64,32 +69,52 @@
- self.wm_deiconify()
- self.wait_window()
-
-+ def SetupStyles(self):
-+ if TTK:
-+ style = Style(self.master)
-+ style.configure('S.TButton', padding=[6, 3])
-+ style.configure('S2.TFrame', padding=2)
-+ style.configure('Color.TFrame', background='blue')
-+ self.ttkstyle = style
-+ self.style = lambda w, style: w.configure(style=style)
-+ else:
-+ self.ttkstyle = PoorManStyle(self, styles={
-+ 'S.TButton': {'pady': 6, 'padx': 3},
-+ 'S2.TFrame': {'padx': 2, 'pady': 2}
-+ }, cfgstyles={'Color.TFrame': 'frameColourSet'})
-+ self.style = self.ttkstyle.style_it
-+
- def CreateWidgets(self):
- self.tabPages = TabbedPageSet(self,
- page_names=['Fonts/Tabs','Highlighting','Keys','General'])
-- frameActionButtons = Frame(self,pady=2)
-+ frameActionButtons = Frame(self)
- #action buttons
- self.buttonHelp = Button(frameActionButtons,text='Help',
-- command=self.Help,takefocus=FALSE,
-- padx=6,pady=3)
-- self.buttonOk = Button(frameActionButtons,text='Ok',
-- command=self.Ok,takefocus=FALSE,
-- padx=6,pady=3)
-- self.buttonApply = Button(frameActionButtons,text='Apply',
-- command=self.Apply,takefocus=FALSE,
-- padx=6,pady=3)
-- self.buttonCancel = Button(frameActionButtons,text='Cancel',
-- command=self.Cancel,takefocus=FALSE,
-- padx=6,pady=3)
-+ command=self.Help, takefocus=FALSE)
-+ self.buttonOk = Button(frameActionButtons, text='Ok',
-+ command=self.Ok, takefocus=FALSE)
-+ self.buttonApply = Button(frameActionButtons, text='Apply',
-+ command=self.Apply, takefocus=FALSE)
-+ self.buttonCancel = Button(frameActionButtons, text='Cancel',
-+ command=self.Cancel, takefocus=FALSE)
-+
-+ # Apply styles
-+ s = self.style
-+ s(frameActionButtons, 'RootColor.TFrame')
-+ s(self.buttonHelp, 'S.TButton')
-+ s(self.buttonOk, 'S.TButton')
-+ s(self.buttonApply, 'S.TButton')
-+ s(self.buttonCancel, 'S.TButton')
-+
- self.CreatePageFontTab()
- self.CreatePageHighlight()
- self.CreatePageKeys()
- self.CreatePageGeneral()
-- self.buttonHelp.pack(side=RIGHT,padx=5)
-- self.buttonOk.pack(side=LEFT,padx=5)
-- self.buttonApply.pack(side=LEFT,padx=5)
-- self.buttonCancel.pack(side=LEFT,padx=5)
-- frameActionButtons.pack(side=BOTTOM)
-+ self.buttonHelp.pack(side=LEFT, pady=6)
-+ self.buttonApply.pack(side=RIGHT, pady=6)
-+ self.buttonOk.pack(side=RIGHT, padx=6, pady=6)
-+ self.buttonCancel.pack(side=RIGHT, pady=6)
-+ frameActionButtons.pack(side=BOTTOM, fill=X, expand=TRUE)
- Frame(self, height=2, borderwidth=0).pack(side=BOTTOM)
- self.tabPages.pack(side=TOP,expand=TRUE,fill=BOTH)
-
-@@ -127,14 +152,19 @@
- frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1)
- self.labelFontSample=Label(frameFontSample,
- text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]',
-- justify=LEFT,font=self.editFont)
-+ justify=LEFT, font=self.editFont)
- #frameIndent
- 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)
-+ orient='horizontal', tickinterval=2,
-+ from_=2, to=16)
-+ if TTK:
-+ self.scaleSpaceNum.configure(
-+ bg=self.ttkstyle.configure('.', 'background'),
-+ highlightthickness=0)
-+
- #widget packing
- #body
- frameFont.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH)
-@@ -149,7 +179,7 @@
- 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)
-+ self.labelFontSample.pack(expand=1, fill=Y)
- #frameIndent
- frameIndentSize.pack(side=TOP,fill=X)
- labelSpaceNumTitle.pack(side=TOP,anchor=W,padx=5)
-@@ -174,7 +204,7 @@
- text=' Highlighting Theme ')
- #frameCustom
- self.textHighlightSample=Text(frameCustom,relief=SOLID,borderwidth=1,
-- font=('courier',12,''),cursor='hand2',width=21,height=10,
-+ font=('courier',12,''), cursor='hand2', width=21, height=11,
- takefocus=FALSE,highlightthickness=0,wrap=NONE)
- text=self.textHighlightSample
- text.bind('<Double-Button-1>',lambda e: 'break')
-@@ -197,12 +227,15 @@
- lambda event,elem=element: event.widget.winfo_toplevel()
- .highlightTarget.set(elem))
- text.config(state=DISABLED)
-- self.frameColourSet=Frame(frameCustom,relief=SOLID,borderwidth=1)
-+
-+ self.frameColourSet=Frame(frameCustom, relief=SOLID, borderwidth=1)
-+ self.style(self.frameColourSet, 'Color.TFrame')
-+
- frameFgBg=Frame(frameCustom)
- buttonSetColour=Button(self.frameColourSet,text='Choose Colour for :',
-- command=self.GetColour,highlightthickness=0)
-+ command=self.GetColour) # XXX
- self.optMenuHighlightTarget=DynOptionMenu(self.frameColourSet,
-- self.highlightTarget,None,highlightthickness=0)#,command=self.SetHighlightTargetBinding
-+ self.highlightTarget, None) # XXX
- self.radioFg=Radiobutton(frameFgBg,variable=self.fgHilite,
- value=1,text='Foreground',command=self.SetColourSampleBinding)
- self.radioBg=Radiobutton(frameFgBg,variable=self.fgHilite,
-@@ -275,8 +308,11 @@
- self.buttonNewKeys=Button(frameCustom,text='Get New Keys for Selection',
- command=self.GetNewKeys,state=DISABLED)
- #frameKeySets
-- frames = [Frame(frameKeySets, padx=2, pady=2, borderwidth=0)
-- for i in range(2)]
-+ frames = []
-+ for i in range(2):
-+ f = Frame(frameKeySets, borderwidth=0)
-+ self.style(f, 'S2.TFrame')
-+ frames.append(f)
- 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,
-@@ -748,14 +784,14 @@
-
- def GetColour(self):
- target=self.highlightTarget.get()
-- prevColour=self.frameColourSet.cget('bg')
-+ prevColour = self.ttkstyle.configure('Color.TFrame', 'background')
- rgbTuplet, colourString = tkColorChooser.askcolor(parent=self,
- title='Pick new colour for : '+target,initialcolor=prevColour)
- if colourString and (colourString!=prevColour):
- #user didn't cancel, and they chose a new colour
- 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.')
-+ 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
- return
-@@ -767,7 +803,7 @@
-
- def OnNewColourSet(self):
- newColour=self.colour.get()
-- self.frameColourSet.config(bg=newColour)#set sample
-+ self.ttkstyle.configure('Color.TFrame', background=newColour)
- if self.fgHilite.get(): plane='foreground'
- else: plane='background'
- sampleElement=self.themeElements[self.highlightTarget.get()][0]
-@@ -777,6 +813,7 @@
- self.AddChangedItem('highlight',theme,themeElement,newColour)
-
- def GetNewThemeName(self,message):
-+ # XXX idle bug here
- usedNames=(idleConf.GetSectionList('user','highlight')+
- idleConf.GetSectionList('default','highlight'))
- newTheme=GetCfgSectionNameDialog(self,'New Custom Theme',
-@@ -846,7 +883,7 @@
- if self.fgHilite.get(): plane='foreground'
- else: plane='background'
- colour=self.textHighlightSample.tag_cget(tag,plane)
-- self.frameColourSet.config(bg=colour)
-+ self.ttkstyle.configure('Color.TFrame', background=colour)
-
- def PaintThemeSample(self):
- if self.themeIsBuiltin.get(): #a default theme
-Index: Lib/idlelib/ReplaceDialog.py
-===================================================================
---- Lib/idlelib/ReplaceDialog.py (revision 63916)
-+++ Lib/idlelib/ReplaceDialog.py (working copy)
-@@ -11,9 +11,12 @@
- dialog.open(text)
-
- class ReplaceDialog(SearchDialogBase):
--
- title = "Replace Dialog"
- icon = "Replace"
-+ bottom_btns = [("Find", 'find_it'),
-+ ("Replace", 'replace_it'),
-+ ("Replace+Find", 'default_command', 1),
-+ ("Replace All", 'replace_all')]
-
- def __init__(self, root, engine):
- SearchDialogBase.__init__(self, root, engine)
-@@ -36,14 +39,10 @@
-
- def create_entries(self):
- SearchDialogBase.create_entries(self)
-- self.replent = self.make_entry("Replace with:", self.replvar)
-+ self.replent = self.make_entry("Replace with", self.replvar)
-
- def create_command_buttons(self):
- SearchDialogBase.create_command_buttons(self)
-- self.make_button("Find", self.find_it)
-- self.make_button("Replace", self.replace_it)
-- self.make_button("Replace+Find", self.default_command, 1)
-- self.make_button("Replace All", self.replace_all)
-
- def find_it(self, event=None):
- self.do_find(0)
-Index: Lib/idlelib/tabbedpages.py
-===================================================================
---- Lib/idlelib/tabbedpages.py (revision 63916)
-+++ Lib/idlelib/tabbedpages.py (working copy)
-@@ -1,490 +1,4 @@
--"""An implementation of tabbed pages using only standard Tkinter.
--
--Originally developed for use in IDLE. Based on tabpage.py.
--
--Classes exported:
--TabbedPageSet -- A Tkinter implementation of a tabbed-page widget.
--TabSet -- A widget containing tabs (buttons) in one or more rows.
--
--"""
--from Tkinter import *
--
--class InvalidNameError(Exception): pass
--class AlreadyExistsError(Exception): pass
--
--
--class TabSet(Frame):
-- """A widget containing tabs (buttons) in one or more rows.
--
-- Only one tab may be selected at a time.
--
-- """
-- def __init__(self, page_set, select_command,
-- tabs=None, n_rows=1, max_tabs_per_row=5,
-- expand_tabs=False, **kw):
-- """Constructor arguments:
--
-- select_command -- A callable which will be called when a tab is
-- selected. It is called with the name of the selected tab as an
-- argument.
--
-- tabs -- A list of strings, the names of the tabs. Should be specified in
-- the desired tab order. The first tab will be the default and first
-- active tab. If tabs is None or empty, the TabSet will be initialized
-- empty.
--
-- n_rows -- Number of rows of tabs to be shown. If n_rows <= 0 or is
-- None, then the number of rows will be decided by TabSet. See
-- _arrange_tabs() for details.
--
-- max_tabs_per_row -- Used for deciding how many rows of tabs are needed,
-- when the number of rows is not constant. See _arrange_tabs() for
-- details.
--
-- """
-- Frame.__init__(self, page_set, **kw)
-- self.select_command = select_command
-- self.n_rows = n_rows
-- self.max_tabs_per_row = max_tabs_per_row
-- self.expand_tabs = expand_tabs
-- self.page_set = page_set
--
-- self._tabs = {}
-- self._tab2row = {}
-- if tabs:
-- self._tab_names = list(tabs)
-- else:
-- self._tab_names = []
-- self._selected_tab = None
-- self._tab_rows = []
--
-- self.padding_frame = Frame(self, height=2,
-- borderwidth=0, relief=FLAT,
-- background=self.cget('background'))
-- self.padding_frame.pack(side=TOP, fill=X, expand=False)
--
-- self._arrange_tabs()
--
-- def add_tab(self, tab_name):
-- """Add a new tab with the name given in tab_name."""
-- if not tab_name:
-- raise InvalidNameError("Invalid Tab name: '%s'" % tab_name)
-- if tab_name in self._tab_names:
-- raise AlreadyExistsError("Tab named '%s' already exists" %tab_name)
--
-- self._tab_names.append(tab_name)
-- self._arrange_tabs()
--
-- def remove_tab(self, tab_name):
-- """Remove the tab named <tab_name>"""
-- if not tab_name in self._tab_names:
-- raise KeyError("No such Tab: '%s" % page_name)
--
-- self._tab_names.remove(tab_name)
-- self._arrange_tabs()
--
-- def set_selected_tab(self, tab_name):
-- """Show the tab named <tab_name> as the selected one"""
-- if tab_name == self._selected_tab:
-- return
-- if tab_name is not None and tab_name not in self._tabs:
-- raise KeyError("No such Tab: '%s" % page_name)
--
-- # deselect the current selected tab
-- if self._selected_tab is not None:
-- self._tabs[self._selected_tab].set_normal()
-- self._selected_tab = None
--
-- if tab_name is not None:
-- # activate the tab named tab_name
-- self._selected_tab = tab_name
-- tab = self._tabs[tab_name]
-- tab.set_selected()
-- # move the tab row with the selected tab to the bottom
-- tab_row = self._tab2row[tab]
-- tab_row.pack_forget()
-- tab_row.pack(side=TOP, fill=X, expand=0)
--
-- def _add_tab_row(self, tab_names, expand_tabs):
-- if not tab_names:
-- return
--
-- tab_row = Frame(self)
-- tab_row.pack(side=TOP, fill=X, expand=0)
-- self._tab_rows.append(tab_row)
--
-- for tab_name in tab_names:
-- tab = TabSet.TabButton(tab_name, self.select_command,
-- tab_row, self)
-- if expand_tabs:
-- tab.pack(side=LEFT, fill=X, expand=True)
-- else:
-- tab.pack(side=LEFT)
-- self._tabs[tab_name] = tab
-- self._tab2row[tab] = tab_row
--
-- # tab is the last one created in the above loop
-- tab.is_last_in_row = True
--
-- def _reset_tab_rows(self):
-- while self._tab_rows:
-- tab_row = self._tab_rows.pop()
-- tab_row.destroy()
-- self._tab2row = {}
--
-- def _arrange_tabs(self):
-- """
-- Arrange the tabs in rows, in the order in which they were added.
--
-- If n_rows >= 1, this will be the number of rows used. Otherwise the
-- number of rows will be calculated according to the number of tabs and
-- max_tabs_per_row. In this case, the number of rows may change when
-- adding/removing tabs.
--
-- """
-- # remove all tabs and rows
-- for tab_name in self._tabs.keys():
-- self._tabs.pop(tab_name).destroy()
-- self._reset_tab_rows()
--
-- if not self._tab_names:
-- return
--
-- if self.n_rows is not None and self.n_rows > 0:
-- n_rows = self.n_rows
-- else:
-- # calculate the required number of rows
-- n_rows = (len(self._tab_names) - 1) // self.max_tabs_per_row + 1
--
-- # not expanding the tabs with more than one row is very ugly
-- expand_tabs = self.expand_tabs or n_rows > 1
-- i = 0 # index in self._tab_names
-- for row_index in xrange(n_rows):
-- # calculate required number of tabs in this row
-- n_tabs = (len(self._tab_names) - i - 1) // (n_rows - row_index) + 1
-- tab_names = self._tab_names[i:i + n_tabs]
-- i += n_tabs
-- self._add_tab_row(tab_names, expand_tabs)
--
-- # re-select selected tab so it is properly displayed
-- selected = self._selected_tab
-- self.set_selected_tab(None)
-- if selected in self._tab_names:
-- self.set_selected_tab(selected)
--
-- class TabButton(Frame):
-- """A simple tab-like widget."""
--
-- bw = 2 # borderwidth
--
-- def __init__(self, name, select_command, tab_row, tab_set):
-- """Constructor arguments:
--
-- name -- The tab's name, which will appear in its button.
--
-- select_command -- The command to be called upon selection of the
-- tab. It is called with the tab's name as an argument.
--
-- """
-- Frame.__init__(self, tab_row, borderwidth=self.bw, relief=RAISED)
--
-- self.name = name
-- self.select_command = select_command
-- self.tab_set = tab_set
-- self.is_last_in_row = False
--
-- self.button = Radiobutton(
-- self, text=name, command=self._select_event,
-- padx=5, pady=1, takefocus=FALSE, indicatoron=FALSE,
-- highlightthickness=0, selectcolor='', borderwidth=0)
-- self.button.pack(side=LEFT, fill=X, expand=True)
--
-- self._init_masks()
-- self.set_normal()
--
-- def _select_event(self, *args):
-- """Event handler for tab selection.
--
-- With TabbedPageSet, this calls TabbedPageSet.change_page, so that
-- selecting a tab changes the page.
--
-- Note that this does -not- call set_selected -- it will be called by
-- TabSet.set_selected_tab, which should be called when whatever the
-- tabs are related to changes.
--
-- """
-- self.select_command(self.name)
-- return
--
-- def set_selected(self):
-- """Assume selected look"""
-- self._place_masks(selected=True)
--
-- def set_normal(self):
-- """Assume normal look"""
-- self._place_masks(selected=False)
--
-- def _init_masks(self):
-- page_set = self.tab_set.page_set
-- background = page_set.pages_frame.cget('background')
-- # mask replaces the middle of the border with the background color
-- self.mask = Frame(page_set, borderwidth=0, relief=FLAT,
-- background=background)
-- # mskl replaces the bottom-left corner of the border with a normal
-- # left border
-- self.mskl = Frame(page_set, borderwidth=0, relief=FLAT,
-- background=background)
-- self.mskl.ml = Frame(self.mskl, borderwidth=self.bw,
-- relief=RAISED)
-- self.mskl.ml.place(x=0, y=-self.bw,
-- width=2*self.bw, height=self.bw*4)
-- # mskr replaces the bottom-right corner of the border with a normal
-- # right border
-- self.mskr = Frame(page_set, borderwidth=0, relief=FLAT,
-- background=background)
-- self.mskr.mr = Frame(self.mskr, borderwidth=self.bw,
-- relief=RAISED)
--
-- def _place_masks(self, selected=False):
-- height = self.bw
-- if selected:
-- height += self.bw
--
-- self.mask.place(in_=self,
-- relx=0.0, x=0,
-- rely=1.0, y=0,
-- relwidth=1.0, width=0,
-- relheight=0.0, height=height)
--
-- self.mskl.place(in_=self,
-- relx=0.0, x=-self.bw,
-- rely=1.0, y=0,
-- relwidth=0.0, width=self.bw,
-- relheight=0.0, height=height)
--
-- page_set = self.tab_set.page_set
-- if selected and ((not self.is_last_in_row) or
-- (self.winfo_rootx() + self.winfo_width() <
-- page_set.winfo_rootx() + page_set.winfo_width())
-- ):
-- # for a selected tab, if its rightmost edge isn't on the
-- # rightmost edge of the page set, the right mask should be one
-- # borderwidth shorter (vertically)
-- height -= self.bw
--
-- self.mskr.place(in_=self,
-- relx=1.0, x=0,
-- rely=1.0, y=0,
-- relwidth=0.0, width=self.bw,
-- relheight=0.0, height=height)
--
-- self.mskr.mr.place(x=-self.bw, y=-self.bw,
-- width=2*self.bw, height=height + self.bw*2)
--
-- # finally, lower the tab set so that all of the frames we just
-- # placed hide it
-- self.tab_set.lower()
--
--class TabbedPageSet(Frame):
-- """A Tkinter tabbed-pane widget.
--
-- Constains set of 'pages' (or 'panes') with tabs above for selecting which
-- page is displayed. Only one page will be displayed at a time.
--
-- Pages may be accessed through the 'pages' attribute, which is a dictionary
-- of pages, using the name given as the key. A page is an instance of a
-- subclass of Tk's Frame widget.
--
-- The page widgets will be created (and destroyed when required) by the
-- TabbedPageSet. Do not call the page's pack/place/grid/destroy methods.
--
-- Pages may be added or removed at any time using the add_page() and
-- remove_page() methods.
--
-- """
-- class Page(object):
-- """Abstract base class for TabbedPageSet's pages.
--
-- Subclasses must override the _show() and _hide() methods.
--
-- """
-- uses_grid = False
--
-- def __init__(self, page_set):
-- self.frame = Frame(page_set, borderwidth=2, relief=RAISED)
--
-- def _show(self):
-- raise NotImplementedError
--
-- def _hide(self):
-- raise NotImplementedError
--
-- class PageRemove(Page):
-- """Page class using the grid placement manager's "remove" mechanism."""
-- uses_grid = True
--
-- def _show(self):
-- self.frame.grid(row=0, column=0, sticky=NSEW)
--
-- def _hide(self):
-- self.frame.grid_remove()
--
-- class PageLift(Page):
-- """Page class using the grid placement manager's "lift" mechanism."""
-- uses_grid = True
--
-- def __init__(self, page_set):
-- super(TabbedPageSet.PageLift, self).__init__(page_set)
-- self.frame.grid(row=0, column=0, sticky=NSEW)
-- self.frame.lower()
--
-- def _show(self):
-- self.frame.lift()
--
-- def _hide(self):
-- self.frame.lower()
--
-- class PagePackForget(Page):
-- """Page class using the pack placement manager's "forget" mechanism."""
-- def _show(self):
-- self.frame.pack(fill=BOTH, expand=True)
--
-- def _hide(self):
-- self.frame.pack_forget()
--
-- def __init__(self, parent, page_names=None, page_class=PageLift,
-- n_rows=1, max_tabs_per_row=5, expand_tabs=False,
-- **kw):
-- """Constructor arguments:
--
-- page_names -- A list of strings, each will be the dictionary key to a
-- page's widget, and the name displayed on the page's tab. Should be
-- specified in the desired page order. The first page will be the default
-- and first active page. If page_names is None or empty, the
-- TabbedPageSet will be initialized empty.
--
-- n_rows, max_tabs_per_row -- Parameters for the TabSet which will
-- manage the tabs. See TabSet's docs for details.
--
-- page_class -- Pages can be shown/hidden using three mechanisms:
--
-- * PageLift - All pages will be rendered one on top of the other. When
-- a page is selected, it will be brought to the top, thus hiding all
-- other pages. Using this method, the TabbedPageSet will not be resized
-- when pages are switched. (It may still be resized when pages are
-- added/removed.)
--
-- * PageRemove - When a page is selected, the currently showing page is
-- hidden, and the new page shown in its place. Using this method, the
-- TabbedPageSet may resize when pages are changed.
--
-- * PagePackForget - This mechanism uses the pack placement manager.
-- When a page is shown it is packed, and when it is hidden it is
-- unpacked (i.e. pack_forget). This mechanism may also cause the
-- TabbedPageSet to resize when the page is changed.
--
-- """
-- Frame.__init__(self, parent, **kw)
--
-- self.page_class = page_class
-- self.pages = {}
-- self._pages_order = []
-- self._current_page = None
-- self._default_page = None
--
-- self.columnconfigure(0, weight=1)
-- self.rowconfigure(1, weight=1)
--
-- self.pages_frame = Frame(self)
-- self.pages_frame.grid(row=1, column=0, sticky=NSEW)
-- if self.page_class.uses_grid:
-- self.pages_frame.columnconfigure(0, weight=1)
-- self.pages_frame.rowconfigure(0, weight=1)
--
-- # the order of the following commands is important
-- self._tab_set = TabSet(self, self.change_page, n_rows=n_rows,
-- max_tabs_per_row=max_tabs_per_row,
-- expand_tabs=expand_tabs)
-- if page_names:
-- for name in page_names:
-- self.add_page(name)
-- self._tab_set.grid(row=0, column=0, sticky=NSEW)
--
-- self.change_page(self._default_page)
--
-- def add_page(self, page_name):
-- """Add a new page with the name given in page_name."""
-- if not page_name:
-- raise InvalidNameError("Invalid TabPage name: '%s'" % page_name)
-- if page_name in self.pages:
-- raise AlreadyExistsError(
-- "TabPage named '%s' already exists" % page_name)
--
-- self.pages[page_name] = self.page_class(self.pages_frame)
-- self._pages_order.append(page_name)
-- self._tab_set.add_tab(page_name)
--
-- if len(self.pages) == 1: # adding first page
-- self._default_page = page_name
-- self.change_page(page_name)
--
-- def remove_page(self, page_name):
-- """Destroy the page whose name is given in page_name."""
-- if not page_name in self.pages:
-- raise KeyError("No such TabPage: '%s" % page_name)
--
-- self._pages_order.remove(page_name)
--
-- # handle removing last remaining, default, or currently shown page
-- if len(self._pages_order) > 0:
-- if page_name == self._default_page:
-- # set a new default page
-- self._default_page = self._pages_order[0]
-- else:
-- self._default_page = None
--
-- if page_name == self._current_page:
-- self.change_page(self._default_page)
--
-- self._tab_set.remove_tab(page_name)
-- page = self.pages.pop(page_name)
-- page.frame.destroy()
--
-- def change_page(self, page_name):
-- """Show the page whose name is given in page_name."""
-- if self._current_page == page_name:
-- return
-- if page_name is not None and page_name not in self.pages:
-- raise KeyError("No such TabPage: '%s'" % page_name)
--
-- if self._current_page is not None:
-- self.pages[self._current_page]._hide()
-- self._current_page = None
--
-- if page_name is not None:
-- self._current_page = page_name
-- self.pages[page_name]._show()
--
-- self._tab_set.set_selected_tab(page_name)
--
--if __name__ == '__main__':
-- # test dialog
-- root=Tk()
-- tabPage=TabbedPageSet(root, page_names=['Foobar','Baz'], n_rows=0,
-- expand_tabs=False,
-- )
-- tabPage.pack(side=TOP, expand=TRUE, fill=BOTH)
-- Label(tabPage.pages['Foobar'].frame, text='Foo', pady=20).pack()
-- Label(tabPage.pages['Foobar'].frame, text='Bar', pady=20).pack()
-- Label(tabPage.pages['Baz'].frame, text='Baz').pack()
-- entryPgName=Entry(root)
-- buttonAdd=Button(root, text='Add Page',
-- command=lambda:tabPage.add_page(entryPgName.get()))
-- buttonRemove=Button(root, text='Remove Page',
-- command=lambda:tabPage.remove_page(entryPgName.get()))
-- labelPgName=Label(root, text='name of page to add/remove:')
-- buttonAdd.pack(padx=5, pady=5)
-- buttonRemove.pack(padx=5, pady=5)
-- labelPgName.pack(padx=5)
-- entryPgName.pack(padx=5)
-- root.mainloop()
-+try:
-+ from idlelib.tabbedpages_new import TabbedPageSet
-+except ImportError:
-+ from idlelib.tabbedpages_old import TabbedPageSet
-Index: Lib/idlelib/keybindingDialog.py
-===================================================================
---- Lib/idlelib/keybindingDialog.py (revision 63916)
-+++ Lib/idlelib/keybindingDialog.py (working copy)
-@@ -5,6 +5,12 @@
- import tkMessageBox
- import string
-
-+from idlelib.configHandler import idleConf
-+
-+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
-+if TTK:
-+ from ttk import *
-+
- class GetKeysDialog(Toplevel):
- def __init__(self,parent,title,action,currentKeySequences):
- """
-@@ -124,6 +130,9 @@
- "separated by a space, eg., <Alt-v> <Meta-v>." )
- labelHelpAdvanced.grid(row=0,column=0,sticky=NSEW)
-
-+ if TTK:
-+ frameButtons['style'] = 'RootColor.TFrame'
-+
- def SetModifiersForPlatform(self):
- """Determine list of names of key modifiers for this platform.
-
-Index: Lib/idlelib/configHelpSourceEdit.py
-===================================================================
---- Lib/idlelib/configHelpSourceEdit.py (revision 63916)
-+++ Lib/idlelib/configHelpSourceEdit.py (working copy)
-@@ -6,7 +6,12 @@
- from Tkinter import *
- import tkMessageBox
- import tkFileDialog
-+from idlelib.configHandler import idleConf
-
-+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
-+if TTK:
-+ from ttk import *
-+
- class GetHelpSourceDialog(Toplevel):
- def __init__(self, parent, title, menuItem='', filePath=''):
- """Get menu entry and url/ local file location for Additional Help
-@@ -25,6 +30,7 @@
- self.protocol("WM_DELETE_WINDOW", self.Cancel)
- self.parent = parent
- self.result = None
-+
- self.CreateWidgets()
- self.menu.set(menuItem)
- self.path.set(filePath)
-@@ -68,11 +74,14 @@
- frameButtons.pack(side=BOTTOM, fill=X)
- self.buttonOk = Button(frameButtons, text='OK',
- width=8, default=ACTIVE, command=self.Ok)
-- self.buttonOk.grid(row=0, column=0, padx=5,pady=5)
-+ self.buttonOk.grid(row=0, column=0, pady=5)
- self.buttonCancel = Button(frameButtons, text='Cancel',
- width=8, command=self.Cancel)
- self.buttonCancel.grid(row=0, column=1, padx=5, pady=5)
-
-+ if TTK:
-+ frameButtons['style'] = 'RootColor.TFrame'
-+
- def browseFile(self):
- filetypes = [
- ("HTML Files", "*.htm *.html", "TEXT"),
-Index: Lib/idlelib/GrepDialog.py
-===================================================================
---- Lib/idlelib/GrepDialog.py (revision 63916)
-+++ Lib/idlelib/GrepDialog.py (working copy)
-@@ -4,7 +4,11 @@
- from Tkinter import *
- import SearchEngine
- from SearchDialogBase import SearchDialogBase
-+from idlelib.configHandler import idleConf
-
-+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
-+ from ttk import *
-+
- def grep(text, io=None, flist=None):
- root = text._root()
- engine = SearchEngine.get(root)
-@@ -15,10 +19,10 @@
- dialog.open(text, searchphrase, io)
-
- class GrepDialog(SearchDialogBase):
--
- title = "Find in Files Dialog"
- icon = "Grep"
- needwrapbutton = 0
-+ bottom_btns = [("Search Files", 'default_command', 1)]
-
- def __init__(self, root, engine, flist):
- SearchDialogBase.__init__(self, root, engine)
-@@ -40,20 +44,18 @@
-
- def create_entries(self):
- SearchDialogBase.create_entries(self)
-- self.globent = self.make_entry("In files:", self.globvar)
-+ self.globent = self.make_entry("In files", self.globvar)
-
- def create_other_buttons(self):
- f = self.make_frame()
-
-- btn = Checkbutton(f, anchor="w",
-- variable=self.recvar,
-+ btn = Checkbutton(f, variable=self.recvar,
- text="Recurse down subdirectories")
- btn.pack(side="top", fill="both")
-- btn.select()
-+ btn.invoke()
-
- def create_command_buttons(self):
- SearchDialogBase.create_command_buttons(self)
-- self.make_button("Search Files", self.default_command, 1)
-
- def default_command(self, event=None):
- prog = self.engine.getprog()
-@@ -126,8 +128,3 @@
- for subdir in subdirs:
- list.extend(self.findfiles(subdir, base, rec))
- return list
--
-- def close(self, event=None):
-- if self.top:
-- self.top.grab_release()
-- self.top.withdraw()
-Index: Lib/idlelib/EditorWindow.py
-===================================================================
---- Lib/idlelib/EditorWindow.py (revision 63916)
-+++ Lib/idlelib/EditorWindow.py (working copy)
-@@ -19,6 +19,10 @@
- import aboutDialog, textView, configDialog
- import macosxSupport
-
-+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
-+ from ttk import Scrollbar
-+
-+
- # The default tab setting for a Text widget, in average-width characters.
- TK_TABWIDTH_DEFAULT = 8
-
-@@ -365,7 +369,7 @@
- self.menudict = menudict = {}
- for name, label in self.menu_specs:
- underline, label = prepstr(label)
-- menudict[name] = menu = Menu(mbar, name=name)
-+ menudict[name] = menu = Menu(mbar, name=name, tearoff=0)
- mbar.add_cascade(label=label, menu=menu, underline=underline)
-
- if sys.platform == 'darwin' and '.framework' in sys.executable:
-Index: Lib/idlelib/aboutDialog.py
-===================================================================
---- Lib/idlelib/aboutDialog.py (revision 63916)
-+++ Lib/idlelib/aboutDialog.py (working copy)
-@@ -1,13 +1,17 @@
--"""About Dialog for IDLE
--
--"""
--
-+"""About Dialog for IDLE"""
- from Tkinter import *
- import os
- import os.path
- import textView
- import idlever
-
-+from idlelib.stylist import PoorManStyle
-+from idlelib.configHandler import idleConf
-+
-+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
-+if TTK:
-+ from ttk import *
-+
- class AboutDialog(Toplevel):
- """Modal about dialog for idle
-
-@@ -15,10 +19,13 @@
- def __init__(self,parent,title):
- Toplevel.__init__(self, parent)
- self.configure(borderwidth=5)
-+
- self.geometry("+%d+%d" % (parent.winfo_rootx()+30,
- parent.winfo_rooty()+30))
- self.bg = "#707070"
- self.fg = "#ffffff"
-+
-+ self.SetupStyles()
- self.CreateWidgets()
- self.resizable(height=FALSE, width=FALSE)
- self.title(title)
-@@ -31,40 +38,44 @@
- self.bind('<Escape>',self.Ok) #dismiss dialog
- self.wait_window()
-
-+ def SetupStyles(self):
-+ if TTK:
-+ style = Style(self.master)
-+ style.configure('Color.TLabel', foreground=self.fg,
-+ background=self.bg)
-+ style.configure('Color.TFrame', background=self.bg)
-+ self.ttkstyle = style
-+ self.style = lambda w, style: w.configure(style=style)
-+ else:
-+ self.style = PoorManStyle(self,
-+ styles={'Color.TLabel': {'fg': self.fg, 'bg': self.bg},
-+ 'Color.TFrame': {'bg': self.bg}}).style_it
-+
- def CreateWidgets(self):
- frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
- frameButtons = Frame(self)
-- frameButtons.pack(side=BOTTOM, fill=X)
-+ frameButtons.pack(side=BOTTOM, pady=3)
- frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
-- self.buttonOk = Button(frameButtons, text='Close',
-- command=self.Ok)
-- self.buttonOk.pack(padx=5, pady=5)
-- #self.picture = Image('photo', data=self.pictureData)
-- frameBg = Frame(frameMain, bg=self.bg)
-+ self.buttonOk = Button(frameButtons, text='Close', command=self.Ok)
-+ self.buttonOk.pack()
-+ frameBg = Frame(frameMain)
- frameBg.pack(expand=TRUE, fill=BOTH)
-- labelTitle = Label(frameBg, text='IDLE', fg=self.fg, bg=self.bg,
-- font=('courier', 24, 'bold'))
-+ labelTitle = Label(frameBg, text='IDLE', font=('courier', 24, 'bold'))
- labelTitle.grid(row=0, column=0, sticky=W, padx=10, pady=10)
-- #labelPicture = Label(frameBg, text='[picture]')
-- #image=self.picture, bg=self.bg)
-- #labelPicture.grid(row=1, column=1, sticky=W, rowspan=2,
-- # padx=0, pady=3)
- byline = "Python's Integrated DeveLopment Environment" + 5*'\n'
-- labelDesc = Label(frameBg, text=byline, justify=LEFT,
-- fg=self.fg, bg=self.bg)
-+ labelDesc = Label(frameBg, text=byline, justify=LEFT)
- labelDesc.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
- labelEmail = Label(frameBg, text='email: idle-dev at python.org',
-- justify=LEFT, fg=self.fg, bg=self.bg)
-+ justify=LEFT)
- labelEmail.grid(row=6, column=0, columnspan=2,
- sticky=W, padx=10, pady=0)
- labelWWW = Label(frameBg, text='www: http://www.python.org/idle/',
-- justify=LEFT, fg=self.fg, bg=self.bg)
-+ justify=LEFT)
- labelWWW.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
-- Frame(frameBg, borderwidth=1, relief=SUNKEN,
-- height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
-- columnspan=3, padx=5, pady=5)
-+ fbg = Frame(frameBg, borderwidth=1, relief=SUNKEN, height=2)
-+ fbg.grid(row=8, column=0, sticky=EW, columnspan=3, padx=5, pady=5)
- labelPythonVer = Label(frameBg, text='Python version: ' + \
-- sys.version.split()[0], fg=self.fg, bg=self.bg)
-+ sys.version.split()[0])
- labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0)
- # handle weird tk version num in windoze python >= 1.6 (?!?)
- tkVer = repr(TkVersion).split('.')
-@@ -72,44 +83,50 @@
- if tkVer[len(tkVer)-1] == '':
- tkVer[len(tkVer)-1] = '0'
- tkVer = '.'.join(tkVer)
-- labelTkVer = Label(frameBg, text='Tk version: '+
-- tkVer, fg=self.fg, bg=self.bg)
-+ labelTkVer = Label(frameBg, text='Tk version: '+ tkVer)
- labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
-- py_button_f = Frame(frameBg, bg=self.bg)
-+ py_button_f = Frame(frameBg)
- py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW)
- buttonLicense = Button(py_button_f, text='License', width=8,
-- highlightbackground=self.bg,
- command=self.ShowLicense)
- buttonLicense.pack(side=LEFT, padx=10, pady=10)
- buttonCopyright = Button(py_button_f, text='Copyright', width=8,
-- highlightbackground=self.bg,
- command=self.ShowCopyright)
- buttonCopyright.pack(side=LEFT, padx=10, pady=10)
- buttonCredits = Button(py_button_f, text='Credits', width=8,
-- highlightbackground=self.bg,
- command=self.ShowPythonCredits)
- buttonCredits.pack(side=LEFT, padx=10, pady=10)
-- Frame(frameBg, borderwidth=1, relief=SUNKEN,
-- height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
-- columnspan=3, padx=5, pady=5)
-- idle_v = Label(frameBg, text='IDLE version: ' + idlever.IDLE_VERSION,
-- fg=self.fg, bg=self.bg)
-+ fbg2 = Frame(frameBg, borderwidth=1, relief=SUNKEN, height=2)
-+ fbg2.grid(row=11, column=0, sticky=EW, columnspan=3, padx=5, pady=5)
-+ idle_v = Label(frameBg, text='IDLE version: ' + idlever.IDLE_VERSION)
- idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0)
-- idle_button_f = Frame(frameBg, bg=self.bg)
-+ idle_button_f = Frame(frameBg)
- idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW)
- idle_about_b = Button(idle_button_f, text='README', width=8,
-- highlightbackground=self.bg,
- command=self.ShowIDLEAbout)
- idle_about_b.pack(side=LEFT, padx=10, pady=10)
- idle_news_b = Button(idle_button_f, text='NEWS', width=8,
-- highlightbackground=self.bg,
- command=self.ShowIDLENEWS)
- idle_news_b.pack(side=LEFT, padx=10, pady=10)
- idle_credits_b = Button(idle_button_f, text='Credits', width=8,
-- highlightbackground=self.bg,
- command=self.ShowIDLECredits)
- idle_credits_b.pack(side=LEFT, padx=10, pady=10)
-
-+ s = self.style
-+ s(frameButtons, 'RootColor.TFrame')
-+ s(frameBg, 'Color.TFrame')
-+ s(labelTitle, 'Color.TLabel')
-+ s(labelDesc, 'Color.TLabel')
-+ s(labelEmail, 'Color.TLabel')
-+ s(labelWWW, 'Color.TLabel')
-+ s(fbg, 'Color.TFrame')
-+ s(labelPythonVer, 'Color.TLabel')
-+ s(labelTkVer, 'Color.TLabel')
-+ s(py_button_f, 'Color.TFrame')
-+ s(fbg2, 'Color.TFrame')
-+ s(idle_v, 'Color.TLabel')
-+ s(idle_button_f, 'Color.TFrame')
-+
- def ShowLicense(self):
- self.display_printer_text('About - License', license)
-
-Index: Lib/idlelib/config-main.def
-===================================================================
---- Lib/idlelib/config-main.def (revision 63916)
-+++ Lib/idlelib/config-main.def (working copy)
-@@ -49,6 +49,7 @@
- print-command-posix=lpr %s
- print-command-win=start /min notepad /p %s
- delete-exitfunc= 1
-+use-ttk=0
-
- [EditorWindow]
- width= 80
-Index: Lib/idlelib/IOBinding.py
-===================================================================
---- Lib/idlelib/IOBinding.py (revision 63916)
-+++ Lib/idlelib/IOBinding.py (working copy)
-@@ -18,6 +18,9 @@
-
- from configHandler import idleConf
-
-+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
-+ from ttk import *
-+
- try:
- from codecs import BOM_UTF8
- except ImportError:
-Index: Lib/idlelib/ScrolledList.py
-===================================================================
---- Lib/idlelib/ScrolledList.py (revision 63916)
-+++ Lib/idlelib/ScrolledList.py (working copy)
-@@ -1,5 +1,9 @@
- from Tkinter import *
-+from idlelib.configHandler import idleConf
-
-+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
-+ from ttk import *
-+
- class ScrolledList:
-
- default = "(None)"
-Index: Lib/idlelib/textView.py
-===================================================================
---- Lib/idlelib/textView.py (revision 63916)
-+++ Lib/idlelib/textView.py (working copy)
-@@ -1,10 +1,13 @@
--"""Simple text browser for IDLE
-+"""Simple text browser for IDLE"""
-
--"""
--
-+import tkMessageBox
- from Tkinter import *
--import tkMessageBox
-+from idlelib.configHandler import idleConf
-
-+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
-+if TTK:
-+ from ttk import *
-+
- class TextViewer(Toplevel):
- """A simple text viewer dialog for IDLE
-
-@@ -42,17 +45,20 @@
- self.buttonOk = Button(frameButtons, text='Close',
- command=self.Ok, takefocus=FALSE)
- self.scrollbarView = Scrollbar(frameText, orient=VERTICAL,
-- takefocus=FALSE, highlightthickness=0)
-- self.textView = Text(frameText, wrap=WORD, highlightthickness=0,
-- fg=self.fg, bg=self.bg)
-+ takefocus=FALSE)
-+ self.textView = Text(frameText, wrap=WORD, fg=self.fg, bg=self.bg,
-+ highlightthickness=0)
- self.scrollbarView.config(command=self.textView.yview)
- self.textView.config(yscrollcommand=self.scrollbarView.set)
- self.buttonOk.pack()
- self.scrollbarView.pack(side=RIGHT,fill=Y)
- self.textView.pack(side=LEFT,expand=TRUE,fill=BOTH)
-- frameButtons.pack(side=BOTTOM,fill=X)
-+ frameButtons.pack(side=BOTTOM)
- frameText.pack(side=TOP,expand=TRUE,fill=BOTH)
-
-+ if TTK:
-+ frameButtons['style'] = 'RootColor.TFrame'
-+
- def Ok(self, event=None):
- self.destroy()
-
-Index: Lib/idlelib/CallTipWindow.py
-===================================================================
---- Lib/idlelib/CallTipWindow.py (revision 63916)
-+++ Lib/idlelib/CallTipWindow.py (working copy)
-@@ -5,7 +5,11 @@
-
- """
- from Tkinter import *
-+from idlelib.configHandler import idleConf
-
-+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
-+ from ttk import *
-+
- HIDE_VIRTUAL_EVENT_NAME = "<<calltipwindow-hide>>"
- HIDE_SEQUENCES = ("<Key-Escape>", "<FocusOut>")
- CHECKHIDE_VIRTUAL_EVENT_NAME = "<<calltipwindow-checkhide>>"
-@@ -163,6 +167,8 @@
- def calltip_hide(self, event):
- self.calltip.hidetip()
-
-+# XXX Bugged test
-+
- def main():
- # Test code
- c=container()
-Index: Lib/idlelib/SearchDialogBase.py
-===================================================================
---- Lib/idlelib/SearchDialogBase.py (revision 63916)
-+++ Lib/idlelib/SearchDialogBase.py (working copy)
-@@ -1,35 +1,40 @@
- from Tkinter import *
-+from idlelib.configHandler import idleConf
-
-+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
-+ from ttk import *
-+
- class SearchDialogBase:
-
- title = "Search Dialog"
- icon = "Search"
- needwrapbutton = 1
-+ bottom_btns = None
-
- def __init__(self, root, engine):
- self.root = root
- self.engine = engine
-- self.top = None
-+ self.ttop = None
-
- def open(self, text, searchphrase=None):
- self.text = text
-- if not self.top:
-+ if not self.ttop:
- self.create_widgets()
- else:
-- self.top.deiconify()
-- self.top.tkraise()
-+ self.ttop.deiconify()
-+ self.ttop.tkraise()
- if searchphrase:
-- self.ent.delete(0,"end")
-- self.ent.insert("end",searchphrase)
-+ self.ent.delete(0, "end")
-+ self.ent.insert("end", searchphrase)
- self.ent.focus_set()
- self.ent.selection_range(0, "end")
- self.ent.icursor(0)
-- self.top.grab_set()
-+ self.ttop.grab_set()
-
- def close(self, event=None):
-- if self.top:
-- self.top.grab_release()
-- self.top.withdraw()
-+ if self.ttop:
-+ self.ttop.grab_release()
-+ self.ttop.withdraw()
-
- def create_widgets(self):
- top = Toplevel(self.root)
-@@ -38,103 +43,96 @@
- top.protocol("WM_DELETE_WINDOW", self.close)
- top.wm_title(self.title)
- top.wm_iconname(self.icon)
-- self.top = top
-+ top.resizable(height=FALSE,width=FALSE)
-+ self.ttop = top
-+ self.top = Frame(top)
-
- self.row = 0
-- self.top.grid_columnconfigure(0, pad=2, weight=0)
-- self.top.grid_columnconfigure(1, pad=2, minsize=100, weight=100)
-+ self.top.grid(sticky='news')
-
- self.create_entries()
- self.create_option_buttons()
- self.create_other_buttons()
-- return self.create_command_buttons()
-+ self.create_command_buttons()
-
-+
- def make_entry(self, label, var):
- l = Label(self.top, text=label)
-- l.grid(row=self.row, column=0, sticky="nw")
-+ l.grid(row=self.row, column=0, sticky="ne", padx=6, pady=6)
- e = Entry(self.top, textvariable=var, exportselection=0)
-- e.grid(row=self.row, column=1, sticky="nwe")
-+ e.grid(row=self.row, column=1, sticky="nwe", padx=6, pady=6)
- self.row = self.row + 1
- return e
-
- def make_frame(self,labeltext=None):
- if labeltext:
- l = Label(self.top, text=labeltext)
-- l.grid(row=self.row, column=0, sticky="nw")
-+ l.grid(row=self.row, column=0, sticky="ne", padx=6, pady=6)
- f = Frame(self.top)
-- f.grid(row=self.row, column=1, columnspan=1, sticky="nwe")
-+ f.grid(row=self.row, column=1, columnspan=1, sticky="nwe",
-+ padx=6, pady=6 if labeltext else 0)
- self.row = self.row + 1
- return f
-
-- def make_button(self, label, command, isdef=0):
-- b = Button(self.buttonframe,
-- text=label, command=command,
-- default=isdef and "active" or "normal")
-- cols,rows=self.buttonframe.grid_size()
-- b.grid(pady=1,row=rows,column=0,sticky="ew")
-- self.buttonframe.grid(rowspan=rows+1)
-- return b
--
- def create_entries(self):
-- self.ent = self.make_entry("Find:", self.engine.patvar)
-+ self.ent = self.make_entry("Find", self.engine.patvar)
-
- def create_option_buttons(self):
- f = self.make_frame("Options")
-
-- btn = Checkbutton(f, anchor="w",
-- variable=self.engine.revar,
-- text="Regular expression")
-+ btn = Checkbutton(f, variable=self.engine.revar,
-+ text="Regular expression")
- btn.pack(side="left", fill="both")
- if self.engine.isre():
-- btn.select()
-+ btn.invoke()
-
-- btn = Checkbutton(f, anchor="w",
-- variable=self.engine.casevar,
-- text="Match case")
-+ btn = Checkbutton(f, variable=self.engine.casevar, text="Match case")
- btn.pack(side="left", fill="both")
- if self.engine.iscase():
-- btn.select()
-+ btn.invoke()
-
-- btn = Checkbutton(f, anchor="w",
-- variable=self.engine.wordvar,
-- text="Whole word")
-+ btn = Checkbutton(f, variable=self.engine.wordvar, text="Whole word")
- btn.pack(side="left", fill="both")
- if self.engine.isword():
-- btn.select()
-+ btn.invoke()
-
- if self.needwrapbutton:
-- btn = Checkbutton(f, anchor="w",
-- variable=self.engine.wrapvar,
-- text="Wrap around")
-+ btn = Checkbutton(f, variable=self.engine.wrapvar,
-+ text="Wrap around")
- btn.pack(side="left", fill="both")
- if self.engine.iswrap():
-- btn.select()
-+ btn.invoke()
-
- def create_other_buttons(self):
- f = self.make_frame("Direction")
-
-- #lbl = Label(f, text="Direction: ")
-- #lbl.pack(side="left")
--
-- btn = Radiobutton(f, anchor="w",
-- variable=self.engine.backvar, value=1,
-- text="Up")
-- btn.pack(side="left", fill="both")
-+ btn = Radiobutton(f, variable=self.engine.backvar, value=1, text="Up")
-+ btn.pack(side="left")
- if self.engine.isback():
-- btn.select()
-+ btn.invoke()
-
-- btn = Radiobutton(f, anchor="w",
-- variable=self.engine.backvar, value=0,
-- text="Down")
-- btn.pack(side="left", fill="both")
-+ btn = Radiobutton(f, variable=self.engine.backvar, value=0, text="Down")
-+ btn.pack(side="left")
- if not self.engine.isback():
-- btn.select()
-+ btn.invoke()
-
- def create_command_buttons(self):
-- #
-- # place button frame on the right
-- f = self.buttonframe = Frame(self.top)
-- f.grid(row=0,column=2,padx=2,pady=2,ipadx=2,ipady=2)
-+ self.bottom_btns = self.bottom_btns or []
-+ f = Frame(self.top)
-+ f.grid(row=self.row, column=0, columnspan=len(self.bottom_btns) + 1,
-+ pady=6)
-
-- b = self.make_button("close", self.close)
-- b.lower()
-+ column = 0
-+ b = Button(f, text="Close", command=self.close)
-+ b.grid(row=self.row, column=column, padx=6, pady=6)
-+ column += 1
-+
-+ btns = {}
-+ for tbtn in self.bottom_btns:
-+ opts = {'text': tbtn[0], 'command': getattr(self, tbtn[1])}
-+ if len(tbtn) == 3:
-+ opts['default'] = tbtn[2] and 'active' or 'normal'
-+
-+ btns[opts['text']] = Button(f, **opts).grid(row=self.row, padx=6,
-+ pady=6, column=column)
-+ column += 1
-Index: Lib/idlelib/SearchDialog.py
-===================================================================
---- Lib/idlelib/SearchDialog.py (revision 63916)
-+++ Lib/idlelib/SearchDialog.py (working copy)
-@@ -21,10 +21,10 @@
- return _setup(text).find_selection(text)
-
- class SearchDialog(SearchDialogBase):
-+ bottom_btns = [("Find", 'default_command', 1)]
-
- def create_widgets(self):
-- f = SearchDialogBase.create_widgets(self)
-- self.make_button("Find", self.default_command, 1)
-+ SearchDialogBase.create_widgets(self)
-
- def default_command(self, event=None):
- if not self.engine.getprog():
-Index: Lib/idlelib/TreeWidget.py
-===================================================================
---- Lib/idlelib/TreeWidget.py (revision 63916)
-+++ Lib/idlelib/TreeWidget.py (working copy)
-@@ -21,6 +21,12 @@
- import ZoomHeight
- from configHandler import idleConf
-
-+from idlelib.configHandler import idleConf
-+
-+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
-+if TTK:
-+ from ttk import *
-+
- ICONDIR = "Icons"
-
- # Look for Icons subdirectory in the same directory as this module
-@@ -248,7 +254,9 @@
- label = self.label
- except AttributeError:
- # padding carefully selected (on Windows) to match Entry widget:
-- self.label = Label(self.canvas, text=text, bd=0, padx=2, pady=2)
-+ self.label = Label(self.canvas, text=text)
-+ if not TTK:
-+ self.label.configure(bd=0, padx=2, pady=2)
- theme = idleConf.GetOption('main','Theme','name')
- if self.selected:
- self.label.configure(idleConf.GetHighlight(theme, 'hilite'))
-@@ -451,6 +459,8 @@
-
- # Testing functions
-
-+# XXX Can't run these tests
-+
- def test():
- import PyShell
- root = Toplevel(PyShell.root)
-Index: Lib/idlelib/dynOptionMenuWidget.py
-===================================================================
---- Lib/idlelib/dynOptionMenuWidget.py (revision 63916)
-+++ Lib/idlelib/dynOptionMenuWidget.py (working copy)
-@@ -2,34 +2,41 @@
- OptionMenu widget modified to allow dynamic menu reconfiguration
- and setting of highlightthickness
- """
--from Tkinter import OptionMenu
-+from Tkinter import OptionMenu, Menu
- from Tkinter import _setit
- import copy
-
-+from configHandler import idleConf
-+TTK = idleConf.GetOption('main', 'General', 'use-ttk', type='int')
-+if TTK:
-+ from ttk import *
-+
- class DynOptionMenu(OptionMenu):
-- """
-- unlike OptionMenu, our kwargs can include highlightthickness
-- """
-+ """Unlike OptionMenu, our kwargs can include highlightthickness"""
- def __init__(self, master, variable, value, *values, **kwargs):
- #get a copy of kwargs before OptionMenu.__init__ munges them
- kwargsCopy=copy.copy(kwargs)
- if 'highlightthickness' in kwargs.keys():
- del(kwargs['highlightthickness'])
-+ self.command=kwargs.get('command')
-+ self.variable=variable
-+
- OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
- self.config(highlightthickness=kwargsCopy.get('highlightthickness'))
-- #self.menu=self['menu']
-- self.variable=variable
-- self.command=kwargs.get('command')
-
-- def SetMenu(self,valueList,value=None):
-+ def SetMenu(self, valueList, value=None):
- """
- clear and reload the menu with a new set of options.
- valueList - list of new options
- value - initial value to set the optionmenu's menubutton to
- """
-- self['menu'].delete(0,'end')
-- for item in valueList:
-- self['menu'].add_command(label=item,
-+ if TTK:
-+ self.set_menu(value, *valueList)
-+ else:
-+ menu = self['menu']
-+ menu.delete(0,'end')
-+ for item in valueList:
-+ menu.add_command(label=item,
- command=_setit(self.variable,item,self.command))
-- if value:
-- self.variable.set(value)
-+ if value:
-+ self.variable.set(value)
-Index: Lib/idlelib/MultiStatusBar.py
-===================================================================
---- Lib/idlelib/MultiStatusBar.py (revision 63916)
-+++ Lib/idlelib/MultiStatusBar.py (working copy)
-@@ -1,5 +1,9 @@
- from Tkinter import *
-+from idlelib.configHandler import idleConf
-
-+if idleConf.GetOption('main', 'General', 'use-ttk', type='int'):
-+ from ttk import Frame, Label
-+
- class MultiStatusBar(Frame):
-
- def __init__(self, master=None, **kw):
-@@ -10,7 +14,7 @@
-
- def set_label(self, name, text='', side=LEFT):
- if not self.labels.has_key(name):
-- label = Label(self, bd=1, relief=SUNKEN, anchor=W)
-+ label = Label(self, relief=SUNKEN, anchor=W)
- label.pack(side=side)
- self.labels[name] = label
- else:
More information about the Python-checkins
mailing list