Hi I''ve just started using wxruby2-preview-0.0.36-i386-mswin32 outsourcing layout part to the external XRC file. Almost everything seems to be fine. Only that I can never retrieve Gauge objects in the main script. What I''ve been trying is something like this: class MainFrame < Wx::Frame include Wx def initialize(parent) super(nil,-1, "") $xml.load_frame_subclass(self, nil, ''ID_MAINFRAME'') @statliclabel = Window.find_window_by_name(''ID_SLABEL1'') #OK @gauge = Window.find_window_by_name(''ID_GAUGE1'') #NG ... Hope someone can give me a hint, or is this a bug? Regards, yohasebe
Hi> I''ve just started using wxruby2-preview-0.0.36-i386-mswin32 > outsourcing layout part to the external XRC file. Almost everything > seems to be fine. Only that I can never retrieve Gauge objects in the > main script. What I''ve been trying is something like this: ><snip> Thanks for your message - may be a bug. Could you post an xrc file that demonstrates the problem please, as I''m not that familiar with it. alex
I found it quite productive to use wxruby with a xrc designer such as DialogBlocks. Probably Wx::Gauge in wxruby2 has a problem with xrc, though. wxruby (0.6) just works fine with the following code, by the way. Thank you anyway for this excellent GUI toolkit. yohasebe ##### main.rb ##### rrequire ''wx'' include Wx class MainFrame < Wx::Frame def initialize() super(nil,-1, "Test") $xml.load_frame_subclass(self, nil, ''ID_FRAME'') evt_close(){get_app.exit_main_loop} @slabel = Window.find_window_by_name(''ID_SLABEL'') @txtctrl = Window.find_window_by_name(''ID_TXTCTRL'') # The next line will not be successfully executed on wxruby2 @gauge = Window.find_window_by_name(''ID_GAUGE'') # main.rb:14:in `find_window_by_name'': wrong argument # type nil (expected Class) (TypeError) end end class XrcApp < Wx::App def on_init init_all_image_handlers() $xml = XmlResource.get() $xml.init_all_handlers() xrc_file = File.join( File.dirname( __FILE__ ), ''test.xrc'' ) $xml.load(xrc_file) $main = MainFrame.new() $main.show(true) end end XrcApp.new().main_loop() ##### end of main.rb ##### ##### test.xrc ##### <?xml version="1.0" encoding="windows-932"?> <resource version="2.3.0.1" xmlns="http://www.wxwidgets.org/wxxrc"> <object class="wxFrame" name="ID_FRAME" subclass="MainFrame"> <style>wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU</style> <size>200,150</size> <title>MainFrame</title> <object class="wxPanel" name="ID_PANEL1"> <style>wxSUNKEN_BORDER|wxTAB_TRAVERSAL</style> <object class="wxBoxSizer"> <orient>wxVERTICAL</orient> <object class="sizeritem"> <flag>wxALIGN_CENTER_HORIZONTAL|wxALL|wxADJUST_MINSIZE</flag> <border>5</border> <object class="wxStaticText" name="ID_SLABEL"> <label>This is Static text</label> </object> </object> <object class="sizeritem"> <flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag> <border>5</border> <option>1</option> <object class="wxTextCtrl" name="ID_TXTCTRL"> <style>wxTE_MULTILINE</style> </object> </object> <object class="sizeritem"> <flag>wxALIGN_CENTER_HORIZONTAL|wxALL</flag> <border>5</border> <object class="wxGauge" name="ID_GAUGE"> <style>wxGA_HORIZONTAL</style> <value>1</value> <range>100</range> </object> </object> </object> </object> </object> </resource> ##### end of test.xrc #####
Yoichiro Hasebe wrote:> I found it quite productive to use wxruby with a xrc designer such as > DialogBlocks.That''s interesting to know thanks, I have been curious which designers work with wxRuby via xrc.> Probably Wx::Gauge in wxruby2 has a problem with xrc, > though. wxruby (0.6) just works fine with the following code, by the > way.The example works for me on OS X 10.3, trying v0.0.37 and HEAD; the gauge is returned. Hmm. So maybe a problem on windows only, or something recently fixed, but I don''t know of any patch recently to fix something like for this. Will try on some other platforms later. alex
Hello I have now tried your example code on Linux/GTK. I can''t reproduce the error you describe - the call to find_window_by_name returns the Wx::Gauge, and methods can be called on it. The bad news is that the frame contents don''t display correctly. I get some unusual GTK warnings about Pizza (!) (wxruby:8729): Gtk-WARNING **: Attempting to add a widget with type GtkPizza to a GtkWindow, but as a GtkBin subclass a GtkWindow can only contain one widget at a time; it already contains a widget of type GtkPizza (wxruby:8729): Gdk-CRITICAL **: gdk_drawable_get_depth: assertion `GDK_IS_DRAWABLE (drawable)'' failed This makes me wonder if there is something wrong about this layout? Sometimes if you are doing something slightly ''wrong'' in the organisation of widgets and sizer, it will work on one platform but not on another. However, although I don''t know XRC, what you have sent looks correct to me. Is this the exact code that DialogBlocks generated? If not, it must be a wxruby2-specific bug. Please test on windows with the next release, and if it''s still not working, please file a bug on rubyforge and we''ll try and look at it for the next release cycle. Thanks alex
Yoichiro Hasebe wrote:> I found it quite productive to use wxruby with a xrc designer such as > DialogBlocks. Probably Wx::Gauge in wxruby2 has a problem with xrc, > though. wxruby (0.6) just works fine with the following code, by the > way.One other thing - as a workaround for your original issue, you might try putting a placeholder widget in the XRC (any class, really), then replacing it in Ruby code with the real gauge you want to show. Use the detach, insert and layout methods of the sizer which contains the widgets, eg sizer.detach(1) # the index of the placeholder widget gauge = Wx::Gauge.new(...) sizer.insert(1, gauge) sizer.layout hth alex
Alex Fenton wrote:> If not, it must be a wxruby2-specific bug. Please test on windows with > the next release, and if it''s still not working, please file a bug on > rubyforge and we''ll try and look at it for the next release cycle. > >I can confirm this bug exists on Windows with the latest builds I have. I was going to track this down but haven''t had any time. Roy
Hi.> One other thing - as a workaround for your original issue, you might try > putting a placeholder widget in the XRC (any class, really), then > replacing it in Ruby code with the real gauge you want to show. Use the > detach, insert and layout methods of the sizer which contains the > widgets, egQuite interesting. Since I needed to use both xrc and gauge on Windows, I also came up with an ad-hoc workaround along the same line. But yours looks better. I''ll give it a try.> This makes me wonder if there is something wrong about this layout? > Sometimes if you are doing something slightly ''wrong'' in the > organisation of widgets and sizer, it will work on one platform but not > on another. However, although I don''t know XRC, what you have sent looks > correct to me. Is this the exact code that DialogBlocks generated?That was the exact code DialogBlocks generated. I can''t say if it''s perfectly well-formed or not, though. One strange thing is, when I checked if the xrc from DialogBlocks is compatible with other xrc capable designers XRCed and VisualWx, the former understood it perfectly whereas the latter didn''t. Anyway, thank you for the follow-ups. yohasebe