def __init__(self, datasource, rowLabels=None, colLabels=None, selectedcolour="green"): ''' [ [value1,value2,value3,...], [value1,value2,value3,...], [value1,value2,value3,...], ... ] ''' grd.PyGridTableBase.__init__(self) self.selectedcolour = selectedcolour self.data = {} self.colLabels = ('√', ) if colLabels: self.colLabels += colLabels self.rowLabels = rowLabels self.rows = len(datasource) #行数 self.cols = len(self.colLabels) #行数 self.attr = attr = grd.GridCellAttr() attr.SetEditor(grd.GridCellBoolEditor()) attr.SetRenderer(grd.GridCellBoolRenderer()) self.boolattr = grd.GridCellAttr() self.boolattr.SetReadOnly() self.boolattr.SetEditor(grd.GridCellBoolEditor()) self.boolattr.SetRenderer(grd.GridCellBoolRenderer()) self.sid_cell = grd.GridCellAttr() self.sid_cell.SetReadOnly(1) i = 0 for row in datasource: self.data[(i, 0)] = '' j = 1 for v in row: self.data[(i, j)] = v #给每一个单元格赋值的方法 j += 1 i += 1 self.cell = grd.GridCellAttr() #self.cell.SetReadOnly() self.cell.SetOverflow(False) self.sid_attr = grd.GridCellAttr() self.sid_attr.SetOverflow(True)
def __init__(self, parent): wx.Panel.__init__(self, parent) self.alphaSort = wx.Button(self, label=u'Sort Alphabetically') self.alphaSort.Bind(wx.EVT_BUTTON, self.onSort) self.explanation = wx.StaticText( self, label=u'\n'.join([ _("Change the Category order by dragging-and-dropping the first grey column in the table." ), _("If 'Use Nth Result Only' is True, 'Team N' specifies the top Nth rider's time to use for the team's time (eg. Team TT, scored on 3rd rider's result)" ), _("If 'Use Nth Result Only' if False, 'Team N' specifies the top riders' times to be totaled for the team result (eg. Team Stage Finish, scored on sum of top 3 results for each team)." ), ])) self.headerNames = [ 'Category', 'Ind. Publish', 'Team N', 'Use Nth Result Only', 'Team Publish' ] self.grid = ReorderableGrid(self, style=wx.BORDER_SUNKEN) self.grid.DisableDragRowSize() self.grid.SetRowLabelSize(64) self.grid.CreateGrid(0, len(self.headerNames)) for col in range(self.grid.GetNumberCols()): self.grid.SetColLabelValue(col, self.headerNames[col]) for col in range(self.grid.GetNumberCols()): attr = gridlib.GridCellAttr() if col == self.CategoryCol: attr.SetReadOnly(True) elif col in (self.PublishCol, self.UseNthScoreCol, self.TeamPublishCol): editor = gridlib.GridCellBoolEditor() editor.UseStringValues('1', '0') attr.SetEditor(editor) attr.SetRenderer(gridlib.GridCellBoolRenderer()) attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) elif col == self.TeamNCol: editor = gridlib.GridCellNumberEditor() attr.SetEditor(editor) attr.SetRenderer(gridlib.GridCellNumberRenderer()) attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.grid.SetColAttr(col, attr) self.Bind(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.onGridLeftClick) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.alphaSort, 0, flag=wx.ALL | wx.ALIGN_RIGHT, border=4) sizer.Add(self.explanation, 0, flag=wx.ALL, border=4) sizer.Add(self.grid, 1, flag=wx.EXPAND | wx.ALL, border=6) self.SetSizer(sizer)
def __init__(self, parent): grd.Grid.__init__(self, parent, -1, pos=(10, 40), size=(420, 95)) self.CreateGrid(3, 3) self.RowLabelSize = 0 self.ColLabelSize = 20 attr = grd.GridCellAttr() attr.SetEditor(grd.GridCellBoolEditor()) attr.SetRenderer(grd.GridCellBoolRenderer()) self.SetColAttr(1, attr) self.SetColSize(1, 20) self.Bind(grd.EVT_GRID_CELL_LEFT_CLICK, self.onMouse) self.Bind(grd.EVT_GRID_SELECT_CELL, self.onCellSelected) self.Bind(grd.EVT_GRID_EDITOR_CREATED, self.onEditorCreated)
def __init__(self,gui,parent,dic,**kwargs): wgrid.Grid.__init__(self,parent,-1,**kwargs) self.rowString,self.colString,data=dic['rows'],dic['cols'],dic['data'] if dic['rows']=='': self.rowString=['']*len(dic['data']) nrow, ncol = len(self.rowString),len(self.colString) self.chk = zeros((nrow,ncol)) ln=[len(x) for x in self.rowString] self.SetRowLabelSize(min(max(ln)*8,170)) lent = sum([len(x.replace(' ','')) for x in self.colString]) if lent==0 : self.SetColLabelSize(0) # if all '', remove col headers self.CreateGrid(nrow,ncol);#print data for j,col in enumerate(self.colString): self.SetColLabelValue(j,col); for i,row in enumerate(self.rowString): self.SetRowLabelValue(i,row) ln = len(data[i]) for j,col in enumerate(self.colString[:ln]): d = data[i][j] if type(d)==type([5,6]): choice_editor = wgrid.GridCellChoiceEditor(d,False) #choice_editor.SetCellAttr() self.SetCellEditor(i,j, choice_editor) #self.SetCellValue(i, j, 1) elif type(d)==type(True): e_boo = wgrid.GridCellBoolEditor() self.SetCellEditor(i,j, e_boo) r_boo = wgrid.GridCellBoolRenderer() self.SetCellRenderer(i,j, r_boo) self.chk[i,j] = 1 self.SetCellValue(i, j, str(d*1)) else : # limit size cell if float try : float(d) #if 'e' not in d: d1 = d[:6] d1 = str(d)[:9] #a real except ValueError: d1 = str(d) self.SetCellValue(i, j, d1) #self.SetCellSize(i,j,8,len(col)*4) self.AutoSizeColumns(True) self.AutoSizeRows(True) wx.EVT_KEY_DOWN(self, self.OnKey)
def __init__(self, parent, callback): grd.Grid.__init__(self, parent, -1) self.callback = callback self.CreateGrid(1, 3) self.RowLabelSize = 0 # self.ColLabelSize = 20 self.SetColLabelValue(0, u"序号") self.SetColLabelValue(1, u"生效") self.SetColLabelValue(2, u"地址") self.SetCellValue(0, 0, "0") self.SetCellValue(0, 1, "1") self.SetCellValue(0, 2, u"OPCServer1.Group1.Item1") attr = grd.GridCellAttr() attr.SetEditor(grd.GridCellBoolEditor()) attr.SetRenderer(grd.GridCellBoolRenderer()) self.SetColAttr(1, attr) self.SetColSize(1, 50) self.SetColSize(2, 300) # self.SetRowLabelSize(0) self.SetMargins(0, 0) self.SetSelectionMode(self.wxGridSelectRows) # self.AutoSizeColumns(True) self.SetReadOnly(0, 0, True) # self.SetReadOnly(0,1,True) self.SetReadOnly(0, 2, True) self.SetDefaultCellBackgroundColour( wx.SystemSettings.GetColour(wx.SYS_COLOUR_FRAMEBK)) self.SetDefaultCellAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.Bind(grd.EVT_GRID_CELL_LEFT_CLICK, self.onMouse) self.Bind(grd.EVT_GRID_SELECT_CELL, self.onCellSelected) self.Bind(grd.EVT_GRID_EDITOR_CREATED, self.onEditorCreated)
def __init__(self, parent): Grid.Grid.__init__(self, parent, -1) self.CreateGrid(25, 4) self._rows = 25 self._cols = 4 self.SetColLabelValue(0, _("Location")) self.SetColLabelValue(1, _("Intensity")) self.SetColLabelValue(2, _("Comment")) self.SetColLabelValue(3, _("Frozen")) attr = Grid.GridCellAttr() attrb = Grid.GridCellAttr() attr.SetEditor(Grid.GridCellFloatEditor()) attrb.SetEditor(Grid.GridCellBoolEditor()) attrb.SetRenderer(Grid.GridCellBoolRenderer()) self.SetColAttr(0, attr) self.SetColAttr(1, attr) self.SetColSize(2, self.GetColSize(2) * 4) self.SetColAttr(3, attrb) self.Bind(Grid.EVT_GRID_LABEL_RIGHT_CLICK, self.OnLabelRightClicked) self.Bind(Grid.EVT_GRID_CELL_CHANGE, self.OnCellChange) wx.EVT_KEY_DOWN(self, self.on_key)
def __init__(self, parent): grid.Grid.__init__(self, parent, -1) self.CreateGrid(8, 4) self.EnableEditing(True) self.SetColLabelValue(0, u"第1列") # 设置行标题 self.SetColLabelAlignment(wx.ALIGN_LEFT, wx.ALIGN_BOTTOM) self.SetRowLabelValue(0, u"第1行") # 设置列标题 self.SetRowLabelAlignment(wx.ALIGN_RIGHT, wx.ALIGN_BOTTOM) self.SetCellValue(0, 0, "Hello") self.SetCellTextColour(0, 0, wx.RED) self.SetCellFont(0, 0, wx.Font(10, wx.ROMAN, wx.ITALIC, wx.NORMAL)) # 设置单元格的字体 self.SetCellValue(1, 0, "Read Only") self.SetReadOnly(1, 0, True) # 设置只读单元格 self.SetCellBackgroundColour(1, 0, wx.RED) # 设置单元格的背景颜色 self.SetCellEditor(2, 0, grid.GridCellNumberEditor(1, 10)) # 嵌入数字选择控件 self.SetCellValue(2, 0, "1") self.SetCellEditor(2, 1, grid.GridCellFloatEditor(0, 1)) # 嵌入浮点数编辑控件 self.SetCellValue(2, 1, "10.19") attr = grid.GridCellAttr() attr.SetTextColour(wx.BLUE) self.SetColAttr(1, attr) # 设置一列的单元格属性 self.SetCellAlignment(5, 1, wx.ALIGN_CENTRE, wx.ALIGN_BOTTOM) self.SetCellValue(5, 1, u"跨行、列的单元格") self.SetCellSize(5, 1, 2, 2) # 设置跨行、列的单元格 self.SetCellEditor(6, 0, grid.GridCellChoiceEditor(["one", "two", "three"])) # 嵌入下拉列表 self.SetCellValue(6, 0, "one") self.SetCellEditor(7, 0, grid.GridCellBoolEditor()) # 嵌入下拉列表 self.SetCellValue(7, 0, "True")
def __init__(self, Child): grd.Grid.__init__(self, Child, -1, size=(250, 460)) self.EnableGridLines(enable=False) self.CreateGrid(len(output_list), len(output_list)) self.RowLabelSize = 0 self.ColLabelSize = 60 attr = grd.GridCellAttr() # type: GridCellAttr attr.SetEditor(grd.GridCellBoolEditor()) attr.SetRenderer(grd.GridCellBoolRenderer()) # digital for i in range( 0, (len(output_list)) ): ###uses the number of grids depending on amount of items in colLabels self.SetColAttr(i, attr) self.SetRowSize(i, 40) self.SetColSize(i, 80) ###sets column 0 size self.SetColLabelValue(i, "Machine " + str(i + 1)) self.Bind(grd.EVT_GRID_CELL_LEFT_CLICK, self.onMouse) self.Bind(grd.EVT_GRID_SELECT_CELL, self.onCellSelected) self.Bind(grd.EVT_GRID_EDITOR_CREATED, self.onEditorCreated)
def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, parent = parent, size = (300,300)) # ---------------- Grid section ---------------- # mock = data.mock_list # Get mock length rows = len(mock) print("Mock lenght = " + str(rows)) # declare grid myGrid = grid.Grid(self, -1, size=(1,1)) # Init grid myGrid.CreateGrid(rows, 4) # ---- pasted code ---- # attr = grid.GridCellAttr() attr.SetEditor(grid.GridCellBoolEditor()) attr.SetRenderer(grid.GridCellBoolRenderer()) for i in range(0, 4): myGrid.SetColAttr(i, attr) myGrid.SetColSize(i, 30) # ---- end pasted code ---- # # Set columns names for i in range(0, 4): myGrid.SetColLabelValue(i, ("Target set " + str(i+1))) # Set rows names for j in range(0, rows): myGrid.SetRowLabelValue(j, (mock[j][0])) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(myGrid, 1, wx.EXPAND) self.SetSizer(sizer)
def __init__(self, parent, id=wx.ID_ANY): wx.Panel.__init__(self, parent, id) self.state = RaceInputState() vs = wx.BoxSizer(wx.VERTICAL) self.ignoreColour = wx.Colour(80, 80, 80) self.inactiveColour = wx.Colour(200, 200, 200) border = 4 flag = wx.ALL hs = wx.BoxSizer(wx.HORIZONTAL) self.activateAllButton = wx.Button(self, label=_('Activate All'), style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onActivateAll, self.activateAllButton) hs.Add(self.activateAllButton, 0, border=border, flag=flag) hs.AddSpacer(6) self.newCategoryButton = wx.Button(self, label=_('New'), style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onNewCategory, self.newCategoryButton) hs.Add(self.newCategoryButton, 0, border=border, flag=flag) self.delCategoryButton = wx.Button(self, label=_('Delete'), style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onDelCategory, self.delCategoryButton) hs.Add(self.delCategoryButton, 0, border=border, flag=(flag & ~wx.LEFT)) hs.AddSpacer(6) self.upCategoryButton = wx.Button(self, label=u'\u2191', style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onUpCategory, self.upCategoryButton) hs.Add(self.upCategoryButton, 0, border=border, flag=flag) self.downCategoryButton = wx.Button(self, label=u'\u2193', style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onDownCategory, self.downCategoryButton) hs.Add(self.downCategoryButton, 0, border=border, flag=(flag & ~wx.LEFT)) hs.AddSpacer(6) self.setGpxDistanceButton = wx.Button(self, label=_('Set Gpx Distance'), style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onSetGpxDistance, self.setGpxDistanceButton) hs.Add(self.setGpxDistanceButton, 0, border=border, flag=flag) hs.AddSpacer(6) self.addExceptionsButton = wx.Button(self, label=_('Bib Exceptions'), style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onAddExceptions, self.addExceptionsButton) hs.Add(self.addExceptionsButton, 0, border=border, flag=flag) hs.AddSpacer(6) ''' self.updateStartWaveNumbersButton = wx.Button(self, label=_('Update Start Wave Bibs'), style=wx.BU_EXACTFIT) self.Bind( wx.EVT_BUTTON, self.onUpdateStartWaveNumbers, self.updateStartWaveNumbersButton ) hs.Add( self.updateStartWaveNumbersButton, 0, border = border, flag = flag ) ''' self.normalizeButton = wx.Button(self, label=_('Normalize'), style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onNormalize, self.normalizeButton) hs.Add(self.normalizeButton, 0, border=border, flag=flag) hs.AddStretchSpacer() self.printButton = wx.Button(self, label=u'{}...'.format(_('Print')), style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onPrint, self.printButton) hs.Add(self.printButton, 0, border=border, flag=flag) self.excelButton = wx.Button(self, label=u'{}...'.format(_('Excel')), style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.onExcel, self.excelButton) hs.Add(self.excelButton, 0, border=border, flag=flag) self.grid = ReorderableGrid(self) self.colNameFields = [ (u'', None), (_('Category Type'), 'catType'), (_('Active'), 'active'), (_('Name'), 'name'), (_('Gender'), 'gender'), (_('Numbers'), 'catStr'), (_('Start\nOffset'), 'startOffset'), (_('Race\nLaps'), 'numLaps'), (_('Race\nMinutes'), 'raceMinutes'), (_('Lapped\nRiders\nContinue'), 'lappedRidersMustContinue'), (_('Distance'), 'distance'), (_('Dist.\nBy'), 'distanceType'), (_('First\nLap\nDist.'), 'firstLapDistance'), (_('80%\nLap\nTime'), 'rule80Time'), (_('CrossMgr\nEstimated\nLaps'), 'suggestedLaps'), (_('Publish'), 'publishFlag'), (_('Upload'), 'uploadFlag'), (_('Series'), 'seriesFlag'), ] self.computedFields = {'rule80Time', 'suggestedLaps'} self.colnames = [ colName if not colName.startswith('_') else _('Name Copy') for colName, fieldName in self.colNameFields ] self.iCol = { fieldName: i for i, (colName, fieldName) in enumerate(self.colNameFields) if fieldName and not colName.startswith('_') } self.activeColumn = self.iCol['active'] self.genderColumn = self.iCol['gender'] self.numbersColumn = self.iCol['catStr'] self.grid.CreateGrid(0, len(self.colnames)) self.grid.SetRowLabelSize(32) self.grid.SetMargins(0, 0) for col, name in enumerate(self.colnames): self.grid.SetColLabelValue(col, name) self.cb = None self.boolCols = set() self.choiceCols = set() self.readOnlyCols = set() self.dependentCols = set() # Set column attributes for the table. for col, (colName, fieldName) in enumerate(self.colNameFields): attr = gridlib.GridCellAttr() if fieldName is None: attr.SetRenderer(CategoryIconRenderer()) attr.SetAlignment(wx.ALIGN_LEFT, wx.ALIGN_CENTRE) attr.SetReadOnly(True) self.readOnlyCols.add(col) elif fieldName == 'catType': self.catTypeWidth = 64 attr.SetEditor( gridlib.GridCellChoiceEditor(self.CategoryTypeChoices, False)) attr.SetAlignment(wx.ALIGN_LEFT, wx.ALIGN_CENTRE) self.choiceCols.add(col) elif fieldName in { 'active', 'lappedRidersMustContinue', 'publishFlag', 'uploadFlag', 'seriesFlag' }: boolEditor = gridlib.GridCellBoolEditor() boolEditor.UseStringValues('1', '0') attr.SetEditor(boolEditor) attr.SetRenderer(gridlib.GridCellBoolRenderer()) attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.boolCols.add(col) if fieldName == 'lappedRidersMustContinue': self.dependentCols.add(col) elif fieldName == 'gender': attr.SetEditor( gridlib.GridCellChoiceEditor( [_('Open'), _('Men'), _('Women')], False)) self.choiceCols.add(col) elif fieldName == 'startOffset': attr.SetEditor(TimeEditor()) attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.dependentCols.add(col) elif fieldName == 'numLaps': attr.SetEditor(wx.grid.GridCellNumberEditor()) attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.dependentCols.add(col) elif fieldName == 'raceMinutes': attr.SetEditor(wx.grid.GridCellNumberEditor()) attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.dependentCols.add(col) elif fieldName in ['rule80Time', 'suggestedLaps']: attr.SetReadOnly(True) attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.readOnlyCols.add(col) self.dependentCols.add(col) elif fieldName in ['distance', 'firstLapDistance']: attr.SetEditor(gridlib.GridCellFloatEditor(7, 3)) attr.SetRenderer(gridlib.GridCellFloatRenderer(7, 3)) attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.dependentCols.add(col) elif fieldName == 'distanceType': attr.SetEditor( gridlib.GridCellChoiceEditor(self.DistanceTypeChoices, False)) attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTRE) self.choiceCols.add(col) self.dependentCols.add(col) elif colName == '_name2': attr.SetAlignment(wx.ALIGN_LEFT, wx.ALIGN_CENTRE) attr.SetBackgroundColour(wx.Colour(240, 240, 240)) attr.SetReadOnly(True) self.grid.SetColAttr(col, attr) self.Bind(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.onGridLeftClick) self.Bind(gridlib.EVT_GRID_SELECT_CELL, self.onCellSelected) self.Bind(gridlib.EVT_GRID_CELL_CHANGED, self.onCellChanged) self.Bind(gridlib.EVT_GRID_EDITOR_CREATED, self.onEditorCreated) vs.Add(hs, 0, flag=wx.EXPAND | wx.ALL, border=4) vs.Add(self.grid, 1, flag=wx.GROW | wx.ALL | wx.EXPAND) self.rowCur = 0 self.colCur = 0 self.SetSizer(vs)
def __set_check_editor(self): for _desc, (row, col) in self.locsCheck.iteritems(): self.grid.SetCellEditor(row, col, wxGrid.GridCellBoolEditor()) self.grid.SetCellAlignment(row, col, wx.ALIGN_RIGHT, wx.ALIGN_CENTRE) self.grid.SetCellRenderer(row, col, CheckBoxCellRenderer(self))
def __init__(self, parent): EnablePanel.__init__(self, parent) self.box = wx.StaticBox( self, label='Result (right-click to enter Bib numbers from keyboard)') boxSizer = wx.StaticBoxSizer(self.box, wx.HORIZONTAL) self.event = None self.SetBackgroundColour(wx.WHITE) self.activeBar = EnableBar(self) self.activeBar.SetToolTip( wx.ToolTip('.\n'.join([ 'Record the Finish Order by dragging the row numbers in the table.', 'Record DNF and DQ in the Status column.', 'Then press OK or Cancel.' ]))) vs = wx.BoxSizer(wx.VERTICAL) self.okButton = MakeRoundButton(self, 'OK') self.cancelButton = MakeRoundButton(self, 'Cancel', isCancel) vs.Add(self.okButton, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=4) vs.Add(self.cancelButton, flag=wx.ALL, border=4) self.headerNames = [ 'Bib', 'Name', 'Team', 'Status', 'Warn', 'Rel', 'Time ' ] self.iColStatus = self.headerNames.index('Status') self.iColWarning = self.headerNames.index('Warn') self.iColRelegation = self.headerNames.index('Rel') self.grid = ReorderableGrid(self, style=wx.BORDER_SUNKEN) self.grid.CreateGrid(4, len(self.headerNames)) self.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnClick) self.grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnRightClick) font = GetFont() self.grid.SetLabelFont(font) for col in six.moves.range(self.grid.GetNumberCols()): self.grid.SetColLabelValue(col, self.headerNames[col]) self.grid.SetCellValue( 0, col, self.headerNames[col]) # Add the label as data. attr = gridlib.GridCellAttr() attr.SetFont(font) if self.headerNames[col] == 'Bib': attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_TOP) attr.SetReadOnly(True) elif self.headerNames[col].startswith('Time'): attr.SetEditor(HighPrecisionTimeEditor()) attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTRE) elif col == 1 or col == 2: attr.SetReadOnly(True) elif col == self.iColStatus: attr.SetEditor( gridlib.GridCellChoiceEditor( choices=['DQ', 'DNF', 'DNS', ''])) elif col == self.iColWarning or col == self.iColRelegation: attr.SetAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) attr.SetEditor(gridlib.GridCellBoolEditor()) attr.SetRenderer(gridlib.GridCellBoolRenderer()) self.grid.SetColAttr(col, attr) self.grid.AutoSizeColumns(False) # Resize to fit the column name. self.grid.AutoSizeRows(False) for col in six.moves.range(self.grid.GetNumberCols()): self.grid.SetCellValue(0, col, '') # Remove the labels. boxSizer.Add(self.activeBar, 0, flag=wx.ALL | wx.EXPAND, border=4) boxSizer.Add(vs, 0, flag=wx.ALL, border=4) boxSizer.Add(self.grid, 1, flag=wx.ALL | wx.EXPAND, border=4) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(boxSizer, 1, flag=wx.EXPAND) self.SetSizer(sizer)
def editor(self): return gridlib.GridCellBoolEditor()
def addData(self, data=None): self.data = data # logger.info(self.GetRowSizes()) # logger.info(self.GetColSizes()) self.ClearGrid() try: if data and len(data) > 0: dataTypeRow = data.get(-1) # logger.info('rows:', self.GetNumberRows()) # logger.info('cols:', self.GetNumberCols()) # self.DeleteRows() currentRows, currentCols = (self.GetNumberRows(), self.GetNumberCols()) newRows = len(data) - 1 if dataTypeRow: newRows = newRows - 1 newCols = len(data[0]) # self.AppendRows(numRows=len(data)-1, updateLabels=True) # if len(data) > 0 : # self.AppendCols(numCols=len(data[0]), updateLabels=True) if newRows < currentRows: # - Delete rows: self.DeleteRows(0, currentRows - newRows, True) if newRows > currentRows: # - append currentRows: self.AppendRows(newRows - currentRows) if newCols < currentCols: # - Delete rows: self.DeleteCols(pos=0, numCols=currentCols - newCols, updateLabels=True) if newCols > currentCols: # - append currentRows: self.AppendCols(newCols - currentCols) for dataKey, dataValue in data.items(): # logger.info(dataKey, dataValue) for idx, colValue in enumerate(dataValue): # logger.info(idx, dataValue) if dataKey == 0: self.SetColLabelValue(idx, str(colValue)) elif dataKey > 0: row = dataKey - 1 col = idx try: # if col==3: # size=self.GetCellSize(row, col) # data='3.jpg' # self.SetCellRenderer(row, col, MegaImageRenderer(self.GetTable(), data)) # elif str(colValue).startswith('-______-'): if str(colValue).startswith('-______-'): newStringValue = str(colValue).replace('-______-', '') self.SetCellFont(row, col, wx.Font(10, wx.FONTFAMILY_SCRIPT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL)) self.SetCellTextColour(row, col, wx.LIGHT_GREY) self.SetCellValue(row, col, newStringValue) else: if dataTypeRow and dataTypeRow[col].lower() == 'blob': # data='3.jpg' if str(colValue).startswith('-______-'): newStringValue = str(colValue).replace('-______-', '') self.SetCellFont(row, col, wx.Font(10, wx.FONTFAMILY_SCRIPT, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL)) self.SetCellTextColour(row, col, wx.LIGHT_GREY) self.SetCellValue(row, col, newStringValue) else: self.SetCellRenderer(row, col, MegaImageRenderer(self.GetTable(), colValue)) elif dataTypeRow and dataTypeRow[col].lower() == 'integer': self.SetCellRenderer(row, col, gridlib.GridCellNumberRenderer()) self.SetCellValue(row, col, str(colValue)) elif dataTypeRow and dataTypeRow[col].lower() == 'datetime': self.SetCellRenderer(row, col, gridlib.GridCellDateTimeRenderer()) self.SetCellValue(row, col, colValue) elif dataTypeRow and dataTypeRow[col].lower() == 'boolean': self.SetCellEditor(row, col, gridlib.GridCellBoolEditor()) self.SetCellRenderer(row, col, CheckBoxCellRenderer(self)) self.SetCellValue(row, col, str(colValue)) self.SetCellAlignment(row, col, wx.ALIGN_RIGHT, wx.ALIGN_CENTRE) # elif dataTypeRow and dataTypeRow[col] in ['varchar', 'int']: else: # self.SetCellFont(dataKey - 1, idx, wx.Font(10, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL)) # self.SetCellTextColour(dataKey - 1, idx,wx.LIGHT_GREY) self.SetCellValue(row, col, str(colValue)) # self.SetCellAlignment(dataKey - 1,idx, wx.ALIGN_RIGHT) except Exception as e: logger.error(e, exc_info=True) else: numCols = self.GetNumberCols() numRows = self.GetNumberRows() logger.debug("numRows:%s, numCol: %s", numRows, numCols) if numRows > 0 and numCols > 0: self.DeleteCols(pos=0, numCols=numCols, updateLabels=True) self.DeleteRows(pos=0, numRows=numRows, updateLabels=True) except Exception as e: logger.error(e, exc_info=True) self.Refresh()