Thread: [Boa Constr] wxGrid in Boa
Status: Beta
Brought to you by:
riaan
From: Lynndon H. <lyn...@ec...> - 2001-08-20 11:01:58
|
Hi all I have been trying to get a grid to work within Boa, and be contained within a panel. My steps were: 1 Create simple Boa app and frame 2 put panel and button on frame (unless another control is on the frame, the panel grabs the whole frame. 3 Insert wxGrid object within panel. 4 Insert code for a grid (which works as a module) into the wxFrame1 code. 5 Change the reference in the original Boa code to refer to the new grid class (dbGrid). When running this I get "TypeError: __init__() got an unexpected keyword argument ....... message from the self.grid1=...... (line 62). Any help would be greatly appreciated. Actually I find the whole wxPython grid a bit of a maze, and would appreciate any help in deciding which class of grid is best suited for which application. TIA Lynndon Harnell Code is as follows: #Boa:Frame:wxFrame1 from wxPython.wx import * from wxPython.grid import * ColHeaders=["PipeID", "Len(m)", "Dia(mm)", "WT(mm)", "Gr", "SYMS(MPa)", "Vol(m3)"] RowHeaders=["1","2"] NCols=len(ColHeaders) NRows=len(RowHeaders) class dbGrid(wxGrid): def __init__(self,parent): wxGrid.__init__(self,parent,-1, style= wxSIMPLE_BORDER|wxSUNKEN_BORDER) self.CreateGrid(NRows,NCols) self.SetGridLineColour(wxColour(128,128,128)) self.EnableEditing(false) self.SetSelectionMode(wxGrid.wxGridSelectColumns) self.SetDefaultCellAlignment(wxRIGHT,wxCENTER) self.SetRowLabelAlignment(wxCENTER,wxCENTER) self.SetColLabelAlignment(wxCENTER,wxCENTER) self.SetColLabelSize(20) self.SetRowLabelSize(10) self.SetCellHighlightColour(wxBLACK) # set cell values self.SetCellValue(0, 0, "1") self.SetCellValue(0, 1, "2120") self.SetCellValue(0, 2, "114.3") self.SetCellValue(0, 3, "4.8") self.SetCellValue(0, 4, "B") for i in range(NCols): self.SetColLabelValue(i,ColHeaders[i]) self.SetColSize(i,50) for i in range(NRows): self.SetRowLabelValue(i,RowHeaders[i]) def SetData(self,data): for row in range(len(data)): for col in range(len(data[row])): self.SetCellValue(row,col,data[row][col]) #--------------------------------------------------------------------------- def create(parent): return wxFrame1(parent) [wxID_WXFRAME1, wxID_WXFRAME1BUTTON1, wxID_WXFRAME1GRID1, wxID_WXFRAME1PANEL1] = map(lambda _init_ctrls: wxNewId(), range(4)) class wxFrame1(wxFrame): def _init_utils(self): pass def _init_ctrls(self, prnt): wxFrame.__init__(self, id = wxID_WXFRAME1, name = '', parent = prnt, pos = wxPoint(196, 126), size = wxSize(377, 232), style = wxDEFAULT_FRAME_STYLE, title = 'wxFrame1') self._init_utils() self.panel1 = wxPanel(id = wxID_WXFRAME1PANEL1, name = 'panel1', parent = self, pos = wxPoint(0, 0), size = wxSize(288, 120), style = wxTAB_TRAVERSAL) # self.grid1 = wxGrid(id = wxID_WXFRAME1GRID1, name = 'grid1', parent = self.panel1, pos = wxPoint(104, 24), size = wxSize(136, 80), style = wxTHICK_FRAME | wxSUNKEN_BORDER) self.grid1 = dbGrid(id = wxID_WXFRAME1GRID1, name = 'grid1', parent = self.panel1, pos = wxPoint(104, 24), size = wxSize(136, 80), style = wxTHICK_FRAME | wxSUNKEN_BORDER) self.button1 = wxButton(id = wxID_WXFRAME1BUTTON1, label = 'button1', name = 'button1', parent = self, pos = wxPoint(168, 176), size = wxSize(75, 23), style = 0) def __init__(self, parent): self._init_ctrls(parent) Lynndon Harnell |
From: Harnell, L. <lyn...@up...> - 2001-08-21 00:22:03
|
>FROM: Riaan Booysen >DATE: 08/20/2001 10:43:42 >SUBJECT: RE: [Boa Constr] wxGrid in Boa >Hi Lynndon, please send plain text mail to the mailing list! Will do. Is this OK? >Luckily there is support already built into Boa to do what you want. >It's called 'custom classes'. The first change you need to make, is to >change your dbGrid class to have the same constructor as the original >wxGrid class. By this do you mean the line?: wxGrid.__init__(self,parent,-1, style= wxSIMPLE_BORDER|wxSUNKEN_BORDER) Boa inserts code like this: self.grid1 = wxGrid(id = wxID_WXFRAME1GRID1, name = 'grid1', parent = self.panel1, pos = wxPoint(104, 24), size = wxSize(136, 80), style= 0) So that I should change the first to something like?: wxGrid.__init__(ID, self,parent,-1, pos, size, style= wxSIMPLE_BORDER|wxSUNKEN_BORDER) >Then uncomment the line ># self.grid1 = wxGrid ... > >and delete the line you added > > self.grid1 = dbGrid ... OK understood >Now add the following _custom_classes line to the top of the wxFrame1 >definition as a class attribute: >class wxFrame1(wxFrame): > _custom_classes = {'wxGrid': ['dbGrid']} > def _init_utils(self): Got that. >Now open the Designer, select the Grid and change the Class property >from wxGrid to dbGrid. That too. >You will notice that the constructor you defined takes 1 parameter, >yet it is called with 5 keyword parameters in the source. Is this the line you mean in referring to the constructor definition, and is the one parameter the style? wxGrid.__init__(self,parent,-1, style= wxSIMPLE_BORDER|wxSUNKEN_BORDER) and is this the line you mean with 5 keywords in the source? There are 6 parameters within the wxGrid brackets (ID,NAME,PARENT,POS,SIZE,STYLE) or is one ignored? self.grid1 = wxGrid(id = wxID_WXFRAME1GRID1, name = 'grid1', parent = self.panel1, pos = wxPoint(104, 24), size = wxSize(136, 80), style= 0) Thanks for all your help. Lynndon |
From: Riaan B. <riaan@e.co.za> - 2001-08-21 20:03:28
|
Hi Lynndon, "Harnell, Lynndon" wrote: > > >FROM: Riaan Booysen > >DATE: 08/20/2001 10:43:42 > >SUBJECT: RE: [Boa Constr] wxGrid in Boa > >Hi Lynndon, please send plain text mail to the mailing list! > > Will do. Is this OK? Perfect, > > >Luckily there is support already built into Boa to do what you want. > > >It's called 'custom classes'. The first change you need to make, is to > >change your dbGrid class to have the same constructor as the original > >wxGrid class. > > By this do you mean the line?: > wxGrid.__init__(self,parent,-1, style= wxSIMPLE_BORDER|wxSUNKEN_BORDER) The line above it would be the class constructor. def __init__(... You defined a new class called dbGrid. Boa will generate source using your class name, but with the same constructor signature as the class we defined your class equivalent to with the line: _custom_classes = {'wxGrid': ['dbGrid']} I don't exactly know how you expect this dbGrid class to behave in the Designer. For the Designer it will be a wxGrid, not your class, so you won't see any new properties or behaviour. I need you to understand what happens here, trying to do what I recommend without really understanding will cause problems later, so if this is still unclear, please ask. > Boa inserts code like this: > self.grid1 = wxGrid(id = wxID_WXFRAME1GRID1, name = 'grid1', parent = > self.panel1, pos = wxPoint(104, 24), size = wxSize(136, 80), style= 0) > > So that I should change the first to something like?: > > wxGrid.__init__(ID, self,parent,-1, pos, size, style= > wxSIMPLE_BORDER|wxSUNKEN_BORDER) See above, There are 2 routes I usually consider: One, to copy the definition from the docs: def __init__(self, parent, id=-1, pos=wxDefaultPosition, size=wxDefaultSize, style=wxWANTS_CHARS, name='grid') wxGrid.__init__(self, parent, id, pos, size, style, name) Two, to copy the wxPython (SWIG) signature: def __init__(self, *_args, **_kwargs): apply(wxGrid.__init__, _args, _kwargs) # access parameters from the _kwargs, e.g. _kwargs['style'] I usually use the second form when using _custom_classes. It's ugly, but it's short and it only passes on the args that are defined. > self.grid1 = wxGrid(id = wxID_WXFRAME1GRID1, name = 'grid1', parent = > self.panel1, pos = wxPoint(104, 24), size = wxSize(136, 80), style= 0) > > >Then uncomment the line > ># self.grid1 = wxGrid ... > > > >and delete the line you added > > > > self.grid1 = dbGrid ... > > OK understood > > >Now add the following _custom_classes line to the top of the wxFrame1 > >definition as a class attribute: > > >class wxFrame1(wxFrame): > > > _custom_classes = {'wxGrid': ['dbGrid']} > > > def _init_utils(self): > > Got that. > > >Now open the Designer, select the Grid and change the Class property > >from wxGrid to dbGrid. > > That too. > > >You will notice that the constructor you defined takes 1 parameter, > >yet it is called with 5 keyword parameters in the source. > > Is this the line you mean in referring to the constructor definition, and is > the one parameter the style? I refered to: def __init__(self,parent): > > wxGrid.__init__(self,parent,-1, style= wxSIMPLE_BORDER|wxSUNKEN_BORDER) Just to clear up terminology, your line above is not the constructor definition/declaration, but where the base class's constructor is called within the constructor's code block. > > and is this the line you mean with 5 keywords in the source? There are 6 > parameters within the wxGrid brackets (ID,NAME,PARENT,POS,SIZE,STYLE) or is > one ignored? Sorry I did not count correctly, but this is beside the point. The point I tried to make was that it was more than the one parameter you had in your __init__ method ;) > > self.grid1 = wxGrid(id = wxID_WXFRAME1GRID1, name = 'grid1', parent = > self.panel1, pos = wxPoint(104, 24), size = wxSize(136, 80), style= 0) > > Thanks for all your help. Hope this is all starting to make sense. > > Lynndon > > _______________________________________________ > Boa-constructor-users mailing list > Boa...@li... > http://lists.sourceforge.net/lists/listinfo/boa-constructor-users -- Riaan Booysen ___________________________________________________ Boa Constructor - RAD GUI building IDE for wxPython http://boa-constructor.sourceforge.net |
From: Riaan B. <riaan@e.co.za> - 2001-08-20 22:02:35
|
Hi Lynndon, please send plain text mail to the mailing list! Lynndon Harnell wrote: > Hi all > > I have been trying to get a grid to work within Boa, and be contained > within a panel. > > My steps were: > 1 Create simple Boa app and frame > > 2 put panel and button on frame (unless another control is on the frame, > the panel grabs the whole frame. > > 3 Insert wxGrid object within panel. > > 4 Insert code for a grid (which works as a module) into the wxFrame1 code. > > 5 Change the reference in the original Boa code to refer to the new grid > class (dbGrid). As I have stated in a previous reply to you, do not change the _init_* methods unless you know what you are doing ;) Luckily there is support already built into Boa to do what you want. It's called 'custom classes'. The first change you need to make, is to change your dbGrid class to have the same constructor as the original wxGrid class. Then uncomment the line # self.grid1 = wxGrid ... and delete the line you added self.grid1 = dbGrid ... Now add the following _custom_classes line to the top of the wxFrame1 definition as a class attribute: class wxFrame1(wxFrame): _custom_classes = {'wxGrid': ['dbGrid']} def _init_utils(self): Now open the Designer, select the Grid and change the Class property from wxGrid to dbGrid. > > When running this I get "TypeError: __init__() got an unexpected keyword > argument ....... message from the self.grid1=...... (line 62). You will notice that the constructor you defined takes 1 parameter, yet it is called with 5 keyword parameters in the source. > > Any help would be greatly appreciated. Actually I find the whole wxPython > grid a bit of a maze, and would appreciate any help in deciding which class > of grid is best suited for which application. I've never really used the grid, sorry. > > TIA Good luck! > > Lynndon Harnell > > Code is as follows: > > #Boa:Frame:wxFrame1 > from wxPython.wx import * > from wxPython.grid import * > ColHeaders=["PipeID", "Len(m)", "Dia(mm)", "WT(mm)", "Gr", "SYMS(MPa)", > "Vol(m3)"] > RowHeaders=["1","2"] > NCols=len(ColHeaders) > NRows=len(RowHeaders) > class dbGrid(wxGrid): > def __init__(self,parent): > wxGrid.__init__(self,parent,-1, style= > wxSIMPLE_BORDER|wxSUNKEN_BORDER) > > self.CreateGrid(NRows,NCols) > > self.SetGridLineColour(wxColour(128,128,128)) > self.EnableEditing(false) > self.SetSelectionMode(wxGrid.wxGridSelectColumns) > self.SetDefaultCellAlignment(wxRIGHT,wxCENTER) > self.SetRowLabelAlignment(wxCENTER,wxCENTER) > self.SetColLabelAlignment(wxCENTER,wxCENTER) > self.SetColLabelSize(20) > self.SetRowLabelSize(10) > self.SetCellHighlightColour(wxBLACK) > # set cell values > self.SetCellValue(0, 0, "1") > self.SetCellValue(0, 1, "2120") > self.SetCellValue(0, 2, "114.3") > self.SetCellValue(0, 3, "4.8") > self.SetCellValue(0, 4, "B") > > for i in range(NCols): > self.SetColLabelValue(i,ColHeaders[i]) > self.SetColSize(i,50) > for i in range(NRows): > self.SetRowLabelValue(i,RowHeaders[i]) > > def SetData(self,data): > for row in range(len(data)): > for col in range(len(data[row])): > self.SetCellValue(row,col,data[row][col]) > #--------------------------------------------------------------------------- > def create(parent): > return wxFrame1(parent) > [wxID_WXFRAME1, wxID_WXFRAME1BUTTON1, wxID_WXFRAME1GRID1, > wxID_WXFRAME1PANEL1] = map(lambda _init_ctrls: wxNewId(), range(4)) > class wxFrame1(wxFrame): > def _init_utils(self): > pass > def _init_ctrls(self, prnt): > wxFrame.__init__(self, id = wxID_WXFRAME1, name = '', parent = > prnt, pos = wxPoint(196, 126), size = wxSize(377, 232), style = > wxDEFAULT_FRAME_STYLE, title = 'wxFrame1') > self._init_utils() > self.panel1 = wxPanel(id = wxID_WXFRAME1PANEL1, name = 'panel1', > parent = self, pos = wxPoint(0, 0), size = wxSize(288, 120), style = > wxTAB_TRAVERSAL) > # self.grid1 = wxGrid(id = wxID_WXFRAME1GRID1, name = 'grid1', > parent = self.panel1, pos = wxPoint(104, 24), size = wxSize(136, 80), style > = wxTHICK_FRAME | wxSUNKEN_BORDER) > self.grid1 = dbGrid(id = wxID_WXFRAME1GRID1, name = 'grid1', > parent = self.panel1, pos = wxPoint(104, 24), size = wxSize(136, 80), style > = wxTHICK_FRAME | wxSUNKEN_BORDER) > self.button1 = wxButton(id = wxID_WXFRAME1BUTTON1, label = > 'button1', name = 'button1', parent = self, pos = wxPoint(168, 176), size = > wxSize(75, 23), style = 0) > def __init__(self, parent): > self._init_ctrls(parent) > Lynndon Harnell -- Riaan Booysen ___________________________________________________ Boa Constructor - RAD GUI building IDE for wxPython http://boa-constructor.sourceforge.net |