I'm experiencing some strange behavior when I add a page to a
wx.lib.agw.flatnotebook. Specifically when I create a new page and add
lots of buttons to it, the buttons draw on the frame before they get
added to the page.
Also my binding to trigger wx.EVT_RIGHT_UP on a button doesn't seem to
working.
I'd appreciate some help. =)
(I tried to rip out as much of the non-relevant code as possible, but
I might have missed some)
<code>
import wx
from wx.lib.agw.flatnotebook import FlatNotebook
from wx.lib.scrolledpanel import ScrolledPanel
from wx.lib.buttons import GenButton
[ID_Self, ID_NewPalette, ID_ImportSaveState, ID_ImportFromThisFile,
ID_Randomize, ID_MenuBar, ID_MENU_EDIT_RENAME_PAGE] = [wx.NewId() for
num in range(7)]
FRAME_SIZE = wx.Size(275, 325)
···
#
-----------------------------------------------------------------------------
class PaletteFrame(wx.MiniFrame):
def __init__(self, prnt):
wx.MiniFrame.__init__(self, prnt, id=ID_Self, title='Color
Palette',
size=FRAME_SIZE,
style=wx.DEFAULT_FRAME_STYLE | wx.FRAME_TOOL_WINDOW |
wx.FRAME_NO_TASKBAR )
self.book = ColoringBook(self)
self.__createPaletteMenu()
def __createPaletteMenu(self):
def doBind(item, handler, updateUI=None):
self.Bind(wx.EVT_MENU, handler, item)
if updateUI is not None:
self.Bind(wx.EVT_UPDATE_UI, updateUI, item)
menubar = wx.MenuBar()
paletteMenu = wx.Menu()
doBind(paletteMenu.Append(ID_NewPalette, "New", "Open a
file"), self.OnNew)
menubar.Append(paletteMenu, "Palette")
self.SetMenuBar(menubar)
def OnNew(self, evt):
numButtons = 256
page = ColoringPage(self, numButtons)
self.book.AddPage(page)
self.Refresh()
#
-----------------------------------------------------------------------------
class ColoringBook(wx.lib.agw.flatnotebook.FlatNotebook):
def __init__(self, prnt):
wx.lib.agw.flatnotebook.FlatNotebook.__init__(self, prnt)
page = ColoringPage(self)
self.AddPage(page)
# How do we do this in the constructor?
style = self.GetWindowStyleFlag()
style |= wx.lib.agw.flatnotebook.FNB_X_ON_TAB
style |= wx.lib.agw.flatnotebook.FNB_MOUSE_MIDDLE_CLOSES_TABS
style |= wx.lib.agw.flatnotebook.FNB_NO_X_BUTTON
self.SetWindowStyleFlag(style)
def AddPage(self, page):
wx.lib.agw.flatnotebook.FlatNotebook.AddPage(self, page,
'test')
#
-----------------------------------------------------------------------------
class ColoringPage(ScrolledPanel):
def __init__(self, prnt, size=256, title='Default'):
ScrolledPanel.__init__(self, prnt)
self.sizer = wx.GridSizer(16,16)
self.SetSizer(self.sizer)
self.SetAutoLayout(1)
self.SetupScrolling()
self.size = size
self.title = title
for color in xrange(size):
self.__createButton()
def __createButton(self):
colorBox = ColoringButton(prnt=self)
self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp, colorBox)
self.sizer.Add(colorBox, 0, wx.ALL, 1)
def OnRightUp(self, evt):
print 'On right Up'
evt.skip()
#
-----------------------------------------------------------------------------
class ColoringButton(wx.lib.buttons.GenButton):
def __init__(self, prnt):
wx.lib.buttons.GenButton.__init__(self, parent = prnt, id=-1, size =
wx.Size(12, 12),
style =
wx.NO_FULL_REPAINT_ON_RESIZE | wx.SIMPLE_BORDER)
#
-----------------------------------------------------------------------------
if __name__ == '__main__':
class MyApp(wx.App):
def OnInit(self):
frame = PaletteFrame(None)
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(False)
app.MainLoop()
</code>