Forum: wxRuby wxruby messagedialog box

Posted by Bruce Loving (Guest)
on 2010-07-27 00:27
(Received via mailing list)
any way to keep a dialog box inside its parent, instead of centered on 
the
screen?
require 'rubygems'
require 'wx'
include Wx


class MyFrame < Frame
    def initialize()
      super(nil,-1,'Wristband Manager',:size => [400,600])
    @my_panel = Panel.new(self)
    @mybutton = Button.new(self,-1,'click')
    evt_button(@mybutton) {onclick}
    show

 end

def onclick
 diagYesno = MessageDialog.new(self,'are you sure','Process 
Request',YES_NO)
   case diagYesno.show_modal
            when Wx::ID_YES
                yesno = 'Yes'
            when Wx::ID_NO
                yesno = 'No'
            end
            puts yesno
end

 end

 class MyApp < App
     def on_init
        frame1 = MyFrame.new

    end
end

### Main Logic


MyApp.new.main_loop()
Posted by Alex Fenton (Guest)
on 2010-07-27 00:39
(Received via mailing list)
hi

On 26/07/2010 23:07, Bruce Loving wrote:
> any way to keep a dialog box inside its parent, instead of centered on 
> the screen?

Try calling centre_on_parent() - or center_on_parent(), if you're that
way inclined

Dialog inherits this method from Wx::Window

cheers
alex
Posted by Mario Steele (Guest)
on 2010-07-27 13:31
(Received via mailing list)
You will need to do this, before you call show_modal, as show_modal will
open the dialog, and wait for a User Response, before returning control 
back
to your program, so just after the creation of your Dialog Object, you 
would
call #centre_on_parent() or #center_on_parent().
Posted by Bruce Loving (Guest)
on 2010-07-27 16:11
(Received via mailing list)
hm, ok, read the docs, but it still doesnt center on parent
also, how come button fills whole frame?

require 'rubygems'
require 'wx'
include Wx

class MyFrame < Frame
    def initialize()
      super(nil,-1,'The Rabbit Hole',:size => [300,300])
      @diagYesno = MessageDialog.new(self,'are you sure','White Rabbit
asks',YES_NO)
         @diagYesno.center_on_parent(BOTH)
    #@my_panel = Panel.new(self)
    @mybutton = Button.new(self,-1,'Drink Me',:pos =>[2,2],:size => 
[30,20])
    evt_button(@mybutton) {onclick}
    show
 end

def onclick

   case @diagYesno.show_modal
            when Wx::ID_YES
                yesno = 'Yes'
            when Wx::ID_NO
                yesno = 'No'
            end
            puts yesno
end

 end

 class MyApp < App
     def on_init
        frame1 = MyFrame.new

    end
end

### Main Logic


MyApp.new.main_loop()
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.