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

In reply to [fixed] Wx with XRC, get handle on objects by wilsond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.