Hi, all
I have been trying to use xrc and subclassing.
Surely, I read TwoStageCreation, SubclassingListCtrlWithXrc.
code is here:
···
####################################################
# -*- coding: utf-8 -*-
import sys
import os
import wx
from wx import xrc
#global
_firstEventType = wx.EVT_SHOW
menculator_xrc = '''\
<?xml version="1.0" ?><resource>
<object class="wxDialog" name="mainframe"
subclass="menculator.MCDialog">
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<object class="wxStaticText" name="qSText"/>
<option>1</option>
<flag>wxALL|wxEXPAND</flag>
</object>
<object class="sizeritem">
<object class="wxTextCtrl" name="aTCtrl"
subclass="menculator.MyTextCtrl"/>
<option>1</option>
<flag>wxALL|wxEXPAND</flag>
</object>
</object>
<option>1</option>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
</object>
</object>
<object class="wxMenuBar"/>
<title>mainframe</title>
<style>wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</style>
</object>
</resource>'''
class MyTextCtrl( wx.TextCtrl ):
def __init__( self , parent ):
pre = wx.PreTextCtrl()
self.PostCreate( pre )
self.Bind( _firstEventType , self.OnCreate )
def OnCreate():
self.Unbind(self._firstEventType)
self.Refresh()
self.Bind( wx.EVT_KEY_UP , self.OnKeyUp )
def OnKeyUp( self , event ):
if self.aTCtrl == self.dlg.FindFocus():
if wx.WXK_RETURN == event.GetKeyCode():
event
class MCDialog( wx.Dialog ):
def __init__( self ):
pre = wx.PreDialog()
global xmlRes
xmlRes.LoadOnDialog( pre , None , "mainframe" )
self.PostCreate( pre )
self.Bind( _firstEventType , self.OnCreate )
def OnCreate( self , event ):
self.Unbind( _firstEventType )
self.Refresh()
self.qSText = self.FindWindowById( xrc.XRCID( 'qSText' ) )
self.aTCtrl = self.FindWindowById( xrc.XRCID( 'aTCtrl' ) )
class Mencualtor( wx.App ):
def __init__( self ):
wx.App.__init__( self , False )
def OnInit( self ):
global xmlRes
menculator_xrc
xmlRes = xrc.EmptyXmlResource()
xmlRes.LoadFromString( menculator_xrc )
return True
def main():
app = Mencualtor()
dlg = MCDialog()
dlg.Show()
app.MainLoop()
main()
####################################################
wx.Dialog, wx.TextCtrl are subclassed, problem is don't created
'aTCtrl'.
after run, error message box shows "Subclass 'menculator.MyTextCtrl'
not found for resource 'aTCtrl', not subclassing!"
I tested LoadDialog function that create child widgets against
LoadOnDialog.
how do i solve it?
============================================
sorry about my poor english