[wxruby-users] WX::Dialog won't close

Mario Steele mario at ruby-im.net
Fri Oct 10 18:16:47 EDT 2008


Another Idea for you Glen,

Instead of using Close,  and Destroy to get rid of the dialog, if it's a
Dialog that is used quite often, I would opt to use show_modal, and
end_modal, and after end_modal is called, just call hide, instead of
destroy.

An Example of this:

class MyDialog < Wx::Dialog
  def initialize(*args)
    super
    ok = Wx::Button.new(self,Wx::ID_OK,"&Ok")
    cancel = Wx::Button.new(self,Wx::ID_CANCEL,"&Cancel")
    # ...... Add your own controls ......
    evt_button(Wx::ID_OK) do
       # ...... do whatever processing you need .......
       end_modal(Wx::ID_OK)
    end
    evt_button(Wx::ID_CANCEL) do
       # ...... Ask any, "Are you sure you want to cancel" here ........
       # Or don't even put this handler in, as it's automatically handled by
Wx::Dialog
    end
  end
end

class MyFrame < Wx::Frame
  def initialize(*args)
    super
    # We create our dialog that we are going to use a lot, and show only
    # when needed.
    @dlg = MyDialog.new(self,-1,"Information Report")
    # .... add the rest of the stuff .......
    evt_button(ID_SHOW_DIALOG) do
      @dlg.show_modal do |response|
          # ..... process response .....
      end
      @dlg.hide
    end
  end
end

This is just a bare bone example, that will not work, least you actually put
it together.  But it gives you an idea of how to use it, especially when you
re-use a dialog multiple times.

Hope this helps,

Mario Steele
On Fri, Oct 10, 2008 at 4:18 PM, Glen Holcomb <damnbigman at gmail.com> wrote:

> On Fri, Oct 10, 2008 at 2:54 PM, Glen Holcomb <damnbigman at gmail.com>wrote:
>
>> On Fri, Oct 10, 2008 at 3:48 AM, Alex Fenton <alex at pressure.to> wrote:
>>
>>> Hi Glen
>>>
>>> Glen Holcomb wrote:
>>>
>>>  It would appear that the only instruction that doesn't run at the end of
>>>> on_okay is close, exit works fine.  This kind of blows, I suppose I'll have
>>>> to start another instance of the app and exit after the populate finishes,
>>>> not the cleanest solution.
>>>>
>>>
>>> I'm sure you won't need to do this.
>>>
>>> Generally, if you want help, please reduce the code to a standalone,
>>> runnable, and ideally short sample. I'm very happy to help, but it's too
>>> much to expect people to install extra libraries and second-guess what the
>>> rest of your app is doing.
>>>
>>> I did try running your code, pruned of the LDAP stuff. It seems fine to
>>> me - there's nothing in the dialog layout itself. I would suggest checking
>>> that the dialog has an explicit parent, not nil - it is better in most cases
>>> that the dialog is linked to a parent frame. In the special case that an
>>> application consists only of a single dialog, you must use Dialog#destroy to
>>> end the app, close is not sufficient.
>>>
>>> If this doesn't help, I would look further into net/ldap and see whether
>>> this is causing it to hang - ie, if ok does nothing but 'close' does it work
>>> fine?
>>>
>>> cheers
>>>
>>> alex
>>>
>>>
>>> _______________________________________________
>>> wxruby-users mailing list
>>> wxruby-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/wxruby-users
>>>
>>
>> Hey Alex,
>>
>> Thanks for the reply, destroy did the trick.  I don't know why I didn't
>> try that before, according to my browser I'd looked at the method definition
>> in the API docs.  Odd that close doesn't work, I'm creating this dialog the
>> same way I do all my others and close works for them.
>>
>> --
>> "Hey brother Christian with your high and mighty errand, Your actions
>> speak so loud, I can't hear a word you're saying."
>>
>> -Greg Graffin (Bad Religion)
>>
>
> I have another dialog behaving the same way now.  My application has one
> frame and from that frame I'm passing self as the parent argument for the
> Dialog Windows.  I do this for other dialogs created by button events and it
> works okay.  The dialogs that are unresponsive after pressing okay are
> created through menu events should I be doing something differently when
> creating a dialog from a menu option?
>
> I will try to pair my code down and post a small working example but it
> will take a while.  If anyone has any ideas off the top of their head I'm
> all ears.  Dialog#destroy does work so I can always do that.
>
> --
> "Hey brother Christian with your high and mighty errand, Your actions speak
> so loud, I can't hear a word you're saying."
>
> -Greg Graffin (Bad Religion)
>
> _______________________________________________
> wxruby-users mailing list
> wxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wxruby-users
>



-- 
Mario Steele
http://www.trilake.net
http://www.ruby-im.net
http://rubyforge.org/projects/wxruby/
http://rubyforge.org/projects/wxride/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20081010/17c27fa8/attachment.html>


More information about the wxruby-users mailing list