wilsond has asked for the wisdom of the Perl Monks concerning the following question:
I figured it out. Use the Wx::Window::FindWindowByName function to get the object. Yes, it says "FindWindow", but it works for anything, not just windows. Silly name, but at least it does the job.
Edit: I've been informed that pretty much all objects that aren't sizers are subclassed from window and are therefore windows, which makes a bit more sense. It doesn't make much sense from a user's point of view, but it does make sense from an internal point of view. In any case, I'm glad it does what I need it to do. If it were named something more obvious to someone without deep internal knowledge, it would have been much easier to figure it all out and therefore not require my seeking Monk support on it.
I'm trying to learn Wx and have hit a wall. I just can't figure out how to get a handle on any of the objects that are loaded in (and created) from the XRC file.
My goal with this test is to populate the text field (m_textCtrl1) and enable/disable the button "Button 1" (m_button1).
How would one get the m_textCtrl1 object into a form that it can be modified via perl code?
It seems that with Python, you should use something like xrc.XRCCTRL(self.frame, 'm_button1') to get the handle on that button, but I can't find the equivalent perl code for this. (reference)
EDIT: How about these apples? my $button = Wx::Window::FindWindowByName('m_button1', $frame); That finds the object. Why is it called "FindWindowByName"? I had to go through all kinds of Python and C code to find this.
The XRC file: test.xrc
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1"> <object class="wxFrame" name="MyFrame1"> <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style> <size>500,300</size> <title></title> <object class="wxBoxSizer"> <orient>wxVERTICAL</orient> <object class="sizeritem"> <option>0</option> <flag>wxALL</flag> <border>5</border> <object class="wxTextCtrl" name="m_textCtrl1"> <style>wxTE_MULTILINE|wxTE_READONLY</style> <size>300,150</size> <value></value> <maxlength>0</maxlength> </object> </object> <object class="sizeritem"> <option>1</option> <flag>wxEXPAND</flag> <border>5</border> <object class="wxBoxSizer"> <orient>wxHORIZONTAL</orient> <object class="spacer"> <option>1</option> <flag>wxEXPAND</flag> <border>5</border> <size>0,0</size> </object> <object class="sizeritem"> <option>0</option> <flag>wxALL</flag> <border>5</border> <object class="wxButton" name="m_button1"> <label>Button 1</label> <default>0</default> </object> </object> <object class="sizeritem"> <option>0</option> <flag>wxALL</flag> <border>5</border> <object class="wxButton" name="m_button2"> <label>Button 2</label> <default>0</default> </object> </object> </object> </object> </object> </object> </resource>
The perl code: test.pl
package MyApp; our $VERSION = '1.2.3.4'; use Wx qw(:everything); use Wx::XRC; use base 'Wx::App'; sub OnInit { my $self = shift; my $xr = Wx::XmlResource->new(); $xr->InitAllHandlers(); $xr->Load('test.xrc'); my $frame = Wx::Frame->new; $xr->LoadFrame($frame, undef, 'MyFrame1'); $frame->Show(1); } package main; MyApp->new->MainLoop;
| While I ask a lot of Win32 questions, I hate Windows with a passion. That's the problem with writing a cross-platform program. I'm a Linux user myself. I wish more people were. |
| If you want to do evil, science provides the most powerful weapons to do evil; but equally, if you want to do good, science puts into your hands the most powerful tools to do so. |
| - Richard Dawkins |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [fixed] Wx with XRC, get handle on objects
by VZ (Acolyte) on Jan 25, 2009 at 18:34 UTC | |
by wilsond (Scribe) on Jan 26, 2009 at 00:07 UTC | |
by VZ (Acolyte) on Jan 26, 2009 at 10:46 UTC | |
by wilsond (Scribe) on Jan 27, 2009 at 09:02 UTC |