| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1288,7 +1288,7 @@ def delay(self, delay=None): | |||
| 1288 | 1288 | def _incrementudc(self): | |
| 1289 | 1289 | """Increment update counter.""" | |
| 1290 | 1290 | if not TurtleScreen._RUNNING: | |
| 1291 | - TurtleScreen._RUNNNING = True | ||
| 1291 | + TurtleScreen._RUNNING = True | ||
| 1292 | 1292 | raise Terminator | |
| 1293 | 1293 | if self._tracing > 0: | |
| 1294 | 1294 | self._updatecounter += 1 | |
@@ -3754,7 +3754,7 @@ def _destroy(self): | |||
| 3754 | 3754 | Turtle._screen = None | |
| 3755 | 3755 | _Screen._root = None | |
| 3756 | 3756 | _Screen._canvas = None | |
| 3757 | - TurtleScreen._RUNNING = True | ||
| 3757 | + TurtleScreen._RUNNING = False | ||
| 3758 | 3758 | root.destroy() | |
| 3759 | 3759 | ||
| 3760 | 3760 | def bye(self): | |
@@ -3795,7 +3795,6 @@ def exitGracefully(x, y): | |||
| 3795 | 3795 | except AttributeError: | |
| 3796 | 3796 | exit(0) | |
| 3797 | 3797 | ||
| 3798 | - | ||
| 3799 | 3798 | class Turtle(RawTurtle): | |
| 3800 | 3799 | """RawTurtle auto-creating (scrolled) canvas. | |
| 3801 | 3800 | ||
@@ -3818,18 +3817,6 @@ def __init__(self, | |||
| 3818 | 3817 | ||
| 3819 | 3818 | Pen = Turtle | |
| 3820 | 3819 | ||
| 3821 | - def _getpen(): | ||
| 3822 | - """Create the 'anonymous' turtle if not already present.""" | ||
| 3823 | - if Turtle._pen is None: | ||
| 3824 | - Turtle._pen = Turtle() | ||
| 3825 | - return Turtle._pen | ||
| 3826 | - | ||
| 3827 | - def _getscreen(): | ||
| 3828 | - """Create a TurtleScreen if not already present.""" | ||
| 3829 | - if Turtle._screen is None: | ||
| 3830 | - Turtle._screen = Screen() | ||
| 3831 | - return Turtle._screen | ||
| 3832 | - | ||
| 3833 | 3820 | def write_docstringdict(filename="turtle_docstringdict"): | |
| 3834 | 3821 | """Create and write docstring-dictionary to file. | |
| 3835 | 3822 | ||
@@ -3952,26 +3939,38 @@ def _screen_docrevise(docstr): | |||
| 3952 | 3939 | ## as functions. So we can enhance, change, add, delete methods to these | |
| 3953 | 3940 | ## classes and do not need to change anything here. | |
| 3954 | 3941 | ||
| 3942 | + __func_body = """\ | ||
| 3943 | + def {name}{paramslist}: | ||
| 3944 | + if {obj} is None: | ||
| 3945 | + if not TurtleScreen._RUNNING: | ||
| 3946 | + TurtleScreen._RUNNING = True | ||
| 3947 | + raise Terminator | ||
| 3948 | + {obj} = {init} | ||
| 3949 | + try: | ||
| 3950 | + return {obj}.{name}{argslist} | ||
| 3951 | + except TK.TclError: | ||
| 3952 | + if not TurtleScreen._RUNNING: | ||
| 3953 | + TurtleScreen._RUNNING = True | ||
| 3954 | + raise Terminator | ||
| 3955 | + raise | ||
| 3956 | + """ | ||
| 3955 | 3957 | ||
| 3956 | - for methodname in _tg_screen_functions: | ||
| 3957 | - pl1, pl2 = getmethparlist(eval('_Screen.' + methodname)) | ||
| 3958 | - if pl1 == "": | ||
| 3959 | - print(">>>>>>", pl1, pl2) | ||
| 3960 | - continue | ||
| 3961 | - defstr = ("def %(key)s%(pl1)s: return _getscreen().%(key)s%(pl2)s" % | ||
| 3962 | - {'key':methodname, 'pl1':pl1, 'pl2':pl2}) | ||
| 3963 | - exec(defstr) | ||
| 3964 | - eval(methodname).__doc__ = _screen_docrevise(eval('_Screen.'+methodname).__doc__) | ||
| 3965 | - | ||
| 3966 | - for methodname in _tg_turtle_functions: | ||
| 3967 | - pl1, pl2 = getmethparlist(eval('Turtle.' + methodname)) | ||
| 3968 | - if pl1 == "": | ||
| 3969 | - print(">>>>>>", pl1, pl2) | ||
| 3970 | - continue | ||
| 3971 | - defstr = ("def %(key)s%(pl1)s: return _getpen().%(key)s%(pl2)s" % | ||
| 3972 | - {'key':methodname, 'pl1':pl1, 'pl2':pl2}) | ||
| 3973 | - exec(defstr) | ||
| 3974 | - eval(methodname).__doc__ = _turtle_docrevise(eval('Turtle.'+methodname).__doc__) | ||
| 3958 | + def _make_global_funcs(functions, cls, obj, init, docrevise): | ||
| 3959 | + for methodname in functions: | ||
| 3960 | + method = getattr(cls, methodname) | ||
| 3961 | + pl1, pl2 = getmethparlist(method) | ||
| 3962 | + if pl1 == "": | ||
| 3963 | + print(">>>>>>", pl1, pl2) | ||
| 3964 | + continue | ||
| 3965 | + defstr = __func_body.format(obj=obj, init=init, name=methodname, | ||
| 3966 | + paramslist=pl1, argslist=pl2) | ||
| 3967 | + exec(defstr, globals()) | ||
| 3968 | + globals()[methodname].__doc__ = docrevise(method.__doc__) | ||
| 3969 | + | ||
| 3970 | + _make_global_funcs(_tg_screen_functions, _Screen, | ||
| 3971 | + 'Turtle._screen', 'Screen()', _screen_docrevise) | ||
| 3972 | + _make_global_funcs(_tg_turtle_functions, Turtle, | ||
| 3973 | + 'Turtle._pen', 'Turtle()', _turtle_docrevise) | ||
| 3975 | 3974 | ||
| 3976 | 3975 | ||
| 3977 | 3976 | done = mainloop | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -344,6 +344,8 @@ def startDemo(self): | |||
| 344 | 344 | else: | |
| 345 | 345 | self.state = DONE | |
| 346 | 346 | except turtle.Terminator: | |
| 347 | + if self.root is None: | ||
| 348 | + return | ||
| 347 | 349 | self.state = DONE | |
| 348 | 350 | result = "stopped!" | |
| 349 | 351 | if self.state == DONE: | |
@@ -369,7 +371,9 @@ def stopIt(self): | |||
| 369 | 371 | turtle.TurtleScreen._RUNNING = False | |
| 370 | 372 | ||
| 371 | 373 | def _destroy(self): | |
| 374 | + turtle.TurtleScreen._RUNNING = False | ||
| 372 | 375 | self.root.destroy() | |
| 376 | + self.root = None | ||
| 373 | 377 | ||
| 374 | 378 | ||
| 375 | 379 | def main(): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,9 @@ Core and Builtins | |||
| 13 | 13 | Library | |
| 14 | 14 | ------- | |
| 15 | 15 | ||
| 16 | + - Issue #6639: Module-level turtle functions no longer raise TclError after | ||
| 17 | + closing the window. | ||
| 18 | + | ||
| 16 | 19 | - Issues #814253, #9179: Warnings now are raised when group references and | |
| 17 | 20 | conditional group references are used in lookbehind assertions in regular | |
| 18 | 21 | expressions. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments