Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Alternative behavior for exit, help, license builtins #133
Conversation
to hide the implementation details from the user. | ||
""" | ||
evt = wx.CommandEvent(wx.ID_EXIT, wx.ID_EXIT) | ||
wx.PostEvent(self.window, evt) |
bittner
Mar 30, 2019
Author
Member
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.
bittner
Mar 30, 2019
Author
Member
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)
cool-RR
Mar 30, 2019
Member
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.
This is good, though I have a few notes about the docstring styling. I prefer:
Example:
|
if object: | ||
print(object.__doc__) | ||
else: | ||
self.window.show_help() |
bittner
Mar 30, 2019
Author
Member
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?
cool-RR
Mar 30, 2019
Member
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') |
bittner
Mar 30, 2019
Author
Member
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?
cool-RR
Mar 30, 2019
Member
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
e3520c4
to
bdc6bc0
bdc6bc0
to
f6a09ec
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)