In addition to manually setting positions, wxPython provides Sizers. Sizers let us add items to an interface without
calculating exact positions. We will be using BoxSizers instead of GridSizers. BoxSizers can either be vertical or horizontal.
When they are initialized, their orientation can be set as follows:
row1 = wx.BoxSizer(wx.HORIZONTAL) or col1 = wx.BoxSizer(wx.VERTICAL)
BoxSizers add objects to a horizontal or vertical space with borders and alignments. We will start with adding two pictures
with 10 pixel borders to the same row as the button panel. The pictures will be 250x250, so the window needs to be set
to new horizontal size of about 760 pixels wide:
#Pictures
pic = wx.lib.activex.ActiveXCtrl(parent=self.frame,size=(250,250),axID='DATARAYOCX.CCDimageCtrl.1')
tpic = wx.lib.activex.ActiveXCtrl(parent=self.frame,size=(250,250), axID='DATARAYOCX.ThreeDviewCtrl.1')
palette=wx.lib.activex.ActiveXCtrl(parent=self.frame,size=(10,250), axID='DATARAYOCX.PaletteBarCtrl.1')
#Formatting
row1 = wx.BoxSizer(wx.HORIZONTAL)
row1.Add(item=bp,flag=wx.RIGHT, border=10)
row1.Add(pic)
row1.Add(item=tpic, flag=wx.LEFT, border=10)
self.frame.SetSizer( row1 )
Along with the item to be added, the BoxSizer takes flags which specify the borders or alignments and the border in pixels.
It also takes a proportion argument, but that is beyond the scope of this tutorial. After adding all the items to the BoxSizer,
we need to set the sizer to the frame. More border types can be specified with wx.TOP, wx.BOTTOM, and wx.ALL. Flags
can be combined by adding the OR operator (|). To add another row to display profiles, we will need another horizontal
BoxSizer and a vertical one to combine the two.
First we create the profiles and set their ID’s. They are set as properties because we will want to access them later.
#Profiles
self.px = wx.lib.activex.ActiveXCtrl(parent=self.frame,size=(300,200),axID='DATARAYOCX.ProfilesCtrl.1')
self.px.ctrl.ProfileID=22
self.py = wx.lib.activex.ActiveXCtrl(parent=self.frame,size=(300,200),axID='DATARAYOCX.ProfilesCtrl.1')
self.py.ctrl.ProfileID = 23
Next, we will add them to a second horizontal BoxSizer with a 100 pixel space between the two.
row2 = wx.BoxSizer(wx.HORIZONTAL)
row2.Add(self.px, 0, wx.RIGHT, 100)# Arguments: item, proportion, flags, border
row2.Add(self.py)
Finally, we add both rows to the vertical BoxSizer and set it to the frame.
col1 = wx.BoxSizer(wx.VERTICAL)
col1.Add(item=row1, flag=wx.BOTTOM, border=10)
col1.Add(item=row2, flag=wx.ALIGN_CENTER_HORIZONTAL)
self.frame.SetSizer(col1)