def ResetView(self): """Trim/extend the control's rows and update all values""" self.GetGrid().BeginBatch() for current, new, delmsg, addmsg in [ (self.grid.GetNumberRows(), self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), (self.grid.GetNumberCols(), self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), ]: if new < current: msg = wx.grid.GridTableMessage( self, delmsg, new, # position current - new, ) self.GetGrid().ProcessTableMessage(msg) elif new > current: msg = wx.grid.GridTableMessage(self, addmsg, new - current) self.GetGrid().ProcessTableMessage(msg) self.UpdateValues() self.GetGrid().EndBatch() # The scroll bars aren't resized (at least on windows) # Jiggling the size of the window rescales the scrollbars grid = self.GetGrid() h, w = grid.GetSize() grid.SetSize((h + 1, w)) grid.SetSize((h, w)) grid.ForceRefresh()
def ResetView(self): """Trim/extend the control's rows and update all values""" grid=self.getGrid() grid.BeginBatch() for current, new, delmsg, addmsg in [ (self.currentRows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), (self.currentCols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), ]: if new < current: msg = wx.grid.GridTableMessage(self, delmsg, new, current-new) #for i in range(current-new): grid.ProcessTableMessage(msg) self.currentRows=new elif new > current: msg = wx.grid.GridTableMessage(self, addmsg, new-current) grid.ProcessTableMessage(msg) self.currentRows=new self.UpdateValues() if len(self._obj)==0: ml=8 else: ml=max([len(x[0]) for x in self._obj]) grid.SetRowLabelSize(ml*10) #10 is an ad-hoc number grid.EndBatch() # print 'current row', self.currentRows # The scroll bars aren't resized (at least on windows) # Jiggling the size of the window rescales the scrollbars w, h = grid.GetSize() grid.SetSize((w+1, h)) grid.SetSize((w, h)) grid.ForceRefresh()
def setGridProperties(variableObj): for grid in variableObj.gridList: grid.SetCellBackgroundColour(0,0,variableObj.constantObj.COLOR_LABEL) #SETTING COLOR FOR CELL (0,0) grid.SetSize((variableObj.maximizedFrameSize[0])-100,variableObj.maximizedFrameSize[1] - 150) #setting the (width, height) in pixels of the grid grid.SetColMinimalAcceptableWidth(70) #setting minimum length of a column possible(in pixel) grid.SetDefaultCellAlignment(ALIGN_CENTRE,ALIGN_CENTRE) #values will be centered aligned grid.AutoSizeColumns() #column will be set to the size of longest element in the column
def creategrid(self): """创建购物车表格""" # 创建网格对象 grid = wx.grid.Grid(self.contentpanel, name='grid') # 初始化表格 # 创建网格中所需的表格 table = CartGridTable(self.data) # 设置网格的表格属性 grid.SetTable(table, True) grid.SetSize(1000, 600) # 设置网格所有行高 rowsizeinfo = wx.grid.GridSizesInfo(40, []) grid.SetRowSizes(rowsizeinfo) # 设置网格所有列宽 colsizeinfo = wx.grid.GridSizesInfo(176, []) grid.SetColSizes(colsizeinfo) # 设置单元格默认字体 grid.SetDefaultCellFont(wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, faceName='微软雅黑')) # 设置行和列标题的默认字体 grid.SetLabelFont(wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, faceName='微软雅黑')) # 设置表格选择模式为行选择 grid.SetSelectionMode(grid.wxGridSelectRows) # 设置不能通过拖动改变行高度 grid.DisableDragRowSize() # 设置不能通过拖动改变列宽度 grid.DisableDragColSize() return grid