Problems using wxFRAME_FLOAT_ON_PARENT with Notebooks

Hi All,

I’m trying to use a floating frame as a notebook page so that I can have a localized toolbar on each notebook page. The wxFRAME_FLOAT_ON_PARENT option on wxFrame would appear to be what I am looking for. I figured by using the CenterOnParent method of wxFrame I would be able to position the frame directly over the client area of the notebook making it appear like any other page. This works to a degree the frame is the correct size (and resizes as I resize the notebook) but for some reason the frame is offset from the client area. I can correct this part of the time by adding a pad to the position in the OnMove Handler (This handler only seems to be called if I bind it to the parent frame is this correct behavior?) but I’m pretty certain this is not going to be a portable solution, moreover, resizing the window causes the frame to snap back to its original incorrect offset. To combat this problem, I tried overriding OnSize but this doesn’t seem to work as the snapping app
ears to
originate after I handle the message and a blanket override produces incorrect behavior in the notebook. Am I missing something about this feature? Should I be using it like this at all? Is there perhaps an easier way to add a toolbar to a notebook page that I am overlooking? A demonstration is included below. Any insight would be appreciated. I’m using wxPython 2.5.2.8 with Python 2.3.3 on Windows XP SP2.

Thanks,

Jenna

import wx

class Notebook(wx.Notebook):
def init(self, parent, id):
wx.Notebook.init(self, parent, id)
self.frame = wx.Frame(self, -1,
style=wx.CLIP_CHILDREN | wx.FRAME_FLOAT_ON_PARENT | wx.FRAME_NO_TASKBAR)
self.frame.CreateToolBar()
self.frame.CreateStatusBar()
self.AddPage(self.frame, “Page 1”)
self.RepositionFloater()

    win = self.MakeDummyPanel()
    self.AddPage(win, "Page2")

self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)

    # Shouldn't I be able to bind these to the notebook.
    # For some reason the OnMove Message handler never gets
    # called when bound to the notebook.
    parent.Bind(wx.EVT_SIZE, self.OnSize)
    parent.Bind(wx.EVT_MOVE, self.OnMove)

def MakeDummyPanel(self):
panel = wx.Panel(self, -1)

def OnCPSize(event, window=panel):
window.SetSize(event.GetSize())

panel.Bind(wx.EVT_SIZE, OnCPSize)
return panel

def OnSize(self, event):
    # The snapping behavior of the floating frame
    # is being produced after this handler is called
    # and eliminating the Skip call causes problems with
    # the notebook.
    self.RepositionFloater()
    event.Skip()
   
def OnMove(self, event):
    self.RepositionFloater()
    event.Skip()
    

def RepositionFloater(self):
    self.frame.CenterOnParent()
    # You can comment the code below to see the effect
    # of a pad to correct the strange offset produced
    # by CenterOnParent. I'm guessing this isnt portable.
    pos = self.frame.GetPosition()
    pos.y = pos.y+22
    self.frame.SetPosition(pos)

def OnPageChanged(self, event):
old = event.GetOldSelection()
new = event.GetSelection()
sel = self.GetSelection()
event.Skip()

def OnPageChanging(self, event):
old = event.GetOldSelection()
new = event.GetSelection()
sel = self.GetSelection()
event.Skip()

class MyApp(wx.App):

def OnInit(self):
frame = wx.Frame(None, -1, “Frame”)
self.notebook = Notebook(frame, -1)

frame.Show(True)
self.SetTopWindow(frame)
return True

app = MyApp(0)
app.MainLoop()

···

Do you Yahoo!?

New and Improved Yahoo! Mail - 100MB free storage!

Jenna Louis wrote:

Hi All,
I'm trying to use a floating frame as a notebook page so that I can have a localized toolbar on each notebook page.

You can't have a top-level window (Frame, Dialog, etc.) as a notebook page. You can however put a toolbar on a panel, you just have to manage it's size and position yourself (via a sizer or whatever.)

···

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

Robin Dunn wrote:

Jenna Louis wrote:

I'm trying to use a floating frame as a notebook page so that I can have a localized toolbar on each notebook page.

You can't have a top-level window (Frame, Dialog, etc.) as a notebook page. You can however put a toolbar on a panel, you just have to manage it's size and position yourself (via a sizer or whatever.)

Maybe this will help:

7600 Sand Point Way NE (206) 526-6329 fax

http://wiki.wxpython.org/index.cgi/WorkingWithToolBars

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris Barker wrote:

Maybe this will help:

7600 Sand Point Way NE (206) 526-6329 fax

oops, I don't think my address is going to help anyone with toolbars

http://wiki.wxpython.org/index.cgi/WorkingWithToolBars

this will though.

copy&paste errors, and being in too much of a hurry for even a quick proofread.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov