News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Response from Message Box
Author Message
ceeuu
Junior Member
**


Posts: 9
Group: Registered
Joined: Jul 2008
Status: Offline
Reputation: 0
Post: #1
Response from Message Box

I have an app with a main window that I need to display a sort of Message Box to the user to confirm whether to continue with a particular operation. The Message Box is created in a function that is called, the function defines the window and its components, populates a text box from the contents of a function argument, and awaits the user to select one of two buttons..

At the end of the function a call to 'window:show()' is used to display the Message Box... but control returns to the calling code immediately. The Message Box window is defined as being modal, which helps to keep the user from clicking off it and trying to continue without responding... that's good, however, I am unable to return to the calling code which button the user chose.

Is there a recommended way to do this?

Thanks,

-CJ

07-29-2011 06:24 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #2
RE: Response from Message Box

I'm not super clear on what you're doing (caffeine hasn't kicked in), but I will say that I've had very little success using modal. It might be an OS-specific thing, or a window manager-specific thing, but for me it tends to steal focus and never return it. So I have stayed away from modal.

07-30-2011 12:15 AM
Find all posts by this user Quote this message in a reply
ceeuu
Junior Member
**


Posts: 9
Group: Registered
Joined: Jul 2008
Status: Offline
Reputation: 0
Post: #3
RE: Response from Message Box

Here is a little example to see what I am trying to do.. The code doesn't run without the return at the bottom of the function (or similar).. what I would want is to somehow block on the call to the function until a button is pressed, or a return statement is encountered...


function displayMsg( msg )
do
local object = fltk:Fl_Double_Window( 200, 110, "Message" );
msg_window = object;
msg_window:box( fltk.Fl_UP_BOX );
do msg_box = fltk:Fl_Box( 15, 15, 170, 40, msg );
msg_box:box( fltk.FL_DOWN_BOX );
end
do continue_button = fltk:Fl_Button( 15, 70, 70, 24, "Continue" );
continue_button:callback(
function( button_cb )
print( "Continue button Selected" );
msg_window:hide();
return 1;
end )
end
do cancel_button = fltk:Fl_Button( 130, 70, 55, 24, "Cancel" );
cancel_button:callback(
function( button_cb )
print( "Cancel button Selected" );
msg_window:hide();
return 2;
end )
end
end
msg_window:show();
-- execution falls through and returns to calling code,
-- how to remain in function until button is pressed ???
-- adding a return here to allow sample code to work...
return 3;
end

do
local object = fltk:Fl_Double_Window( 220, 200, "Msg Test" );
main_window = object;
main_window:box( fltk.Fl_UP_BOX );
do my_button = fltk:Fl_Button( 160, 160, 50, 25, "Push" );
my_button:callback(
function( button_cb )
print( "button press.." );
print( "calling displayMsg.." );
rc = displayMsg( "Continue or Not?" );
print( "return from displayMsg.." );
print( "return code: "..rc );
end )
end
end

main_window:show();
Fl:run();

07-30-2011 03:04 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #4
RE: Response from Message Box

Are you aware that Fltk has a built-in dialog that can be used in this way? The fl_choice dialog prevents access to its parent window until a choice is made, either by selection of one of the choices or by escaping out of the dialog.

In this example fl_choice is used as an exit confirmation. If "yes" is not chosen, the dialog closes and nothing happens. You could easily enough add a default condition, in case the user simply closes the dialog.

Code:
function my_exit()
  my_confirm=fltk.fl_choice("sure you want to quit?","no","yes",NULL)
  if my_confirm == 1 then os.exit(0) end
end
my_window:callback(my_exit)

07-31-2011 01:11 AM
Find all posts by this user Quote this message in a reply
ceeuu
Junior Member
**


Posts: 9
Group: Registered
Joined: Jul 2008
Status: Offline
Reputation: 0
Post: #5
RE: Response from Message Box

I wasn't aware of that call, I'll try it out and see if it will do what I am after (looks like it will).

Thanks!

07-31-2011 11:09 AM
Find all posts by this user Quote this message in a reply
roydobbins
Junior Member
**


Posts: 7
Group: Registered
Joined: Nov 2010
Status: Offline
Reputation: 0
Post: #6
RE: Response from Message Box

ceeuu Wrote:
I wasn't aware of that call, I'll try it out and see if it will do what I am after (looks like it will).

Thanks!


In case you want to pursue this further, here is the general approach that i have used for this type of problem:

--launch the dialog, as in your example, setting it modal
--as part of calling the dialog function, supply a callback function as a parameter
--when user clicks a button in the dialog, invoke the callback function, including any data you want to pass back

the caller is still active while the dialog is open, and can process any callbacks

user needs to exit the dialog before main app can continue

this is an asynchronous model, is very flexible and can be used in many situations

hope this helps
-roy

08-05-2011 11:37 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: