Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: macosxSupport.py
"""
[0] Fix | Delete
A number of functions that enhance IDLE on Mac OSX.
[1] Fix | Delete
"""
[2] Fix | Delete
import sys
[3] Fix | Delete
import Tkinter
[4] Fix | Delete
from os import path
[5] Fix | Delete
[6] Fix | Delete
[7] Fix | Delete
import warnings
[8] Fix | Delete
[9] Fix | Delete
def runningAsOSXApp():
[10] Fix | Delete
warnings.warn("runningAsOSXApp() is deprecated, use isAquaTk()",
[11] Fix | Delete
DeprecationWarning, stacklevel=2)
[12] Fix | Delete
return isAquaTk()
[13] Fix | Delete
[14] Fix | Delete
def isCarbonAquaTk(root):
[15] Fix | Delete
warnings.warn("isCarbonAquaTk(root) is deprecated, use isCarbonTk()",
[16] Fix | Delete
DeprecationWarning, stacklevel=2)
[17] Fix | Delete
return isCarbonTk()
[18] Fix | Delete
[19] Fix | Delete
_tk_type = None
[20] Fix | Delete
[21] Fix | Delete
def _initializeTkVariantTests(root):
[22] Fix | Delete
"""
[23] Fix | Delete
Initializes OS X Tk variant values for
[24] Fix | Delete
isAquaTk(), isCarbonTk(), isCocoaTk(), and isXQuartz().
[25] Fix | Delete
"""
[26] Fix | Delete
global _tk_type
[27] Fix | Delete
if sys.platform == 'darwin':
[28] Fix | Delete
ws = root.tk.call('tk', 'windowingsystem')
[29] Fix | Delete
if 'x11' in ws:
[30] Fix | Delete
_tk_type = "xquartz"
[31] Fix | Delete
elif 'aqua' not in ws:
[32] Fix | Delete
_tk_type = "other"
[33] Fix | Delete
elif 'AppKit' in root.tk.call('winfo', 'server', '.'):
[34] Fix | Delete
_tk_type = "cocoa"
[35] Fix | Delete
else:
[36] Fix | Delete
_tk_type = "carbon"
[37] Fix | Delete
else:
[38] Fix | Delete
_tk_type = "other"
[39] Fix | Delete
[40] Fix | Delete
def isAquaTk():
[41] Fix | Delete
"""
[42] Fix | Delete
Returns True if IDLE is using a native OS X Tk (Cocoa or Carbon).
[43] Fix | Delete
"""
[44] Fix | Delete
assert _tk_type is not None
[45] Fix | Delete
return _tk_type == "cocoa" or _tk_type == "carbon"
[46] Fix | Delete
[47] Fix | Delete
def isCarbonTk():
[48] Fix | Delete
"""
[49] Fix | Delete
Returns True if IDLE is using a Carbon Aqua Tk (instead of the
[50] Fix | Delete
newer Cocoa Aqua Tk).
[51] Fix | Delete
"""
[52] Fix | Delete
assert _tk_type is not None
[53] Fix | Delete
return _tk_type == "carbon"
[54] Fix | Delete
[55] Fix | Delete
def isCocoaTk():
[56] Fix | Delete
"""
[57] Fix | Delete
Returns True if IDLE is using a Cocoa Aqua Tk.
[58] Fix | Delete
"""
[59] Fix | Delete
assert _tk_type is not None
[60] Fix | Delete
return _tk_type == "cocoa"
[61] Fix | Delete
[62] Fix | Delete
def isXQuartz():
[63] Fix | Delete
"""
[64] Fix | Delete
Returns True if IDLE is using an OS X X11 Tk.
[65] Fix | Delete
"""
[66] Fix | Delete
assert _tk_type is not None
[67] Fix | Delete
return _tk_type == "xquartz"
[68] Fix | Delete
[69] Fix | Delete
def tkVersionWarning(root):
[70] Fix | Delete
"""
[71] Fix | Delete
Returns a string warning message if the Tk version in use appears to
[72] Fix | Delete
be one known to cause problems with IDLE.
[73] Fix | Delete
1. Apple Cocoa-based Tk 8.5.7 shipped with Mac OS X 10.6 is unusable.
[74] Fix | Delete
2. Apple Cocoa-based Tk 8.5.9 in OS X 10.7 and 10.8 is better but
[75] Fix | Delete
can still crash unexpectedly.
[76] Fix | Delete
"""
[77] Fix | Delete
[78] Fix | Delete
if isCocoaTk():
[79] Fix | Delete
patchlevel = root.tk.call('info', 'patchlevel')
[80] Fix | Delete
if patchlevel not in ('8.5.7', '8.5.9'):
[81] Fix | Delete
return False
[82] Fix | Delete
return (r"WARNING: The version of Tcl/Tk ({0}) in use may"
[83] Fix | Delete
r" be unstable.\n"
[84] Fix | Delete
r"Visit http://www.python.org/download/mac/tcltk/"
[85] Fix | Delete
r" for current information.".format(patchlevel))
[86] Fix | Delete
else:
[87] Fix | Delete
return False
[88] Fix | Delete
[89] Fix | Delete
def addOpenEventSupport(root, flist):
[90] Fix | Delete
"""
[91] Fix | Delete
This ensures that the application will respond to open AppleEvents, which
[92] Fix | Delete
makes is feasible to use IDLE as the default application for python files.
[93] Fix | Delete
"""
[94] Fix | Delete
def doOpenFile(*args):
[95] Fix | Delete
for fn in args:
[96] Fix | Delete
flist.open(fn)
[97] Fix | Delete
[98] Fix | Delete
# The command below is a hook in aquatk that is called whenever the app
[99] Fix | Delete
# receives a file open event. The callback can have multiple arguments,
[100] Fix | Delete
# one for every file that should be opened.
[101] Fix | Delete
root.createcommand("::tk::mac::OpenDocument", doOpenFile)
[102] Fix | Delete
[103] Fix | Delete
def hideTkConsole(root):
[104] Fix | Delete
try:
[105] Fix | Delete
root.tk.call('console', 'hide')
[106] Fix | Delete
except Tkinter.TclError:
[107] Fix | Delete
# Some versions of the Tk framework don't have a console object
[108] Fix | Delete
pass
[109] Fix | Delete
[110] Fix | Delete
def overrideRootMenu(root, flist):
[111] Fix | Delete
"""
[112] Fix | Delete
Replace the Tk root menu by something that is more appropriate for
[113] Fix | Delete
IDLE with an Aqua Tk.
[114] Fix | Delete
"""
[115] Fix | Delete
# The menu that is attached to the Tk root (".") is also used by AquaTk for
[116] Fix | Delete
# all windows that don't specify a menu of their own. The default menubar
[117] Fix | Delete
# contains a number of menus, none of which are appropriate for IDLE. The
[118] Fix | Delete
# Most annoying of those is an 'About Tck/Tk...' menu in the application
[119] Fix | Delete
# menu.
[120] Fix | Delete
#
[121] Fix | Delete
# This function replaces the default menubar by a mostly empty one, it
[122] Fix | Delete
# should only contain the correct application menu and the window menu.
[123] Fix | Delete
#
[124] Fix | Delete
# Due to a (mis-)feature of TkAqua the user will also see an empty Help
[125] Fix | Delete
# menu.
[126] Fix | Delete
from Tkinter import Menu
[127] Fix | Delete
from idlelib import Bindings
[128] Fix | Delete
from idlelib import WindowList
[129] Fix | Delete
[130] Fix | Delete
closeItem = Bindings.menudefs[0][1][-2]
[131] Fix | Delete
[132] Fix | Delete
# Remove the last 3 items of the file menu: a separator, close window and
[133] Fix | Delete
# quit. Close window will be reinserted just above the save item, where
[134] Fix | Delete
# it should be according to the HIG. Quit is in the application menu.
[135] Fix | Delete
del Bindings.menudefs[0][1][-3:]
[136] Fix | Delete
Bindings.menudefs[0][1].insert(6, closeItem)
[137] Fix | Delete
[138] Fix | Delete
# Remove the 'About' entry from the help menu, it is in the application
[139] Fix | Delete
# menu
[140] Fix | Delete
del Bindings.menudefs[-1][1][0:2]
[141] Fix | Delete
# Remove the 'Configure Idle' entry from the options menu, it is in the
[142] Fix | Delete
# application menu as 'Preferences'
[143] Fix | Delete
del Bindings.menudefs[-2][1][0]
[144] Fix | Delete
menubar = Menu(root)
[145] Fix | Delete
root.configure(menu=menubar)
[146] Fix | Delete
menudict = {}
[147] Fix | Delete
[148] Fix | Delete
menudict['windows'] = menu = Menu(menubar, name='windows', tearoff=0)
[149] Fix | Delete
menubar.add_cascade(label='Window', menu=menu, underline=0)
[150] Fix | Delete
[151] Fix | Delete
def postwindowsmenu(menu=menu):
[152] Fix | Delete
end = menu.index('end')
[153] Fix | Delete
if end is None:
[154] Fix | Delete
end = -1
[155] Fix | Delete
[156] Fix | Delete
if end > 0:
[157] Fix | Delete
menu.delete(0, end)
[158] Fix | Delete
WindowList.add_windows_to_menu(menu)
[159] Fix | Delete
WindowList.register_callback(postwindowsmenu)
[160] Fix | Delete
[161] Fix | Delete
def about_dialog(event=None):
[162] Fix | Delete
"Handle Help 'About IDLE' event."
[163] Fix | Delete
# Synchronize with EditorWindow.EditorWindow.about_dialog.
[164] Fix | Delete
from idlelib import aboutDialog
[165] Fix | Delete
aboutDialog.AboutDialog(root, 'About IDLE')
[166] Fix | Delete
[167] Fix | Delete
def config_dialog(event=None):
[168] Fix | Delete
"Handle Options 'Configure IDLE' event."
[169] Fix | Delete
# Synchronize with EditorWindow.EditorWindow.config_dialog.
[170] Fix | Delete
from idlelib import configDialog
[171] Fix | Delete
root.instance_dict = flist.inversedict
[172] Fix | Delete
configDialog.ConfigDialog(root, 'Settings')
[173] Fix | Delete
[174] Fix | Delete
def help_dialog(event=None):
[175] Fix | Delete
"Handle Help 'IDLE Help' event."
[176] Fix | Delete
# Synchronize with EditorWindow.EditorWindow.help_dialog.
[177] Fix | Delete
from idlelib import help
[178] Fix | Delete
help.show_idlehelp(root)
[179] Fix | Delete
[180] Fix | Delete
root.bind('<<about-idle>>', about_dialog)
[181] Fix | Delete
root.bind('<<open-config-dialog>>', config_dialog)
[182] Fix | Delete
root.createcommand('::tk::mac::ShowPreferences', config_dialog)
[183] Fix | Delete
if flist:
[184] Fix | Delete
root.bind('<<close-all-windows>>', flist.close_all_callback)
[185] Fix | Delete
[186] Fix | Delete
# The binding above doesn't reliably work on all versions of Tk
[187] Fix | Delete
# on MacOSX. Adding command definition below does seem to do the
[188] Fix | Delete
# right thing for now.
[189] Fix | Delete
root.createcommand('exit', flist.close_all_callback)
[190] Fix | Delete
[191] Fix | Delete
if isCarbonTk():
[192] Fix | Delete
# for Carbon AquaTk, replace the default Tk apple menu
[193] Fix | Delete
menudict['application'] = menu = Menu(menubar, name='apple',
[194] Fix | Delete
tearoff=0)
[195] Fix | Delete
menubar.add_cascade(label='IDLE', menu=menu)
[196] Fix | Delete
Bindings.menudefs.insert(0,
[197] Fix | Delete
('application', [
[198] Fix | Delete
('About IDLE', '<<about-idle>>'),
[199] Fix | Delete
None,
[200] Fix | Delete
]))
[201] Fix | Delete
tkversion = root.tk.eval('info patchlevel')
[202] Fix | Delete
if tuple(map(int, tkversion.split('.'))) < (8, 4, 14):
[203] Fix | Delete
# for earlier AquaTk versions, supply a Preferences menu item
[204] Fix | Delete
Bindings.menudefs[0][1].append(
[205] Fix | Delete
('_Preferences....', '<<open-config-dialog>>'),
[206] Fix | Delete
)
[207] Fix | Delete
if isCocoaTk():
[208] Fix | Delete
# replace default About dialog with About IDLE one
[209] Fix | Delete
root.createcommand('tkAboutDialog', about_dialog)
[210] Fix | Delete
# replace default "Help" item in Help menu
[211] Fix | Delete
root.createcommand('::tk::mac::ShowHelp', help_dialog)
[212] Fix | Delete
# remove redundant "IDLE Help" from menu
[213] Fix | Delete
del Bindings.menudefs[-1][1][0]
[214] Fix | Delete
[215] Fix | Delete
def setupApp(root, flist):
[216] Fix | Delete
"""
[217] Fix | Delete
Perform initial OS X customizations if needed.
[218] Fix | Delete
Called from PyShell.main() after initial calls to Tk()
[219] Fix | Delete
[220] Fix | Delete
There are currently three major versions of Tk in use on OS X:
[221] Fix | Delete
1. Aqua Cocoa Tk (native default since OS X 10.6)
[222] Fix | Delete
2. Aqua Carbon Tk (original native, 32-bit only, deprecated)
[223] Fix | Delete
3. X11 (supported by some third-party distributors, deprecated)
[224] Fix | Delete
There are various differences among the three that affect IDLE
[225] Fix | Delete
behavior, primarily with menus, mouse key events, and accelerators.
[226] Fix | Delete
Some one-time customizations are performed here.
[227] Fix | Delete
Others are dynamically tested throughout idlelib by calls to the
[228] Fix | Delete
isAquaTk(), isCarbonTk(), isCocoaTk(), isXQuartz() functions which
[229] Fix | Delete
are initialized here as well.
[230] Fix | Delete
"""
[231] Fix | Delete
_initializeTkVariantTests(root)
[232] Fix | Delete
if isAquaTk():
[233] Fix | Delete
hideTkConsole(root)
[234] Fix | Delete
overrideRootMenu(root, flist)
[235] Fix | Delete
addOpenEventSupport(root, flist)
[236] Fix | Delete
[237] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function