# Exiting a DialogBox created with FoxGUIb

**URL:** <https://www.ruby-forum.com/t/exiting-a-dialogbox-created-with-foxguib/78765>\
**Category:** Ruby\
**Created:** [December 8, 2006, 12:14pm UTC](https://www.ruby-forum.com/t/exiting-a-dialogbox-created-with-foxguib/78765 "2006-12-08T12:14:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![e\_aldaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@e\_aldaz](https://www.ruby-forum.com/u/e_aldaz)\
**Post date:** [December 8, 2006, 12:14pm UTC](https://www.ruby-forum.com/t/exiting-a-dialogbox-created-with-foxguib/78765/1 "2006-12-08T12:14:25Z")

</div>

Dear All

I am new to FOX and FoxGUIb. I have found FoxGUIb very  
useful and I have created an application with menus,  
one of which calls a DialogBox for the user to enter  
some values. After finishing the user will press OK to  
save data.

Unfortunately I don’t know how to let the  
DialogBox know tha tonce the OK button is pressed it  
should exit. It seems I need to send message ID\_ACCEPT  
to some recipient (not sure which) when the button OK  
is clicked? But no idea how to do that with the code  
that is generated by FoxGUIb as the button is created  
in a different way to what I have seen in the examples  
in the web, and I have no idea how to relate them (  
I’m afraid I haven’t really understood the FXButton  
API)

The dialog box examples I have seen do something like  
the following:

# Accept

```
accept = FXButton.new(buttons, "&Accept", nil,

```

self, ID\_ACCEPT,  
FRAME\_RAISED|FRAME\_THICK|LAYOUT\_RIGHT|LAYOUT\_CENTER\_Y)

However the FoxGUIb creates a button doing:

FX::Button.new(@verticalframe7){|w|  
@button\_ok=w  
w.wdg\_name=‘button\_ok’  
w.text=“Ok”  
w.width=21  
w.y=4  
w.height=21  
w.layoutHints=40  
w.x=26  
w.selector=FX::DialogBox::ID\_QUIT

```
            @button_ok.connect(Fox::SEL_COMMAND){
                        lat = textfield_lat.text
                        lon = textfield_lon.text
                        heading

```

=textfield\_heading.text  
#How  
do I indicate that I want to accept and exit?:?

```
            }

```

}

So in this last example, how do I exit the dialog when  
button is clicked?

Thanks very much for your help  
Eduardo

Send instant messages to your online friends

> **[Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos](https://www.yahoo.com/)**
>
> Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

---

<div class="post-metadata">

**Author:** ![e\_aldaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@e\_aldaz](https://www.ruby-forum.com/u/e_aldaz)\
**Post date:** [December 8, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/exiting-a-dialogbox-created-with-foxguib/78765/2 "2006-12-08T16:37:02Z")

</div>

On 12/8/06, e aldaz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> should exit. It seems I need to send message ID\_ACCEPT  
> to some recipient (not sure which) when the button OK  
> is clicked? But no idea how to do that with the code  
> that is generated by FoxGUIb as the button is created  
> in a different way to what I have seen in the examples  
> in the web, and I have no idea how to relate them (  
> I’m afraid I haven’t really understood the FXButton  
> API)

me neither 😉 … there are some very hackish things that make the use  
of fox toolkit not as easy as it could be.

> However the FoxGUIb creates a button doing:  
> w.selector=FX::DialogBox::ID\_QUIT  
> }
> 
> So in this last example, how do I exit the dialog when  
> button is clicked?

the most simple aproach would be like this:  
@button\_ok.connect(Fox::SEL\_COMMAND){  
…  
@topwin.hide() # assuming that @topwin is the name of the dialogbox  
}

however if your dialog box has been run modal this will not work. the  
dialog box disappears but is still modal. in this case you have to  
send an ID\_ACCEPT message to @topwin like this:

@topwin.handle(@button, FXSEL(Fox::SEL\_COMMAND,  
Fox::FXDialogBox::ID\_ACCEPT), nil)

hope this helps,  
– meinrad (henon)

---

<div class="post-metadata">

**Author:** ![e\_aldaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@e\_aldaz](https://www.ruby-forum.com/u/e_aldaz)\
**Post date:** [December 9, 2006, 6:49pm UTC](https://www.ruby-forum.com/t/exiting-a-dialogbox-created-with-foxguib/78765/3 "2006-12-09T18:49:48Z")

</div>

Hi Meinrad,  
Thank you very much for your help.  
Where would i put the message handler:  
@topwin.handle(@button,  
FXSEL(Fox::SEL\_COMMAND,Fox::FXDialogBox::ID\_ACCEPT),  
nil)  
Would i put it inside the button\_ok.connect method?

FX::Button.new(@verticalframe7){|w|  
@button\_ok=w  
w.wdg\_name=‘button\_ok’  
w.text=“Ok”  
w.width=21  
w.y=4  
w.height=21  
w.layoutHints=40  
w.x=26  
w.selector=FX::DialogBox::ID\_QUIT

```
             @button_ok.connect(Fox::SEL_COMMAND){
             lat = textfield_lat.text
             lon = textfield_lon.text
             heading =textfield_heading.text
             @topwin.handle(@button,

```

FXSEL(Fox::SEL\_COMMAND,Fox::FXDialogBox::ID\_ACCEPT),  
nil)  
}  
}

Thanks again!  
Eduardo

— Meinrad R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> OK to  
> code  
> me neither 😉 … there are some very hackish things
> 
> > self, ID\_ACCEPT,

FRAME\_RAISED|FRAME\_THICK|LAYOUT\_RIGHT|LAYOUT\_CENTER\_Y)

> > ```
> > w.height=21
> > heading
> > 
> > ```
> > 
> > button is clicked?  
> > dialog box disappears but is still modal. in this  
> > Eduardo

* * *

The all-new Yahoo! Mail goes wherever you go - free your email address  
from your Internet provider. [http://uk.docs.yahoo.com/nowyoucan.html](http://uk.docs.yahoo.com/nowyoucan.html)

---

<div class="post-metadata">

**Author:** ![e\_aldaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@e\_aldaz](https://www.ruby-forum.com/u/e_aldaz)\
**Post date:** [December 9, 2006, 8:52pm UTC](https://www.ruby-forum.com/t/exiting-a-dialogbox-created-with-foxguib/78765/4 "2006-12-09T20:52:00Z")

</div>

On 12/9/06, e aldaz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Meinrad
> 
> I have included the call you mentioned in the funcion  
> connect and i get the error:
> 
> @topwin.handle(@button, FXSEL(Fox::SEL\_COMMAND,  
> Fox::FXDialogBox::ID\_ACCEPT), nil)
> 
> undefined method `FXSEL’ for #DialogBox:0x7f5e230

yeah, sorry, i forgot to prefix FXSEL with Fox:: like this:

@topwin.handle(@button\_ok,  
Fox::FXSEL(Fox::SEL\_COMMAND,Fox::FXDialogBox::ID\_ACCEPT), nil)

– meinrad

---

<div class="post-metadata">

**Author:** ![e\_aldaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@e\_aldaz](https://www.ruby-forum.com/u/e_aldaz)\
**Post date:** [December 9, 2006, 7:17pm UTC](https://www.ruby-forum.com/t/exiting-a-dialogbox-created-with-foxguib/78765/5 "2006-12-09T19:17:52Z")

</div>

Hi Meinrad

I have included the call you mentioned in the funcion  
connect and i get the error:

@topwin.handle(@button, FXSEL(Fox::SEL\_COMMAND,  
Fox::FXDialogBox::ID\_ACCEPT), nil)

undefined method `FXSEL’ for #DialogBox:0x7f5e230

I have also seen mention of using something like:  
getApp().stopModal(@topwin, 1)  
@topwin.hide  
But didn’t work for me either  
I have included all the code created by the FoxGUIb,  
hoping it could make things clearer.

Thanks again !  
Eduardo

# source generated by foxGUIb 0.7.1

class DialogBox  
def initialize( parent)  
construct\_widget\_tree( parent)  
init if respond\_to? ‘init’  
end

```
def construct_widget_tree( parent)
	@topwin=
	FX::DialogBox.new(parent){|w|
		@dialogBox=w
		w.wdg_name='dialogBox'
		w.width=137
		w.shown=true
		w.y=472
		w.height=125
		w.title="TrackerPod Data"
		w.x=-543
		FX::HorizontalFrame.new(@dialogBox){|w|
			@horizontalframe3=w
			w.wdg_name='horizontalframe3'
			w.width=137
			w.height=30
			w.layoutHints=1536
			FX::Label.new(@horizontalframe3){|w|
				@label_dialog_title=w
				w.wdg_name='label_dialog_title'
				w.text="TRACKER POD DATA:"

```

w.font=FX::Font.new.from\_s(‘Tahoma|100|70|5|0|0|0’).to\_FXFont  
w.width=137  
w.y=5  
w.height=20  
w.layoutHints=40  
}  
}  
FX::HorizontalFrame.new(@dialogBox){|w|  
@horizontalframe2=w  
w.wdg\_name=‘horizontalframe2’  
w.width=137  
w.y=34  
w.height=57  
w.layoutHints=1024  
FX::VerticalFrame.new(@horizontalframe2){|w|  
@verticalframe4=w  
w.wdg\_name=‘verticalframe4’  
w.width=56  
w.height=57  
FX::Label.new(@verticalframe4){|w|  
@label\_lat=w  
w.wdg\_name=‘label\_lat’  
w.text=“Lat:”  
w.width=23  
w.height=17  
}  
FX::Label.new(@verticalframe4){|w|  
@label\_lon=w  
w.wdg\_name=‘label\_lon’  
w.text=“Lon:”  
w.width=25  
w.y=17  
w.height=17  
}  
FX::Label.new(@verticalframe4){|w|  
@label\_heading=w  
w.wdg\_name=‘label\_heading’  
w.text=“Heading:”  
w.width=47  
w.y=34  
w.height=17  
}  
}  
FX::VerticalFrame.new(@horizontalframe2){|w|  
@verticalframe6=w  
w.wdg\_name=‘verticalframe6’  
w.width=81  
w.height=57  
w.x=56  
FX::TextField.new(@verticalframe6){|w|  
@textfield\_lat=w  
w.wdg\_name=‘textfield\_lat’  
w.width=66  
w.height=19  
w.numColumns=10  
}  
FX::TextField.new(@verticalframe6){|w|  
@textfield\_lon=w  
w.wdg\_name=‘textfield\_lon’  
w.width=66  
w.y=19  
w.height=19  
w.numColumns=10  
}  
FX::TextField.new(@verticalframe6){|w|  
@textfield\_heading=w  
w.wdg\_name=‘textfield\_heading’  
w.width=66  
w.y=38  
w.height=19  
w.numColumns=10  
}  
}  
}  
FX::HorizontalFrame.new(@dialogBox){|w|  
@horizontalframe4=w  
w.wdg\_name=‘horizontalframe4’  
w.width=137  
w.y=95  
w.height=30  
w.layoutHints=3584  
FX::VerticalFrame.new(@horizontalframe4){|w|  
@verticalframe7=w  
w.wdg\_name=‘verticalframe7’  
w.width=47  
w.height=30  
FX::Button.new(@verticalframe7){|w|  
@button\_ok=w  
w.wdg\_name=‘button\_ok’  
w.text=“Ok”  
w.width=21  
w.y=4  
w.height=21  
w.layoutHints=40  
w.x=13  
@button\_ok.connect(Fox::SEL\_COMMAND){  
lat = textfield\_lat.text  
lon = textfield\_lon.text  
heading = textfield\_heading.text  
#No idea how to close the window. something  
about ID\_ACCEPT

#@topwin.handle(nil,MKUINT(w::ID\_ACCEPT,SEL\_COMMAND),nil)  
#@topwin.handle(@button\_ok,  
FXINT(Fox::SEL\_COMMAND,Fox::FXDialogBox::ID\_ACCEPT),  
nil)

@topwin.handle(@button\_ok,  
FXSEL(Fox::SEL\_COMMAND,Fox::FXDialogBox::ID\_ACCEPT),  
nil)  
#getApp().stopModal(@topwin, 1)  
#@topwin.hide

```
					}
				}
			}
			FX::VerticalFrame.new(@horizontalframe4){|w|
				@verticalframe9=w
				w.wdg_name='verticalframe9'
				w.width=90
				w.height=30
				w.x=47
				FX::Button.new(@verticalframe9){|w|
					@button_cancel=w
					w.wdg_name='button_cancel'
					w.text="Cancel"
					w.width=40
					w.y=4
					w.height=21
					w.layoutHints=40
					w.x=25
				}
			}
		}
	}
end
attr_reader :topwin
attr_reader :dialogBox
attr_reader :horizontalframe3
attr_reader :label_dialog_title
attr_reader :horizontalframe2
attr_reader :verticalframe4
attr_reader :label_lat
attr_reader :label_lon
attr_reader :label_heading
attr_reader :verticalframe6
attr_reader :textfield_lat
attr_reader :textfield_lon
attr_reader :textfield_heading
attr_reader :horizontalframe4
attr_reader :verticalframe7
attr_reader :button_ok
attr_reader :verticalframe9
attr_reader :button_cancel

```

end

#unit test  
if **FILE** ==$0  
require ‘libGUIb16’  
app=FX::App.new  
w=DialogBox.new app  
w.topwin.show(Fox::PLACEMENT\_SCREEN)  
app.create  
app.run  
end

* * *

All new Yahoo! Mail “The new Interface is stunning in its simplicity and  
ease of use.” - PC Magazine  
[http://uk.docs.yahoo.com/nowyoucan.html](http://uk.docs.yahoo.com/nowyoucan.html)

---

<div class="post-metadata">

**Author:** ![e\_aldaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e57/32.png) [@e\_aldaz](https://www.ruby-forum.com/u/e_aldaz)\
**Post date:** [December 9, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/exiting-a-dialogbox-created-with-foxguib/78765/6 "2006-12-09T22:52:15Z")

</div>

Meinrad, it works perfectly, thank you very much

— Meinrad R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > undefined method `FXSEL’ for  
> > #DialogBox:0x7f5e230
> 
> yeah, sorry, i forgot to prefix FXSEL with Fox::  
> like this:
> 
> @topwin.handle(@button\_ok,

Fox::FXSEL(Fox::SEL\_COMMAND,Fox::FXDialogBox::ID\_ACCEPT),

> nil)
> 
> – meinrad

* * *

All new Yahoo! Mail “The new Interface is stunning in its simplicity and  
ease of use.” - PC Magazine  
[http://uk.docs.yahoo.com/nowyoucan.html](http://uk.docs.yahoo.com/nowyoucan.html)
