Forum: wxRuby Xrc Q ; using mulitple layouts(Frames , dialogs , panels)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
702e7be0363212fda673e1aaf3b55b0d?d=identicon&s=25 Jn Jacob (jnruby)
on 2008-11-19 21:32
Hi ,
  I am developing a simple GUI with wxruby. I am using wxFormbuilder to
get the xrc file.
  I need a simple Frame with menu item file and submenu open,save and
exit. And when I click on open(submenu) it should launch an
panel(dialog) which has filepicker.

 I believe I would be able to develop a dailog also under the same
project in wxFormbuilder(which it allowed without any warnings or
errors) ,when I run xrcise I get 2 classes under same xrc file. but when
try to load it when I click on open the applicaiton crashes.

 Can someone point to any sample program which uses multiple layouts
with xrc. What is the sequence of loading the objects .
Thanks
Jn

========================================================================


# This class was automatically generated from XRC source. It is not
# recommended that this file is edited directly; instead, inherit from
# this class and extend its behaviour there.
#
# Source file: TestXrc.xrc
# Generated at: Wed Nov 19 12:00:04 -0800 2008

class TextXrc < Wx::Frame

  attr_reader :m_menubar2, :m_menu4, :m_menuitem5, :m_menuitem6,
              :m_menu5

  def initialize(parent = nil)
    super()
    xml = Wx::XmlResource.get
    xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
    xml.init_all_handlers
    xml.load("TestXrc.xrc")
    xml.load_frame_subclass(self, parent, "MyFrame2")

    finder = lambda do | x |
      int_id = Wx::xrcid(x)
      begin
        Wx::Window.find_window_by_id(int_id, self) || int_id
      # Temporary hack to work around regression in 1.9.2; remove
      # begin/rescue clause in later versions
      rescue RuntimeError
        int_id
      end
    end

    @m_menubar2 = finder.call("m_menubar2")
    @m_menu4 = finder.call("m_menu4")
    @m_menuitem5 = finder.call("m_menuItem5")
    @m_menuitem6 = finder.call("m_menuItem6")
    @m_menu5 = finder.call("m_menu5")
    if self.class.method_defined? "on_init"
      self.on_init()
    end
  end
end



# This class was automatically generated from XRC source. It is not
# recommended that this file is edited directly; instead, inherit from
# this class and extend its behaviour there.
#
# Source file: TestXrc.xrc
# Generated at: Wed Nov 19 12:00:04 -0800 2008

class BrowseFile < Wx::Dialog

  attr_reader :m_filepicker2

  def initialize(parent = nil)
    super()
    xml = Wx::XmlResource.get
    xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
    xml.init_all_handlers
    xml.load("TestXrc.xrc")
    xml.load_dialog_subclass(self, parent, "MyDialog2")

    finder = lambda do | x |
      int_id = Wx::xrcid(x)
      begin
        Wx::Window.find_window_by_id(int_id, self) || int_id
      # Temporary hack to work around regression in 1.9.2; remove
      # begin/rescue clause in later versions
      rescue RuntimeError
        int_id
      end
    end

    @m_filepicker2 = finder.call("m_filePicker2")
    if self.class.method_defined? "on_init"
      self.on_init()
    end
  end
end
======================================================================
06f6780c99d4a8dd71f2b474082ea9ce?d=identicon&s=25 Alex Fenton (Guest)
on 2008-11-20 00:52
(Received via mailing list)
Jn Jn wrote:
>
Could you please post the error message that you get when you click on
'open'? It's hard to know what's happening otherwise. Also please say
what platform (eg Win XP) and version of wxRuby you're using.

Lastly, please show the code you've written to open the initial window
from Ruby.

>  Can someone point to any sample program which uses multiple layouts
> with xrc. What is the sequence of loading the objects .
>


There shouldn't be any problem having any number of different dialogs
and frames in a single project. I have one (using DialogBlocks) which
has at least 10 separate top-level windows.

alex
702e7be0363212fda673e1aaf3b55b0d?d=identicon&s=25 Jn Jacob (jnruby)
on 2008-11-20 05:19
Problem 1
   I had overlooked the error, my bad.

./TestXrc.rb:69:in `find_window_by_id': Error wrapping object; class
`wxFilePickerCtrl' is not supported in wxRuby (NotImplementedError)
  from ./TestXrc.rb:69:in `initialize'
  from ./TestXrc.rb:77:in `call'
  from ./TestXrc.rb:77:in `initialize'
  from ./TestWrapperClass.rb:7:in `new'
  from ./TestWrapperClass.rb:7:in `initialize'
  from TestApp.rb:12:in `call'
  from TestApp.rb:12:in `process_event'
  from TestApp.rb:12:in `main_loop'
  from TestApp.rb:12

   As wxruby does not support wxFilePicker, is there an alternative (
and FileDialog (Which I suppose I could have used, is not there on
wxFormbuilder) is there any other alternative?

Problem 2.
  I put a textbox+button combo to work around the unavailablity of
filepickerctrl. but now I am in a sort of design issue due lack
understanding on how I can make the dialog a child of frame and from
there I can catch its events

 Here is the design
    TestXrcWrapperClass << TestXrc(BaseFrame) and
    BrowseFileWrapperClass << Browsefile(OpenfileDialog)
    TestApp creats TestXrcWrapperClass which create
BrowsefilewarraperClass.

  Q. How will I get the close events from dialog to the Frame?
  Q. How do I put it into a parent child framework(the Dialog and Base
Frame). ?Is that a better way to go?

Code attached :



==================================================================

TestApp.rb
=================================================================

require 'wx'
require 'TestWrapperClass'

class TestApp < Wx::App
  def on_init
    TestWrapperClass.new().show
  end
end


app = TestApp.new
app.main_loop
==================================================================
TestXrc.rb
=================================================================
# This class was automatically generated from XRC source. It is not
# recommended that this file is edited directly; instead, inherit from
# this class and extend its behaviour there.
#
# Source file: TestXrc.xrc
# Generated at: Wed Nov 19 19:29:39 -0800 2008

class TestXrc < Wx::Frame

  attr_reader :m_menubar2, :m_file, :m_open, :m_exit, :m_help,
              :m_notebook1

  def initialize(parent = nil)
    super()
    xml = Wx::XmlResource.get
    xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
    xml.init_all_handlers
    xml.load("TestXrc.xrc")
    xml.load_frame_subclass(self, parent, "TestFrame")

    finder = lambda do | x |
      int_id = Wx::xrcid(x)
      begin
        Wx::Window.find_window_by_id(int_id, self) || int_id
      # Temporary hack to work around regression in 1.9.2; remove
      # begin/rescue clause in later versions
      rescue RuntimeError
        int_id
      end
    end

    @m_menubar2 = finder.call("m_menubar2")
    @m_file = finder.call("m_file")
    @m_open = finder.call("m_open")
    @m_exit = finder.call("m_exit")
    @m_help = finder.call("m_help")
    @m_notebook1 = finder.call("m_notebook1")
    if self.class.method_defined? "on_init"
      self.on_init()
    end
  end
end
====================================================================
TestWrapperClass.rb
==================================================================

require 'TestXrc'
require 'BrowseFileWrapperClass'

class TestWrapperClass < TestXrc
      def initialize()
        super()
        evt_menu(@m_open){
             @dialog=BrowseFileWrapperClass.new
             @dialog.show()
        }
        evt_menu(@m_exit){exit}
      end
end
================================================================
BrowseFileWrapperClass.rb
================================================================

require 'TestXrc'
class BrowseFileWrapperClass < BrowseFile
  attr_accessor :filename
  def initialize
    super()
      evt_button(@m_browsefile_button){
            @filename=@m_browsefile_text.value
            close
            }
  end
end
702e7be0363212fda673e1aaf3b55b0d?d=identicon&s=25 Jn Jacob (jnruby)
on 2008-11-21 04:04
I forgot to add , I am using windows xp
06f6780c99d4a8dd71f2b474082ea9ce?d=identicon&s=25 Alex Fenton (Guest)
on 2008-11-23 09:59
(Received via mailing list)
Jn Jn wrote:
> ./TestXrc.rb:69:in `find_window_by_id': Error wrapping object; class
> `wxFilePickerCtrl' is not supported in wxRuby (NotImplementedError)
>   from ./TestXrc.rb:69:in `initialize'
>
>
...
>    As wxruby does not support wxFilePicker, is there an alternative (
> and FileDialog (Which I suppose I could have used, is not there on
> wxFormbuilder) is there any other alternative?
>

The alternative is to do what you've done below. In fact, this is what
wxWidgets does anyway on Windows and OS X; the "wxFilePicker" is only a
native control on GTK. This is the main reason the class isn't ported.

> Problem 2.
>   I put a textbox+button combo to work around the unavailablity of
> filepickerctrl. but now I am in a sort of design issue due lack
> understanding on how I can make the dialog a child of frame and from
> there I can catch its events
>

I'm not clear which dialog you mean, or where the FilePicker goes. If
all you want to do is allow the user to choose a file to open (like an
"Open" item in a menu), you don't need FilePicker. The simplest way is
just to use Wx::file_selector function

evt_menu(Wx::ID_OPEN) do
  file_to_open = Wx::file_selector('Choose a file')
  # .... note that file_to_open will be an empty string if the user
chose Cancel
end

For more control, use Wx::FileDialog - see the docs and the dialog
sample.

>  Here is the design
>     TestXrcWrapperClass << TestXrc(BaseFrame) and
>     BrowseFileWrapperClass << Browsefile(OpenfileDialog)
>     TestApp creats TestXrcWrapperClass which create
> BrowsefilewarraperClass.
>
>   Q. How will I get the close events from dialog to the Frame?

dlg = MyDialog.new(self, ...)
dlg.evt_close { | evt | puts 'my child dialog has closed'; evt.skip }

But conventionally, modal (blocking) dialogs communicate the user's
selection back to the calling frame through the return value of
show_modal, eg:

dlg = Wx::FileDialog.newl(self, ...)
result = dlg.show_modal
if result = Wx::ID_OK
  puts 'you chose' + dlg.file
else
  puts 'you cancelled'
end
end

>   Q. How do I put it into a parent child framework(the Dialog and Base
> Frame). ?Is that a better way to go?

You should definitely make a modal dialog a child of the calling frame.
I'd suggest you have a look at the dialogs.rb sample to see how it's
done.

alex
This topic is locked and can not be replied to.