classification
Title: OS X IDLE 3.2 Save As menu accelerator opens two Save windows
Type: Stage: resolved
Components: IDLE, macOS Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: ned.deily Nosy List: ned.deily, ronaldoussoren
Priority: normal Keywords: needs review, patch

Created on 2011-01-29 04:03 by ned.deily, last changed 2011-07-22 01:38 by ned.deily. This issue is now closed.

Files
File name Uploaded Description Edit
issue11055.txt ronaldoussoren, 2011-03-15 22:10 review
Messages (10)
msg127378 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-01-29 04:03
With the menu accelerators corrected (as patched in Issue10940), IDLE 3.2 with Cocoa Tk 8.5 opens two Save As dialog windows instead of one.  This doesn't happen when the Save As item is selected with the mouse nor does it happen with Carbon Tk 8.4.  The simple workaround is to dismiss the second dialog window.  This can be investigated and fixed post 3.2 release.
msg130995 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2011-03-15 16:42
To reproduce install ActiveState Tcl 8.5.9 and then build python using:

../configure --enable-framework --enable-universalsdk=/ --with-universal-archs=intel MACOSX_DEPLOYMENT_TARGET=10.6

Both 3.2 and 3.3 fail can be used. Install the framework and then open an existing file, use SHIFT+CMD+S to save the file and you'll see two dialogs (both labelled 'Save').

Some investigation learns that the save_as method in IOBindings  gets called twice. 

The attached patch (for 3.2) is a crude hack, but does result in a working copy of IDLE that doesn't show two save dialogs.

I'm inclined to commit the patch, it is a hack but there are already other workarounds for Tk-on-OSX weirdness.

Comments?
msg131000 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2011-03-15 17:46
Please ignore the patch, it doesn't work after all.  It was too good to be true after all.
msg131052 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2011-03-15 22:10
This is not caused by unwanted interaction with Tk's default bindings, changing the save-as bindings to Shift+Cmd+M doesn't "fix" the issue.

It seems that the save event is generated twice, for reasons I don't yet understand (I'm definitely not enough of a Tkinter user to understand what's going on).

I have attached a new patch that fixes the issue for me, by recognizing that a save event is getting in while already saving. The fix is only active on OSX.

BTW. This issue probably also affects 2.7, I haven't done a rebuild of 2.7 yet to check that.
msg131087 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-03-16 03:45
Another data point: the key binding for Undo (Shift-Command-Z) exhibits similar behavior, i.e. it is executed twice.  And trying with Python 2.7.1 linked with A/S Tk 8.5 and with the old key bindings where Shift-Command-S is Save Copy rather than Save As, it appears that now two Save Copy events happen.  So it appears to happen in general (?) when Shift is combined with another accelerator. But it doesn't happen with Option-Command-S in 3.2.  And, using the Wish 8.5 menu demo, I was not able to reproduce the problem there by simply changing the accelerators to from Command-<letter> to Shift-Command-<letter>.  So it's hard not to rule out something in IDLE yet.
msg131164 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2011-03-16 19:57
The double execution is definitely caused by having multiple event, one of which is a real keyboard event and the other one is a ghost one.

I'm seeing calls to save_as with 2 events: the first is a ghost event, with type 35 and '??' as the keycode and keysym. The second one seems to be the real event with type 2, keysym 'S' and keycode 65651.
msg131165 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2011-03-16 20:11
It's getting weirder by the minute. Not only do we get multiple events, we also get additional keybindings we never asked for.

*Cmd+Ctrl+S also works as save as
*Cmd+Shift+S gives two save as events (as was already known)
msg131233 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-03-17 07:22
The actual unwanted event is being generated as a result of the menu "add command" accelerator.  You can see that by playing with Wish.

set w .menu
catch {destroy $w}
toplevel $w
wm title $w "Menu Shift"
menu $w.menu -tearoff 0
set m $w.menu.basic
$w.menu add cascade -label "Basic" -menu $m -underline 0
menu $m -tearoff 0

$m add command -label "Test" \
	     -command "puts command" -accelerator Command-Shift-A
bind $w <Command-Shift-A> "puts bind"

$w configure -menu $w.menu

It appears that there is a bug in the Cocoa Tk right now where accelerators with "Shift" (at least) in them are not being properly ignored by Tk.  In the Carbon Tk and the X11 Tk, I believe the only effect of the "accelerator" definitions on the "add command" is to be used to create the shortcut characters displayed in the menu entry.  However, apparently a side effect of using the Cocoa APIs is that the menu definitions now cause notifications back into Tk which are not supposed to be translated into Tcl/Tk events back to the app.  For some reason, the shift ones are not being ignored.

https://github.com/das/tcltk/blob/master/tk/macosx/tkMacOSXMenu.c

Also, it seems that with all three of the Tk implementations (Carbon, X11, and Cocoa), using a capital letter for the menu accelerator implies Shift.
msg140559 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-07-18 05:25
There is now a patch in the Tcl pipeline for this problem.  See:
http://permalink.gmane.org/gmane.comp.lang.tcl.mac/6965
msg140854 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-07-22 01:38
A fix for this problem has been released in ActiveTcl 8.5.10.1 as of 2011-07-21.
History
Date User Action Args
2014-07-29 00:08:34ned.deilylinkissue22099 superseder
2011-07-22 01:38:21ned.deilysetstatus: open -> closed
resolution: out of date
messages: + msg140854

stage: needs patch -> resolved
2011-07-18 05:25:33ned.deilysetmessages: + msg140559
2011-03-17 07:22:05ned.deilysetmessages: + msg131233
2011-03-16 20:11:05ronaldoussorensetmessages: + msg131165
2011-03-16 19:57:36ronaldoussorensetmessages: + msg131164
2011-03-16 03:45:20ned.deilysetmessages: + msg131087
2011-03-15 22:10:31ronaldoussorensetfiles: + issue11055.txt

messages: + msg131052
2011-03-15 22:07:45ronaldoussorensetfiles: - issue11055.patch
2011-03-15 17:46:52ronaldoussorensetnosy: - kbk
messages: + msg131000
2011-03-15 16:42:11ronaldoussorensetfiles: + issue11055.patch

nosy: + kbk, ronaldoussoren
messages: + msg130995

keywords: + patch, needs review
2011-01-29 04:03:38ned.deilycreate