problem with wxGrid from XRCed

I am trying to add a wxGrid to my gui using XRCed. I am running XRCed 0.2.1-0 and wxPython 2.9.4 on OSX 10.8.4.

In the XRCed dialog I see an icon of something that looks like a wxGrid. This code gets added to my xrc file:

        <object class="sizeritem">
          <object class="wxGrid" name="params_grid"/>
        </object>

I have this code in my OnInit method:

    self.params_grid = xrc.XRCCTRL(self.frame, "params_grid")
    self.params_grid.CreateGrid(10,2)

and it leads to this traceback:

rkrauss>DT_TMM_gui$ python test_ryans_first_xrc.py

loading ryans_first_xrc.xrc
Traceback (most recent call last):
File “test_ryans_first_xrc.py”, line 139, in
app = MyApp(0)
File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py”, line 8631, in init

self._BootstrapApp()

File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py”, line 8196, in _BootstrapApp
return core.PyApp__BootstrapApp(*args, **kwargs)

File “test_ryans_first_xrc.py”, line 118, in OnInit
self.params_grid.CreateGrid(10,2)
AttributeError: ‘ScrolledWindow’ object has no attribute ‘CreateGrid’

which seems to imply that my wxGrid is really a ScrolledWindow. What am I doing wrong here?

I am attaching the xrc and py files.

Thanks,

Ryan

test_ryans_first_xrc.py (4.17 KB)

ryans_first_xrc.xrc (1.48 KB)

Hi Ryan,

···

On Thursday, August 22, 2013 11:25:28 AM UTC-5, Ryan Krauss wrote:

I am trying to add a wxGrid to my gui using XRCed. I am running XRCed 0.2.1-0 and wxPython 2.9.4 on OSX 10.8.4.

In the XRCed dialog I see an icon of something that looks like a wxGrid. This code gets added to my xrc file:

        <object class="sizeritem">
          <object class="wxGrid" name="params_grid"/>
        </object>

I have this code in my OnInit method:

    self.params_grid = xrc.XRCCTRL(self.frame, "params_grid")
    self.params_grid.CreateGrid(10,2)

and it leads to this traceback:

rkrauss>DT_TMM_gui$ python test_ryans_first_xrc.py

loading ryans_first_xrc.xrc
Traceback (most recent call last):
File “test_ryans_first_xrc.py”, line 139, in
app = MyApp(0)
File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py”, line 8631, in init

self._BootstrapApp()

File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py”, line 8196, in _BootstrapApp
return core.PyApp__BootstrapApp(*args, **kwargs)

File “test_ryans_first_xrc.py”, line 118, in OnInit
self.params_grid.CreateGrid(10,2)
AttributeError: ‘ScrolledWindow’ object has no attribute ‘CreateGrid’

which seems to imply that my wxGrid is really a ScrolledWindow. What am I doing wrong here?

I am attaching the xrc and py files.

Thanks,

Ryan

Yeah, we were actually discussing this question last month. I ended up doing an article on the topic: wxPython: Creating a Grid with XRC - Mouse Vs Python

The answer is really simple though. Just import wx.grid at the top of your script and it will suddenly start working! Here’s a link to the last thread that talked about this:

https://groups.google.com/forum/?fromgroups=#!topic/wxpython-users/IfjW9f7LEhQ

Have fun!
Mike

Thanks Mike. That worked great.

···

On Thursday, August 22, 2013 3:33:02 PM UTC-5, Mike Driscoll wrote:

Hi Ryan,

On Thursday, August 22, 2013 11:25:28 AM UTC-5, Ryan Krauss wrote:

I am trying to add a wxGrid to my gui using XRCed. I am running XRCed 0.2.1-0 and wxPython 2.9.4 on OSX 10.8.4.

In the XRCed dialog I see an icon of something that looks like a wxGrid. This code gets added to my xrc file:

        <object class="sizeritem">
          <object class="wxGrid" name="params_grid"/>
        </object>

I have this code in my OnInit method:

    self.params_grid = xrc.XRCCTRL(self.frame, "params_grid")
    self.params_grid.CreateGrid(10,2)

and it leads to this traceback:

rkrauss>DT_TMM_gui$ python test_ryans_first_xrc.py

loading ryans_first_xrc.xrc
Traceback (most recent call last):
File “test_ryans_first_xrc.py”, line 139, in
app = MyApp(0)
File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py”, line 8631, in init

self._BootstrapApp()

File “/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py”, line 8196, in _BootstrapApp
return core.PyApp__BootstrapApp(*args, **kwargs)

File “test_ryans_first_xrc.py”, line 118, in OnInit
self.params_grid.CreateGrid(10,2)
AttributeError: ‘ScrolledWindow’ object has no attribute ‘CreateGrid’

which seems to imply that my wxGrid is really a ScrolledWindow. What am I doing wrong here?

I am attaching the xrc and py files.

Thanks,

Ryan

Yeah, we were actually discussing this question last month. I ended up doing an article on the topic: http://www.blog.pythonlibrary.org/2013/07/24/wxpython-creating-a-grid-with-xrc/

The answer is really simple though. Just import wx.grid at the top of your script and it will suddenly start working! Here’s a link to the last thread that talked about this:

https://groups.google.com/forum/?fromgroups=#!topic/wxpython-users/IfjW9f7LEhQ

Have fun!
Mike