Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pythonturtle/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, *args, **keywords):
self.init_help_screen()

self.turtle_process = turtleprocess.TurtleProcess()
self.turtle_process.window = self
self.turtle_process.start()
self.turtle_queue = self.turtle_process.turtle_queue

Expand Down Expand Up @@ -220,6 +221,7 @@ def on_about(self, event=None):
def run():
multiprocessing.freeze_support()
app = wx.App()
ApplicationWindow(None, -1, pythonturtle.name, size=(600, 600))
# import cProfile; cProfile.run("app.MainLoop()")
ApplicationWindow(parent=None,
title=pythonturtle.name,
size=(600, 600))
app.MainLoop()
48 changes: 44 additions & 4 deletions pythonturtle/turtleprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
A TurtleProcess is a subclass of ``multiprocessing.Process``.
It is the process from which the user of PythonTurtle works.
"""
import builtins
import copy
import math
import multiprocessing
import sys
import time
import builtins
import webbrowser

from . import shelltoprocess
from .misc import smartsleep
Expand Down Expand Up @@ -51,11 +52,50 @@ def send_report(self):

def run(self):

builtins.help = builtins.license = builtins.exit = \
lambda *args, **kwargs: print('Not supported')

self.turtle = Turtle()

def exit():
"""
Close the app when a user types `exit()` or `quit()`.

The built-in exit and quit functions terminate the
interpreter hence making the application unusable. We
terminate the application directly instead.
"""
print(self.window.Close())
print(self.window.Destroy())

builtins.exit = exit
builtins.quit = exit

def help(object=None):
"""
Show a command's docstring or the app's help screen.

The built-in help function prints to the console and is
interactive there, thus blocking the UI. We simply display
the docstring of an object, when called with an argument,
or show the application help screen otherwise.
"""
if object:
print(object.__doc__)
else:
self.window.show_help()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work either. For some reason the window has lost some attributes:

>>> help()
Traceback (most recent call last):
  File "/usr/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/home/peter/PythonTurtle/pythonturtle/turtleprocess.py", line 80, in help
    self.window.show_help()
  File "/home/peter/PythonTurtle/pythonturtle/application.py", line 177, in show_help
    self.help_menu_item.Check()
AttributeError: 'ApplicationWindow' object has no attribute 'help_menu_item'

@cool-RR, do you know a way to trigger the "Teach me" button or the <F1> key?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try calling ApplicationWindow.show_help?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what the code does, isn't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I'm a dumbass. I could investigate, but this is very unimportant. You can make it a no-op in the case where an object wasn't specified.


builtins.help = help

def license():
"""
Open a browser window with Python's license explained.

The built-in license function is interactive and blocks the
UI. We open the default web browser with the Python website
displaying the license instead.
"""
webbrowser.open('https://docs.python.org/3/license.html')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a compromise that does, of course, not work offline. We could try to find out whether the license is available as a file in a Python installation and is somehow accessible for printing out. Otherwise, I'd guess this is acceptable. Who will run this function anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely some very esoteric functionality. Your solution is above and beyond what we need.


builtins.license = license

def go(distance):
"""
Makes the turtle walk the specified distance. Use a negative number
Expand Down