diff -r d0570cba3749 Lib/turtledemo/__main__.py --- a/Lib/turtledemo/__main__.py Sat Jul 26 19:40:16 2014 -0400 +++ b/Lib/turtledemo/__main__.py Tue Jul 29 17:56:35 2014 -0400 @@ -3,6 +3,7 @@ import os from tkinter import * +from tkinter import ttk from idlelib.Percolator import Percolator from idlelib.ColorDelegator import ColorDelegator from idlelib.textView import view_file # TextViewer @@ -12,6 +13,7 @@ import time demo_dir = os.path.dirname(os.path.abspath(__file__)) +darwin = sys.platform == 'darwin' STARTUP = 1 READY = 2 @@ -21,7 +23,11 @@ menufont = ("Arial", 12, NORMAL) btnfont = ("Arial", 12, 'bold') -txtfont = ('Lucida Console', 8, 'normal') +txtfont = ['Lucida Console', 8, 'normal'] + +MINIMUM_FONT_SIZE = 8 +MAXIMUM_FONT_SIZE = 400 +FONT_OPTIONS = [8, 9, 10, 11, 12, 14, 18, 24, 30, 26, 48, 60, 72, 96] def getExampleEntries(): return [entry[:-3] for entry in os.listdir(demo_dir) if @@ -48,6 +54,7 @@ self.mBar = Frame(root, relief=RAISED, borderwidth=2) self.ExamplesBtn = self.makeLoadDemoMenu() + self.FontBtn = self.makeFontMenu() self.OptionsBtn = self.makeHelpMenu() self.mBar.grid(row=0, columnspan=4, sticky='news') @@ -102,7 +109,7 @@ hbar['command'] = text.xview hbar.pack(side=BOTTOM, fill=X) - text['font'] = txtfont + text['font'] = tuple(txtfont) text['yscrollcommand'] = vbar.set text['xscrollcommand'] = hbar.set text.pack(side=LEFT, fill=BOTH, expand=1) @@ -115,7 +122,7 @@ turtle._Screen._canvas = self._canvas = canvas = turtle.ScrolledCanvas( root, 800, 600, self.canvwidth, self.canvheight) canvas.adjustScrolls() - canvas._rootwindow.bind('', self.onResize) + self._makeBindings(canvas._rootwindow) canvas._canvas['borderwidth'] = 0 self.screen = _s_ = turtle.Screen() @@ -124,6 +131,37 @@ turtle.RawTurtle.screens = [_s_] return canvas + def _makeBindings(self, widget): + shortcut = 'Command' if darwin else 'Control' + widget.bind('', self.onResize) + widget.bind_all('<%s-minus>' % shortcut, self._decreaseFont) + widget.bind_all('<%s-equal>' % shortcut, self._increaseFont) + widget.bind_all('<%s-plus>' % shortcut, self._increaseFont) + widget.bind_all('', self._updateFontByMouseWheel) + widget.bind('', self._increaseFont) + widget.bind('', self._decreaseFont) + + def _updateFontByComboBox(self, *args): + txtfont[1] = max(int(self.FontBtn.get()), MINIMUM_FONT_SIZE) + self.text['font'] = tuple(txtfont) + self.FontBtn.set(str(txtfont[1])) + + def _updateFontByMouseWheel(self, event): + txtfont[1] = max(txtfont[1] + event.delta // (-1 if darwin else 120), + MINIMUM_FONT_SIZE) + self.text['font'] = tuple(txtfont) + self.FontBtn.set(str(txtfont[1])) + + def _decreaseFont(self, dummy): + txtfont[1] = max(txtfont[1] - 1, MINIMUM_FONT_SIZE) + self.text['font'] = tuple(txtfont) + self.FontBtn.set(str(txtfont[1])) + + def _increaseFont(self, dummy): + txtfont[1] = min(txtfont[1] + 1, MAXIMUM_FONT_SIZE) + self.text['font'] = tuple(txtfont) + self.FontBtn.set(str(txtfont[1])) + def configGUI(self, menu, start, stop, clear, txt="", color="blue"): self.ExamplesBtn.config(state=menu) @@ -178,6 +216,17 @@ CmdBtn['menu'] = CmdBtn.menu return CmdBtn + def makeFontMenu(self): + style = ttk.Style() + style.theme_use('clam') + combobox = ttk.Combobox(self.mBar, font=menufont, width=4) + combobox['values'] = tuple(FONT_OPTIONS) + combobox.bind("<>", self._updateFontByComboBox) + combobox.bind("", self._updateFontByComboBox) + combobox.current(0) + combobox.pack(side=LEFT, padx='2m') + return combobox + def refreshCanvas(self): if not self.dirty: return self.screen.clear()