Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 827822e

Browse files
committedFeb 12, 2009
Fix for issue5194, based on a patch by Ned Deily.
1 parent de09acf commit 827822e

File tree

8 files changed

+65
-15
lines changed

8 files changed

+65
-15
lines changed
 

‎Lib/idlelib/Bindings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"""
1111
import sys
1212
from idlelib.configHandler import idleConf
13+
from idlelib import macosxSupport
1314

1415
menudefs = [
1516
# underscore prefixes character to underscore
@@ -80,7 +81,7 @@
8081
]),
8182
]
8283

83-
if sys.platform == 'darwin' and '.app' in sys.executable:
84+
if macosxSupport.runningAsOSXApp():
8485
# Running as a proper MacOS application bundle. This block restructures
8586
# the menus a little to make them conform better to the HIG.
8687

‎Lib/idlelib/EditorWindow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def createmenubar(self):
363363
underline, label = prepstr(label)
364364
menudict[name] = menu = Menu(mbar, name=name)
365365
mbar.add_cascade(label=label, menu=menu, underline=underline)
366-
if sys.platform == 'darwin' and '.framework' in sys.executable:
366+
if macosxSupport.runningAsOSXApp():
367367
# Insert the application menu
368368
menudict['application'] = menu = Menu(mbar, name='apple')
369369
mbar.add_cascade(label='IDLE', menu=menu)

‎Lib/idlelib/MultiCall.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import sys
3333
import re
3434
import tkinter
35+
from idlelib import macosxSupport
3536

3637
# the event type constants, which define the meaning of mc_type
3738
MC_KEYPRESS=0; MC_KEYRELEASE=1; MC_BUTTONPRESS=2; MC_BUTTONRELEASE=3;
@@ -44,7 +45,7 @@
4445
MC_OPTION = 1<<6; MC_COMMAND = 1<<7
4546

4647
# define the list of modifiers, to be used in complex event types.
47-
if sys.platform == "darwin" and sys.executable.count(".app"):
48+
if macosxSupport.runningAsOSXApp():
4849
_modifiers = (("Shift",), ("Control",), ("Option",), ("Command",))
4950
_modifier_masks = (MC_SHIFT, MC_CONTROL, MC_OPTION, MC_COMMAND)
5051
else:

‎Lib/idlelib/keybindingDialog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from tkinter import *
55
import tkinter.messagebox as tkMessageBox
66
import string
7+
from idlelib import macosxSupport
78

89
class GetKeysDialog(Toplevel):
910
def __init__(self,parent,title,action,currentKeySequences):
@@ -133,7 +134,7 @@ def SetModifiersForPlatform(self):
133134
config-keys.def must use the same ordering.
134135
"""
135136
import sys
136-
if sys.platform == 'darwin' and sys.argv[0].count('.app'):
137+
if macosxSupport.runningAsOSXApp():
137138
self.modifiers = ['Shift', 'Control', 'Option', 'Command']
138139
else:
139140
self.modifiers = ['Control', 'Alt', 'Shift']

‎Lib/idlelib/macosxSupport.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
import tkinter
77

88
def runningAsOSXApp():
9-
""" Returns True iff running from the IDLE.app bundle on OSX """
10-
return (sys.platform == 'darwin' and 'IDLE.app' in sys.argv[0])
9+
"""
10+
Returns True if Python is running from within an app on OSX.
11+
If so, assume that Python was built with Aqua Tcl/Tk rather than
12+
X11 Tck/Tk.
13+
"""
14+
return (sys.platform == 'darwin' and '.app' in sys.executable)
1115

1216
def addOpenEventSupport(root, flist):
1317
"""

‎Mac/IDLE/IDLE.app/Contents/MacOS/IDLE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!%prefix%/Resources/Python.app/Contents/MacOS/Python3
1+
#!%prefix%/Resources/Python.app/Contents/MacOS/%exe%
22

33
import sys, os
44
execdir = os.path.dirname(sys.argv[0])

‎Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
"""
44
import sys, os
55

6-
from idlelib.PyShell import main
7-
86
# Change the current directory the user's home directory, that way we'll get
97
# a more useful default location in the open/save dialogs.
108
os.chdir(os.path.expanduser('~/Documents'))
@@ -13,10 +11,54 @@
1311
# Make sure sys.executable points to the python interpreter inside the
1412
# framework, instead of at the helper executable inside the application
1513
# bundle (the latter works, but doesn't allow access to the window server)
16-
if sys.executable.endswith('-32'):
17-
sys.executable = os.path.join(sys.prefix, 'bin', 'python-32')
18-
else:
19-
sys.executable = os.path.join(sys.prefix, 'bin', 'python')
14+
#
15+
# .../IDLE.app/
16+
# Contents/
17+
# MacOS/
18+
# IDLE (a python script)
19+
# Python{-32} (symlink)
20+
# Resources/
21+
# idlemain.py (this module)
22+
# ...
23+
#
24+
# ../IDLE.app/Contents/MacOS/Python{-32} is symlinked to
25+
# ..Library/Frameworks/Python.framework/Versions/m.n
26+
# /Resources/Python.app/Contents/MacOS/Python{-32}
27+
# which is the Python interpreter executable
28+
#
29+
# The flow of control is as follows:
30+
# 1. IDLE.app is launched which starts python running the IDLE script
31+
# 2. IDLE script exports
32+
# PYTHONEXECUTABLE = .../IDLE.app/Contents/MacOS/Python{-32}
33+
# (the symlink to the framework python)
34+
# 3. IDLE script alters sys.argv and uses os.execve to replace itself with
35+
# idlemain.py running under the symlinked python.
36+
# This is the magic step.
37+
# 4. During interpreter initialization, because PYTHONEXECUTABLE is defined,
38+
# sys.executable may get set to an unuseful value.
39+
#
40+
# (Note that the IDLE script and the setting of PYTHONEXECUTABLE is
41+
# generated automatically by bundlebuilder in the Python 2.x build.
42+
# Also, IDLE invoked via command line, i.e. bin/idle, bypasses all of
43+
# this.)
44+
#
45+
# Now fix up the execution environment before importing idlelib.
46+
47+
# Reset sys.executable to its normal value, the actual path of
48+
# the interpreter in the framework, by following the symlink
49+
# exported in PYTHONEXECUTABLE.
50+
pyex = os.environ['PYTHONEXECUTABLE']
51+
sys.executable = os.path.join(os.path.dirname(pyex), os.readlink(pyex))
52+
53+
# Remove any sys.path entries for the Resources dir in the IDLE.app bundle.
54+
p = pyex.partition('.app')
55+
if p[2].startswith('/Contents/MacOS/Python'):
56+
sys.path = [value for value in sys.path if
57+
value.partition('.app') != (p[0], p[1], '/Contents/Resources')]
58+
59+
# Unexport PYTHONEXECUTABLE so that the other Python processes started
60+
# by IDLE have a normal sys.executable.
61+
del os.environ['PYTHONEXECUTABLE']
2062

2163
# Look for the -psn argument that the launcher adds and remove it, it will
2264
# only confuse the IDLE startup code.
@@ -25,6 +67,7 @@
2567
del sys.argv[idx]
2668
break
2769

28-
#argvemulator.ArgvCollector().mainloop()
70+
# Now it is safe to import idlelib.
71+
from idlelib.PyShell import main
2972
if __name__ == '__main__':
3073
main()

‎Mac/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ install_Python4way: install_Python
215215

216216
install_IDLE:
217217
test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)"
218-
-test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app"
218+
-test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -rf "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app"
219219
/bin/cp -PR "$(srcdir)/IDLE/IDLE.app" "$(DESTDIR)$(PYTHONAPPSDIR)"
220220
ln -sf $(INSTALLED_PYTHONAPP) "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/Python"
221221
sed -e "s!%prefix%!$(prefix)!g" -e 's!%exe%!$(PYTHONFRAMEWORK)!g' < "$(srcdir)/IDLE/IDLE.app/Contents/MacOS/IDLE" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/IDLE"

0 commit comments

Comments
 (0)
Please sign in to comment.