I was trying to make a wx.grid inside a wx.notebook, the first test is here, is just a simple grid example from either Mike Driscoll or the python demo with a few tweaks. AutoSizeColumns(True) and AutoSizeRows(True) work as intended:
import wx
import wx.grid
app = wx.App(False)
class InfoPane(wx.grid.Grid):
def init(self, parent):
wx.grid.Grid.init(self, parent)
# Set up the presentation
self.SetRowLabelSize(0)
self.SetColLabelSize(0)
self.CreateGrid(7, 8)
self.SetCellValue(0,0,str("Vid0604a654dsd04 fa5sd0f 6asd f1"))
self.SetCellValue(0,1,str("RQWERTYUI0LKKGHJDFSDASFASVXCZVFSF"))
self.AutoSizeColumns(True)
self.AutoSizeRows(True)
frame = wx.Frame(None)
panel = wx.Panel(frame)
info_pane = InfoPane(panel)
note_sizer = wx.BoxSizer()
note_sizer.Add(info_pane, 1, wx.EXPAND)
panel.SetSizer(note_sizer)
frame_sizer = wx.BoxSizer(wx.VERTICAL)
frame_sizer.Add(panel, 1, wx.EXPAND)
frame.SetSizerAndFit(frame_sizer)
frame.Show()
app.MainLoop()
···
The second example is a notebook with two pages:
import wx
import wx.grid as gridlib
Some classes to use for the notebook pages.
class PageOne(wx.Panel):
def init(self, parent):
wx.Panel.init(self, parent)
myGrid = gridlib.Grid(self)
myGrid.SetRowLabelSize(0)
myGrid.SetColLabelSize(0)
myGrid.CreateGrid(10, 2)
frame_sizer = wx.BoxSizer(wx.VERTICAL)
frame_sizer.Add(myGrid, 10, wx.ALL | wx.EXPAND, 1)
self.SetSizer(frame_sizer)
myGrid.SetCellValue(0,0,str("Vid0604a654dsd04 fa5sd0f 6asd f1"))
myGrid.SetCellValue(0,1,str("RQWERTYUI0LKKGHJDFSDASFASVXCZVFSF"))
myGrid.SetCellFont(0, 0, wx.Font(12, wx.FONTFAMILY_DECORATIVE, wx.NORMAL, wx.FONTWEIGHT_BOLD))
class PageTwo(wx.Panel):
def init(self, parent):
wx.Panel.init(self, parent)
myGrid = gridlib.Grid(self)
myGrid.CreateGrid(10, 2)
myGrid.SetRowLabelSize(0)
myGrid.SetColLabelSize(0)
myGrid.AutoSizeColumns(True)
myGrid.AutoSizeRows(True)
myGrid.SetCellValue(0,0, "Vid0604a654dsd04")
myGrid.SetCellFont(0, 0, wx.Font(12, wx.ROMAN, wx.ITALIC, wx.NORMAL))
print myGrid.GetCellValue(0,0)
myGrid.SetCellValue(1,1, "RQWERTYUI0LKKGHJDFSDASFASVXCZVFSF")
myGrid.SetCellTextColour(1, 1, wx.RED)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(myGrid)
self.SetSizer(sizer)
class MainFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, title=“Simple Notebook Example”)
# Here we create a panel and a notebook on the panel
p = wx.Panel(self)
nb = wx.Notebook(p)
# create the page windows as children of the notebook
page1 = PageOne(nb)
page2 = PageTwo(nb)
# add the pages to the notebook with the label to show on the tab
nb.AddPage(page1, "Page 1")
nb.AddPage(page2, "Page 2")
# finally, put the notebook in a sizer for the panel to manage
# the layout
sizer = wx.BoxSizer()
sizer.Add(nb, 1, wx.EXPAND)
p.SetSizer(sizer)
if name == “main”:
app = wx.App()
MainFrame().Show()
app.MainLoop()
on the first page of the notebook I don’t have the AutoSize, and in the second one I have it, in the first page, the cells are wide, but not wide enough (which is correct), but in the second page, where the Autosize is on I have a tiny space. I’ve been playing around for a while changing it’s values but still don’t have a clue of why it’s not working…
Any help or workaround would be apreciated.