-
Notifications
You must be signed in to change notification settings - Fork 107
Alternative behavior for exit, help, license builtins #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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() | ||
|
||
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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:
@cool-RR, do you know a way to trigger the "Teach me" button or the <F1> key?
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.