]> granicus.if.org Git - python/commitdiff
Issue #17172: Add the ability to run turtledemo from Idle.
authorTerry Jan Reedy <tjreedy@udel.edu>
Tue, 29 Jul 2014 02:23:59 +0000 (22:23 -0400)
committerTerry Jan Reedy <tjreedy@udel.edu>
Tue, 29 Jul 2014 02:23:59 +0000 (22:23 -0400)
Make turtledemo start as active on Mac even when run with subprocess.
Patch by Ramchandra Apt, Lita Cho, and Ned Daily.

Lib/idlelib/Bindings.py
Lib/idlelib/EditorWindow.py
Lib/turtledemo/__main__.py

index df2b251426a91f5c298e3352c80a79510558a194..c9bef217b96e089415c7889ef075532d1c70e447 100644 (file)
@@ -8,6 +8,8 @@ the PythonShell window, and a Format menu which is only present in the Editor
 windows.
 
 """
+from importlib.util import find_spec
+
 from idlelib.configHandler import idleConf
 
 #   Warning: menudefs is altered in macosxSupport.overrideRootMenu()
@@ -86,4 +88,7 @@ menudefs = [
    ]),
 ]
 
+if find_spec('turtledemo'):
+    menudefs[-1][1].append(('Turtle Demo', '<<open-turtle-demo>>'))
+
 default_keydefs = idleConf.GetCurrentKeySet()
index f3df8eacc919c4f5f42ece4d336f7cc0df66d8a4..94cf31429dd7be422235e18fb8d45fd0e53df64a 100644 (file)
@@ -222,6 +222,7 @@ class EditorWindow(object):
             text.bind("<<close-all-windows>>", self.flist.close_all_callback)
             text.bind("<<open-class-browser>>", self.open_class_browser)
             text.bind("<<open-path-browser>>", self.open_path_browser)
+            text.bind("<<open-turtle-demo>>", self.open_turtle_demo)
 
         self.set_status_bar()
         vbar['command'] = text.yview
@@ -705,6 +706,14 @@ class EditorWindow(object):
         from idlelib import PathBrowser
         PathBrowser.PathBrowser(self.flist)
 
+    def open_turtle_demo(self, event = None):
+        import subprocess
+
+        cmd = [sys.executable,
+               '-c',
+               'from turtledemo.__main__ import main; main()']
+        p = subprocess.Popen(cmd, shell=False)
+
     def gotoline(self, lineno):
         if lineno is not None and lineno > 0:
             self.text.mark_set("insert", "%d.0" % lineno)
index 07560c353955fe699726904855f2875a536ad64d..63f97e294651df1b2ce5483df85c1ab00a539406 100755 (executable)
@@ -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)