[wxPython-users] sorry, troubling every one for wx.grid again.
C M
cmpython at gmail.com
Tue Sep 4 08:41:49 PDT 2007
Krishnakant,
I am really not understanding the concept of wx.grid, so troubling the
> list again.
wx.Grid is basically a spreadsheet, just like Excel. Every grid has a
certain number of columns and rows, so for example 3 columns by
3 rows gives a grid with 9 cells. The cells contain data: text, numbers,
etc. It has column and row labels. It is definitely what you want for your
purposes (as you described them).
> the examples in the demo sounded too complex for a person like me who
> is using this kind of grid class.
The code for the examples is sometimes confusing, but the point is just
to physically see the grids in action to have an idea of what they are meant
to do.
> so kindly explain me in very simple
> terms as to how I can create a spreadsheet like application with
> column headers (lables) at the top and vertical columns of edit boxes.
> I would choose a horizontal line of buttons at the bottom of the
> screen just above the status bar. I wil use a box sizer for this
> work.
> Kindly explain me what classes are used for what work related to wx.grid?
The various methods that wx.grid has are in that page I mentioned, at
http://www.wxwidgets.org/manuals/2.6/wx_wxgrid.html#wxgridsetcollabelvalue
There's tons of them, and they allow you to set all the properties of the
grid.
Things like what color it will be, how wide the columns will be, whether the
user can edit the grid or not, plus actions you can take on the grid like to
clear the cells, get values from the cells, set values, set column and row
labels, etc. Any of these actions will look something of the form of:
self.grid1.SetColLabelValue(0, "Name")
so please help me with a very small example.
> please make sure to provide comments in the code.
> thanks a lot and again sorry to trouble with such a simple question.
I've posted below a small example that doesn't use comboboxes yet,
just a very basic grid with some buttons under it. I used Boa Constructor
to make it and it only took a few minutes, so maybe this could help you
understand wxGrid a bit more. You might be thinking it is more complex
than it really is (I think it can be complex, but just a basic grid
shouldn't
be too bad). One thing to remember is you have to use CreateGrid() to
actually have the grid created.
If this seems OK, we can look at adding comboboxes to it.
Hope this helps,
CM
------------------------------------------
#Boa:Frame:Frame1
import wx
import wx.grid
#of course you have to import the wx.grid class
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1BUTTON3,
wxID_FRAME1BUTTON4, wxID_FRAME1GRID1, wxID_FRAME1PANEL1,
] =3D [wx.NewId() for _init_ctrls in range(7)]
class Frame1(wx.Frame):
#anything that mentions sizers, this is just to lay things out nicely...they
are independent
#from the properties of the wx.Grid. You might want to ignore these parts
dealing with
#sizers for now...
def _init_coll_flexGridSizer1_Items(self, parent):
# generated method, don't edit
parent.AddWindow(self.button1, 0, border=3D0, flag=3D0)
parent.AddWindow(self.button2, 0, border=3D0, flag=3D0)
parent.AddWindow(self.button3, 0, border=3D0, flag=3D0)
parent.AddWindow(self.button4, 0, border=3D0, flag=3D0)
def _init_coll_boxSizer1_Items(self, parent):
# generated method, don't edit
parent.AddWindow(self.grid1, 0, border=3D5, flag=3Dwx.EXPAND | wx.A=
LL)
parent.AddSizer(self.flexGridSizer1, 0, border=3D5,
flag=3Dwx.EXPAND | wx.ALL)
def _init_sizers(self):
# generated method, don't edit
self.boxSizer1 =3D wx.BoxSizer(orient=3Dwx.VERTICAL)
self.flexGridSizer1 =3D wx.FlexGridSizer(cols=3D0, hgap=3D0, rows=
=3D1,
vgap=3D0)
self._init_coll_boxSizer1_Items(self.boxSizer1)
self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
self.panel1.SetSizer(self.boxSizer1)
#here is where the various controls begin...
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=3DwxID_FRAME1, name=3D'', parent=3Dprnt,
pos=3Dwx.Point(233, 201), size=3Dwx.Size(342, 189),
style=3Dwx.DEFAULT_FRAME_STYLE, title=3D'Frame1')
self.SetClientSize(wx.Size(334, 155))
#this is the only panel of the Frame.
self.panel1 =3D wx.Panel(id=3DwxID_FRAME1PANEL1, name=3D'panel1',
parent=3Dself,
pos=3Dwx.Point(0, 0), size=3Dwx.Size(334, 155),
style=3Dwx.TAB_TRAVERSAL)
#here is the grid itself...this just starts a small grid but this is not
enough,
#as you'll see below...we need to specifiy a few more things in a moment...
self.grid1 =3D wx.grid.Grid(id=3DwxID_FRAME1GRID1, name=3D'grid1',
parent=3Dself.panel1, pos=3Dwx.Point(5, 5), size=3Dwx.Size(32=
4,
107),
style=3D0)
#adding four basic buttons...
self.button1 =3D wx.Button(id=3DwxID_FRAME1BUTTON1, label=3D'button=
1',
name=3D'button1', parent=3Dself.panel1, pos=3Dwx.Point(5, 122=
),
size=3Dwx.Size(75, 23), style=3D0)
self.button2 =3D wx.Button(id=3DwxID_FRAME1BUTTON2, label=3D'button=
2',
name=3D'button2', parent=3Dself.panel1, pos=3Dwx.Point(80, 12=
2),
size=3Dwx.Size(75, 23), style=3D0)
self.button3 =3D wx.Button(id=3DwxID_FRAME1BUTTON3, label=3D'button=
3',
name=3D'button3', parent=3Dself.panel1, pos=3Dwx.Point(155, 1=
22),
size=3Dwx.Size(75, 23), style=3D0)
self.button4 =3D wx.Button(id=3DwxID_FRAME1BUTTON4, label=3D'button=
4',
name=3D'button4', parent=3Dself.panel1, pos=3Dwx.Point(230, 1=
22),
size=3Dwx.Size(75, 23), style=3D0)
#lastly, this line will run all the sizers functions at the top and lay
things
#out nicely...
self._init_sizers()
def __init__(self, parent):
self._init_ctrls(parent)
self.create_my_grid()
#create_my_grid is a function I wrote to just make a 3 by 3 grid, and then
#label the 3 columns. Notice it gets called when the __init__ is run.
def create_my_grid(self):
self.grid1.CreateGrid(3,3)
self.grid1.SetColLabelValue(0, "Name")
self.grid1.SetColLabelValue(1, "Address")
self.grid1.SetColLabelValue(2, "Phone")
if __name__ =3D=3D '__main__':
app =3D wx.PySimpleApp()
frame =3D create(None)
frame.Show()
app.MainLoop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200709=
04/08beb171/attachment.htm
More information about the wxpython-users
mailing list