GridBagSizer: Items not in the correct positions
Egon Frerich
e.frerich at nord-com.net
Sun Apr 6 08:30:13 PDT 2008
I have a little class which combines two widgets (Button and TextCtrl):
> import wx
>
> class Taganzeige(wx.Window):
> def __init__(self, parent, *args, **kwds):
> self.parent = parent
> self.text = kwds.pop('text')
> super(Taganzeige, self).__init__(parent,
> *args, **kwds)
> self.panel_1 = wx.Panel(self.parent, -1)
> self.tagnr = wx.Button(self.panel_1, -1, "button", style=wx.NO_BORDER)
> self.ereignisse = wx.TextCtrl(self.panel_1, -1,
> value=self.text,
> size=(118,88),
> style=wx.TE_MULTILINE|wx.TE_READONLY|wx.NO_BORDER)
>
> self.__set_properties()
> self.__do_layout()
>
> self.panel_1.Bind(wx.EVT_BUTTON, self.taggewaehlt, self.tagnr)
>
> def __set_properties(self):
> self.tagnr.SetMinSize((118, 22))
> self.tagnr.SetBackgroundColour(wx.Colour(255, 255, 0))
> self.tagnr.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
> self.ereignisse.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
>
> def __do_layout(self):
> sizer_2 = wx.BoxSizer(wx.VERTICAL)
> sizer_3 = wx.BoxSizer(wx.VERTICAL)
> sizer_3.Add(self.tagnr, 0, 0, 0)
> sizer_3.Add(self.ereignisse, 1, 0, 0)
> self.panel_1.SetSizer(sizer_3)
> sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0)
> self.SetSizer(sizer_2)
> sizer_2.Fit(self)
> self.Layout()
>
> def taggewaehlt(self, event): # wxGlade: MyFrame.<event_handler>
> print "Event handler `taggewaehlt' not implemented!"
> event.Skip()
In the following program I create some instances of this class and put
them into a grid:
> import wx
> from taganzeige import Taganzeige
>
> class Hauptfenster(wx.Frame):
> def __init__(self, *args, **kwds):
> # begin wxGlade: Hauptfenster.__init__
> kwds["style"] = wx.DEFAULT_FRAME_STYLE
> wx.Frame.__init__(self, *args, **kwds)
> self.panel_1 = wx.Panel(self, -1)
> self.SetTitle("frame_1")
> self.SetSize((600, 840))
> grid_sizer_1 = self.gbs = wx.GridBagSizer()
> for zeile in range(5):
> for spalte in range(7):
> t = Taganzeige(self.panel_1, -1,
> text="("+str(zeile)+","+str(spalte)+")")
> n=grid_sizer_1.Add(t, (zeile,spalte))
> print zeile,spalte,n
> print grid_sizer_1.CalcMin()
> self.panel_1.SetSizerAndFit(grid_sizer_1)
> print self.panel_1.GetSize()
> self.SetClientSize(self.panel_1.GetSize())
>
>
> if __name__ == "__main__":
> app = wx.PySimpleApp(0)
> wx.InitAllImageHandlers()
> frame_1 = Hauptfenster(None, -1, "")
> app.SetTopWindow(frame_1)
> frame_1.Show()
> app.MainLoop()
If you run this program only one instance Taganzeige is shown in
position (0,0). The print test instructions tells me that the
grid_sizer_1 gets bigger and bigger.
The last lines:
> 4 5 <wx._core.GBSizerItem; proxy of <Swig Object of type 'wxGBSizerItem *' at 0x100cd50> >
> (826, 550)
> 4 6 <wx._core.GBSizerItem; proxy of <Swig Object of type 'wxGBSizerItem *' at 0x1019de0> >
> (826, 550)
> (826, 550)
Can somebody find my error?
Egon
More information about the wx-users
mailing list