Re: Separating Code
- Posted by Vinoba Dec 09, 2011
- 1546 views
We did use predefined code for common tasks in an include file.
Here is a function created for setting up labels (text,size, colour, font, etc.) in multiple grids within one window.
As you can see, it becomes fairly large and complex to allow for many variables in a major work, but it does work well enough to ease the life of the next person to use it. We never measured the speed deterioration, if any.
This work was done by a student before we changed to shortened version of wxEuphoria.
global function StartLbl (atom qGrid,atom qWhichGrid) -- -- Submitted by: __________________________________ -- -- Assignment: -- Create a common module for setting labels to multiple grids in a Window. -- Assume that the Window and Grids are already defined. -- Extract the appropriate Label parameters from the related sequences -- Allow for adding own label or not adding a label -- Use the defined two dimentional sequences for Label size, colour and text -- Optionally redefine them, if you want to. -- Label size, colour, default row and column size, colour and font should be set. -- Also initialize the defualt cell colors and initialise the cell sizes, and label and cell fonts -- -- Use AllLabSz, AllLabClr, AllLabFont, AllCellDefSz, AllCellDefClr -- DO NOT USE AllCellSz, AllCellClr, AllCellFont, AllCell Txt here -- THOSE WILL BE USED IN FUNCTION StartCell LATER. -- -- Row and column count atom qRowCt,qColCt,qMaxRow,qMaxCol,qFill,qCellDefFont qRowCt = get_number_rows( qGrid ) qColCt = get_number_cols( qGrid ) sequence qLabTxt = AllLabTxt[qWhichGrid] sequence qLabSz=AllLabSz[qWhichGrid] sequence qLabClr=AllLabClr[qWhichGrid] sequence qLabTxtR=qLabTxt[1] sequence qLabTxtC=qLabTxt[2] atom qLabFont=AllLabFont[qWhichGrid] sequence qCellDefSz=AllCellDefSz[qWhichGrid] sequence qCellDefClr=AllCellDefClr[qWhichGrid] -- Row and colunm Default Lable and Cell sizes set_row_label_size( qGrid, qLabSz[1] ) set_col_label_size( qGrid, qLabSz[2] ) set_default_row_size( qGrid, qCellDefSz[1], 1 ) set_default_col_size( qGrid, qCellDefSz[2], 1 ) -- Row and colunm Default Label and Cell colours and fonts set_grid_label_text_color(qGrid,qLabClr[1] ) set_grid_label_background_color(qGrid, qLabClr[2] ) set_default_cell_text_color( qGrid, qCellDefClr[1] ) set_default_cell_background_color( qGrid, qCellDefClr[2] ) set_grid_label_font( qGrid, qLabFont) set_default_cell_font(qGrid,qLabFont) -- Label Text if available, other wise it will be 1-100 and A-Z defaults of Grid if length(qLabTxtR[1]) < 2 then -- Do not change the row labels if Row labels do not exist qMaxRow = qRowCt else qMaxRow=length(qLabTxtR) if qMaxRow>qRowCt then -- Can't allow more rows than maximum grid size qMaxRow=qRowCt end if -- Fill defined Row labels with supplied text for i = 0 to qMaxRow-1 do set_row_label( qGrid, i, qLabTxtR[i+1] ) end for qFill=qRowCt-qMaxRow -- Fill undefined Row labels with Blanks for i = qMaxRow to qFill-1 do set_row_label( qGrid, i, " ") end for end if if length(qLabTxtC[1]) < 2 then -- Do not change the row labels if Row labels do not exist qMaxCol=qColCt else qMaxCol=length(qLabTxtC) if qMaxCol>qColCt then -- Can't allow more columns than maximum grid size qMaxCol=qColCt end if -- Fill defined Column labels with supplied text for i = 0 to qMaxCol-1 do set_col_label( qGrid, i, qLabTxtC[i+1] ) end for qFill=qColCt-qMaxCol -- Fill undefined Column labels with Blanks for i = qMaxCol to qFill-1 do set_col_label( qGrid, i, " ") end for end if -- Retrun pairs of derived information. sequnece qReturn ={ {qGrid,qWhichGrid }, {qRowCt,qColCt},{qMaxRow,qMaxCol}, {qLabFont,qLabFont} } return qReturn end function