# Question about modal window

**URL:** <https://www.ruby-forum.com/t/question-about-modal-window/213948>\
**Category:** Ruby-Gnome 2\
**Created:** [November 17, 2011, 7:03am UTC](https://www.ruby-forum.com/t/question-about-modal-window/213948 "2011-11-17T07:03:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [November 17, 2011, 7:03am UTC](https://www.ruby-forum.com/t/question-about-modal-window/213948/1 "2011-11-17T07:03:57Z")

</div>

Dear all,

I need to create a modal child window.  
So far I use gtk\_window, but it has one problem

# usually I have _self.modal = true_ in initialize method and \*self.modal

false\* in close method.  
problem is close method doesn’t work if the child window is closed by  
clicking x button at the frame,  
so if a user click it, child window disappear but modal state doesn’t  
change to false so parent window can’t be accessed

so my question is,

is it the right way to create a modal child window, if not, what widget  
should I use?  
or  
if it is, what event can I use for changing modal state before close,  
I already use \*delete\_event _and_ destroy \*but it doesn’t work

Thanks

---

<div class="post-metadata">

**Author:** ![hendra\_kusuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/5f8ce5/32.png) [@hendra\_kusuma](https://www.ruby-forum.com/u/hendra_kusuma)\
**Post date:** [November 17, 2011, 7:42am UTC](https://www.ruby-forum.com/t/question-about-modal-window/213948/2 "2011-11-17T07:42:12Z")

</div>

Subject: [ruby-gnome2-devel-en] question about modal window  
Date: gio 17 nov 11 12:54:30 +0800

Quoting hendra kusuma ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)):

> so my question is,
> 
> is it the right way to create a modal child window, if not, what widget  
> should I use?

When I need a modal window, I use Dialog:

dialog=Gtk::Dialog::new(“Title”,@parent\_window,Gtk::Dialog::MODAL)

I pack dialog.vbox with whatever I want to show, and I add one or more  
buttons - for example, if I just want the user to close the window I  
write:

dialog.add\_button(‘CLOSE’,Gtk::Dialog::RESPONSE\_CANCEL)  
dialog.signal\_connect(‘response’) do |w,r|  
dialog.destroy()  
end

and I complete with

dialog.show\_all()

I hope this helps

Carlo

–

- 

```
    Se la Strada e la sua Virtu' non fossero state messe da 

```

parte,

- K \* Carlo E. Prelz - [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) che bisogno ci  
sarebbe
  - 

```
          di parlare tanto di amore e di rettitudine? 

```

(Chuang-Tzu)

---

<div class="post-metadata">

**Author:** ![hendra\_kusuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/5f8ce5/32.png) [@hendra\_kusuma](https://www.ruby-forum.com/u/hendra_kusuma)\
**Post date:** [November 17, 2011, 10:41am UTC](https://www.ruby-forum.com/t/question-about-modal-window/213948/3 "2011-11-17T10:41:44Z")

</div>

On Thu, Nov 17, 2011 at 2:41 PM, Carlo E. Prelz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > problem is close method doesn’t work if the child window is closed by
> 
> and I complete with
> 
> dialog.show\_all()
> 
> I hope this helps
> 
> Carlo

Thanks  
I manage to get it right using dialog like your suggestion, although  
many  
part of code needs to change
