# wxDirDialog and show\_modal don't work

**URL:** <https://www.ruby-forum.com/t/wxdirdialog-and-show-modal-dont-work/142378>\
**Category:** wxRuby\
**Created:** [July 7, 2008, 1:38pm UTC](https://www.ruby-forum.com/t/wxdirdialog-and-show-modal-dont-work/142378 "2008-07-07T13:38:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tracerek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tracerek](https://www.ruby-forum.com/u/tracerek)\
**Post date:** [July 7, 2008, 1:38pm UTC](https://www.ruby-forum.com/t/wxdirdialog-and-show-modal-dont-work/142378/1 "2008-07-07T13:38:05Z")

</div>

Hi,  
I’m playing around with wxRuby and XRC and I’m unable to create modal  
WxDirDialog. After opening it I’m always able to get focus on parent  
window.

class TestApp \< Wx::App  
def on\_init  
@test = Main.new.show  
end  
end

class Main \< MainFrame  
def initialize  
super  
self.size = ([133,191])  
evt\_button(basic\_config) { | event | butt\_event(event) }  
end  
end

def butt\_eventos(event)  
adr = Wx::DirDialog.new( @test, “Choose a folder”)  
case adr.show\_modal()  
when Wx::ID\_OK  
puts “Directory: %s” %  
[adr.get\_path]  
when Wx::ID\_CANCEL  
puts “NOT OK”  
end  
adr.destroy()  
end

After changing DirDialog to FileDialog or MessageDialog it works great,  
and those dialogs are modal, so it looks that in Dirdialog is buggy, bt  
maybe I’m doing something wrong. Any ideas? Thnx.  
(I’m using latest wxRuby,wx\_sugar, tested on winXP and Vista)

---

<div class="post-metadata">

**Author:** ![tracerek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tracerek](https://www.ruby-forum.com/u/tracerek)\
**Post date:** [July 8, 2008, 12:40pm UTC](https://www.ruby-forum.com/t/wxdirdialog-and-show-modal-dont-work/142378/2 "2008-07-08T12:40:36Z")

</div>

You are looking for the fit() method.

From the docs:  
window.Fit(): The Fit() method sets the size of a window to fit around  
its children. If it has no children then nothing is done, if it does  
have children then the size of the window is set to the window’s best  
size.

[http://docs.wxwidgets.org/stable/wx\_windowsizingoverview.html#windowsizingoverview](http://docs.wxwidgets.org/stable/wx_windowsizingoverview.html#windowsizingoverview)

and  
[http://wxruby.rubyforge.org/doc/window.html#Window\_fit](http://wxruby.rubyforge.org/doc/window.html#Window_fit)

ps. frames that resize themselves aren’t really considered user-friendly  
either.

Best of luck,  
Jonathan

---

<div class="post-metadata">

**Author:** ![tracerek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tracerek](https://www.ruby-forum.com/u/tracerek)\
**Post date:** [July 8, 2008, 12:51pm UTC](https://www.ruby-forum.com/t/wxdirdialog-and-show-modal-dont-work/142378/3 "2008-07-08T12:51:46Z")

</div>

Sorry about that, Thunderbird wasn’t cooperating causing me to  
accidentally responded to the wrong message.

My bad.
