MCPcopy Index your code
hub / github.com/python/cpython / _undogoto

Method _undogoto

Lib/turtle.py:3315–3378  ·  view source on GitHub ↗

Reverse a _goto. Used for undo()

(self, entry)

Source from the content-addressed store, hash-verified

3313 self._update() #count=True)
3314
3315 def _undogoto(self, entry):
3316 """Reverse a _goto. Used for undo()
3317 """
3318 old, new, go_modes, coodata = entry
3319 drawing, pc, ps, filling = go_modes
3320 cLI, cL, pl, items = coodata
3321 screen = self.screen
3322 if abs(self._position - new) > 0.5:
3323 print ("undogoto: HALLO-DA-STIMMT-WAS-NICHT!")
3324 # restore former situation
3325 self.currentLineItem = cLI
3326 self.currentLine = cL
3327
3328 if pl == [(0, 0), (0, 0)]:
3329 usepc = ""
3330 else:
3331 usepc = pc
3332 screen._drawline(cLI, pl, fill=usepc, width=ps)
3333
3334 todelete = [i for i in self.items if (i not in items) and
3335 (screen._type(i) == "line")]
3336 for i in todelete:
3337 screen._delete(i)
3338 self.items.remove(i)
3339
3340 start = old
3341 if self._speed and screen._tracing == 1:
3342 diff = old - new
3343 diffsq = (diff[0]*screen.xscale)**2 + (diff[1]*screen.yscale)**2
3344 nhops = 1+int((diffsq**0.5)/(3*(1.1**self._speed)*self._speed))
3345 delta = diff * (1.0/nhops)
3346 for n in range(1, nhops):
3347 if n == 1:
3348 top = True
3349 else:
3350 top = False
3351 self._position = new + delta * n
3352 if drawing:
3353 screen._drawline(self.drawingLineItem,
3354 (start, self._position),
3355 pc, ps, top)
3356 self._update()
3357 if drawing:
3358 screen._drawline(self.drawingLineItem, ((0, 0), (0, 0)),
3359 fill="", width=ps)
3360 # Turtle now at position old,
3361 self._position = old
3362 ## if undo is done during creating a polygon, the last vertex
3363 ## will be deleted. if the polygon is entirely deleted,
3364 ## creatingPoly will be set to False.
3365 ## Polygons created before the last one will not be affected by undo()
3366 if self._creatingPoly:
3367 if len(self._poly) > 0:
3368 self._poly.pop()
3369 if self._poly == []:
3370 self._creatingPoly = False
3371 self._poly = None
3372 if filling:

Callers 1

_undoMethod · 0.95

Calls 7

_updateMethod · 0.95
absFunction · 0.85
_drawlineMethod · 0.80
_typeMethod · 0.80
_deleteMethod · 0.45
removeMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected