Crash with DividedShape on a wxPanel (?)

Hello,

I'm writing an app where I use OGL to create various shapes on a panel. I
have a problem with wxDividedShape: when I try to add such a shape to the
panel the app crashes. I have studied the demo app and the only meaningful
diff I can discern is that wxShapeCanvas is added to a wxFrame in that
case, while I'm adding it to a wxPanel. I'm attaching a minimal example
that exhibits the problem: I create a wxApp, which creates a wxFrame, which
has a wxPanel with the wxShapeCanvas (in real life this panel would also
have other components besides the canvas). In the canvas I create a vanilla
wxDividedShape and when I show it, the program crashes.

This is with Python 2.2.2 and wxWindows 2.4.0.7 on Windows XP.

Any hints? Many thanks,
Davide

···

----
from wxPython.wx import *
from wxPython.ogl import *

class Canvas(wxShapeCanvas):
  def __init__(self, frame, panel):
    wxShapeCanvas.__init__(self, panel)
    self.dc = wxClientDC(self)
    self.diagram = wxDiagram()
    self.SetDiagram(self.diagram)
    self.diagram.SetCanvas(self)
    # try a simple divided shape
    ds = wxDividedShape(50, 60)
    region = wxShapeRegion()
    region.SetProportions(0.0, 0.25)
    region.SetText("text 1")
    ds.AddRegion(region)
    region = wxShapeRegion()
    region.SetProportions(0.0, 0.5)
    region.SetText("text 2")
    ds.AddRegion(region)
    region = wxShapeRegion()
    region.SetProportions(0.0, 0.25)
    region.SetText("text 3")
    ds.AddRegion(region)
    ds.SetRegionSizes()
    ds.SetSize(50,60)
    ds.SetPen(wxBLACK_PEN)
    ds.SetBrush(wxWHITE_BRUSH)
    ds.SetCanvas(self)
    self.diagram.AddShape(ds)
    ds.Show(True)
class Frame(wxFrame):
  def __init__(self, parent, id, title):
    wxFrame.__init__(self, parent, id, title, pos=(50,50))
    self.SetSize((640,480))
    self.topPanel = wxPanel(self, -1, style=wxSIMPLE_BORDER)
    self.canvas = Canvas(self, self.topPanel)
    topSizer = wxBoxSizer(wxHORIZONTAL)
    topSizer.Add(self.canvas, 1, wxEXPAND)
    
    self.topPanel.SetAutoLayout(True)
    self.topPanel.SetSizer(topSizer)
class MyApp(wxApp):
  def OnInit(self):
    wxInitAllImageHandlers()
    frame = Frame(None, -1, "Test App")
    frame.Show(1)
    return 1
if __name__ == "__main__":
  app = MyApp(0)
  app.MainLoop()

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

Davide Salomoni wrote:

Hello,

I'm writing an app where I use OGL to create various shapes on a panel. I
have a problem with wxDividedShape: when I try to add such a shape to the
panel the app crashes. I have studied the demo app and the only meaningful
diff I can discern is that wxShapeCanvas is added to a wxFrame in that
case, while I'm adding it to a wxPanel. I'm attaching a minimal example
that exhibits the problem: I create a wxApp, which creates a wxFrame, which
has a wxPanel with the wxShapeCanvas (in real life this panel would also
have other components besides the canvas). In the canvas I create a vanilla
wxDividedShape and when I show it, the program crashes.

You need to call wxOGLInitialize().

···

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