Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 March 30, 2019 12:23
to hide the implementation details from the user.
"""
evt = wx.CommandEvent(wx.ID_EXIT, wx.ID_EXIT)
wx.PostEvent(self.window, evt)
Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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)

Copy link
Member

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.

Copy link
Member

@cool-RR cool-RR left a 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:

  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()
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.

@cool-RR
Copy link
Member

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

@bittner
Copy link
Member Author

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 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 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 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 feature/make-disabled-builtins-useful branch from c5fb9a5 to e3520c4 Compare April 1, 2019 01:15
@bittner bittner force-pushed the feature/make-disabled-builtins-useful branch from e3520c4 to bdc6bc0 Compare August 10, 2019 11:12
@bittner bittner force-pushed the feature/make-disabled-builtins-useful branch from bdc6bc0 to f6a09ec Compare August 10, 2019 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants