Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, I have tried to get an extension to create an event source and get the event loop to drive the action. It kind of works but when I do this: $ /usr/local/bin/wish8.4 % source sample.tcl I can see that the event source is created but nothing happens until I move the mouse over the wish window, likewise if I use tclsh8.4, after the event source is created nothing seems to happen. Is that normal or do I need to do something to boot the event loop? Thanks, Andres P.S. Please excuse me if these question ends up appearing several times, my news server seems to be acting up.
Post Follow-up to this messageAndres Garcia wrote: > Hi, > > I have tried to get an extension to create an event > source and get the event loop to drive the action. > > It kind of works but when I do this: > > $ /usr/local/bin/wish8.4 > % source sample.tcl > > I can see that the event source is created but nothing > happens until I move the mouse over the wish window, > likewise if I use tclsh8.4, after the event source > is created nothing seems to happen. > > Is that normal or do I need to do something to boot the > event loop? > When you run wish an event loop is automatically started; when you run tclsh it is not. Does that answer your question?
Post Follow-up to this messageHi, > When you run wish an event loop is automatically started; when you run > tclsh it is not. Does that answer your question? Not really, if the loop is automatically started in wish, why doesn't anything happen until I move the mouse over the wish window? Andres
Post Follow-up to this messageAndres Garcia wrote: > Hi, > > > > > Not really, if the loop is automatically started in wish, why doesn't > anything happen until I move the mouse over the wish window? I'd have to have more specifics to answer that. Can you post a small block of code that illustrates the problem? Also, what platform is this one? Is it possible you have a window manager that is configured to suspend windows that aren't in the foreground?
Post Follow-up to this messageHi,
> I'd have to have more specifics to answer that. Can you post a small
> block of code that illustrates the problem? Also, what platform is this
> one? Is it possible you have a window manager that is configured to
> suspend windows that aren't in the foreground?
The platform is Mandrake 10 with Kde, but I have tried with Gnome
and the same thing happens, the events are only triggered while am
I moving the mouse over the wish window, even though it is not the
selected window.
The code I am using to create the event source,after removing the
specifics of what it does, is the following:
int
InitSource(Tcl_Interp *interp, struct myData *myDataPtr,
int objc,Tcl_Obj *CONST objv[]) {
Tcl_CreateEventSource((Tcl_EventSetupPro
c *)NULL,
(Tcl_EventCheckProc *)EventCheck, (ClientData *)myDataPtr);
return TCL_OK;
}
void
EventCheck(ClientData clientData, int flags) {
struct curlMultiObjData *curlMultiData=
(struct curlMultiObjData *)clientData;
Tcl_Event *eventToInvokePtr;
struct curlEvent *curlEventPtr;
int selectCode;
selectCode=CheckIfSomethingToDo(myDataPt
r);
if (myDataPtr->running==0) {
Tcl_DeleteEventSource((Tcl_EventSetupPro
c *)NULL,
(Tcl_EventCheckProc *)curlEventCheck,
(ClientData *)curlMultiData);
} else {
if (selectCode>=0) {
EventPtr=(struct Event *)Tcl_Alloc(sizeof(struct Event));
EventPtr->proc=EventProc;
EventPtr->myDataPtr=myDataPtr;
Tcl_QueueEvent((Tcl_Event *)EventPtr, TCL_QUEUE_TAIL);
}
}
}
int
EventProc(Tcl_Event *evPtr,int flags) {
struct myData *myDataPtr=(struct myData *)
((struct Event *)evPtr)->myDataPtr;
DoSomething(myDataPtr);
return 1;
}
Thanks for your help,
Andres
Post Follow-up to this messageAndres Garcia wrote:
> Hi,
>
>
>
>
> The platform is Mandrake 10 with Kde, but I have tried with Gnome
> and the same thing happens, the events are only triggered while am
> I moving the mouse over the wish window, even though it is not the
> selected window.
>
> The code I am using to create the event source,after removing the
> specifics of what it does, is the following:
>
> int
> InitSource(Tcl_Interp *interp, struct myData *myDataPtr,
> int objc,Tcl_Obj *CONST objv[]) {
>
We're suddenly out of my depth; I was hoping maybe the problem lay at
the tcl level. Apparently not, and I'm not familiar with the internals.
Sorry I can't be of more help.
Post Follow-up to this messageHello, Andres Garcia wrote: > Hi, > > I have tried to get an extension to create an event > source and get the event loop to drive the action. > > It kind of works but when I do this: > > $ /usr/local/bin/wish8.4 > % source sample.tcl > > I can see that the event source is created but nothing > happens until I move the mouse over the wish window, > likewise if I use tclsh8.4, after the event source > is created nothing seems to happen. > > Is that normal or do I need to do something to boot the > event loop? This is because the Tcl event loop is waiting for event, and your code doesn't seem to unblock it. When you move the mouse cursor, Tcl event loop unblock and then your event is queued by your Tcl_EventCheckProc. If you need to poll your events (as it seem to be), use Tcl_SetMaxBlockTime() in your Tcl_EventCheckProc if when you don't queue event. If you have another mechanism that get events in another thread, under Windows, you can use Tcl_ThreadAlert(), even is non-threaded Tcl. Under Unix, this is more complicated, you need a file descriptor for Tcl_CreateFileHandler() which help you to unblock the event loop. -- -eric
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.