Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../usr/lib64/python3....
File: turtle.py
arguments:
[500] Fix | Delete
coordlist is sequence of coordinates
[501] Fix | Delete
fill is filling color
[502] Fix | Delete
outline is outline color
[503] Fix | Delete
top is a boolean value, which specifies if polyitem
[504] Fix | Delete
will be put on top of the canvas' displaylist so it
[505] Fix | Delete
will not be covered by other items.
[506] Fix | Delete
"""
[507] Fix | Delete
cl = []
[508] Fix | Delete
for x, y in coordlist:
[509] Fix | Delete
cl.append(x * self.xscale)
[510] Fix | Delete
cl.append(-y * self.yscale)
[511] Fix | Delete
self.cv.coords(polyitem, *cl)
[512] Fix | Delete
if fill is not None:
[513] Fix | Delete
self.cv.itemconfigure(polyitem, fill=fill)
[514] Fix | Delete
if outline is not None:
[515] Fix | Delete
self.cv.itemconfigure(polyitem, outline=outline)
[516] Fix | Delete
if width is not None:
[517] Fix | Delete
self.cv.itemconfigure(polyitem, width=width)
[518] Fix | Delete
if top:
[519] Fix | Delete
self.cv.tag_raise(polyitem)
[520] Fix | Delete
[521] Fix | Delete
def _createline(self):
[522] Fix | Delete
"""Create an invisible line item on canvas self.cv)
[523] Fix | Delete
"""
[524] Fix | Delete
return self.cv.create_line(0, 0, 0, 0, fill="", width=2,
[525] Fix | Delete
capstyle = TK.ROUND)
[526] Fix | Delete
[527] Fix | Delete
def _drawline(self, lineitem, coordlist=None,
[528] Fix | Delete
fill=None, width=None, top=False):
[529] Fix | Delete
"""Configure lineitem according to provided arguments:
[530] Fix | Delete
coordlist is sequence of coordinates
[531] Fix | Delete
fill is drawing color
[532] Fix | Delete
width is width of drawn line.
[533] Fix | Delete
top is a boolean value, which specifies if polyitem
[534] Fix | Delete
will be put on top of the canvas' displaylist so it
[535] Fix | Delete
will not be covered by other items.
[536] Fix | Delete
"""
[537] Fix | Delete
if coordlist is not None:
[538] Fix | Delete
cl = []
[539] Fix | Delete
for x, y in coordlist:
[540] Fix | Delete
cl.append(x * self.xscale)
[541] Fix | Delete
cl.append(-y * self.yscale)
[542] Fix | Delete
self.cv.coords(lineitem, *cl)
[543] Fix | Delete
if fill is not None:
[544] Fix | Delete
self.cv.itemconfigure(lineitem, fill=fill)
[545] Fix | Delete
if width is not None:
[546] Fix | Delete
self.cv.itemconfigure(lineitem, width=width)
[547] Fix | Delete
if top:
[548] Fix | Delete
self.cv.tag_raise(lineitem)
[549] Fix | Delete
[550] Fix | Delete
def _delete(self, item):
[551] Fix | Delete
"""Delete graphics item from canvas.
[552] Fix | Delete
If item is"all" delete all graphics items.
[553] Fix | Delete
"""
[554] Fix | Delete
self.cv.delete(item)
[555] Fix | Delete
[556] Fix | Delete
def _update(self):
[557] Fix | Delete
"""Redraw graphics items on canvas
[558] Fix | Delete
"""
[559] Fix | Delete
self.cv.update()
[560] Fix | Delete
[561] Fix | Delete
def _delay(self, delay):
[562] Fix | Delete
"""Delay subsequent canvas actions for delay ms."""
[563] Fix | Delete
self.cv.after(delay)
[564] Fix | Delete
[565] Fix | Delete
def _iscolorstring(self, color):
[566] Fix | Delete
"""Check if the string color is a legal Tkinter color string.
[567] Fix | Delete
"""
[568] Fix | Delete
try:
[569] Fix | Delete
rgb = self.cv.winfo_rgb(color)
[570] Fix | Delete
ok = True
[571] Fix | Delete
except TK.TclError:
[572] Fix | Delete
ok = False
[573] Fix | Delete
return ok
[574] Fix | Delete
[575] Fix | Delete
def _bgcolor(self, color=None):
[576] Fix | Delete
"""Set canvas' backgroundcolor if color is not None,
[577] Fix | Delete
else return backgroundcolor."""
[578] Fix | Delete
if color is not None:
[579] Fix | Delete
self.cv.config(bg = color)
[580] Fix | Delete
self._update()
[581] Fix | Delete
else:
[582] Fix | Delete
return self.cv.cget("bg")
[583] Fix | Delete
[584] Fix | Delete
def _write(self, pos, txt, align, font, pencolor):
[585] Fix | Delete
"""Write txt at pos in canvas with specified font
[586] Fix | Delete
and color.
[587] Fix | Delete
Return text item and x-coord of right bottom corner
[588] Fix | Delete
of text's bounding box."""
[589] Fix | Delete
x, y = pos
[590] Fix | Delete
x = x * self.xscale
[591] Fix | Delete
y = y * self.yscale
[592] Fix | Delete
anchor = {"left":"sw", "center":"s", "right":"se" }
[593] Fix | Delete
item = self.cv.create_text(x-1, -y, text = txt, anchor = anchor[align],
[594] Fix | Delete
fill = pencolor, font = font)
[595] Fix | Delete
x0, y0, x1, y1 = self.cv.bbox(item)
[596] Fix | Delete
self.cv.update()
[597] Fix | Delete
return item, x1-1
[598] Fix | Delete
[599] Fix | Delete
## def _dot(self, pos, size, color):
[600] Fix | Delete
## """may be implemented for some other graphics toolkit"""
[601] Fix | Delete
[602] Fix | Delete
def _onclick(self, item, fun, num=1, add=None):
[603] Fix | Delete
"""Bind fun to mouse-click event on turtle.
[604] Fix | Delete
fun must be a function with two arguments, the coordinates
[605] Fix | Delete
of the clicked point on the canvas.
[606] Fix | Delete
num, the number of the mouse-button defaults to 1
[607] Fix | Delete
"""
[608] Fix | Delete
if fun is None:
[609] Fix | Delete
self.cv.tag_unbind(item, "<Button-%s>" % num)
[610] Fix | Delete
else:
[611] Fix | Delete
def eventfun(event):
[612] Fix | Delete
x, y = (self.cv.canvasx(event.x)/self.xscale,
[613] Fix | Delete
-self.cv.canvasy(event.y)/self.yscale)
[614] Fix | Delete
fun(x, y)
[615] Fix | Delete
self.cv.tag_bind(item, "<Button-%s>" % num, eventfun, add)
[616] Fix | Delete
[617] Fix | Delete
def _onrelease(self, item, fun, num=1, add=None):
[618] Fix | Delete
"""Bind fun to mouse-button-release event on turtle.
[619] Fix | Delete
fun must be a function with two arguments, the coordinates
[620] Fix | Delete
of the point on the canvas where mouse button is released.
[621] Fix | Delete
num, the number of the mouse-button defaults to 1
[622] Fix | Delete
[623] Fix | Delete
If a turtle is clicked, first _onclick-event will be performed,
[624] Fix | Delete
then _onscreensclick-event.
[625] Fix | Delete
"""
[626] Fix | Delete
if fun is None:
[627] Fix | Delete
self.cv.tag_unbind(item, "<Button%s-ButtonRelease>" % num)
[628] Fix | Delete
else:
[629] Fix | Delete
def eventfun(event):
[630] Fix | Delete
x, y = (self.cv.canvasx(event.x)/self.xscale,
[631] Fix | Delete
-self.cv.canvasy(event.y)/self.yscale)
[632] Fix | Delete
fun(x, y)
[633] Fix | Delete
self.cv.tag_bind(item, "<Button%s-ButtonRelease>" % num,
[634] Fix | Delete
eventfun, add)
[635] Fix | Delete
[636] Fix | Delete
def _ondrag(self, item, fun, num=1, add=None):
[637] Fix | Delete
"""Bind fun to mouse-move-event (with pressed mouse button) on turtle.
[638] Fix | Delete
fun must be a function with two arguments, the coordinates of the
[639] Fix | Delete
actual mouse position on the canvas.
[640] Fix | Delete
num, the number of the mouse-button defaults to 1
[641] Fix | Delete
[642] Fix | Delete
Every sequence of mouse-move-events on a turtle is preceded by a
[643] Fix | Delete
mouse-click event on that turtle.
[644] Fix | Delete
"""
[645] Fix | Delete
if fun is None:
[646] Fix | Delete
self.cv.tag_unbind(item, "<Button%s-Motion>" % num)
[647] Fix | Delete
else:
[648] Fix | Delete
def eventfun(event):
[649] Fix | Delete
try:
[650] Fix | Delete
x, y = (self.cv.canvasx(event.x)/self.xscale,
[651] Fix | Delete
-self.cv.canvasy(event.y)/self.yscale)
[652] Fix | Delete
fun(x, y)
[653] Fix | Delete
except Exception:
[654] Fix | Delete
pass
[655] Fix | Delete
self.cv.tag_bind(item, "<Button%s-Motion>" % num, eventfun, add)
[656] Fix | Delete
[657] Fix | Delete
def _onscreenclick(self, fun, num=1, add=None):
[658] Fix | Delete
"""Bind fun to mouse-click event on canvas.
[659] Fix | Delete
fun must be a function with two arguments, the coordinates
[660] Fix | Delete
of the clicked point on the canvas.
[661] Fix | Delete
num, the number of the mouse-button defaults to 1
[662] Fix | Delete
[663] Fix | Delete
If a turtle is clicked, first _onclick-event will be performed,
[664] Fix | Delete
then _onscreensclick-event.
[665] Fix | Delete
"""
[666] Fix | Delete
if fun is None:
[667] Fix | Delete
self.cv.unbind("<Button-%s>" % num)
[668] Fix | Delete
else:
[669] Fix | Delete
def eventfun(event):
[670] Fix | Delete
x, y = (self.cv.canvasx(event.x)/self.xscale,
[671] Fix | Delete
-self.cv.canvasy(event.y)/self.yscale)
[672] Fix | Delete
fun(x, y)
[673] Fix | Delete
self.cv.bind("<Button-%s>" % num, eventfun, add)
[674] Fix | Delete
[675] Fix | Delete
def _onkeyrelease(self, fun, key):
[676] Fix | Delete
"""Bind fun to key-release event of key.
[677] Fix | Delete
Canvas must have focus. See method listen
[678] Fix | Delete
"""
[679] Fix | Delete
if fun is None:
[680] Fix | Delete
self.cv.unbind("<KeyRelease-%s>" % key, None)
[681] Fix | Delete
else:
[682] Fix | Delete
def eventfun(event):
[683] Fix | Delete
fun()
[684] Fix | Delete
self.cv.bind("<KeyRelease-%s>" % key, eventfun)
[685] Fix | Delete
[686] Fix | Delete
def _onkeypress(self, fun, key=None):
[687] Fix | Delete
"""If key is given, bind fun to key-press event of key.
[688] Fix | Delete
Otherwise bind fun to any key-press.
[689] Fix | Delete
Canvas must have focus. See method listen.
[690] Fix | Delete
"""
[691] Fix | Delete
if fun is None:
[692] Fix | Delete
if key is None:
[693] Fix | Delete
self.cv.unbind("<KeyPress>", None)
[694] Fix | Delete
else:
[695] Fix | Delete
self.cv.unbind("<KeyPress-%s>" % key, None)
[696] Fix | Delete
else:
[697] Fix | Delete
def eventfun(event):
[698] Fix | Delete
fun()
[699] Fix | Delete
if key is None:
[700] Fix | Delete
self.cv.bind("<KeyPress>", eventfun)
[701] Fix | Delete
else:
[702] Fix | Delete
self.cv.bind("<KeyPress-%s>" % key, eventfun)
[703] Fix | Delete
[704] Fix | Delete
def _listen(self):
[705] Fix | Delete
"""Set focus on canvas (in order to collect key-events)
[706] Fix | Delete
"""
[707] Fix | Delete
self.cv.focus_force()
[708] Fix | Delete
[709] Fix | Delete
def _ontimer(self, fun, t):
[710] Fix | Delete
"""Install a timer, which calls fun after t milliseconds.
[711] Fix | Delete
"""
[712] Fix | Delete
if t == 0:
[713] Fix | Delete
self.cv.after_idle(fun)
[714] Fix | Delete
else:
[715] Fix | Delete
self.cv.after(t, fun)
[716] Fix | Delete
[717] Fix | Delete
def _createimage(self, image):
[718] Fix | Delete
"""Create and return image item on canvas.
[719] Fix | Delete
"""
[720] Fix | Delete
return self.cv.create_image(0, 0, image=image)
[721] Fix | Delete
[722] Fix | Delete
def _drawimage(self, item, pos, image):
[723] Fix | Delete
"""Configure image item as to draw image object
[724] Fix | Delete
at position (x,y) on canvas)
[725] Fix | Delete
"""
[726] Fix | Delete
x, y = pos
[727] Fix | Delete
self.cv.coords(item, (x * self.xscale, -y * self.yscale))
[728] Fix | Delete
self.cv.itemconfig(item, image=image)
[729] Fix | Delete
[730] Fix | Delete
def _setbgpic(self, item, image):
[731] Fix | Delete
"""Configure image item as to draw image object
[732] Fix | Delete
at center of canvas. Set item to the first item
[733] Fix | Delete
in the displaylist, so it will be drawn below
[734] Fix | Delete
any other item ."""
[735] Fix | Delete
self.cv.itemconfig(item, image=image)
[736] Fix | Delete
self.cv.tag_lower(item)
[737] Fix | Delete
[738] Fix | Delete
def _type(self, item):
[739] Fix | Delete
"""Return 'line' or 'polygon' or 'image' depending on
[740] Fix | Delete
type of item.
[741] Fix | Delete
"""
[742] Fix | Delete
return self.cv.type(item)
[743] Fix | Delete
[744] Fix | Delete
def _pointlist(self, item):
[745] Fix | Delete
"""returns list of coordinate-pairs of points of item
[746] Fix | Delete
Example (for insiders):
[747] Fix | Delete
>>> from turtle import *
[748] Fix | Delete
>>> getscreen()._pointlist(getturtle().turtle._item)
[749] Fix | Delete
[(0.0, 9.9999999999999982), (0.0, -9.9999999999999982),
[750] Fix | Delete
(9.9999999999999982, 0.0)]
[751] Fix | Delete
>>> """
[752] Fix | Delete
cl = self.cv.coords(item)
[753] Fix | Delete
pl = [(cl[i], -cl[i+1]) for i in range(0, len(cl), 2)]
[754] Fix | Delete
return pl
[755] Fix | Delete
[756] Fix | Delete
def _setscrollregion(self, srx1, sry1, srx2, sry2):
[757] Fix | Delete
self.cv.config(scrollregion=(srx1, sry1, srx2, sry2))
[758] Fix | Delete
[759] Fix | Delete
def _rescale(self, xscalefactor, yscalefactor):
[760] Fix | Delete
items = self.cv.find_all()
[761] Fix | Delete
for item in items:
[762] Fix | Delete
coordinates = list(self.cv.coords(item))
[763] Fix | Delete
newcoordlist = []
[764] Fix | Delete
while coordinates:
[765] Fix | Delete
x, y = coordinates[:2]
[766] Fix | Delete
newcoordlist.append(x * xscalefactor)
[767] Fix | Delete
newcoordlist.append(y * yscalefactor)
[768] Fix | Delete
coordinates = coordinates[2:]
[769] Fix | Delete
self.cv.coords(item, *newcoordlist)
[770] Fix | Delete
[771] Fix | Delete
def _resize(self, canvwidth=None, canvheight=None, bg=None):
[772] Fix | Delete
"""Resize the canvas the turtles are drawing on. Does
[773] Fix | Delete
not alter the drawing window.
[774] Fix | Delete
"""
[775] Fix | Delete
# needs amendment
[776] Fix | Delete
if not isinstance(self.cv, ScrolledCanvas):
[777] Fix | Delete
return self.canvwidth, self.canvheight
[778] Fix | Delete
if canvwidth is canvheight is bg is None:
[779] Fix | Delete
return self.cv.canvwidth, self.cv.canvheight
[780] Fix | Delete
if canvwidth is not None:
[781] Fix | Delete
self.canvwidth = canvwidth
[782] Fix | Delete
if canvheight is not None:
[783] Fix | Delete
self.canvheight = canvheight
[784] Fix | Delete
self.cv.reset(canvwidth, canvheight, bg)
[785] Fix | Delete
[786] Fix | Delete
def _window_size(self):
[787] Fix | Delete
""" Return the width and height of the turtle window.
[788] Fix | Delete
"""
[789] Fix | Delete
width = self.cv.winfo_width()
[790] Fix | Delete
if width <= 1: # the window isn't managed by a geometry manager
[791] Fix | Delete
width = self.cv['width']
[792] Fix | Delete
height = self.cv.winfo_height()
[793] Fix | Delete
if height <= 1: # the window isn't managed by a geometry manager
[794] Fix | Delete
height = self.cv['height']
[795] Fix | Delete
return width, height
[796] Fix | Delete
[797] Fix | Delete
def mainloop(self):
[798] Fix | Delete
"""Starts event loop - calling Tkinter's mainloop function.
[799] Fix | Delete
[800] Fix | Delete
No argument.
[801] Fix | Delete
[802] Fix | Delete
Must be last statement in a turtle graphics program.
[803] Fix | Delete
Must NOT be used if a script is run from within IDLE in -n mode
[804] Fix | Delete
(No subprocess) - for interactive use of turtle graphics.
[805] Fix | Delete
[806] Fix | Delete
Example (for a TurtleScreen instance named screen):
[807] Fix | Delete
>>> screen.mainloop()
[808] Fix | Delete
[809] Fix | Delete
"""
[810] Fix | Delete
self.cv.tk.mainloop()
[811] Fix | Delete
[812] Fix | Delete
def textinput(self, title, prompt):
[813] Fix | Delete
"""Pop up a dialog window for input of a string.
[814] Fix | Delete
[815] Fix | Delete
Arguments: title is the title of the dialog window,
[816] Fix | Delete
prompt is a text mostly describing what information to input.
[817] Fix | Delete
[818] Fix | Delete
Return the string input
[819] Fix | Delete
If the dialog is canceled, return None.
[820] Fix | Delete
[821] Fix | Delete
Example (for a TurtleScreen instance named screen):
[822] Fix | Delete
>>> screen.textinput("NIM", "Name of first player:")
[823] Fix | Delete
[824] Fix | Delete
"""
[825] Fix | Delete
return simpledialog.askstring(title, prompt, parent=self.cv)
[826] Fix | Delete
[827] Fix | Delete
def numinput(self, title, prompt, default=None, minval=None, maxval=None):
[828] Fix | Delete
"""Pop up a dialog window for input of a number.
[829] Fix | Delete
[830] Fix | Delete
Arguments: title is the title of the dialog window,
[831] Fix | Delete
prompt is a text mostly describing what numerical information to input.
[832] Fix | Delete
default: default value
[833] Fix | Delete
minval: minimum value for input
[834] Fix | Delete
maxval: maximum value for input
[835] Fix | Delete
[836] Fix | Delete
The number input must be in the range minval .. maxval if these are
[837] Fix | Delete
given. If not, a hint is issued and the dialog remains open for
[838] Fix | Delete
correction. Return the number input.
[839] Fix | Delete
If the dialog is canceled, return None.
[840] Fix | Delete
[841] Fix | Delete
Example (for a TurtleScreen instance named screen):
[842] Fix | Delete
>>> screen.numinput("Poker", "Your stakes:", 1000, minval=10, maxval=10000)
[843] Fix | Delete
[844] Fix | Delete
"""
[845] Fix | Delete
return simpledialog.askfloat(title, prompt, initialvalue=default,
[846] Fix | Delete
minvalue=minval, maxvalue=maxval,
[847] Fix | Delete
parent=self.cv)
[848] Fix | Delete
[849] Fix | Delete
[850] Fix | Delete
##############################################################################
[851] Fix | Delete
### End of Tkinter - interface ###
[852] Fix | Delete
##############################################################################
[853] Fix | Delete
[854] Fix | Delete
[855] Fix | Delete
class Terminator (Exception):
[856] Fix | Delete
"""Will be raised in TurtleScreen.update, if _RUNNING becomes False.
[857] Fix | Delete
[858] Fix | Delete
This stops execution of a turtle graphics script.
[859] Fix | Delete
Main purpose: use in the Demo-Viewer turtle.Demo.py.
[860] Fix | Delete
"""
[861] Fix | Delete
pass
[862] Fix | Delete
[863] Fix | Delete
[864] Fix | Delete
class TurtleGraphicsError(Exception):
[865] Fix | Delete
"""Some TurtleGraphics Error
[866] Fix | Delete
"""
[867] Fix | Delete
[868] Fix | Delete
[869] Fix | Delete
class Shape(object):
[870] Fix | Delete
"""Data structure modeling shapes.
[871] Fix | Delete
[872] Fix | Delete
attribute _type is one of "polygon", "image", "compound"
[873] Fix | Delete
attribute _data is - depending on _type a poygon-tuple,
[874] Fix | Delete
an image or a list constructed using the addcomponent method.
[875] Fix | Delete
"""
[876] Fix | Delete
def __init__(self, type_, data=None):
[877] Fix | Delete
self._type = type_
[878] Fix | Delete
if type_ == "polygon":
[879] Fix | Delete
if isinstance(data, list):
[880] Fix | Delete
data = tuple(data)
[881] Fix | Delete
elif type_ == "image":
[882] Fix | Delete
if isinstance(data, str):
[883] Fix | Delete
if data.lower().endswith(".gif") and isfile(data):
[884] Fix | Delete
data = TurtleScreen._image(data)
[885] Fix | Delete
# else data assumed to be Photoimage
[886] Fix | Delete
elif type_ == "compound":
[887] Fix | Delete
data = []
[888] Fix | Delete
else:
[889] Fix | Delete
raise TurtleGraphicsError("There is no shape type %s" % type_)
[890] Fix | Delete
self._data = data
[891] Fix | Delete
[892] Fix | Delete
def addcomponent(self, poly, fill, outline=None):
[893] Fix | Delete
"""Add component to a shape of type compound.
[894] Fix | Delete
[895] Fix | Delete
Arguments: poly is a polygon, i. e. a tuple of number pairs.
[896] Fix | Delete
fill is the fillcolor of the component,
[897] Fix | Delete
outline is the outline color of the component.
[898] Fix | Delete
[899] Fix | Delete
call (for a Shapeobject namend s):
[900] Fix | Delete
-- s.addcomponent(((0,0), (10,10), (-10,10)), "red", "blue")
[901] Fix | Delete
[902] Fix | Delete
Example:
[903] Fix | Delete
>>> poly = ((0,0),(10,-5),(0,10),(-10,-5))
[904] Fix | Delete
>>> s = Shape("compound")
[905] Fix | Delete
>>> s.addcomponent(poly, "red", "blue")
[906] Fix | Delete
>>> # .. add more components and then use register_shape()
[907] Fix | Delete
"""
[908] Fix | Delete
if self._type != "compound":
[909] Fix | Delete
raise TurtleGraphicsError("Cannot add component to %s Shape"
[910] Fix | Delete
% self._type)
[911] Fix | Delete
if outline is None:
[912] Fix | Delete
outline = fill
[913] Fix | Delete
self._data.append([poly, fill, outline])
[914] Fix | Delete
[915] Fix | Delete
[916] Fix | Delete
class Tbuffer(object):
[917] Fix | Delete
"""Ring buffer used as undobuffer for RawTurtle objects."""
[918] Fix | Delete
def __init__(self, bufsize=10):
[919] Fix | Delete
self.bufsize = bufsize
[920] Fix | Delete
self.buffer = [[None]] * bufsize
[921] Fix | Delete
self.ptr = -1
[922] Fix | Delete
self.cumulate = False
[923] Fix | Delete
def reset(self, bufsize=None):
[924] Fix | Delete
if bufsize is None:
[925] Fix | Delete
for i in range(self.bufsize):
[926] Fix | Delete
self.buffer[i] = [None]
[927] Fix | Delete
else:
[928] Fix | Delete
self.bufsize = bufsize
[929] Fix | Delete
self.buffer = [[None]] * bufsize
[930] Fix | Delete
self.ptr = -1
[931] Fix | Delete
def push(self, item):
[932] Fix | Delete
if self.bufsize > 0:
[933] Fix | Delete
if not self.cumulate:
[934] Fix | Delete
self.ptr = (self.ptr + 1) % self.bufsize
[935] Fix | Delete
self.buffer[self.ptr] = item
[936] Fix | Delete
else:
[937] Fix | Delete
self.buffer[self.ptr].append(item)
[938] Fix | Delete
def pop(self):
[939] Fix | Delete
if self.bufsize > 0:
[940] Fix | Delete
item = self.buffer[self.ptr]
[941] Fix | Delete
if item is None:
[942] Fix | Delete
return None
[943] Fix | Delete
else:
[944] Fix | Delete
self.buffer[self.ptr] = [None]
[945] Fix | Delete
self.ptr = (self.ptr - 1) % self.bufsize
[946] Fix | Delete
return (item)
[947] Fix | Delete
def nr_of_items(self):
[948] Fix | Delete
return self.bufsize - self.buffer.count([None])
[949] Fix | Delete
def __repr__(self):
[950] Fix | Delete
return str(self.buffer) + " " + str(self.ptr)
[951] Fix | Delete
[952] Fix | Delete
[953] Fix | Delete
[954] Fix | Delete
class TurtleScreen(TurtleScreenBase):
[955] Fix | Delete
"""Provides screen oriented methods like setbg etc.
[956] Fix | Delete
[957] Fix | Delete
Only relies upon the methods of TurtleScreenBase and NOT
[958] Fix | Delete
upon components of the underlying graphics toolkit -
[959] Fix | Delete
which is Tkinter in this case.
[960] Fix | Delete
"""
[961] Fix | Delete
_RUNNING = True
[962] Fix | Delete
[963] Fix | Delete
def __init__(self, cv, mode=_CFG["mode"],
[964] Fix | Delete
colormode=_CFG["colormode"], delay=_CFG["delay"]):
[965] Fix | Delete
TurtleScreenBase.__init__(self, cv)
[966] Fix | Delete
[967] Fix | Delete
self._shapes = {
[968] Fix | Delete
"arrow" : Shape("polygon", ((-10,0), (10,0), (0,10))),
[969] Fix | Delete
"turtle" : Shape("polygon", ((0,16), (-2,14), (-1,10), (-4,7),
[970] Fix | Delete
(-7,9), (-9,8), (-6,5), (-7,1), (-5,-3), (-8,-6),
[971] Fix | Delete
(-6,-8), (-4,-5), (0,-7), (4,-5), (6,-8), (8,-6),
[972] Fix | Delete
(5,-3), (7,1), (6,5), (9,8), (7,9), (4,7), (1,10),
[973] Fix | Delete
(2,14))),
[974] Fix | Delete
"circle" : Shape("polygon", ((10,0), (9.51,3.09), (8.09,5.88),
[975] Fix | Delete
(5.88,8.09), (3.09,9.51), (0,10), (-3.09,9.51),
[976] Fix | Delete
(-5.88,8.09), (-8.09,5.88), (-9.51,3.09), (-10,0),
[977] Fix | Delete
(-9.51,-3.09), (-8.09,-5.88), (-5.88,-8.09),
[978] Fix | Delete
(-3.09,-9.51), (-0.00,-10.00), (3.09,-9.51),
[979] Fix | Delete
(5.88,-8.09), (8.09,-5.88), (9.51,-3.09))),
[980] Fix | Delete
"square" : Shape("polygon", ((10,-10), (10,10), (-10,10),
[981] Fix | Delete
(-10,-10))),
[982] Fix | Delete
"triangle" : Shape("polygon", ((10,-5.77), (0,11.55),
[983] Fix | Delete
(-10,-5.77))),
[984] Fix | Delete
"classic": Shape("polygon", ((0,0),(-5,-9),(0,-7),(5,-9))),
[985] Fix | Delete
"blank" : Shape("image", self._blankimage())
[986] Fix | Delete
}
[987] Fix | Delete
[988] Fix | Delete
self._bgpics = {"nopic" : ""}
[989] Fix | Delete
[990] Fix | Delete
self._mode = mode
[991] Fix | Delete
self._delayvalue = delay
[992] Fix | Delete
self._colormode = _CFG["colormode"]
[993] Fix | Delete
self._keys = []
[994] Fix | Delete
self.clear()
[995] Fix | Delete
if sys.platform == 'darwin':
[996] Fix | Delete
# Force Turtle window to the front on OS X. This is needed because
[997] Fix | Delete
# the Turtle window will show behind the Terminal window when you
[998] Fix | Delete
# start the demo from the command line.
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function