Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c6a1c02c
Commit
c6a1c02c
authored
Sep 03, 2014
by
Terry Jan Reedy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #21933: Users can now change the font size for example code.
Original patch by Lita Cho.
parent
282124b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
22 deletions
+71
-22
Lib/turtledemo/__main__.py
Lib/turtledemo/__main__.py
+71
-22
No files found.
Lib/turtledemo/__main__.py
View file @
c6a1c02c
...
...
@@ -17,14 +17,17 @@
The (syntax coloured) source code appears in the left
source code window. IT CANNOT BE EDITED, but ONLY VIEWED!
- Press START button to start the demo.
- Stop execution by pressing the STOP button.
- Clear screen by pressing the CLEAR button
.
- Restart by pressing the START button again
.
The demo viewer windows can be resized. The divider between text
and canvas can be moved by grabbing it with the mouse. The text font
size can be changed from the menu and with Control/Command- '-'/'+'
.
It can also be changed on most systems with Control-mousewheel
.
SPECIAL demos are those which run EVENTDRIVEN.
(For example clock.py - or oldTurtleDemo.py which
in the end expects a mouse click.):
Press START button to start the demo.
Stop execution by pressing the STOP button.
Clear screen by pressing the CLEAR button.
Restart by pressing the START button again.
SPECIAL demos, such as clock.py are those which run EVENTDRIVEN.
Press START button to start the demo.
...
...
@@ -87,7 +90,7 @@ import os
from
tkinter
import
*
from
idlelib.Percolator
import
Percolator
from
idlelib.ColorDelegator
import
ColorDelegator
from
idlelib.textView
import
view_text
# TextViewer
from
idlelib.textView
import
view_text
from
importlib
import
reload
from
turtledemo
import
__doc__
as
about_turtledemo
...
...
@@ -95,6 +98,7 @@ import turtle
import
time
demo_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
darwin
=
sys
.
platform
==
'darwin'
STARTUP
=
1
READY
=
2
...
...
@@ -104,7 +108,11 @@ EVENTDRIVEN = 5
menufont
=
(
"Arial"
,
12
,
NORMAL
)
btnfont
=
(
"Arial"
,
12
,
'bold'
)
txtfont
=
(
'Lucida Console'
,
8
,
'normal'
)
txtfont
=
[
'Lucida Console'
,
10
,
'normal'
]
MINIMUM_FONT_SIZE
=
6
MAXIMUM_FONT_SIZE
=
100
font_sizes
=
[
8
,
9
,
10
,
11
,
12
,
14
,
18
,
20
,
22
,
24
,
30
]
def
getExampleEntries
():
return
[
entry
[:
-
3
]
for
entry
in
os
.
listdir
(
demo_dir
)
if
...
...
@@ -123,7 +131,7 @@ class DemoWindow(object):
root
.
title
(
'Python turtle-graphics examples'
)
root
.
wm_protocol
(
"WM_DELETE_WINDOW"
,
self
.
_destroy
)
if
sys
.
platform
==
'darwin'
:
if
darwin
:
import
subprocess
# Make sure we are the currently activated OS X application
# so that our menu bar appears.
...
...
@@ -136,8 +144,7 @@ class DemoWindow(object):
'-e'
,
'end tell'
,
],
stderr
=
subprocess
.
DEVNULL
,
stdout
=
subprocess
.
DEVNULL
,
)
stdout
=
subprocess
.
DEVNULL
,)
root
.
grid_rowconfigure
(
0
,
weight
=
1
)
root
.
grid_columnconfigure
(
0
,
weight
=
1
)
...
...
@@ -147,9 +154,11 @@ class DemoWindow(object):
self
.
mBar
=
Menu
(
root
,
relief
=
RAISED
,
borderwidth
=
2
)
self
.
mBar
.
add_cascade
(
menu
=
self
.
makeLoadDemoMenu
(
self
.
mBar
),
label
=
'Examples'
,
underline
=
0
,
font
=
menufont
)
label
=
'Examples'
,
underline
=
0
)
self
.
mBar
.
add_cascade
(
menu
=
self
.
makeFontMenu
(
self
.
mBar
),
label
=
'Fontsize'
,
underline
=
0
)
self
.
mBar
.
add_cascade
(
menu
=
self
.
makeHelpMenu
(
self
.
mBar
),
label
=
'Help'
,
underline
=
0
,
font
=
menufont
)
label
=
'Help'
,
underline
=
0
)
root
[
'menu'
]
=
self
.
mBar
pane
=
PanedWindow
(
orient
=
HORIZONTAL
,
sashwidth
=
5
,
...
...
@@ -203,7 +212,7 @@ class DemoWindow(object):
hbar
[
'command'
]
=
text
.
xview
hbar
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
text
[
'font'
]
=
t
xtfont
text
[
'font'
]
=
t
uple
(
txtfont
)
text
[
'yscrollcommand'
]
=
vbar
.
set
text
[
'xscrollcommand'
]
=
hbar
.
set
text
.
pack
(
side
=
LEFT
,
fill
=
BOTH
,
expand
=
1
)
...
...
@@ -216,7 +225,7 @@ class DemoWindow(object):
turtle
.
_Screen
.
_canvas
=
self
.
_canvas
=
canvas
=
turtle
.
ScrolledCanvas
(
root
,
800
,
600
,
self
.
canvwidth
,
self
.
canvheight
)
canvas
.
adjustScrolls
()
canvas
.
_rootwindow
.
bind
(
'<Configure>'
,
self
.
onResize
)
self
.
makeBindings
(
canvas
.
_rootwindow
)
canvas
.
_canvas
[
'borderwidth'
]
=
0
self
.
screen
=
_s_
=
turtle
.
Screen
()
...
...
@@ -225,6 +234,35 @@ class DemoWindow(object):
turtle
.
RawTurtle
.
screens
=
[
_s_
]
return
canvas
def
makeBindings
(
self
,
widget
):
widget
.
bind
(
'<Configure>'
,
self
.
onResize
)
shortcut
=
'Command'
if
darwin
else
'Control'
widget
.
bind_all
(
'<%s-minus>'
%
shortcut
,
self
.
decrease_size
)
widget
.
bind_all
(
'<%s-underscore>'
%
shortcut
,
self
.
decrease_size
)
widget
.
bind_all
(
'<%s-equal>'
%
shortcut
,
self
.
increase_size
)
widget
.
bind_all
(
'<%s-plus>'
%
shortcut
,
self
.
increase_size
)
widget
.
bind_all
(
'<Control-MouseWheel>'
,
self
.
update_mousewheel
)
widget
.
bind
(
'<Control-Button-4>'
,
self
.
increase_size
)
widget
.
bind
(
'<Control-Button-5>'
,
self
.
decrease_size
)
def
set_txtsize
(
self
,
size
):
txtfont
[
1
]
=
size
self
.
text
[
'font'
]
=
tuple
(
txtfont
)
self
.
output_lbl
[
'text'
]
=
'Font size %d'
%
size
def
decrease_size
(
self
,
dummy
=
None
):
self
.
set_txtsize
(
max
(
txtfont
[
1
]
-
1
,
MINIMUM_FONT_SIZE
))
def
increase_size
(
self
,
dummy
=
None
):
self
.
set_txtsize
(
min
(
txtfont
[
1
]
+
1
,
MAXIMUM_FONT_SIZE
))
def
update_mousewheel
(
self
,
event
):
# For wheel up, event.delte = 120 on Windows, -1 on darwin.
# X-11 sends Control-Button-4 event instead.
(
self
.
decrease_size
()
if
(
event
.
delta
<
0
and
not
darwin
)
else
self
.
increase_size
())
def
configGUI
(
self
,
start
,
stop
,
clear
,
txt
=
""
,
color
=
"blue"
):
self
.
start_btn
.
config
(
state
=
start
,
bg
=
"#d00"
if
start
==
NORMAL
else
"#fca"
)
...
...
@@ -238,13 +276,25 @@ class DemoWindow(object):
menu
=
Menu
(
master
)
for
entry
in
getExampleEntries
():
def
loadexample
(
x
):
def
emit
():
self
.
loadfile
(
x
)
return
emit
def
load
(
entry
=
entry
):
self
.
loadfile
(
entry
)
menu
.
add_command
(
label
=
entry
,
underline
=
0
,
font
=
menufont
,
command
=
loadexample
(
entry
))
font
=
menufont
,
command
=
load
)
return
menu
def
makeFontMenu
(
self
,
master
):
menu
=
Menu
(
master
)
menu
.
add_command
(
label
=
"Decrease (C-'-')"
,
command
=
self
.
decrease_size
,
font
=
menufont
)
menu
.
add_command
(
label
=
"Increase (C-'+')"
,
command
=
self
.
increase_size
,
font
=
menufont
)
menu
.
add_separator
()
for
size
in
font_sizes
:
def
resize
(
size
=
size
):
self
.
set_txtsize
(
size
)
menu
.
add_command
(
label
=
str
(
size
),
underline
=
0
,
font
=
menufont
,
command
=
resize
)
return
menu
def
makeHelpMenu
(
self
,
master
):
...
...
@@ -254,7 +304,6 @@ class DemoWindow(object):
def
show
(
help_label
=
help_label
,
help_file
=
help_file
):
view_text
(
self
.
root
,
help_label
,
help_file
)
menu
.
add_command
(
label
=
help_label
,
font
=
menufont
,
command
=
show
)
return
menu
def
refreshCanvas
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment