Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: turtle.py
[3500] Fix | Delete
Example:
[3501] Fix | Delete
>>> pet = getturtle()
[3502] Fix | Delete
>>> pet.fd(50)
[3503] Fix | Delete
>>> pet
[3504] Fix | Delete
<turtle.Turtle object at 0x0187D810>
[3505] Fix | Delete
>>> turtles()
[3506] Fix | Delete
[<turtle.Turtle object at 0x0187D810>]
[3507] Fix | Delete
"""
[3508] Fix | Delete
return self
[3509] Fix | Delete
[3510] Fix | Delete
getpen = getturtle
[3511] Fix | Delete
[3512] Fix | Delete
[3513] Fix | Delete
################################################################
[3514] Fix | Delete
### screen oriented methods recurring to methods of TurtleScreen
[3515] Fix | Delete
################################################################
[3516] Fix | Delete
[3517] Fix | Delete
def _delay(self, delay=None):
[3518] Fix | Delete
"""Set delay value which determines speed of turtle animation.
[3519] Fix | Delete
"""
[3520] Fix | Delete
return self.screen.delay(delay)
[3521] Fix | Delete
[3522] Fix | Delete
def onclick(self, fun, btn=1, add=None):
[3523] Fix | Delete
"""Bind fun to mouse-click event on this turtle on canvas.
[3524] Fix | Delete
[3525] Fix | Delete
Arguments:
[3526] Fix | Delete
fun -- a function with two arguments, to which will be assigned
[3527] Fix | Delete
the coordinates of the clicked point on the canvas.
[3528] Fix | Delete
btn -- number of the mouse-button defaults to 1 (left mouse button).
[3529] Fix | Delete
add -- True or False. If True, new binding will be added, otherwise
[3530] Fix | Delete
it will replace a former binding.
[3531] Fix | Delete
[3532] Fix | Delete
Example for the anonymous turtle, i. e. the procedural way:
[3533] Fix | Delete
[3534] Fix | Delete
>>> def turn(x, y):
[3535] Fix | Delete
... left(360)
[3536] Fix | Delete
...
[3537] Fix | Delete
>>> onclick(turn) # Now clicking into the turtle will turn it.
[3538] Fix | Delete
>>> onclick(None) # event-binding will be removed
[3539] Fix | Delete
"""
[3540] Fix | Delete
self.screen._onclick(self.turtle._item, fun, btn, add)
[3541] Fix | Delete
self._update()
[3542] Fix | Delete
[3543] Fix | Delete
def onrelease(self, fun, btn=1, add=None):
[3544] Fix | Delete
"""Bind fun to mouse-button-release event on this turtle on canvas.
[3545] Fix | Delete
[3546] Fix | Delete
Arguments:
[3547] Fix | Delete
fun -- a function with two arguments, to which will be assigned
[3548] Fix | Delete
the coordinates of the clicked point on the canvas.
[3549] Fix | Delete
btn -- number of the mouse-button defaults to 1 (left mouse button).
[3550] Fix | Delete
[3551] Fix | Delete
Example (for a MyTurtle instance named joe):
[3552] Fix | Delete
>>> class MyTurtle(Turtle):
[3553] Fix | Delete
... def glow(self,x,y):
[3554] Fix | Delete
... self.fillcolor("red")
[3555] Fix | Delete
... def unglow(self,x,y):
[3556] Fix | Delete
... self.fillcolor("")
[3557] Fix | Delete
...
[3558] Fix | Delete
>>> joe = MyTurtle()
[3559] Fix | Delete
>>> joe.onclick(joe.glow)
[3560] Fix | Delete
>>> joe.onrelease(joe.unglow)
[3561] Fix | Delete
[3562] Fix | Delete
Clicking on joe turns fillcolor red, unclicking turns it to
[3563] Fix | Delete
transparent.
[3564] Fix | Delete
"""
[3565] Fix | Delete
self.screen._onrelease(self.turtle._item, fun, btn, add)
[3566] Fix | Delete
self._update()
[3567] Fix | Delete
[3568] Fix | Delete
def ondrag(self, fun, btn=1, add=None):
[3569] Fix | Delete
"""Bind fun to mouse-move event on this turtle on canvas.
[3570] Fix | Delete
[3571] Fix | Delete
Arguments:
[3572] Fix | Delete
fun -- a function with two arguments, to which will be assigned
[3573] Fix | Delete
the coordinates of the clicked point on the canvas.
[3574] Fix | Delete
btn -- number of the mouse-button defaults to 1 (left mouse button).
[3575] Fix | Delete
[3576] Fix | Delete
Every sequence of mouse-move-events on a turtle is preceded by a
[3577] Fix | Delete
mouse-click event on that turtle.
[3578] Fix | Delete
[3579] Fix | Delete
Example (for a Turtle instance named turtle):
[3580] Fix | Delete
>>> turtle.ondrag(turtle.goto)
[3581] Fix | Delete
[3582] Fix | Delete
Subsequently clicking and dragging a Turtle will move it
[3583] Fix | Delete
across the screen thereby producing handdrawings (if pen is
[3584] Fix | Delete
down).
[3585] Fix | Delete
"""
[3586] Fix | Delete
self.screen._ondrag(self.turtle._item, fun, btn, add)
[3587] Fix | Delete
[3588] Fix | Delete
[3589] Fix | Delete
def _undo(self, action, data):
[3590] Fix | Delete
"""Does the main part of the work for undo()
[3591] Fix | Delete
"""
[3592] Fix | Delete
if self.undobuffer is None:
[3593] Fix | Delete
return
[3594] Fix | Delete
if action == "rot":
[3595] Fix | Delete
angle, degPAU = data
[3596] Fix | Delete
self._rotate(-angle*degPAU/self._degreesPerAU)
[3597] Fix | Delete
dummy = self.undobuffer.pop()
[3598] Fix | Delete
elif action == "stamp":
[3599] Fix | Delete
stitem = data[0]
[3600] Fix | Delete
self.clearstamp(stitem)
[3601] Fix | Delete
elif action == "go":
[3602] Fix | Delete
self._undogoto(data)
[3603] Fix | Delete
elif action in ["wri", "dot"]:
[3604] Fix | Delete
item = data[0]
[3605] Fix | Delete
self.screen._delete(item)
[3606] Fix | Delete
self.items.remove(item)
[3607] Fix | Delete
elif action == "dofill":
[3608] Fix | Delete
item = data[0]
[3609] Fix | Delete
self.screen._drawpoly(item, ((0, 0),(0, 0),(0, 0)),
[3610] Fix | Delete
fill="", outline="")
[3611] Fix | Delete
elif action == "beginfill":
[3612] Fix | Delete
item = data[0]
[3613] Fix | Delete
self._fillitem = self._fillpath = None
[3614] Fix | Delete
if item in self.items:
[3615] Fix | Delete
self.screen._delete(item)
[3616] Fix | Delete
self.items.remove(item)
[3617] Fix | Delete
elif action == "pen":
[3618] Fix | Delete
TPen.pen(self, data[0])
[3619] Fix | Delete
self.undobuffer.pop()
[3620] Fix | Delete
[3621] Fix | Delete
def undo(self):
[3622] Fix | Delete
"""undo (repeatedly) the last turtle action.
[3623] Fix | Delete
[3624] Fix | Delete
No argument.
[3625] Fix | Delete
[3626] Fix | Delete
undo (repeatedly) the last turtle action.
[3627] Fix | Delete
Number of available undo actions is determined by the size of
[3628] Fix | Delete
the undobuffer.
[3629] Fix | Delete
[3630] Fix | Delete
Example (for a Turtle instance named turtle):
[3631] Fix | Delete
>>> for i in range(4):
[3632] Fix | Delete
... turtle.fd(50); turtle.lt(80)
[3633] Fix | Delete
...
[3634] Fix | Delete
>>> for i in range(8):
[3635] Fix | Delete
... turtle.undo()
[3636] Fix | Delete
...
[3637] Fix | Delete
"""
[3638] Fix | Delete
if self.undobuffer is None:
[3639] Fix | Delete
return
[3640] Fix | Delete
item = self.undobuffer.pop()
[3641] Fix | Delete
action = item[0]
[3642] Fix | Delete
data = item[1:]
[3643] Fix | Delete
if action == "seq":
[3644] Fix | Delete
while data:
[3645] Fix | Delete
item = data.pop()
[3646] Fix | Delete
self._undo(item[0], item[1:])
[3647] Fix | Delete
else:
[3648] Fix | Delete
self._undo(action, data)
[3649] Fix | Delete
[3650] Fix | Delete
turtlesize = shapesize
[3651] Fix | Delete
[3652] Fix | Delete
RawPen = RawTurtle
[3653] Fix | Delete
[3654] Fix | Delete
### Screen - Singleton ########################
[3655] Fix | Delete
[3656] Fix | Delete
def Screen():
[3657] Fix | Delete
"""Return the singleton screen object.
[3658] Fix | Delete
If none exists at the moment, create a new one and return it,
[3659] Fix | Delete
else return the existing one."""
[3660] Fix | Delete
if Turtle._screen is None:
[3661] Fix | Delete
Turtle._screen = _Screen()
[3662] Fix | Delete
return Turtle._screen
[3663] Fix | Delete
[3664] Fix | Delete
class _Screen(TurtleScreen):
[3665] Fix | Delete
[3666] Fix | Delete
_root = None
[3667] Fix | Delete
_canvas = None
[3668] Fix | Delete
_title = _CFG["title"]
[3669] Fix | Delete
[3670] Fix | Delete
def __init__(self):
[3671] Fix | Delete
# XXX there is no need for this code to be conditional,
[3672] Fix | Delete
# as there will be only a single _Screen instance, anyway
[3673] Fix | Delete
# XXX actually, the turtle demo is injecting root window,
[3674] Fix | Delete
# so perhaps the conditional creation of a root should be
[3675] Fix | Delete
# preserved (perhaps by passing it as an optional parameter)
[3676] Fix | Delete
if _Screen._root is None:
[3677] Fix | Delete
_Screen._root = self._root = _Root()
[3678] Fix | Delete
self._root.title(_Screen._title)
[3679] Fix | Delete
self._root.ondestroy(self._destroy)
[3680] Fix | Delete
if _Screen._canvas is None:
[3681] Fix | Delete
width = _CFG["width"]
[3682] Fix | Delete
height = _CFG["height"]
[3683] Fix | Delete
canvwidth = _CFG["canvwidth"]
[3684] Fix | Delete
canvheight = _CFG["canvheight"]
[3685] Fix | Delete
leftright = _CFG["leftright"]
[3686] Fix | Delete
topbottom = _CFG["topbottom"]
[3687] Fix | Delete
self._root.setupcanvas(width, height, canvwidth, canvheight)
[3688] Fix | Delete
_Screen._canvas = self._root._getcanvas()
[3689] Fix | Delete
TurtleScreen.__init__(self, _Screen._canvas)
[3690] Fix | Delete
self.setup(width, height, leftright, topbottom)
[3691] Fix | Delete
[3692] Fix | Delete
def setup(self, width=_CFG["width"], height=_CFG["height"],
[3693] Fix | Delete
startx=_CFG["leftright"], starty=_CFG["topbottom"]):
[3694] Fix | Delete
""" Set the size and position of the main window.
[3695] Fix | Delete
[3696] Fix | Delete
Arguments:
[3697] Fix | Delete
width: as integer a size in pixels, as float a fraction of the screen.
[3698] Fix | Delete
Default is 50% of screen.
[3699] Fix | Delete
height: as integer the height in pixels, as float a fraction of the
[3700] Fix | Delete
screen. Default is 75% of screen.
[3701] Fix | Delete
startx: if positive, starting position in pixels from the left
[3702] Fix | Delete
edge of the screen, if negative from the right edge
[3703] Fix | Delete
Default, startx=None is to center window horizontally.
[3704] Fix | Delete
starty: if positive, starting position in pixels from the top
[3705] Fix | Delete
edge of the screen, if negative from the bottom edge
[3706] Fix | Delete
Default, starty=None is to center window vertically.
[3707] Fix | Delete
[3708] Fix | Delete
Examples (for a Screen instance named screen):
[3709] Fix | Delete
>>> screen.setup (width=200, height=200, startx=0, starty=0)
[3710] Fix | Delete
[3711] Fix | Delete
sets window to 200x200 pixels, in upper left of screen
[3712] Fix | Delete
[3713] Fix | Delete
>>> screen.setup(width=.75, height=0.5, startx=None, starty=None)
[3714] Fix | Delete
[3715] Fix | Delete
sets window to 75% of screen by 50% of screen and centers
[3716] Fix | Delete
"""
[3717] Fix | Delete
if not hasattr(self._root, "set_geometry"):
[3718] Fix | Delete
return
[3719] Fix | Delete
sw = self._root.win_width()
[3720] Fix | Delete
sh = self._root.win_height()
[3721] Fix | Delete
if isinstance(width, float) and 0 <= width <= 1:
[3722] Fix | Delete
width = sw*width
[3723] Fix | Delete
if startx is None:
[3724] Fix | Delete
startx = (sw - width) / 2
[3725] Fix | Delete
if isinstance(height, float) and 0 <= height <= 1:
[3726] Fix | Delete
height = sh*height
[3727] Fix | Delete
if starty is None:
[3728] Fix | Delete
starty = (sh - height) / 2
[3729] Fix | Delete
self._root.set_geometry(width, height, startx, starty)
[3730] Fix | Delete
self.update()
[3731] Fix | Delete
[3732] Fix | Delete
def title(self, titlestring):
[3733] Fix | Delete
"""Set title of turtle-window
[3734] Fix | Delete
[3735] Fix | Delete
Argument:
[3736] Fix | Delete
titlestring -- a string, to appear in the titlebar of the
[3737] Fix | Delete
turtle graphics window.
[3738] Fix | Delete
[3739] Fix | Delete
This is a method of Screen-class. Not available for TurtleScreen-
[3740] Fix | Delete
objects.
[3741] Fix | Delete
[3742] Fix | Delete
Example (for a Screen instance named screen):
[3743] Fix | Delete
>>> screen.title("Welcome to the turtle-zoo!")
[3744] Fix | Delete
"""
[3745] Fix | Delete
if _Screen._root is not None:
[3746] Fix | Delete
_Screen._root.title(titlestring)
[3747] Fix | Delete
_Screen._title = titlestring
[3748] Fix | Delete
[3749] Fix | Delete
def _destroy(self):
[3750] Fix | Delete
root = self._root
[3751] Fix | Delete
if root is _Screen._root:
[3752] Fix | Delete
Turtle._pen = None
[3753] Fix | Delete
Turtle._screen = None
[3754] Fix | Delete
_Screen._root = None
[3755] Fix | Delete
_Screen._canvas = None
[3756] Fix | Delete
TurtleScreen._RUNNING = False
[3757] Fix | Delete
root.destroy()
[3758] Fix | Delete
[3759] Fix | Delete
def bye(self):
[3760] Fix | Delete
"""Shut the turtlegraphics window.
[3761] Fix | Delete
[3762] Fix | Delete
Example (for a TurtleScreen instance named screen):
[3763] Fix | Delete
>>> screen.bye()
[3764] Fix | Delete
"""
[3765] Fix | Delete
self._destroy()
[3766] Fix | Delete
[3767] Fix | Delete
def exitonclick(self):
[3768] Fix | Delete
"""Go into mainloop until the mouse is clicked.
[3769] Fix | Delete
[3770] Fix | Delete
No arguments.
[3771] Fix | Delete
[3772] Fix | Delete
Bind bye() method to mouseclick on TurtleScreen.
[3773] Fix | Delete
If "using_IDLE" - value in configuration dictionary is False
[3774] Fix | Delete
(default value), enter mainloop.
[3775] Fix | Delete
If IDLE with -n switch (no subprocess) is used, this value should be
[3776] Fix | Delete
set to True in turtle.cfg. In this case IDLE's mainloop
[3777] Fix | Delete
is active also for the client script.
[3778] Fix | Delete
[3779] Fix | Delete
This is a method of the Screen-class and not available for
[3780] Fix | Delete
TurtleScreen instances.
[3781] Fix | Delete
[3782] Fix | Delete
Example (for a Screen instance named screen):
[3783] Fix | Delete
>>> screen.exitonclick()
[3784] Fix | Delete
[3785] Fix | Delete
"""
[3786] Fix | Delete
def exitGracefully(x, y):
[3787] Fix | Delete
"""Screen.bye() with two dummy-parameters"""
[3788] Fix | Delete
self.bye()
[3789] Fix | Delete
self.onclick(exitGracefully)
[3790] Fix | Delete
if _CFG["using_IDLE"]:
[3791] Fix | Delete
return
[3792] Fix | Delete
try:
[3793] Fix | Delete
mainloop()
[3794] Fix | Delete
except AttributeError:
[3795] Fix | Delete
exit(0)
[3796] Fix | Delete
[3797] Fix | Delete
class Turtle(RawTurtle):
[3798] Fix | Delete
"""RawTurtle auto-creating (scrolled) canvas.
[3799] Fix | Delete
[3800] Fix | Delete
When a Turtle object is created or a function derived from some
[3801] Fix | Delete
Turtle method is called a TurtleScreen object is automatically created.
[3802] Fix | Delete
"""
[3803] Fix | Delete
_pen = None
[3804] Fix | Delete
_screen = None
[3805] Fix | Delete
[3806] Fix | Delete
def __init__(self,
[3807] Fix | Delete
shape=_CFG["shape"],
[3808] Fix | Delete
undobuffersize=_CFG["undobuffersize"],
[3809] Fix | Delete
visible=_CFG["visible"]):
[3810] Fix | Delete
if Turtle._screen is None:
[3811] Fix | Delete
Turtle._screen = Screen()
[3812] Fix | Delete
RawTurtle.__init__(self, Turtle._screen,
[3813] Fix | Delete
shape=shape,
[3814] Fix | Delete
undobuffersize=undobuffersize,
[3815] Fix | Delete
visible=visible)
[3816] Fix | Delete
[3817] Fix | Delete
Pen = Turtle
[3818] Fix | Delete
[3819] Fix | Delete
def write_docstringdict(filename="turtle_docstringdict"):
[3820] Fix | Delete
"""Create and write docstring-dictionary to file.
[3821] Fix | Delete
[3822] Fix | Delete
Optional argument:
[3823] Fix | Delete
filename -- a string, used as filename
[3824] Fix | Delete
default value is turtle_docstringdict
[3825] Fix | Delete
[3826] Fix | Delete
Has to be called explicitly, (not used by the turtle-graphics classes)
[3827] Fix | Delete
The docstring dictionary will be written to the Python script <filname>.py
[3828] Fix | Delete
It is intended to serve as a template for translation of the docstrings
[3829] Fix | Delete
into different languages.
[3830] Fix | Delete
"""
[3831] Fix | Delete
docsdict = {}
[3832] Fix | Delete
[3833] Fix | Delete
for methodname in _tg_screen_functions:
[3834] Fix | Delete
key = "_Screen."+methodname
[3835] Fix | Delete
docsdict[key] = eval(key).__doc__
[3836] Fix | Delete
for methodname in _tg_turtle_functions:
[3837] Fix | Delete
key = "Turtle."+methodname
[3838] Fix | Delete
docsdict[key] = eval(key).__doc__
[3839] Fix | Delete
[3840] Fix | Delete
with open("%s.py" % filename,"w") as f:
[3841] Fix | Delete
keys = sorted(x for x in docsdict
[3842] Fix | Delete
if x.split('.')[1] not in _alias_list)
[3843] Fix | Delete
f.write('docsdict = {\n\n')
[3844] Fix | Delete
for key in keys[:-1]:
[3845] Fix | Delete
f.write('%s :\n' % repr(key))
[3846] Fix | Delete
f.write(' """%s\n""",\n\n' % docsdict[key])
[3847] Fix | Delete
key = keys[-1]
[3848] Fix | Delete
f.write('%s :\n' % repr(key))
[3849] Fix | Delete
f.write(' """%s\n"""\n\n' % docsdict[key])
[3850] Fix | Delete
f.write("}\n")
[3851] Fix | Delete
f.close()
[3852] Fix | Delete
[3853] Fix | Delete
def read_docstrings(lang):
[3854] Fix | Delete
"""Read in docstrings from lang-specific docstring dictionary.
[3855] Fix | Delete
[3856] Fix | Delete
Transfer docstrings, translated to lang, from a dictionary-file
[3857] Fix | Delete
to the methods of classes Screen and Turtle and - in revised form -
[3858] Fix | Delete
to the corresponding functions.
[3859] Fix | Delete
"""
[3860] Fix | Delete
modname = "turtle_docstringdict_%(language)s" % {'language':lang.lower()}
[3861] Fix | Delete
module = __import__(modname)
[3862] Fix | Delete
docsdict = module.docsdict
[3863] Fix | Delete
for key in docsdict:
[3864] Fix | Delete
try:
[3865] Fix | Delete
# eval(key).im_func.__doc__ = docsdict[key]
[3866] Fix | Delete
eval(key).__doc__ = docsdict[key]
[3867] Fix | Delete
except Exception:
[3868] Fix | Delete
print("Bad docstring-entry: %s" % key)
[3869] Fix | Delete
[3870] Fix | Delete
_LANGUAGE = _CFG["language"]
[3871] Fix | Delete
[3872] Fix | Delete
try:
[3873] Fix | Delete
if _LANGUAGE != "english":
[3874] Fix | Delete
read_docstrings(_LANGUAGE)
[3875] Fix | Delete
except ImportError:
[3876] Fix | Delete
print("Cannot find docsdict for", _LANGUAGE)
[3877] Fix | Delete
except Exception:
[3878] Fix | Delete
print ("Unknown Error when trying to import %s-docstring-dictionary" %
[3879] Fix | Delete
_LANGUAGE)
[3880] Fix | Delete
[3881] Fix | Delete
[3882] Fix | Delete
def getmethparlist(ob):
[3883] Fix | Delete
"""Get strings describing the arguments for the given object
[3884] Fix | Delete
[3885] Fix | Delete
Returns a pair of strings representing function parameter lists
[3886] Fix | Delete
including parenthesis. The first string is suitable for use in
[3887] Fix | Delete
function definition and the second is suitable for use in function
[3888] Fix | Delete
call. The "self" parameter is not included.
[3889] Fix | Delete
"""
[3890] Fix | Delete
defText = callText = ""
[3891] Fix | Delete
# bit of a hack for methods - turn it into a function
[3892] Fix | Delete
# but we drop the "self" param.
[3893] Fix | Delete
# Try and build one for Python defined functions
[3894] Fix | Delete
args, varargs, varkw = inspect.getargs(ob.__code__)
[3895] Fix | Delete
items2 = args[1:]
[3896] Fix | Delete
realArgs = args[1:]
[3897] Fix | Delete
defaults = ob.__defaults__ or []
[3898] Fix | Delete
defaults = ["=%r" % (value,) for value in defaults]
[3899] Fix | Delete
defaults = [""] * (len(realArgs)-len(defaults)) + defaults
[3900] Fix | Delete
items1 = [arg + dflt for arg, dflt in zip(realArgs, defaults)]
[3901] Fix | Delete
if varargs is not None:
[3902] Fix | Delete
items1.append("*" + varargs)
[3903] Fix | Delete
items2.append("*" + varargs)
[3904] Fix | Delete
if varkw is not None:
[3905] Fix | Delete
items1.append("**" + varkw)
[3906] Fix | Delete
items2.append("**" + varkw)
[3907] Fix | Delete
defText = ", ".join(items1)
[3908] Fix | Delete
defText = "(%s)" % defText
[3909] Fix | Delete
callText = ", ".join(items2)
[3910] Fix | Delete
callText = "(%s)" % callText
[3911] Fix | Delete
return defText, callText
[3912] Fix | Delete
[3913] Fix | Delete
def _turtle_docrevise(docstr):
[3914] Fix | Delete
"""To reduce docstrings from RawTurtle class for functions
[3915] Fix | Delete
"""
[3916] Fix | Delete
import re
[3917] Fix | Delete
if docstr is None:
[3918] Fix | Delete
return None
[3919] Fix | Delete
turtlename = _CFG["exampleturtle"]
[3920] Fix | Delete
newdocstr = docstr.replace("%s." % turtlename,"")
[3921] Fix | Delete
parexp = re.compile(r' \(.+ %s\):' % turtlename)
[3922] Fix | Delete
newdocstr = parexp.sub(":", newdocstr)
[3923] Fix | Delete
return newdocstr
[3924] Fix | Delete
[3925] Fix | Delete
def _screen_docrevise(docstr):
[3926] Fix | Delete
"""To reduce docstrings from TurtleScreen class for functions
[3927] Fix | Delete
"""
[3928] Fix | Delete
import re
[3929] Fix | Delete
if docstr is None:
[3930] Fix | Delete
return None
[3931] Fix | Delete
screenname = _CFG["examplescreen"]
[3932] Fix | Delete
newdocstr = docstr.replace("%s." % screenname,"")
[3933] Fix | Delete
parexp = re.compile(r' \(.+ %s\):' % screenname)
[3934] Fix | Delete
newdocstr = parexp.sub(":", newdocstr)
[3935] Fix | Delete
return newdocstr
[3936] Fix | Delete
[3937] Fix | Delete
## The following mechanism makes all methods of RawTurtle and Turtle available
[3938] Fix | Delete
## as functions. So we can enhance, change, add, delete methods to these
[3939] Fix | Delete
## classes and do not need to change anything here.
[3940] Fix | Delete
[3941] Fix | Delete
__func_body = """\
[3942] Fix | Delete
def {name}{paramslist}:
[3943] Fix | Delete
if {obj} is None:
[3944] Fix | Delete
if not TurtleScreen._RUNNING:
[3945] Fix | Delete
TurtleScreen._RUNNING = True
[3946] Fix | Delete
raise Terminator
[3947] Fix | Delete
{obj} = {init}
[3948] Fix | Delete
try:
[3949] Fix | Delete
return {obj}.{name}{argslist}
[3950] Fix | Delete
except TK.TclError:
[3951] Fix | Delete
if not TurtleScreen._RUNNING:
[3952] Fix | Delete
TurtleScreen._RUNNING = True
[3953] Fix | Delete
raise Terminator
[3954] Fix | Delete
raise
[3955] Fix | Delete
"""
[3956] Fix | Delete
[3957] Fix | Delete
def _make_global_funcs(functions, cls, obj, init, docrevise):
[3958] Fix | Delete
for methodname in functions:
[3959] Fix | Delete
method = getattr(cls, methodname)
[3960] Fix | Delete
pl1, pl2 = getmethparlist(method)
[3961] Fix | Delete
if pl1 == "":
[3962] Fix | Delete
print(">>>>>>", pl1, pl2)
[3963] Fix | Delete
continue
[3964] Fix | Delete
defstr = __func_body.format(obj=obj, init=init, name=methodname,
[3965] Fix | Delete
paramslist=pl1, argslist=pl2)
[3966] Fix | Delete
exec(defstr, globals())
[3967] Fix | Delete
globals()[methodname].__doc__ = docrevise(method.__doc__)
[3968] Fix | Delete
[3969] Fix | Delete
_make_global_funcs(_tg_screen_functions, _Screen,
[3970] Fix | Delete
'Turtle._screen', 'Screen()', _screen_docrevise)
[3971] Fix | Delete
_make_global_funcs(_tg_turtle_functions, Turtle,
[3972] Fix | Delete
'Turtle._pen', 'Turtle()', _turtle_docrevise)
[3973] Fix | Delete
[3974] Fix | Delete
[3975] Fix | Delete
done = mainloop
[3976] Fix | Delete
[3977] Fix | Delete
if __name__ == "__main__":
[3978] Fix | Delete
def switchpen():
[3979] Fix | Delete
if isdown():
[3980] Fix | Delete
pu()
[3981] Fix | Delete
else:
[3982] Fix | Delete
pd()
[3983] Fix | Delete
[3984] Fix | Delete
def demo1():
[3985] Fix | Delete
"""Demo of old turtle.py - module"""
[3986] Fix | Delete
reset()
[3987] Fix | Delete
tracer(True)
[3988] Fix | Delete
up()
[3989] Fix | Delete
backward(100)
[3990] Fix | Delete
down()
[3991] Fix | Delete
# draw 3 squares; the last filled
[3992] Fix | Delete
width(3)
[3993] Fix | Delete
for i in range(3):
[3994] Fix | Delete
if i == 2:
[3995] Fix | Delete
begin_fill()
[3996] Fix | Delete
for _ in range(4):
[3997] Fix | Delete
forward(20)
[3998] Fix | Delete
left(90)
[3999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function