Skip to content
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

Alternative behavior for exit, help, license builtins #133

Open
wants to merge 1 commit into
base: master
from

Conversation

@bittner
Copy link
Member

@bittner bittner commented Mar 30, 2019

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 object
  • help() can mimic pressing the Help button on the UI
  • license() opens a web browser on the Python website showing the license (unless we can draw it from the file system)
@bittner bittner requested a review from cool-RR Mar 30, 2019
to hide the implementation details from the user.
"""
evt = wx.CommandEvent(wx.ID_EXIT, wx.ID_EXIT)
wx.PostEvent(self.window, evt)

This comment has been minimized.

@bittner

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. 😟

This comment has been minimized.

@cool-RR

cool-RR Mar 30, 2019
Member

How about calling the .Close method on the Frame?

This comment has been minimized.

@bittner

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)

This comment has been minimized.

@cool-RR

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.

Copy link
Member

@cool-RR cool-RR left a comment

This is good, though I have a few notes about the docstring styling. I prefer:

  1. Triple single quotes instead of triple double quotes.
  2. The first sentence should be separated from any paragraphs that follow it, and separated with a blank line.
  3. 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()

This comment has been minimized.

@bittner

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?

This comment has been minimized.

@cool-RR

cool-RR Mar 30, 2019
Member

Did you try calling ApplicationWindow.show_help?

This comment has been minimized.

@bittner

bittner Mar 30, 2019
Author Member

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

This comment has been minimized.

@cool-RR

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.

@cool-RR
Copy link
Member

@cool-RR cool-RR commented Mar 30, 2019

@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')

This comment has been minimized.

@bittner

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?

This comment has been minimized.

@cool-RR

cool-RR Mar 30, 2019
Member

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

@bittner
Copy link
Member Author

@bittner bittner commented Mar 30, 2019

1. Triple single quotes instead of triple double quotes.

Let's stick to PEP 257. I can change it accordingly.

@cool-RR
Copy link
Member

@cool-RR cool-RR commented Mar 30, 2019

1. Triple single quotes instead of triple double quotes.

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 """ and the first word. Could we do a newline between them like in my example and your current code?

@bittner
Copy link
Member Author

@bittner bittner commented Mar 31, 2019

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 window member attached to the TurtleProcess instance? Anything that comes to your mind about this, @cool-RR?

@cool-RR
Copy link
Member

@cool-RR cool-RR commented Mar 31, 2019

Could that be why the code behaves weird when I access the window member attached to the TurtleProcess instance?

This explanation sounds very likely. I think that to implement exit, you'll need to send an "exit" message through a queue similar to the queues defined in console.py, and have code that listens to the message and quits the program. Ensure you're joining the TurtleProcess if that's not done automatically already.

@bittner bittner force-pushed the bittner:feature/make-disabled-builtins-useful branch from c5fb9a5 to e3520c4 Apr 1, 2019
@bittner bittner force-pushed the bittner:feature/make-disabled-builtins-useful branch from e3520c4 to bdc6bc0 Aug 10, 2019
@bittner bittner force-pushed the bittner:feature/make-disabled-builtins-useful branch from bdc6bc0 to f6a09ec Aug 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.