Re: program flow--please help



On Thu, 6 Dec 2001, A R Hummaida wrote:

>     Dear All
>
> I am kind of new to gtk's event based flow..
>
> i have a call back function A that within it calls another function B.
> the later displays a window for the user to confirm something.
> during this time fuction A does not wait for B to return, but carries
> till it finshes. thats not what i am used to in c.
> how could i get A to wait untill B returns ?(ie after a user confirms
> within B). i have generated most of the code using Glade.

	A function calling another function will never continue its work
before the called function really returned. You shouldn't falsify the rule
that you are used to in C ! What you experienced is called a "non modal
dialog". Your function B will open a non modal dialog window that waits
for user input but will allow the program to continue with other work.

	From the processes point of view the function B you called will
return immediately after firing the event request to open the window. Then
of course A will continue its work, since B has actually finished. There
is a greate chance that glade lets you set the dialog window which is
opened by B into "modal" mode, where the application will wait for user
input before allowing any other input.

	But there is also a chance that the function B still returns
immediately, when the dialog window is in modal mode. The same reason
forces this: The dialog window is only requested by the function B.

	The code that you execute in function A, where you will use the
results of user input MUST NOT be called before the USER INPUT EVENT
occures from the dialog window. You have to catch this event. If you
really want to stop the whole application flow, which means even stop
redrawing hidden parts from your application windows, when they are
exposed again, you have to write your own sub application loop. It is a
good exercise to write such a temporary application loop which waits for
the user input event from the dialog, but wont execute any other event.

	Once the event occurred, you can return from this temporary
application loop, continuing the standard loop:

       +----------------<-----------------------------+
       |                                              |
[application loop]                                    |
       |                                              |
       |                                              |
       +-->--[event]---[function A]---[function B]    |
                                           |          |
					   |          |
       +-[wait for dialog input]-----<-----+          |
       |	   |                                  |
       |	   |                                  |
       |        [event]                    [work with dialog input]
       |	   |                                  |
       |  [is event=dialog input event?]--YES->-------+
       |           |
       |          NO
       |	   |
       +-----<-----+

I hope this helps you. I would be glad if you mail me your
[wait for dialog input] solution.

CU INGO




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]