I’ve followed the tutorial at http://wiki.wxpython.org/XRCed%20Component%20Plugins and have successfully added FloatSpin to the gizmo menu. (For backward compatibility reasons I’m using a stand-alone version of FloatSpin and not the one in agw.
However, when I save an xrc and try to load it in, I get the following error:
/usr/local/lib/wxPython-unicode-2.8.9.2/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/xrc.pyc in LoadFrame(*args, **kwargs)
147 def LoadFrame(*args, **kwargs):
148 “”“LoadFrame(self, Window parent, String name) -> wxFrame”""
–> 149 return _xrc.XmlResource_LoadFrame(*args, **kwargs)
150
151 def LoadOnFrame(*args, **kwargs):
PyAssertionError: C++ assertion “wxAssertFailure” failed at /BUILD/wxPython-src-2.8.9.2/src/common/sizer.cpp(379) in SetDimension(): can’t set size of uninitialized sizer item
WARNING: Failure executing file: <plot_set_editor.py>
This same error occurs with the TreeListCtrl that is already in the gizmos menu. I am fundamentally missing a step in the process, or is this some sort of bug? I’m on OS X 10.5, Python 2.5.4, wxPython 2.8.9.2.
I’m just learning XRCed and it seems great, but without the capability to add custom controls, it’s unfortunately not going to be very useful for me.
My component plugin files are:
xh_floatspin.py:
import wx
import wx.xrc as xrc
import FloatSpin as FS
class FloatSpinCtrlXmlHandler(xrc.XmlResourceHandler):
def init(self):
xrc.XmlResourceHandler.init(self)
# Standard styles
self.AddWindowStyles()
# Custom styles
self.AddStyle(‘FS_LEFT’, FS.FS_LEFT)
self.AddStyle(‘FS_RIGHT’, FS.FS_RIGHT)
self.AddStyle(‘FS_CENTRE’, FS.FS_CENTRE)
self.AddStyle(‘FS_READONLY’, FS.FS_READONLY)
def CanHandle(self,node):
return self.IsOfClass(node, ‘FloatSpin’)
# Process XML parameters and create the object
def DoCreateResource(self):
assert self.GetInstance() is None
try:
min_val = float(self.GetText(‘min_val’))
except:
min_val = None
try:
max_val = float(self.GetText(‘max_val’))
except:
max_val = None
try:
increment = float(self.GetText(‘increment’))
except:
increment = 1.0
w = FS.FloatSpin(parent = self.GetParentAsWindow(),
id = self.GetID(),
pos = self.GetPosition(),
size = self.GetSize(),
extrastyle=self.GetStyle(),
min_val=min_val,
max_val=max_val,
increment=increment)
try:
w.SetValue(float(self.GetText('value')))
except:
w.SetValue(0.0)
try:
w.SetDigits(int(self.GetText('digits')))
except:
pass
self.SetupWindow(w)
return w
floatspin.crx:
<?xml version="1.0" ?> control pos size value min_val max_val increment digits 1 FS_LEFT FS_RIGHT FS_CENTRE FS_READONLY EVT_FLOATSPIN xh_floatspin FloatSpinCtrlXmlHandler gizmo FloatSpin Floating Point SpinCtrl 10The XRC file is
PlotSetEditor.xrc:
My python script is
plot_set_editor.py:
import wx
import wx.xrc as xrc
from wx.gizmos import TreeListCtrl
if name == ‘main’:
if 1:
app = wx.App()
res=xrc.XmlResource ( ‘resources/PlotSetEditor.xrc’ )
mainFrame=res.LoadFrame( None, “plotSetEditor” )
mainFrame.Show()
app.MainLoop()
If anyone can give any insight as to whats going on, I’d appreciate it.
···
–
- Rob Falck