Problem with a wx notebook
Mel
mwilson at the-wire.com
Thu Oct 20 17:49:24 EDT 2011
Prasad, Ramit wrote:
> I've created a wx NoteBook in wich I set multiples panels in wich I
> set one or more sizers. But nothing displays in the notebook,
> everything is outside. I've been searching an answer for 2 days ><.
> Can you help me plz ? Here is my code(with only one panel, to sum up
> the code) :
>
> class StreamingActivationDialog(wx.Dialog):
> def __init__(self, *args, **kwds):
> # begin wxGlade: StreamingActivationDialog.__init__
> kwds["style"] = wx.DEFAULT_DIALOG_STYLE
> wx.Dialog.__init__(self, *args, **kwds)
> self.bitmap_1_copy = wx.StaticBitmap(self, -1, wx.Bitmap("img\
> \logo.png", wx.BITMAP_TYPE_ANY))
> self.labelDnD = wx.StaticText(self, -1, "Si vous avez déjà un
> fichier d'activation, faite le glisser dans cette fenetre")
> self.keyBitmap = wx.StaticBitmap(self, -1, wx.Bitmap("img\
> \key.bmp", wx.BITMAP_TYPE_ANY))
> self.conclude = wx.StaticText(self, -1, _("test"),
> style=wx.ALIGN_CENTRE)
>
> ### Panel ###
> self.intro3_label = wx.StaticText(self, -1, "Envoyez un mail à
> \nactivation at monmail.com\ncontenant le code :",style=wx.ALIGN_CENTRE)
> self.activationCode_label= wx.StaticText(self, -1,
> "123456789", style=wx.TE_READONLY)
> self.copy2_Button = wx.Button(self, -1, "Copier dans le presse-
> papier")
> self.copy2_Button.Bind(wx.EVT_BUTTON, PanelMail.onCopy)
> ##############
>
> self.note = wx.Notebook(self, wx.ID_ANY, style=wx.BK_LEFT,
> size=wx.Size(100, 341))
> self.page3 = wx.Panel(self.note)
>
> imagelist = wx.ImageList(94, 94)
> bitmap1 = wx.Bitmap("img\\a.bmp", wx.BITMAP_TYPE_BMP )
> imagelist.Add(bitmap1)
> self.note.AssignImageList(imagelist)
>
> self.__set_properties()
> self.__do_layout()
> # end wxGlade
>
> def __set_properties(self):
> # begin wxGlade: StreamingActivationDialog.__set_properties
> self.SetTitle(_("Activation de FlashProcess"))
> self.SetBackgroundColour(wx.Colour(255, 255, 255))
> #self.linkProblem.SetForegroundColour(wx.Colour(0, 0, 0))
> # end wxGlade
>
> def __do_layout(self):
> # begin wxGlade: StreamingActivationDialog.__do_layout
> self.grid_sizer_1 = wx.FlexGridSizer(6, 1, 0, 0)
> self.grid_sizer_2 = wx.FlexGridSizer(1, 2, 0, 30)
> self.grid_sizer_1.Add(self.bitmap_1_copy, 0, wx.TOP|wx.BOTTOM|
> wx.EXPAND, 10)
>
>
> ### Page 3 ###
> sizer = wx.BoxSizer(wx.VERTICAL)
> sizer.Add(self.intro3_label, 0, wx.BOTTOM|wx.ALIGN_CENTER, 5)
> sizer.Add(self.activationCode_label, 0, wx.BOTTOM|
> wx.ALIGN_CENTER, 20)
> sizer.Add(self.copy2_Button, 0, wx.ALIGN_CENTER, 20)
>
> self.page3.SetSizer(sizer)
> sizer.Fit(self.page3)
> ##############
>
> self.note.AddPage(self.page3, "", False, 0)
[ ... ]
It looks a though all the controls that are meant for page3 have been
created with the top-level dialog as their parent. AFAIK this cannot be.
self.page3 is (correctly) a child window of self.note, but the controls to
be shown inside have to be children of self.page3 . Putting things into the
sizers is not enough.
In my own code, I usually define a separate class descended from wx.Panel to
create a page3 instance with its own sizers, then create one of those with a
a wx.Notebook instance as a parent, and add it to the notebook:
def _new_capture_page (self):
new_trace = TraceWindow (self.tracebook)
self.tracebook.AddPage (new_trace, 'Capture %d' %
(self.capture_serial,), select=True)
return new_trace
Hope this helps,
Mel.
More information about the Python-list
mailing list