diff options
Diffstat (limited to 'Lib/idlelib')
-rw-r--r-- | Lib/idlelib/Bindings.py | 26 | ||||
-rw-r--r-- | Lib/idlelib/CREDITS.txt | 15 | ||||
-rw-r--r-- | Lib/idlelib/CallTipWindow.py | 6 | ||||
-rw-r--r-- | Lib/idlelib/CallTips.py | 2 | ||||
-rw-r--r-- | Lib/idlelib/CodeContext.py | 3 | ||||
-rw-r--r-- | Lib/idlelib/ColorDelegator.py | 30 | ||||
-rw-r--r-- | Lib/idlelib/Debugger.py | 9 | ||||
-rw-r--r-- | Lib/idlelib/EditorWindow.py | 49 | ||||
-rw-r--r-- | Lib/idlelib/NEWS.txt | 43 | ||||
-rw-r--r-- | Lib/idlelib/ParenMatch.py | 7 | ||||
-rw-r--r-- | Lib/idlelib/PyShell.py | 31 | ||||
-rw-r--r-- | Lib/idlelib/ScriptBinding.py | 5 | ||||
-rw-r--r-- | Lib/idlelib/ZoomHeight.py | 9 | ||||
-rw-r--r-- | Lib/idlelib/buildapp.py | 17 | ||||
-rw-r--r-- | Lib/idlelib/config-keys.def | 53 | ||||
-rw-r--r-- | Lib/idlelib/configHandler.py | 16 | ||||
-rw-r--r-- | Lib/idlelib/configHelpSourceEdit.py | 5 | ||||
-rw-r--r-- | Lib/idlelib/idlever.py | 2 | ||||
-rw-r--r-- | Lib/idlelib/keybindingDialog.py | 4 | ||||
-rw-r--r-- | Lib/idlelib/macosxSupport.py | 112 |
20 files changed, 377 insertions, 67 deletions
diff --git a/Lib/idlelib/Bindings.py b/Lib/idlelib/Bindings.py index b5e90b0..d24be3f 100644 --- a/Lib/idlelib/Bindings.py +++ b/Lib/idlelib/Bindings.py @@ -80,6 +80,32 @@ menudefs = [ ]), ] +import sys +if sys.platform == 'darwin' and '.app' in sys.executable: + # Running as a proper MacOS application bundle. This block restructures + # the menus a little to make them conform better to the HIG. + + quitItem = menudefs[0][1][-1] + closeItem = menudefs[0][1][-2] + + # Remove the last 3 items of the file menu: a separator, close window and + # quit. Close window will be reinserted just above the save item, where + # it should be according to the HIG. Quit is in the application menu. + del menudefs[0][1][-3:] + menudefs[0][1].insert(6, closeItem) + + # Remove the 'About' entry from the help menu, it is in the application + # menu + del menudefs[-1][1][0:2] + + menudefs.insert(0, + ('application', [ + ('About IDLE', '<<about-idle>>'), + None, + ('_Preferences....', '<<open-config-dialog>>'), + ])) + + default_keydefs = idleConf.GetCurrentKeySet() del sys diff --git a/Lib/idlelib/CREDITS.txt b/Lib/idlelib/CREDITS.txt index 6f4e95d..e838c03 100644 --- a/Lib/idlelib/CREDITS.txt +++ b/Lib/idlelib/CREDITS.txt @@ -19,17 +19,18 @@ the integration of the RPC and remote debugger, implemented the threaded subprocess, and made a number of usability enhancements. Other contributors include Raymond Hettinger, Tony Lownds (Mac integration), -Neal Norwitz (code check and clean-up), and Chui Tey (RPC integration, debugger -integration and persistent breakpoints). +Neal Norwitz (code check and clean-up), Ronald Oussoren (Mac integration), +Noam Raphael (Code Context, Call Tips, many other patches), and Chui Tey (RPC +integration, debugger integration and persistent breakpoints). -Scott David Daniels, Hernan Foffani, Christos Georgiou, Martin v. Löwis, -Jason Orendorff, Noam Raphael, Josh Robb, Nigel Rowe, Bruce Sherwood, and -Jeff Shute have submitted useful patches. Thanks, guys! +Scott David Daniels, Tal Einat, Hernan Foffani, Christos Georgiou, +Martin v. Löwis, Jason Orendorff, Josh Robb, Nigel Rowe, Bruce Sherwood, +and Jeff Shute have submitted useful patches. Thanks, guys! For additional details refer to NEWS.txt and Changelog. -Please contact the IDLE maintainer to have yourself included here if you -are one of those we missed! +Please contact the IDLE maintainer (kbk@shore.net) to have yourself included +here if you are one of those we missed! diff --git a/Lib/idlelib/CallTipWindow.py b/Lib/idlelib/CallTipWindow.py index afd4439..2223885 100644 --- a/Lib/idlelib/CallTipWindow.py +++ b/Lib/idlelib/CallTipWindow.py @@ -49,7 +49,11 @@ class CallTip: """ # truncate overly long calltip if len(text) >= 79: - text = text[:75] + ' ...' + textlines = text.splitlines() + for i, line in enumerate(textlines): + if len(line) > 79: + textlines[i] = line[:75] + ' ...' + text = '\n'.join(textlines) self.text = text if self.tipwindow or not self.text: return diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/CallTips.py index 47a1d55..997eb13 100644 --- a/Lib/idlelib/CallTips.py +++ b/Lib/idlelib/CallTips.py @@ -127,7 +127,7 @@ def get_arg_text(ob): argText = "" if ob is not None: argOffset = 0 - if type(ob)==types.ClassType: + if type(ob) in (types.ClassType, types.TypeType): # Look for the highest __init__ in the class chain. fob = _find_constructor(ob) if fob is None: diff --git a/Lib/idlelib/CodeContext.py b/Lib/idlelib/CodeContext.py index 5d55f77..63cc82c 100644 --- a/Lib/idlelib/CodeContext.py +++ b/Lib/idlelib/CodeContext.py @@ -11,11 +11,10 @@ not open blocks are not shown in the context hints pane. """ import Tkinter from configHandler import idleConf -from sets import Set import re from sys import maxint as INFINITY -BLOCKOPENERS = Set(["class", "def", "elif", "else", "except", "finally", "for", +BLOCKOPENERS = set(["class", "def", "elif", "else", "except", "finally", "for", "if", "try", "while"]) UPDATEINTERVAL = 100 # millisec FONTUPDATEINTERVAL = 1000 # millisec diff --git a/Lib/idlelib/ColorDelegator.py b/Lib/idlelib/ColorDelegator.py index f258b34..e55f9e6 100644 --- a/Lib/idlelib/ColorDelegator.py +++ b/Lib/idlelib/ColorDelegator.py @@ -8,28 +8,29 @@ from configHandler import idleConf DEBUG = False -def any(name, list): - return "(?P<%s>" % name + "|".join(list) + ")" +def any(name, alternates): + "Return a named group pattern matching list of alternates." + return "(?P<%s>" % name + "|".join(alternates) + ")" def make_pat(): kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b" builtinlist = [str(name) for name in dir(__builtin__) if not name.startswith('_')] # self.file = file("file") : - # 1st 'file' colorized normal, 2nd as builtin, 3rd as comment - builtin = r"([^.'\"\\]\b|^)" + any("BUILTIN", builtinlist) + r"\b" + # 1st 'file' colorized normal, 2nd as builtin, 3rd as string + builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b" comment = any("COMMENT", [r"#[^\n]*"]) - sqstring = r"(\b[rR])?'[^'\\\n]*(\\.[^'\\\n]*)*'?" - dqstring = r'(\b[rR])?"[^"\\\n]*(\\.[^"\\\n]*)*"?' - sq3string = r"(\b[rR])?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?" - dq3string = r'(\b[rR])?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?' + sqstring = r"(\b[rRuU])?'[^'\\\n]*(\\.[^'\\\n]*)*'?" + dqstring = r'(\b[rRuU])?"[^"\\\n]*(\\.[^"\\\n]*)*"?' + sq3string = r"(\b[rRuU])?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?" + dq3string = r'(\b[rRuU])?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?' string = any("STRING", [sq3string, dq3string, sqstring, dqstring]) return kw + "|" + builtin + "|" + comment + "|" + string +\ "|" + any("SYNC", [r"\n"]) prog = re.compile(make_pat(), re.S) idprog = re.compile(r"\s+(\w+)", re.S) -asprog = re.compile(r".*?\b(as)\b", re.S) +asprog = re.compile(r".*?\b(as)\b") class ColorDelegator(Delegator): @@ -208,10 +209,15 @@ class ColorDelegator(Delegator): head + "+%dc" % a, head + "+%dc" % b) elif value == "import": - # color all the "as" words on same line; - # cheap approximation to the truth + # color all the "as" words on same line, except + # if in a comment; cheap approximation to the + # truth + if '#' in chars: + endpos = chars.index('#') + else: + endpos = len(chars) while True: - m1 = self.asprog.match(chars, b) + m1 = self.asprog.match(chars, b, endpos) if not m1: break a, b = m1.span(1) diff --git a/Lib/idlelib/Debugger.py b/Lib/idlelib/Debugger.py index 7a9d02f..f56460a 100644 --- a/Lib/idlelib/Debugger.py +++ b/Lib/idlelib/Debugger.py @@ -4,6 +4,7 @@ import types from Tkinter import * from WindowList import ListedToplevel from ScrolledList import ScrolledList +import macosxSupport class Idb(bdb.Bdb): @@ -322,7 +323,13 @@ class Debugger: class StackViewer(ScrolledList): def __init__(self, master, flist, gui): - ScrolledList.__init__(self, master, width=80) + if macosxSupport.runningAsOSXApp(): + # At least on with the stock AquaTk version on OSX 10.4 you'll + # get an shaking GUI that eventually kills IDLE if the width + # argument is specified. + ScrolledList.__init__(self, master) + else: + ScrolledList.__init__(self, master, width=80) self.flist = flist self.gui = gui self.stack = [] diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py index 59440f0..6b8ab63 100644 --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -17,6 +17,7 @@ import ReplaceDialog import PyParse from configHandler import idleConf import aboutDialog, textView, configDialog +import macosxSupport # The default tab setting for a Text widget, in average-width characters. TK_TABWIDTH_DEFAULT = 8 @@ -66,26 +67,40 @@ class EditorWindow(object): 'Python%d%d.chm' % sys.version_info[:2]) if os.path.isfile(chmfile): dochome = chmfile + + elif macosxSupport.runningAsOSXApp(): + # documentation is stored inside the python framework + dochome = os.path.join(sys.prefix, + 'Resources/English.lproj/Documentation/index.html') + dochome = os.path.normpath(dochome) if os.path.isfile(dochome): EditorWindow.help_url = dochome + if sys.platform == 'darwin': + # Safari requires real file:-URLs + EditorWindow.help_url = 'file://' + EditorWindow.help_url else: EditorWindow.help_url = "http://www.python.org/doc/current" currentTheme=idleConf.CurrentTheme() self.flist = flist root = root or flist.root self.root = root + try: + sys.ps1 + except AttributeError: + sys.ps1 = '>>> ' self.menubar = Menu(root) self.top = top = WindowList.ListedToplevel(root, menu=self.menubar) if flist: self.tkinter_vars = flist.vars #self.top.instance_dict makes flist.inversedict avalable to #configDialog.py so it can access all EditorWindow instaces - self.top.instance_dict=flist.inversedict + self.top.instance_dict = flist.inversedict else: self.tkinter_vars = {} # keys: Tkinter event names # values: Tkinter variable instances - self.recent_files_path=os.path.join(idleConf.GetUserCfgDir(), + self.top.instance_dict = {} + self.recent_files_path = os.path.join(idleConf.GetUserCfgDir(), 'recent-files.lst') self.vbar = vbar = Scrollbar(top, name='vbar') self.text_frame = text_frame = Frame(top) @@ -111,6 +126,9 @@ class EditorWindow(object): self.top.protocol("WM_DELETE_WINDOW", self.close) self.top.bind("<<close-window>>", self.close_event) + if macosxSupport.runningAsOSXApp(): + # Command-W on editorwindows doesn't work without this. + text.bind('<<close-window>>', self.close_event) text.bind("<<cut>>", self.cut) text.bind("<<copy>>", self.copy) text.bind("<<paste>>", self.paste) @@ -278,6 +296,10 @@ class EditorWindow(object): def set_status_bar(self): self.status_bar = self.MultiStatusBar(self.top) + if macosxSupport.runningAsOSXApp(): + # Insert some padding to avoid obscuring some of the statusbar + # by the resize widget. + self.status_bar.set_label('_padding1', ' ', side=RIGHT) self.status_bar.set_label('column', 'Col: ?', side=RIGHT) self.status_bar.set_label('line', 'Ln: ?', side=RIGHT) self.status_bar.pack(side=BOTTOM, fill=X) @@ -301,6 +323,11 @@ class EditorWindow(object): ("help", "_Help"), ] + if macosxSupport.runningAsOSXApp(): + del menu_specs[-3] + menu_specs[-2] = ("windows", "_Window") + + def createmenubar(self): mbar = self.menubar self.menudict = menudict = {} @@ -308,6 +335,12 @@ class EditorWindow(object): underline, label = prepstr(label) menudict[name] = menu = Menu(mbar, name=name) mbar.add_cascade(label=label, menu=menu, underline=underline) + + if sys.platform == 'darwin' and '.framework' in sys.executable: + # Insert the application menu + menudict['application'] = menu = Menu(mbar, name='apple') + mbar.add_cascade(label='IDLE', menu=menu) + self.fill_menus() self.base_helpmenu_length = self.menudict['help'].index(END) self.reset_help_menu_entries() @@ -649,7 +682,7 @@ class EditorWindow(object): def __extra_help_callback(self, helpfile): "Create a callback with the helpfile value frozen at definition time" def display_extra_help(helpfile=helpfile): - if not (helpfile.startswith('www') or helpfile.startswith('http')): + if not helpfile.startswith(('www', 'http')): url = os.path.normpath(helpfile) if sys.platform[:3] == 'win': os.startfile(helpfile) @@ -1244,13 +1277,13 @@ class EditorWindow(object): "Toggle tabs", "Turn tabs " + ("on", "off")[self.usetabs] + "?\nIndent width " + - ("will be", "remains at")[self.usetabs] + " 8.", + ("will be", "remains at")[self.usetabs] + " 8." + + "\n Note: a tab is always 8 columns", parent=self.text): self.usetabs = not self.usetabs - # Try to prevent mixed tabs/spaces. - # User must reset indent width manually after using tabs - # if he insists on getting into trouble. - self.indentwidth = 8 + # Try to prevent inconsistent indentation. + # User must change indent width manually after using tabs. + self.indentwidth = 8 return "break" # XXX this isn't bound to anything -- see tabwidth comments diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index 25e5d40..235963e 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -1,3 +1,46 @@ +What's New in IDLE 1.2c1? +========================= + +*Release date: XX-AUG-2006* + +- Changing tokenize (39046) to detect dedent broke tabnanny check (since 1.2a1) + +- ToggleTab dialog was setting indent to 8 even if cancelled (since 1.2a1). + +- When used w/o subprocess, all exceptions were preceded by an error + message claiming they were IDLE internal errors (since 1.2a1). + +What's New in IDLE 1.2b3? +========================= + +*Release date: 03-AUG-2006* + +- EditorWindow.test() was failing. Bug 1417598 + +- EditorWindow failed when used stand-alone if sys.ps1 not set. + Bug 1010370 Dave Florek + +- Tooltips failed on new-syle class __init__ args. Bug 1027566 Loren Guthrie + +- Avoid occasional failure to detect closing paren properly. + Patch 1407280 Tal Einat + +- Rebinding Tab key was inserting 'tab' instead of 'Tab'. Bug 1179168. + +- Colorizer now handles #<builtin> correctly, also unicode strings and + 'as' keyword in comment directly following import command. Closes 1325071. + Patch 1479219 Tal Einat + +What's New in IDLE 1.2b2? +========================= + +*Release date: 11-JUL-2006* + +What's New in IDLE 1.2b1? +========================= + +*Release date: 20-JUN-2006* + What's New in IDLE 1.2a2? ========================= diff --git a/Lib/idlelib/ParenMatch.py b/Lib/idlelib/ParenMatch.py index 673aee2..250ae8b 100644 --- a/Lib/idlelib/ParenMatch.py +++ b/Lib/idlelib/ParenMatch.py @@ -8,7 +8,7 @@ parentheses, square brackets, and curly braces. from HyperParser import HyperParser from configHandler import idleConf -keysym_opener = {"parenright":'(', "bracketright":'[', "braceright":'{'} +_openers = {')':'(',']':'[','}':'{'} CHECK_DELAY = 100 # miliseconds class ParenMatch: @@ -100,12 +100,13 @@ class ParenMatch: def paren_closed_event(self, event): # If it was a shortcut and not really a closing paren, quit. - if self.text.get("insert-1c") not in (')',']','}'): + closer = self.text.get("insert-1c") + if closer not in _openers: return hp = HyperParser(self.editwin, "insert-1c") if not hp.is_in_code(): return - indices = hp.get_surrounding_brackets(keysym_opener[event.keysym], True) + indices = hp.get_surrounding_brackets(_openers[closer], True) if indices is None: self.warn_mismatched() return diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index b6abe40..25eb446 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -11,6 +11,7 @@ import time import threading import traceback import types +import macosxSupport import linecache from code import InteractiveInterpreter @@ -721,8 +722,12 @@ class ModifiedInterpreter(InteractiveInterpreter): else: self.showtraceback() except: - print>>sys.stderr, "IDLE internal error in runcode()" + if use_subprocess: + print >> self.tkconsole.stderr, \ + "IDLE internal error in runcode()" self.showtraceback() + if use_subprocess: + self.tkconsole.endexecuting() finally: if not use_subprocess: self.tkconsole.endexecuting() @@ -777,6 +782,11 @@ class PyShell(OutputWindow): ("help", "_Help"), ] + if macosxSupport.runningAsOSXApp(): + del menu_specs[-3] + menu_specs[-2] = ("windows", "_Window") + + # New classes from IdleHistory import History @@ -1300,10 +1310,6 @@ def main(): script = None startup = False try: - sys.ps1 - except AttributeError: - sys.ps1 = '>>> ' - try: opts, args = getopt.getopt(sys.argv[1:], "c:deihnr:st:") except getopt.error, msg: sys.stderr.write("Error: %s\n" % str(msg)) @@ -1371,9 +1377,12 @@ def main(): enable_shell = enable_shell or not edit_start # start editor and/or shell windows: root = Tk(className="Idle") + fixwordbreaks(root) root.withdraw() flist = PyShellFileList(root) + macosxSupport.setupApp(root, flist) + if enable_edit: if not (cmd or script): for filename in args: @@ -1381,8 +1390,17 @@ def main(): if not args: flist.new() if enable_shell: - if not flist.open_shell(): + shell = flist.open_shell() + if not shell: return # couldn't open shell + + if macosxSupport.runningAsOSXApp() and flist.dict: + # On OSX: when the user has double-clicked on a file that causes + # IDLE to be launched the shell window will open just in front of + # the file she wants to see. Lower the interpreter window when + # there are open files. + shell.top.lower() + shell = flist.pyshell # handle remaining options: if debug: @@ -1403,6 +1421,7 @@ def main(): elif script: shell.interp.prepend_syspath(script) shell.interp.execfile(script) + root.mainloop() root.destroy() diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py index 084c607..f325ad1 100644 --- a/Lib/idlelib/ScriptBinding.py +++ b/Lib/idlelib/ScriptBinding.py @@ -51,7 +51,7 @@ class ScriptBinding: # Provide instance variables referenced by Debugger # XXX This should be done differently self.flist = self.editwin.flist - self.root = self.flist.root + self.root = self.editwin.root def check_module_event(self, event): filename = self.getfilename() @@ -76,6 +76,9 @@ class ScriptBinding: self.editwin.gotoline(nag.get_lineno()) self.errorbox("Tab/space error", indent_message) return False + except IndentationError: + # From tokenize(), let compile() in checksyntax find it again. + pass return True def checksyntax(self, filename): diff --git a/Lib/idlelib/ZoomHeight.py b/Lib/idlelib/ZoomHeight.py index 2ab4656..83ca3a6 100644 --- a/Lib/idlelib/ZoomHeight.py +++ b/Lib/idlelib/ZoomHeight.py @@ -2,6 +2,7 @@ import re import sys +import macosxSupport class ZoomHeight: @@ -29,6 +30,14 @@ def zoom_height(top): if sys.platform == 'win32': newy = 0 newheight = newheight - 72 + + elif macosxSupport.runningAsOSXApp(): + # The '88' below is a magic number that avoids placing the bottom + # of the window below the panel on my machine. I don't know how + # to calculate the correct value for this with tkinter. + newy = 22 + newheight = newheight - newy - 88 + else: #newy = 24 newy = 0 diff --git a/Lib/idlelib/buildapp.py b/Lib/idlelib/buildapp.py deleted file mode 100644 index 672eb1e..0000000 --- a/Lib/idlelib/buildapp.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# After running python setup.py install, run this program from the command -# line like so: -# -# % python2.3 buildapp.py build -# -# A double-clickable IDLE application will be created in the build/ directory. -# - -from bundlebuilder import buildapp - -buildapp( - name="IDLE", - mainprogram="idle.py", - argv_emulation=1, - iconfile="Icons/idle.icns", -) diff --git a/Lib/idlelib/config-keys.def b/Lib/idlelib/config-keys.def index 0653746..fb0aaf4 100644 --- a/Lib/idlelib/config-keys.def +++ b/Lib/idlelib/config-keys.def @@ -159,3 +159,56 @@ toggle-tabs=<Control-Key-t> change-indentwidth=<Control-Key-u> del-word-left=<Control-Key-BackSpace> del-word-right=<Control-Key-Delete> + +[IDLE Classic OSX] +toggle-tabs = <Control-Key-t> +interrupt-execution = <Control-Key-c> +untabify-region = <Control-Key-6> +remove-selection = <Key-Escape> +print-window = <Command-Key-p> +replace = <Command-Key-r> +goto-line = <Command-Key-j> +plain-newline-and-indent = <Control-Key-j> +history-previous = <Control-Key-p> +beginning-of-line = <Control-Key-Left> +end-of-line = <Control-Key-Right> +comment-region = <Control-Key-3> +redo = <Shift-Command-Key-Z> +close-window = <Command-Key-w> +restart-shell = <Control-Key-F6> +save-window-as-file = <Command-Key-S> +close-all-windows = <Command-Key-q> +view-restart = <Key-F6> +tabify-region = <Control-Key-5> +find-again = <Command-Key-g> <Key-F3> +find = <Command-Key-f> +toggle-auto-coloring = <Control-Key-slash> +select-all = <Command-Key-a> +smart-backspace = <Key-BackSpace> +change-indentwidth = <Control-Key-u> +do-nothing = <Control-Key-F12> +smart-indent = <Key-Tab> +center-insert = <Control-Key-l> +history-next = <Control-Key-n> +del-word-right = <Option-Key-Delete> +undo = <Command-Key-z> +save-window = <Command-Key-s> +uncomment-region = <Control-Key-4> +cut = <Command-Key-x> +find-in-files = <Command-Key-F3> +dedent-region = <Command-Key-bracketleft> +copy = <Command-Key-c> +paste = <Command-Key-v> +indent-region = <Command-Key-bracketright> +del-word-left = <Option-Key-BackSpace> <Option-Command-Key-BackSpace> +newline-and-indent = <Key-Return> <Key-KP_Enter> +end-of-file = <Control-Key-d> +open-class-browser = <Command-Key-b> +open-new-window = <Command-Key-n> +open-module = <Command-Key-m> +find-selection = <Shift-Command-Key-F3> +python-context-help = <Shift-Key-F1> +save-copy-of-window-as-file = <Shift-Command-Key-s> +open-window-from-file = <Command-Key-o> +python-docs = <Key-F1> + diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py index 191a87c..826fb5d 100644 --- a/Lib/idlelib/configHandler.py +++ b/Lib/idlelib/configHandler.py @@ -20,6 +20,7 @@ configuration problem notification and resolution. import os import sys import string +import macosxSupport from ConfigParser import ConfigParser, NoOptionError, NoSectionError class InvalidConfigType(Exception): pass @@ -406,7 +407,7 @@ class IdleConf: names=extnNameList kbNameIndicies=[] for name in names: - if name.endswith('_bindings') or name.endswith('_cfgBindings'): + if name.endswith(('_bindings', '_cfgBindings')): kbNameIndicies.append(names.index(name)) kbNameIndicies.sort() kbNameIndicies.reverse() @@ -495,7 +496,18 @@ class IdleConf: return binding def GetCurrentKeySet(self): - return self.GetKeySet(self.CurrentKeys()) + result = self.GetKeySet(self.CurrentKeys()) + + if macosxSupport.runningAsOSXApp(): + # We're using AquaTk, replace all keybingings that use the + # Alt key by ones that use the Option key because the former + # don't work reliably. + for k, v in result.items(): + v2 = [ x.replace('<Alt-', '<Option-') for x in v ] + if v != v2: + result[k] = v2 + + return result def GetKeySet(self,keySetName): """ diff --git a/Lib/idlelib/configHelpSourceEdit.py b/Lib/idlelib/configHelpSourceEdit.py index 8924f79..6611621 100644 --- a/Lib/idlelib/configHelpSourceEdit.py +++ b/Lib/idlelib/configHelpSourceEdit.py @@ -127,7 +127,7 @@ class GetHelpSourceDialog(Toplevel): parent=self) self.entryPath.focus_set() pathOk = False - elif path.startswith('www.') or path.startswith('http'): + elif path.startswith(('www.', 'http')): pass else: if path[:5] == 'file:': @@ -146,8 +146,7 @@ class GetHelpSourceDialog(Toplevel): self.path.get().strip()) if sys.platform == 'darwin': path = self.result[1] - if (path.startswith('www') or path.startswith('file:') - or path.startswith('http:')): + if path.startswith(('www', 'file:', 'http:')): pass else: # Mac Safari insists on using the URI form for local files diff --git a/Lib/idlelib/idlever.py b/Lib/idlelib/idlever.py index b7deb3f..07d3d82 100644 --- a/Lib/idlelib/idlever.py +++ b/Lib/idlelib/idlever.py @@ -1 +1 @@ -IDLE_VERSION = "1.2a2" +IDLE_VERSION = "1.2b3" diff --git a/Lib/idlelib/keybindingDialog.py b/Lib/idlelib/keybindingDialog.py index ea57958..aff9cac 100644 --- a/Lib/idlelib/keybindingDialog.py +++ b/Lib/idlelib/keybindingDialog.py @@ -133,7 +133,7 @@ class GetKeysDialog(Toplevel): config-keys.def must use the same ordering. """ import sys - if sys.platform == 'darwin' and sys.executable.count('.app'): + if sys.platform == 'darwin' and sys.argv[0].count('.app'): self.modifiers = ['Shift', 'Control', 'Option', 'Command'] else: self.modifiers = ['Control', 'Alt', 'Shift'] @@ -202,7 +202,7 @@ class GetKeysDialog(Toplevel): ':':'colon',',':'comma','.':'period','<':'less','>':'greater', '/':'slash','?':'question','Page Up':'Prior','Page Down':'Next', 'Left Arrow':'Left','Right Arrow':'Right','Up Arrow':'Up', - 'Down Arrow': 'Down', 'Tab':'tab'} + 'Down Arrow': 'Down', 'Tab':'Tab'} if key in translateDict.keys(): key = translateDict[key] if 'Shift' in modifiers and key in string.ascii_lowercase: diff --git a/Lib/idlelib/macosxSupport.py b/Lib/idlelib/macosxSupport.py new file mode 100644 index 0000000..ad61fff --- /dev/null +++ b/Lib/idlelib/macosxSupport.py @@ -0,0 +1,112 @@ +""" +A number of function that enhance IDLE on MacOSX when it used as a normal +GUI application (as opposed to an X11 application). +""" +import sys + +def runningAsOSXApp(): + """ Returns True iff running from the IDLE.app bundle on OSX """ + return (sys.platform == 'darwin' and 'IDLE.app' in sys.argv[0]) + +def addOpenEventSupport(root, flist): + """ + This ensures that the application will respont to open AppleEvents, which + makes is feaseable to use IDLE as the default application for python files. + """ + def doOpenFile(*args): + for fn in args: + flist.open(fn) + + # The command below is a hook in aquatk that is called whenever the app + # receives a file open event. The callback can have multiple arguments, + # one for every file that should be opened. + root.createcommand("::tk::mac::OpenDocument", doOpenFile) + +def hideTkConsole(root): + root.tk.call('console', 'hide') + +def overrideRootMenu(root, flist): + """ + Replace the Tk root menu by something that's more appropriate for + IDLE. + """ + # The menu that is attached to the Tk root (".") is also used by AquaTk for + # all windows that don't specify a menu of their own. The default menubar + # contains a number of menus, none of which are appropriate for IDLE. The + # Most annoying of those is an 'About Tck/Tk...' menu in the application + # menu. + # + # This function replaces the default menubar by a mostly empty one, it + # should only contain the correct application menu and the window menu. + # + # Due to a (mis-)feature of TkAqua the user will also see an empty Help + # menu. + from Tkinter import Menu, Text, Text + from EditorWindow import prepstr, get_accelerator + import Bindings + import WindowList + from MultiCall import MultiCallCreator + + menubar = Menu(root) + root.configure(menu=menubar) + menudict = {} + + menudict['windows'] = menu = Menu(menubar, name='windows') + menubar.add_cascade(label='Window', menu=menu, underline=0) + + def postwindowsmenu(menu=menu): + end = menu.index('end') + if end is None: + end = -1 + + if end > 0: + menu.delete(0, end) + WindowList.add_windows_to_menu(menu) + WindowList.register_callback(postwindowsmenu) + + menudict['application'] = menu = Menu(menubar, name='apple') + menubar.add_cascade(label='IDLE', menu=menu) + + def about_dialog(event=None): + import aboutDialog + aboutDialog.AboutDialog(root, 'About IDLE') + + def config_dialog(event=None): + import configDialog + configDialog.ConfigDialog(root, 'Settings') + + root.bind('<<about-idle>>', about_dialog) + root.bind('<<open-config-dialog>>', config_dialog) + if flist: + root.bind('<<close-all-windows>>', flist.close_all_callback) + + for mname, entrylist in Bindings.menudefs: + menu = menudict.get(mname) + if not menu: + continue + for entry in entrylist: + if not entry: + menu.add_separator() + else: + label, eventname = entry + underline, label = prepstr(label) + accelerator = get_accelerator(Bindings.default_keydefs, + eventname) + def command(text=root, eventname=eventname): + text.event_generate(eventname) + menu.add_command(label=label, underline=underline, + command=command, accelerator=accelerator) + + + + + +def setupApp(root, flist): + """ + Perform setup for the OSX application bundle. + """ + if not runningAsOSXApp(): return + + hideTkConsole(root) + overrideRootMenu(root, flist) + addOpenEventSupport(root, flist) |