Tk Source Code

View Ticket
Login
Ticket UUID: 1038760
Title: Tcl_DoOneEvent doesn't return when modal dialog is open.
Type: Bug Version: None
Submitter: nirajvdesai Created on: 2004-10-01 22:35:27
Subsystem: 70. Event Loop Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Open Last Modified: 2005-04-21 00:12:17
Resolution: None Closed By:
    Closed on:
Description:
     I have a problem with Tcl_DoOneEvent when used 
with modal dialog box. 
I am using C-Tcl/Tk interface on linux platform with C as 
backend and Tcl/Tk as GUI front end. In C program I use 
the call Tcl_DoOneEvent to service all Tcl events. If 
TCL_DONT_WAIT flag is specified with this call, this call  
should return when there are no events to handle. It 
does return normally, but not when a modal dialog is 
opened in Tcl/Tk. Thus, when a modal dialog box is 
opened, my C program is effectively 'blocked' and I 
cannot use C program to update display in GUI front 
end. 
  I have attached a sample C and Tcl program to 
simulate this problem. It can be compiled for linux with
gcc -o tclmodal main.c -ltcl8.4 -tk8.4

  Following is the event loop shown here from attached 
file main.c
while (TclIsRunning) {
      while (Tcl_DoOneEvent(TCL_ALL_EVENTS | 
TCL_DONT_WAIT));
printf("Returned from Tcl_DoOneEvent ");
usleep(10);   
}
When you run tclmodal, it will repeatedly print "Returned 
from Tcl_DoOneEvent". But if you click File->Open, it will 
open a dialog box and you will see that print messages 
are stopped indicating that Tcl_DoOneEvent has not 
returned. Closing the dialog box will resume printf 
messages. 
   Can anybody explain this behavior of Tcl_DoOneEvent 
and help me find a solution so that my C program is 
not 'blocked' when modal dialog box is open ? I would 
really appreciate the help. 

The file attached is : main.c   
I could attach only one file with the tracker, so I have 
printed here contents of modaldlg.tcl. Just copy 
following part to modaldlg.tcl file and run C application.  
# modaldlg.tcl file for eventloop testing
. configure -menu .mbar
menu .mbar
.mbar add cascade -label "File" -menu .mbar.file
menu .mbar.file -tearoff 0
.mbar.file add command -label "Open..." \
-command {set openFile [tk_getOpenFile -
title "Select File to Open"]}
User Comments: hobbs added on 2005-04-21 00:12:17:
Logged In: YES 
user_id=72656

See the notifier docs for Tcl_ServiceAll, especially with
respect to External Event Loops.  For example, the open file
dialogs do:

    oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
    if (open != 0) {
winCode = GetOpenFileNameW(&ofn);
    } else {
winCode = GetSaveFileNameW(&ofn);
    }
    Tcl_SetServiceMode(oldMode);

I'm not sure if this exactly the fix required, but it should
be tested.

nirajvdesai added on 2004-10-02 05:41:20:

File Added - 103518: modaldlg.tcl

Logged In: YES 
user_id=1014454

I found a way to attach second file also and here it is - 
modaldlg.tcl

nirajvdesai added on 2004-10-02 05:35:28:

File Added - 103516: main.c

Attachments: