summaryrefslogtreecommitdiff
path: root/Lib/turtledemo/__main__.py
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2014-07-28 22:23:59 -0400
committerTerry Jan Reedy <tjreedy@udel.edu>2014-07-28 22:23:59 -0400
commit7e55db2bc566381bfda3ddcd44c048f0c627880f (patch)
tree3cc079e69282249043a7408b26d5bd10c519eeb2 /Lib/turtledemo/__main__.py
parentc61c170b419be5896608baf47ca3737b94cc15da (diff)
downloadcpython-git-7e55db2bc566381bfda3ddcd44c048f0c627880f.tar.gz
Issue #17172: Add the ability to run turtledemo from Idle.
Make turtledemo start as active on Mac even when run with subprocess. Patch by Ramchandra Apt, Lita Cho, and Ned Daily.
Diffstat (limited to 'Lib/turtledemo/__main__.py')
-rwxr-xr-xLib/turtledemo/__main__.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/turtledemo/__main__.py b/Lib/turtledemo/__main__.py
index 07560c3539..63f97e2946 100755
--- a/Lib/turtledemo/__main__.py
+++ b/Lib/turtledemo/__main__.py
@@ -40,6 +40,22 @@ class DemoWindow(object):
root.title('Python turtle-graphics examples')
root.wm_protocol("WM_DELETE_WINDOW", self._destroy)
+ if sys.platform == 'darwin':
+ import subprocess
+ # Make sure we are the currently activated OS X application
+ # so that our menu bar appears.
+ p = subprocess.Popen(
+ [
+ 'osascript',
+ '-e', 'tell application "System Events"',
+ '-e', 'set frontmost of the first process whose '
+ 'unix id is {} to true'.format(os.getpid()),
+ '-e', 'end tell',
+ ],
+ stderr=subprocess.DEVNULL,
+ stdout=subprocess.DEVNULL,
+ )
+
root.grid_rowconfigure(1, weight=1)
root.grid_columnconfigure(0, weight=1)
root.grid_columnconfigure(1, minsize=90, weight=1)