-
Notifications
You must be signed in to change notification settings - Fork 106
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?
Alternative behavior for exit, help, license builtins #133
Conversation
pythonturtle/turtleprocess.py
Outdated
to hide the implementation details from the user. | ||
""" | ||
evt = wx.CommandEvent(wx.ID_EXIT, wx.ID_EXIT) | ||
wx.PostEvent(self.window, evt) |
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.
I want to fire an "exit the application" event. Unfortunately, this doesn't work. Any idea, @cool-RR?
Unfortunately, brute-force attempts like wx.Abort()
behave just like os._exit(0)
, which makes the application window hang. 😟
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.
How about calling the .Close
method on the Frame
?
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.
It does nothing. It even returns True
, which translates to "event was handled". I also tried with force=True
, it behaves the same:
self.window.Close(force=true)
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.
I could investigate but it's not worth the time. As far as I'm concerned you can make exit
just do nothing. Honestly this is very esoteric. If you're doing this for fun you can just ask on the wxPython forum and you're likely to get an answer.
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 is good, though I have a few notes about the docstring styling. I prefer:
- Triple single quotes instead of triple double quotes.
- The first sentence should be separated from any paragraphs that follow it, and separated with a blank line.
- The first sentence should be in straightforward language and an imperative mood.
Example:
def license():
'''
Show the Python license in a browser window.
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.
'''
if object: | ||
print(object.__doc__) | ||
else: | ||
self.window.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.
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?
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.
@bittner Did you get my emails? I'd like to chat with you on Telegram, if you're available. |
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 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?
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 is definitely some very esoteric functionality. Your solution is above and beyond what we need.
Let's stick to PEP 257. I can change it accordingly. |
Compromise: I'm okay with double quotes, but I really hate the lack of space that PEP 257 suggests between the first |
Trying a few things and looking at the code after discussing the problem on the wxPython-users Google Group I figured that the problem I'm facing could be related to multiprocessing. PythonTurtle, when you start it up, is actually running two processes: The main process, hosting all the wxPython business (if I figure correctly), and the TurtleProcess, which is forked as a separate process from the parent process (according to the Unix OS theory). Could that be why the code behaves weird when I access the |
This explanation sounds very likely. I think that to implement |
c5fb9a5
to
e3520c4
Compare
e3520c4
to
bdc6bc0
Compare
bdc6bc0
to
f6a09ec
Compare
Instead of simply deactivating the builtins that cause trouble on the UI we can implement some useful behavior:
exit()
should terminate the PythonTurtle application (as it would terminate the Python interpreter)help(<object>)
can show the docstrings of an objecthelp()
can mimic pressing the Help button on the UIlicense()
opens a web browser on the Python website showing the license (unless we can draw it from the file system)