Re: [Boa Constr] wxGrid in Boa
Status: Beta
Brought to you by:
riaan
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 |