I've gotten a csheet instance to work directly in a frame or notebook,
but can't get it to work within a panel. I basically need the
spreadsheet to be a sub-portion of the frame. Is there something
special for this? If not is there a way to hide notebook tabs?
Matt,
···
On Aug 25, 3:38 pm, Matt <dres...@gmail.com> wrote:
I've gotten a csheet instance to work directly in a frame or notebook,
but can't get it to work within a panel. I basically need the
spreadsheet to be a sub-portion of the frame. Is there something
special for this? If not is there a way to hide notebook tabs?
What is a csheet? Notebooks are basically panels with a tab on them.
Maybe you're not giving the "csheet" the correct parent...or not using
a sizer...it's pretty hard to tell with no code, no wxpython version,
no python version and no idea what OS version you're using...
- Mike
csheet is just a subclass of grid, basically a spreadsheet. Just
wanted
to fit it into a panel.
I got it working for default size values, but can't seem to get the
spreadsheet within a static area, say size (300,300)
I tried adding size=(300,300) restriction to the panel but it's same
thing.
here's the code nonetheless:
import wx
import wx.lib.sheet
class DataSpreadSheet(wx.lib.sheet.CSheet):
def __init__(self, parent):
wx.lib.sheet.CSheet.__init__(self, parent)
self.SetRowLabelAlignment(wx.ALIGN_CENTRE,wx.ALIGN_CENTRE)
self.row = self.col = 0
self.SetNumberRows(55)
self.SetNumberCols(25)
row_size = 20
col_size = 100
# set row and column widths
for row in range(self.GetNumberRows()):
self.SetRowSize(row, row_size)
for col in range(self.GetNumberCols()):
self.SetColSize(col, col_size)
# define attributes for all cells
self.attr = wx.grid.GridCellAttr()
self.attr.SetTextColour('black')
self.attr.SetBackgroundColour('white')
self.attr.SetFont(wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.NORMAL))
def OnGridSelectCell(self, event):
self.row, self.col = event.GetRow(), event.GetCol()
event.Skip()
class Main(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, -1, title)
box = wx.BoxSizer(wx.VERTICAL)
panelbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
button1 = wx.Button(self,-1,'Button1')
button2 = wx.Button(self,-1,'Button2')
button3 = wx.Button(self,-1,'Button3')
button4 = wx.Button(self,-1,'Button4')
hbox.Add(button1)
hbox.Add(button2)
hbox2.Add(button3)
hbox2.Add(button4)
p = wx.Panel(self)
p.SetSizer(panelbox)
self.SetSizer(box)
sheet1 = DataSpreadSheet(p)
panelbox.Add(sheet1, 1, wx.EXPAND)
box.Add(p, 0)
self.SetSizer(box)
self.Show(True)
···
On Aug 25, 2:07 pm, Mike Driscoll <kyoso...@gmail.com> wrote:
Matt,
On Aug 25, 3:38 pm, Matt <dres...@gmail.com> wrote:
> I've gotten a csheet instance to work directly in a frame or notebook,
> but can't get it to work within a panel. I basically need the
> spreadsheet to be a sub-portion of the frame. Is there something
> special for this? If not is there a way to hide notebook tabs?What is a csheet? Notebooks are basically panels with a tab on them.
Maybe you're not giving the "csheet" the correct parent...or not using
a sizer...it's pretty hard to tell with no code, no wxpython version,
no python version and no idea what OS version you're using...- Mike
If you want the grid to be a specific size, than do not do this:
panelbox.Add(sheet1, 1, wx.EXPAND)
That tells wxPython that you want the grid to expand and will up all available room. Instead, you would want something like this instead:
panelbox.Add(sheet1, 0, wx.ALL, 5)
Hope that helps. Have fun!
···
On Tue, Aug 25, 2009 at 5:20 PM, Matt dresdek@gmail.com wrote:
csheet is just a subclass of grid, basically a spreadsheet. Just
wantedto fit it into a panel.
I got it working for default size values, but can’t seem to get the
spreadsheet within a static area, say size (300,300)
I tried adding size=(300,300) restriction to the panel but it’s same
thing.
Mike Driscoll
Thanks for responding. I tried what you suggested but when I try
removing the wx.EXPAND from 'panelbox.Add()' and realized even when I
don't have 'box.Add(p, 1, wx.EXPAND)' it cuts off the scrollbars for
the spreadsheet, I can't seem to find a combination that works. Tried
setting either or both to zero proportion and with or without
wx.EXPAND flag but don't seem to produce the right outcome.
class Main(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, -1, title, size=(600,600))
box = wx.BoxSizer(wx.VERTICAL)
panelbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
button1 = wx.Button(self,-1,'Load Data')
button2 = wx.Button(self,-1,'Save to File')
button3 = wx.Button(self,-1,'Insert File')
button4 = wx.Button(self,-1,'Clear')
hbox.Add(button1)
hbox.Add(button2)
hbox2.Add(button3)
hbox2.Add(button4)
p = wx.Panel(self, size=(300,300))
p.SetSizer(panelbox)
self.SetSizer(box)
sheet1 = DataSpreadSheet(p)
sheet1.SetFocus()
panelbox.Add(sheet1, 1, wx.EXPAND)
box.Add(hbox, 0, wx.EXPAND)
box.Add(p, 1, wx.EXPAND)
box.Add(hbox2, 0, wx.EXPAND)
self.Show(True)
···
On Aug 25, 4:29 pm, Mike Driscoll <m...@pythonlibrary.org> wrote:
On Tue, Aug 25, 2009 at 5:20 PM, Matt <dres...@gmail.com> wrote:
> csheet is just a subclass of grid, basically a spreadsheet. Just
> wanted
> to fit it into a panel.> I got it working for default size values, but can't seem to get the
> spreadsheet within a static area, say size (300,300)
> I tried adding size=(300,300) restriction to the panel but it's same
> thing.If you want the grid to be a specific size, than do not do this:
panelbox.Add(sheet1, 1, wx.EXPAND)
That tells wxPython that you want the grid to expand and will up all
available room. Instead, you would want something like this instead:panelbox.Add(sheet1, 0, wx.ALL, 5)
Hope that helps. Have fun!
--------------------
Mike Driscoll
Hmmm...you're using something I've never messed with before and it
seems to behave differently than wx.grid.Grid. I'm not sure what is
going on here. Maybe Robin will know.
- Mike
···
On Aug 25, 8:17 pm, Matt <dres...@gmail.com> wrote:
Thanks for responding. I tried what you suggested but when I try
removing the wx.EXPAND from 'panelbox.Add()' and realized even when I
don't have 'box.Add(p, 1, wx.EXPAND)' it cuts off the scrollbars for
the spreadsheet, I can't seem to find a combination that works. Tried
setting either or both to zero proportion and with or without
wx.EXPAND flag but don't seem to produce the right outcome.
Matt wrote:
Thanks for responding. I tried what you suggested but when I try
removing the wx.EXPAND from 'panelbox.Add()' and realized even when I
don't have 'box.Add(p, 1, wx.EXPAND)' it cuts off the scrollbars for
the spreadsheet, I can't seem to find a combination that works. Tried
setting either or both to zero proportion and with or without
wx.EXPAND flag but don't seem to produce the right outcome.
When you want something to be a specific size that is not what the widget would normally do all by itself then the easiest thing to do is to set it's MinSize. The sizer will honor that value and unless the proportion and flags tell it to expand or resize then it will keep it at that size. So in your case set the MinSize of your csheet to 300,300 and when you add it to the panel's sizer use proportion=0 and don't use the wx.EXPAND flag. Then because of its sizer the panel's minsize will use that 300,300 in its calculations and so on up the containment hierarchy.
···
--
Robin Dunn
Software Craftsman
Perfect, thanks!
···
On Aug 26, 4:23 pm, Robin Dunn <ro...@alldunn.com> wrote:
Matt wrote:
> Thanks for responding. I tried what you suggested but when I try
> removing the wx.EXPAND from 'panelbox.Add()' and realized even when I
> don't have 'box.Add(p, 1, wx.EXPAND)' it cuts off the scrollbars for
> the spreadsheet, I can't seem to find a combination that works. Tried
> setting either or both to zero proportion and with or without
> wx.EXPAND flag but don't seem to produce the right outcome.When you want something to be a specific size that is not what the
widget would normally do all by itself then the easiest thing to do is
to set it's MinSize. The sizer will honor that value and unless the
proportion and flags tell it to expand or resize then it will keep it at
that size. So in your case set the MinSize of your csheet to 300,300
and when you add it to the panel's sizer use proportion=0 and don't use
the wx.EXPAND flag. Then because of its sizer the panel's minsize will
use that 300,300 in its calculations and so on up the containment hierarchy.--
Robin Dunn
Software Craftsmanhttp://wxPython.org