def __init__(self): """Constructor""" wx.Frame.__init__(self, parent=None, title="Grid Tutorial Two", size=(800, 600)) panel = wx.Panel(self) myGrid = gridlib.Grid(panel) myGrid.CreateGrid(20, 8) myGrid.SetCellValue(0, 0, "Hello") print(myGrid.GetCellValue(0, 0)) myGrid.GetCellEditor(4, 5) # for i in range(5): # print(i) # myGrid.SelectBlock(4,i,4,i) # myGrid.SelectBlock(1,1,1,1) myGrid.SetCellValue(1, 1, "I'm in red!") myGrid.SetCellTextColour(1, 1, wx.RED) myGrid.SetCellEditor(5, 0, gridlib.GridCellNumberEditor(1, 1000)) myGrid.SetCellValue(5, 0, "123") myGrid.SetCellEditor(6, 0, gridlib.GridCellFloatEditor()) myGrid.SetCellValue(6, 0, "123.34") myGrid.SetCellEditor(7, 0, gridlib.GridCellNumberEditor()) # self.Bind(gridlib.EVT_GRID_SELECT_CELL, self.OnSelectCell) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(myGrid) panel.SetSizer(sizer)
def CreationLigne(self): """ Création d'une ligne """ numLigne = self.GetNumberRows()-1 ## if numLigne > 24 : ## dlg = wx.MessageDialog(self, _(u"Vous ne pouvez saisir qu'un maximum de 26 lignes !"), "Erreur", wx.OK | wx.ICON_EXCLAMATION) ## dlg.ShowModal() ## dlg.Destroy() ## return # Création de la ligne self.AppendRows(1) numLigne += 1 self.SetRowLabelValue(numLigne, str(numLigne+1)) #self.SetRowLabelValue(numLigne, ALPHABET[numLigne]) self.SetRowSize(numLigne, 20) # Mémorisation de la ligne if self.dictDonnees.has_key(self.code) == False : self.dictDonnees[self.code] = {} if self.dictDonnees[self.code].has_key(numLigne) == False : self.dictDonnees[self.code][numLigne] = {} # Configuration des cases numColonne = 0 for indexColonne in self.listeColonnes : codeEditeur = LISTE_COLONNES[indexColonne]["editeur"] if codeEditeur == "decimal" : renderer = gridlib.GridCellFloatRenderer(6, 2) editor = gridlib.GridCellFloatEditor(6, 2) elif codeEditeur == "decimal3" : renderer = gridlib.GridCellFloatRenderer(6, 3) editor = gridlib.GridCellFloatEditor(6, 3) elif codeEditeur == "decimal4" : renderer = gridlib.GridCellFloatRenderer(6, 4) editor = gridlib.GridCellFloatEditor(6, 4) elif codeEditeur == "decimal6" : renderer = gridlib.GridCellFloatRenderer(6, 6) editor = gridlib.GridCellFloatEditor(6, 6) elif codeEditeur == "entier" : renderer = gridlib.GridCellNumberRenderer() editor = gridlib.GridCellNumberEditor(0, 100) elif codeEditeur == "heure" : renderer = None editor = EditeurHeure() elif codeEditeur == "date" : renderer = None editor = EditeurDate() elif codeEditeur == "questionnaire" : listeChoix = [(0, ""),] for dictQuestion in self.listeQuestions : if dictQuestion["controle"] in ("montant", "decimal") : label = dictQuestion["label"] + " (%s)" % dictQuestion["type"].capitalize() listeChoix.append((dictQuestion["IDquestion"], label)) renderer = RendererChoix(listeChoix) editor = EditeurChoix(listeChoix) else: renderer = None editor = None if renderer != None : self.SetCellRenderer(numLigne, numColonne, renderer) if editor != None : self.SetCellEditor(numLigne, numColonne, editor) self.SetCellBackgroundColour(numLigne, numColonne, COULEUR_FOND_CASE) numColonne += 1
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): wx.Panel.__init__(self, parent) font = wx.Font( (0,FontSize), wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL ) self.title = wx.StaticText(self, wx.ID_ANY, u"Seeding" + u':') self.title.SetFont( font ) self.communiqueLabel = wx.StaticText( self, label=u'Communiqu\u00E9:' ) self.communiqueLabel.SetFont( font ) self.communiqueNumber = wx.TextCtrl( self, size=(64,-1) ) self.communiqueNumber.SetFont( font ) self.randomizeButton = wx.Button( self, wx.ID_ANY, 'Randomize...' ) self.randomizeButton.Bind( wx.EVT_BUTTON, self.doRandomize ) self.randomizeButton.SetFont( font ) self.importButton = wx.Button( self, wx.ID_ANY, 'Import From Excel' ) self.importButton.Bind( wx.EVT_BUTTON, self.doImportFromExcel ) self.importButton.SetFont( font ) self.headerNames = ['Bib', 'First Name', 'Last Name', 'Team', 'Team Code', 'License'] self.grid = ReorderableGrid( self, style = wx.BORDER_SUNKEN ) self.grid.DisableDragRowSize() self.grid.SetRowLabelSize( 64 ) self.grid.CreateGrid( 200, len(self.headerNames) ) self.setColNames() # Set specialized editors for appropriate columns. self.grid.SetLabelFont( font ) for col in six.moves.range(self.grid.GetNumberCols()): attr = gridlib.GridCellAttr() attr.SetFont( font ) if col == 0: attr.SetRenderer( gridlib.GridCellNumberRenderer() ) attr.SetEditor( gridlib.GridCellNumberEditor() ) self.grid.SetColAttr( col, attr ) hs = wx.BoxSizer( wx.HORIZONTAL ) hs.Add( self.title, 0, flag=wx.ALIGN_CENTRE_VERTICAL|wx.RIGHT, border = 8 ) hs.Add( self.communiqueLabel, 0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=4 ) hs.Add( self.communiqueNumber, 0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, border=4 ) hs.AddStretchSpacer() hs.Add( self.randomizeButton, 0, flag=wx.ALL, border=4 ) hs.Add( self.importButton, 0, flag=wx.ALL, border=4 ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( hs, 0, flag=wx.ALL|wx.EXPAND, border=6 ) sizer.Add( wx.StaticText(self, label=u'Set Bib to 0 to Delete row. Drag-and-drop row numbers to Change Sequence.'), flag=wx.LEFT, border = 8 ) sizer.Add(self.grid, 1, flag=wx.EXPAND|wx.ALL, border=6) self.SetSizer(sizer)
def __init__(self): """Constructor""" wx.Frame.__init__(self, parent=None, title="Grid Tutorial Two", size=(650, 320)) panel = wx.Panel(self) myGrid = gridlib.Grid(panel) myGrid.CreateGrid(15, 6) myGrid.SetCellValue(0, 0, "Hello") myGrid.SetCellFont(0, 0, wx.Font(12, wx.ROMAN, wx.ITALIC, wx.NORMAL)) print myGrid.GetCellValue(0, 0) myGrid.SetCellValue(1, 1, "I'm in red!") myGrid.SetCellTextColour(1, 1, wx.RED) myGrid.SetCellBackgroundColour(2, 2, wx.CYAN) myGrid.SetCellValue(3, 3, "This cell is read-only") myGrid.SetReadOnly(3, 3, True) myGrid.SetCellEditor(5, 0, gridlib.GridCellNumberEditor(1, 1000)) myGrid.SetCellValue(5, 0, "123") myGrid.SetCellEditor(6, 0, gridlib.GridCellFloatEditor()) myGrid.SetCellValue(6, 0, "123.34") myGrid.SetCellEditor(7, 0, gridlib.GridCellNumberEditor()) myGrid.SetCellSize(11, 1, 3, 3) myGrid.SetCellAlignment(11, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) myGrid.SetCellValue(11, 1, "This cell is set to span 3 rows and 3 columns") sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(myGrid) panel.SetSizer(sizer)
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_table(self): # set col title for idx, val in enumerate(self.columns): self.myGrid.SetColLabelValue(idx, val) self.current_lists = [] for row_id, row in self.df.iterrows(): self.myGrid.SetReadOnly(0, row_id, False) self.current_lists.append(row_id) for col_id, val in enumerate(self.columns): if self.df[val].dtype == 'object': self.myGrid.SetCellEditor(row_id, col_id, gridlib.GridCellTextEditor()) else: self.myGrid.SetCellEditor(row_id, col_id, gridlib.GridCellNumberEditor()) if str(row[val]) != 'nan': self.myGrid.SetCellValue(row_id, col_id, str(row[val])) else: self.myGrid.SetCellValue(row_id, col_id, "")
def __init__(self, parent, log): gridlib.Grid.__init__(self, parent, -1) ##mixins.GridAutoEditMixin.__init__(self) #打印log信息 self.log = log self.moveTo = None self.Bind(wx.EVT_IDLE, self.OnIdle) #创建一个25X25的电子表格 self.CreateGrid(25, 25) #, gridlib.Grid.SelectRows) ##self.EnableEditing(False) #simple cell formatting #设置第index=3列的宽度大小,像素=200 self.SetColSize(col=3, width=200) #设置第index=4行的高度大小,像素=45 self.SetRowSize(4, 45) #设置 row=0,col=0,value="First cell" self.SetCellValue(0, 0, "First cell") #设置 row=1,col=1,value="Another cell" self.SetCellValue(1, 1, "Another cell") #设置 row=2,col=2,value="Yet another cell" self.SetCellValue(2, 2, "Yet another cell") #设置 row=3,col=3,value="This cell is read-only" self.SetCellValue(3, 3, "This cell is read-only") #设置字体格式 self.SetCellFont( 0, 0, wx.Font(12, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_ITALIC, wx.FONTWEIGHT_NORMAL)) #设置字体颜色 self.SetCellTextColour(1, 1, wx.RED) #设置cell背景颜色 self.SetCellBackgroundColour(2, 2, wx.CYAN) #设置只读属性 self.SetReadOnly(3, 3, True) #设置 row=5,col=0,数字编辑器 self.SetCellEditor(5, 0, gridlib.GridCellNumberEditor(1, 1000)) #设置 row=5,col=0,value="123" self.SetCellValue(5, 0, "123") #设置 row=6,col=0,浮点数 self.SetCellEditor(6, 0, gridlib.GridCellFloatEditor()) #设置 row=6,col=0,value="123.34" self.SetCellValue(6, 0, "123.34") #设置 self.SetCellEditor(7, 0, gridlib.GridCellNumberEditor()) #设置 row=6,col=3,value="You can veto editing this cell" self.SetCellValue(6, 3, "You can veto editing this cell") #self.SetRowLabelSize(0) #self.SetColLabelSize(0) # attribute objects let you keep a set of formatting values # in one spot, and reuse them if needed #wx.grid.GridCellAttr #这个类可以用来通过改变它们的默认属性来改变网格在网格中的外观。 attr = gridlib.GridCellAttr() #字体颜色:黑色 attr.SetTextColour(wx.BLACK) #设置背景颜色:红色 attr.SetBackgroundColour(wx.RED) #设置字体格式 attr.SetFont( wx.Font(10, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) # you can set cell attributes for the whole row (or column) #设置Row=5,attr self.SetRowAttr(5, attr) #设置Col=0,LableValue =Custom self.SetColLabelValue(0, "Custom") self.SetRowLabelValue(0, "日期") #设置Col=1,LabelValue = "column" self.SetColLabelValue(1, "column") #设置Col=2,LabelValue = labels self.SetColLabelValue(2, "labels") #设置列表标签左右以及上下对齐方式:左对齐,下沉 self.SetColLabelAlignment(wx.ALIGN_LEFT, wx.ALIGN_BOTTOM) #self.SetDefaultCellOverflow(False) #r = gridlib.GridCellAutoWrapStringRenderer() #self.SetCellRenderer(9, 1, r) #overflow cells self.SetCellValue( 9, 1, "This default cell will overflow into neighboring cells, but not if you turn overflow off." ) #单元格合并处理:3x3 self.SetCellSize(11, 1, 3, 3) #设置单元格对齐方式:中间,中间 self.SetCellAlignment(11, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) #设置单元格值 self.SetCellValue(11, 1, "This cell is set to span 3 rows and 3 columns") #设置 editor = gridlib.GridCellTextEditor() #值长度 editor.SetParameters('10') #设置格式 self.SetCellEditor(0, 4, editor) #设置值 self.SetCellValue(0, 4, "Limited text") #可以用来格式化单元格中的字符串数据。 renderer = gridlib.GridCellAutoWrapStringRenderer() self.SetCellRenderer(15, 0, renderer) self.SetCellValue( 15, 0, "The text in this cell will be rendered with word-wrapping") # test all the events #左单击 self.Bind(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick) #右单击 self.Bind(gridlib.EVT_GRID_CELL_RIGHT_CLICK, self.OnCellRightClick) #左双击 self.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.OnCellLeftDClick) #右双击 self.Bind(gridlib.EVT_GRID_CELL_RIGHT_DCLICK, self.OnCellRightDClick) #label 左单击 self.Bind(gridlib.EVT_GRID_LABEL_LEFT_CLICK, self.OnLabelLeftClick) #label 右单击 self.Bind(gridlib.EVT_GRID_LABEL_RIGHT_CLICK, self.OnLabelRightClick) #label 左双击 self.Bind(gridlib.EVT_GRID_LABEL_LEFT_DCLICK, self.OnLabelLeftDClick) #label 右双击 self.Bind(gridlib.EVT_GRID_LABEL_RIGHT_DCLICK, self.OnLabelRightDClick) self.Bind(gridlib.EVT_GRID_COL_SORT, self.OnGridColSort) #拖动Row大小 self.Bind(gridlib.EVT_GRID_ROW_SIZE, self.OnRowSize) #拖动Col大小 self.Bind(gridlib.EVT_GRID_COL_SIZE, self.OnColSize) self.Bind(gridlib.EVT_GRID_RANGE_SELECT, self.OnRangeSelect) self.Bind(gridlib.EVT_GRID_CELL_CHANGED, self.OnCellChange) self.Bind(gridlib.EVT_GRID_SELECT_CELL, self.OnSelectCell) self.Bind(gridlib.EVT_GRID_EDITOR_SHOWN, self.OnEditorShown) self.Bind(gridlib.EVT_GRID_EDITOR_HIDDEN, self.OnEditorHidden) self.Bind(gridlib.EVT_GRID_EDITOR_CREATED, self.OnEditorCreated)
def __init__(self, parent, log): gridlib.Grid.__init__(self, parent, -1) ##mixins.GridAutoEditMixin.__init__(self) self.log = log self.moveTo = None self.Bind(wx.EVT_IDLE, self.OnIdle) self.CreateGrid(25, 25)#, gridlib.Grid.SelectRows) ##self.EnableEditing(False) # simple cell formatting self.SetColSize(3, 200) self.SetRowSize(4, 45) self.SetCellValue(0, 0, "First cell") self.SetCellValue(1, 1, "Another cell") self.SetCellValue(2, 2, "Yet another cell") self.SetCellValue(3, 3, "This cell is read-only") self.SetCellFont(0, 0, wx.Font(12, wx.ROMAN, wx.ITALIC, wx.NORMAL)) self.SetCellTextColour(1, 1, wx.RED) self.SetCellBackgroundColour(2, 2, wx.CYAN) self.SetReadOnly(3, 3, True) self.SetCellEditor(5, 0, gridlib.GridCellNumberEditor(1,1000)) self.SetCellValue(5, 0, "123") self.SetCellEditor(6, 0, gridlib.GridCellFloatEditor()) self.SetCellValue(6, 0, "123.34") self.SetCellEditor(7, 0, gridlib.GridCellNumberEditor()) self.SetCellValue(6, 3, "You can veto editing this cell") #self.SetRowLabelSize(0) #self.SetColLabelSize(0) # attribute objects let you keep a set of formatting values # in one spot, and reuse them if needed attr = gridlib.GridCellAttr() attr.SetTextColour(wx.BLACK) attr.SetBackgroundColour(wx.RED) attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) # you can set cell attributes for the whole row (or column) self.SetRowAttr(5, attr) self.SetColLabelValue(0, "Custom") self.SetColLabelValue(1, "column") self.SetColLabelValue(2, "labels") self.SetColLabelAlignment(wx.ALIGN_LEFT, wx.ALIGN_BOTTOM) #self.SetDefaultCellOverflow(False) #r = gridlib.GridCellAutoWrapStringRenderer() #self.SetCellRenderer(9, 1, r) # overflow cells self.SetCellValue( 9, 1, "This default cell will overflow into neighboring cells, but not if you turn overflow off."); self.SetCellSize(11, 1, 3, 3); self.SetCellAlignment(11, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE); self.SetCellValue(11, 1, "This cell is set to span 3 rows and 3 columns"); editor = gridlib.GridCellTextEditor() editor.SetParameters('10') self.SetCellEditor(0, 4, editor) self.SetCellValue(0, 4, "Limited text") renderer = gridlib.GridCellAutoWrapStringRenderer() self.SetCellRenderer(15,0, renderer) self.SetCellValue(15,0, "The text in this cell will be rendered with word-wrapping") # test all the events self.Bind(gridlib.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick) self.Bind(gridlib.EVT_GRID_CELL_RIGHT_CLICK, self.OnCellRightClick) self.Bind(gridlib.EVT_GRID_CELL_LEFT_DCLICK, self.OnCellLeftDClick) self.Bind(gridlib.EVT_GRID_CELL_RIGHT_DCLICK, self.OnCellRightDClick) self.Bind(gridlib.EVT_GRID_LABEL_LEFT_CLICK, self.OnLabelLeftClick) self.Bind(gridlib.EVT_GRID_LABEL_RIGHT_CLICK, self.OnLabelRightClick) self.Bind(gridlib.EVT_GRID_LABEL_LEFT_DCLICK, self.OnLabelLeftDClick) self.Bind(gridlib.EVT_GRID_LABEL_RIGHT_DCLICK, self.OnLabelRightDClick) self.Bind(gridlib.EVT_GRID_ROW_SIZE, self.OnRowSize) self.Bind(gridlib.EVT_GRID_COL_SIZE, self.OnColSize) self.Bind(gridlib.EVT_GRID_RANGE_SELECT, self.OnRangeSelect) self.Bind(gridlib.EVT_GRID_CELL_CHANGE, self.OnCellChange) self.Bind(gridlib.EVT_GRID_SELECT_CELL, self.OnSelectCell) self.Bind(gridlib.EVT_GRID_EDITOR_SHOWN, self.OnEditorShown) self.Bind(gridlib.EVT_GRID_EDITOR_HIDDEN, self.OnEditorHidden) self.Bind(gridlib.EVT_GRID_EDITOR_CREATED, self.OnEditorCreated)
def editor(self): return gridlib.GridCellNumberEditor(*self.args)
def __init__( self, parent, controller, id = wx.ID_ANY ): wx.Panel.__init__(self, parent, id) self.SetBackgroundColour( wx.WHITE ) self.controller = controller self.headerNames = [_('Time'), _('Bib')] self.maxRows = 10 fontSize = 18 self.font = wx.FontFromPixelSize( wx.Size(0,fontSize), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL ) self.bigFont = wx.FontFromPixelSize( wx.Size(0,int(fontSize*1.3)), wx.FONTFAMILY_SWISS, wx.NORMAL, wx.FONTWEIGHT_NORMAL ) self.vbs = wx.BoxSizer(wx.VERTICAL) tapForTimeLabel = _('Tap for Time') if 'WXMAC' in wx.Platform: self.recordTimeButton = wx.lib.buttons.ThemedGenButton( self, label=tapForTimeLabel ) self.recordTimeButton.Bind( wx.EVT_BUTTON, self.doRecordTime ) else: self.recordTimeButton = wx.Button( self, label=tapForTimeLabel ) self.recordTimeButton.Bind( wx.EVT_LEFT_DOWN, self.doRecordTime ) self.recordTimeButton.SetFont( self.bigFont ) self.recordTimeButton.SetToolTip(wx.ToolTip(u'\n'.join( [_('Tap to Record Times (or press the "t" key).'), _('Then enter the Bib numbers and Save as soon as possible.')]) )) hbs = wx.BoxSizer( wx.HORIZONTAL ) hbs.Add( self.recordTimeButton, 0 ) self.grid = ReorderableGrid( self, style = wx.BORDER_SUNKEN ) self.grid.SetFont( self.font ) self.grid.EnableReorderRows( False ) dc = wx.WindowDC( self.grid ) dc.SetFont( self.font ) width, height = dc.GetTextExtent(" 999 ") self.rowLabelSize = width self.grid.SetRowLabelSize( self.rowLabelSize ) self.grid.CreateGrid( self.maxRows, len(self.headerNames) ) self.grid.Bind( gridlib.EVT_GRID_LABEL_LEFT_CLICK, self.doClickLabel ) for col, name in enumerate(self.headerNames): self.grid.SetColLabelValue( col, name ) self.grid.SetLabelFont( self.font ) for col in xrange(self.grid.GetNumberCols()): attr = gridlib.GridCellAttr() attr.SetFont( self.font ) if col == 0: attr.SetEditor( HighPrecisionTimeEditor() ) elif col == 1: attr.SetRenderer( gridlib.GridCellNumberRenderer() ) attr.SetEditor( gridlib.GridCellNumberEditor() ) self.grid.SetColAttr( col, attr ) saveLabel = _('Save') if 'WXMAC' in wx.Platform: self.commitButton = wx.lib.buttons.ThemedGenButton( self, label=saveLabel ) else: self.commitButton = wx.Button( self, label=saveLabel ) self.commitButton.Bind( wx.EVT_BUTTON, self.doCommit ) self.commitButton.SetFont( self.bigFont ) self.commitButton.SetToolTip(wx.ToolTip(_('Save Entries (or press the "s" key)'))) self.vbs.Add( hbs, 0, flag=wx.ALL|wx.EXPAND, border = 4 ) self.vbs.Add( self.grid, 1, flag=wx.ALL|wx.EXPAND, border = 4 ) self.vbs.Add( self.commitButton, flag=wx.ALL|wx.ALIGN_RIGHT, border = 4 ) idRecordAcceleratorId, idCommitAccelleratorId = wx.NewId(), wx.NewId() self.Bind(wx.EVT_MENU, self.doRecordTime, id=idRecordAcceleratorId) self.Bind(wx.EVT_MENU, self.doCommit, id=idCommitAccelleratorId) accel_tbl = wx.AcceleratorTable([ (wx.ACCEL_NORMAL, ord('T'), idRecordAcceleratorId), (wx.ACCEL_NORMAL, ord('S'), idCommitAccelleratorId), ]) self.SetAcceleratorTable(accel_tbl) self.SetSizer(self.vbs) self.Fit()
def on_initialize(self, event): self.log = sys.stdout self.moveTo = None ## wx.EVT_IDLE(self, self.OnIdle) mygrid = self.components.mygrid mygrid.CreateGrid(25, 25) #, wxGrid.wxGridSelectRows) ##mygrid.EnableEditing(False) # simple cell formatting mygrid.SetColSize(3, 200) mygrid.SetRowSize(4, 45) mygrid.SetCellValue(0, 0, "First cell") mygrid.SetCellValue(1, 1, "Another cell") mygrid.SetCellValue(2, 2, "Yet another cell") mygrid.SetCellValue(3, 3, "This cell is read-only") mygrid.SetCellFont(0, 0, wx.Font(12, wx.ROMAN, wx.ITALIC, wx.NORMAL)) mygrid.SetCellTextColour(1, 1, wx.RED) mygrid.SetCellBackgroundColour(2, 2, wx.CYAN) mygrid.SetReadOnly(3, 3, True) mygrid.SetCellEditor(5, 0, grid.GridCellNumberEditor(1, 1000)) mygrid.SetCellValue(5, 0, "123") mygrid.SetCellEditor(6, 0, grid.GridCellFloatEditor()) mygrid.SetCellValue(6, 0, "123.34") mygrid.SetCellEditor(7, 0, grid.GridCellNumberEditor()) mygrid.SetCellValue(6, 3, "You can veto editing this cell") # attribute objects let you keep a set of formatting values # in one spot, and reuse them if needed attr = grid.GridCellAttr() attr.SetTextColour(wx.BLACK) attr.SetBackgroundColour(wx.RED) attr.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) # you can set cell attributes for the whole row (or column) mygrid.SetRowAttr(5, attr) mygrid.SetColLabelValue(0, "Custom") mygrid.SetColLabelValue(1, "column") mygrid.SetColLabelValue(2, "labels") mygrid.SetColLabelAlignment(wx.ALIGN_LEFT, wx.ALIGN_BOTTOM) #mygrid.SetDefaultCellOverflow(False) #r = wx.GridCellAutoWrapStringRenderer() #mygrid.SetCellRenderer(9, 1, r) # overflow cells mygrid.SetCellValue( 9, 1, "This default cell will overflow into neighboring cells, but not if you turn overflow off." ) mygrid.SetCellSize(11, 1, 3, 3) mygrid.SetCellAlignment(11, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) mygrid.SetCellValue(11, 1, "This cell is set to span 3 rows and 3 columns") sizer1 = wx.BoxSizer(wx.VERTICAL) sizer1.Add(self.components.mygrid, 1, wx.EXPAND) sizer1.Fit(self) sizer1.SetSizeHints(self) self.panel.SetSizer(sizer1) self.panel.SetAutoLayout(1) self.panel.Layout()