> I've been playing with wxPython/Pyglet but I've run into a problem, I
> can't seem to make the wx.BoxSizers work in the WxCanvas it provides.
> They never seem to want to expand to fill the available space in the
> client.  Has anyone else tried sizers or other layout tools for
> wxPython/Pyglet?

I solved this by creating a Panel to which I only add 1 element, the
wxCanvas in a boxsizer. In a sense, you can hide the wxCanvas from the
wxPython by adding it to a Panel in this way. No other code needs to
know that the panel contains a pyglet window.

This was useful for other reasons, such as separating the canvas
drawing code from the editor input code: In MainEditorPanel.PostInit()
I bind events on the canvas to callbacks on the panel.

Here is a cut-down version of my code. It doesn't run or anything, but
you could probably compare it to your own. Note that I use XRC
resources for constructing the actual window layout, so just ignore
the PrePanel() and PostCreate() stuff if you are not.

class EditorCanvas(WxCanvas):
    def __init__(self, parent, id=-1, config=None, context=None):
        canvas.WxCanvas.__init__(self, parent, id, config, context)

    def on_draw(self):
        pass

    def on_resize(self,w2,h2):
        pass

    def redraw(self):
        self.Refresh(True)

class MainEditorPanel(wx.Panel):
    def __init__(self):
        pre = wx.PrePanel()
        self.PostCreate(pre)
        self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

    def OnCreate(self, event):
        self.Unbind(wx.EVT_WINDOW_CREATE)
        wx.CallAfter(self._PostInit)
        event.Skip()
        return True

    def _PostInit(self):
        # Do all init here
        self._canvas = EditorCanvas(self)

        self.sizer = wx.BoxSizer()
        self.sizer.Add(self._canvas,1,wx.EXPAND)
        self.SetSizer(self.sizer)
        self.SetAutoLayout(1)
        self.sizer.Fit(self)

        self._canvas.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        self._canvas.Bind(wx.EVT_MOTION, self.OnMouseMotion)
        self._canvas.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to