Clarification with XRC, pywxrc, TextCtrl, and EVT_KILL_FOCUS all-in-one?

Hello,

I'm currently using xrced to create the GUI and to generate the Python code,
which is working almost perfectly. I'm running into one specific problem, though.

When trying to set up EVT_KILL_FOCUS on a text control in XRCed, it generates
the following code:

self.Bind(wx.EVT_KILL_FOCUS, self.OnKill_focus_TaskTextCtrl,
id=xrc.XRCID('TaskTextCtrl'))

Now, I've been reading around, and the event seems to need to be binded to the
control itself (self.textctrl.Bind vs. self.Bind). However, I can't seem to find
a way to do that while using pywxrc generated python code and an XRC file.

The main program (guibutter.py) is as follows:

import wx

from butterchurn_xrc import *

class ButterChurnAppFrame(xrcButterChurnMainFrame):
    def __init__(self, parent):
        xrcButterChurnMainFrame.__init__(self, parent)

class ButterChurnApp(wx.App):

    def OnInit(self):
        self.main_application_frame = ButterChurnAppFrame(None)
        self.main_application_frame.Center()
        self.main_application_frame.Show(1)
        return True
    
if __name__ == '__main__':
    app = ButterChurnApp()
    app.MainLoop()

I've tried different ways of doing self.textcontrol.Bind, by trying to rebind it
in guibutter.py and by trying to tweak the butterchurn_xrc.py file directly, but
to no avail.

Any ideas? Feel free to ask any questions if I'm not clear enough.

Ben McKenzie wrote:

Hello,

I'm currently using xrced to create the GUI and to generate the Python code,
which is working almost perfectly. I'm running into one specific problem, though.

When trying to set up EVT_KILL_FOCUS on a text control in XRCed, it generates the following code:

self.Bind(wx.EVT_KILL_FOCUS, self.OnKill_focus_TaskTextCtrl,
id=xrc.XRCID('TaskTextCtrl'))

Now, I've been reading around, and the event seems to need to be binded to the
control itself (self.textctrl.Bind vs. self.Bind).

Correct.

However, I can't seem to find
a way to do that while using pywxrc generated python code and an XRC file.

If you tick the box to assign a variable for the textctrl (on the Code tab of the properties notebook) then you can easily do it in the derived class. For example, given the above then the assign variable option will create self.TaskTextCtrl for you so you can do

  self.TasktextCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)

in the code you write for the derived class.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!