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"]}
main.c file for simulating c-Tcl interface showing Tcl_DoOneEvent problem.
Tcl file for simulating c-tcl interface showing Tcl_DoOneEvent problem.
Logged In: YES
user_id=1014454
I found a way to attach second file also and here it is -
modaldlg.tcl
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.