Tk Source Code

View Ticket
Login
Ticket UUID: 922427
Title: Grabs get confused with multiple interpreters
Type: Bug Version: None
Submitter: jaspert Created on: 2004-03-24 13:12:05
Subsystem: 56. [grab] Assigned To: jenglish
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2023-08-23 16:24:30
Resolution: Fixed Closed By: chrstphrchvz
    Closed on: 2023-08-23 16:24:30
Description:
I'm not sure if this is the right category, or even if
I'm doing something I'm not supposed to, but I got some
very strange behaviour which I'd better report...

If you have Tk running in two interpreters, and one of
them executes a grab command, then if the other tries
to do so as well an error dialogue is produced that
cannot be killed. Here's a simple example:

[jaspert@spirograph jaspert]$ /usr/local/ActiveTcl/bin/wish
% info patchlevel
8.4.6
% set foo [interp create]
interp0
% $foo eval package require Tk
8.4
% pack [button .b -text Test -command tk_getOpenFile]
% # Clicking button results in file dialogue
% $foo eval grab .
% bgerror failed to handle background error.
    Original error: grab failed: another application
has grab
    Error in bgerror: grab failed: another application
has grab

The above is produced when ckicking the Test button,
followed by OK or Cancel in the file dialogue. At this
stage an Application Error dialogue is also produced,
which expands when the Show Details button is hit, but
cannot be removed. That dialogue has this text:

grab failed: another application has grab
grab failed: another application has grab
    while executing
"grab $oldGrab"
    (procedure "::tk::RestoreFocusGrab" line 21)
    invoked from within
"::tk::RestoreFocusGrab $w $data(ent) withdraw"
    (procedure "::tk::dialog::file::" line 94)
    invoked from within
"::tk::dialog::file:: save -title {Select Log File}
-filetypes {{{Log Files} .log} {{Text Files} .txt}
{{All Files} *}} -defaultextension .log -parent ..."
    ("eval" body line 1)
    invoked from within
"eval ::tk::dialog::file:: save $args"
    (procedure "tk_getSaveFile" line 5)
    invoked from within
"tk_getSaveFile -title [mc "Select Log File"] 
-filetypes $types -defaultextension .log -parent
.bgerrorDialog"
    (procedure "SaveToLog" line 8)
    invoked from within
"SaveToLog {grab failed: another application has grab
grab failed: another application has grab
    while executing
"grab $oldGrab"
    (procedure "::t..."
    (in namespace inscope "::tk::dialog::error" script
line 1)
    invoked from within
"::namespace inscope ::tk::dialog::error SaveToLog
{grab failed: another application has grab
grab failed: another application has grab
    while execu..."
    invoked from within
".bgerrorDialog.function invoke"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 [list $w invoke]"
    (procedure "tk::ButtonUp" line 22)
    invoked from within
"tk::ButtonUp .bgerrorDialog.function"
    (command bound to event)

I'm not sure what ought to happen; either the grab
should apply to both interpreters, which I'd prefer, or
they should be independent of one another like
different processes.
User Comments: chrstphrchvz added on 2023-08-23 16:24:30:

I have tried adjusting the necessary steps, and while I can observe similar error messages on 8.6.13, I do not encounter any unkillable bgerror dialogs as originally described. I only encounter up to 2 bgerror dialogs in succession, and they can be dismissed.

However as of [d25b5a7ecb] this issue is no longer possible, because catch will suppress this error:

grab failed: another application has grab
    while executing
"grab $oldGrab"
    (procedure "::tk::RestoreFocusGrab" line 21)


jenglish added on 2006-01-21 05:47:28:
Logged In: YES 
user_id=68433

(From discussions with Schelte Bron on the tcl'ers chat):

jaspert added on 2004-03-24 20:56:52:
Logged In: YES 
user_id=456242

After a bit more fiddling, it seems one very simple
manifestation of the problem is that if you execute a grab
in one interpreter, then execute grab current in another,
the name of the grabbed widget from the first interpreter is
returned.