curious embedded wxpython behavior

Lin Shao wrote:

Hi,

I assume people know about embedded.cpp, the sample code that shows
how to embed wxPython in a C++ application. What I found curious is
the following:

if I add f.SetBackgroundColour(wx.LIGHT_GREY) to python_code1, i.e.,

char* python_code1 = "\
import wx\n\
f = wx.Frame(None, -1, 'Hello from wxPython!', size=(250, 150))\n\
f.SetBackgroundColour(wx.LIGHT_GREY)\n\
f.Show()\n\
";

then when I click "Make wxPython frame" menu item, I got an exception TypeError:

Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "C:\Priithon_25_win\wx\_core.py", line 9799, in SetBackgroundColour
    return _core_.Window_SetBackgroundColour(*args, **kwargs)
TypeError: Expected a wxColour object, a string containing a colour
name or '#RRGGBB', or a 3- or 4-tuple of integers.

It looks like wx.LIGHT_GREY (or any other pre-made color, pen, brush,
etc.) is not recognized as a correct wx object. Does anybody know why?
Am I not supposed to do it this way?

When a wxPython app is created normally the stock GDI objects (or their Python proxy objects actually) are not initialized until after the wx library has been initialized. This is done automatically between the wx.App's __init__ and when the derived class's OnInit is called. Since in the embedded case the wxApp is created in C++ then this extra initialization code is not called. You can add a call to wx.StockGDI._initStockObjects() before you want to use wx.LIGHT_GREY, or you can simply use "light grey".

ยทยทยท

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