Core Windows/Controls → Grid
wxPhoenix
|
1#
wxPhoenix 发表于 2007-04-19 18:59
Core Windows/Controls → Gridimport wx import wx.grid class Frame(wx.Frame): def __init__( self, parent=None, id=-1, title='wx.grid.Grid', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE ): wx.Frame.__init__(self, parent, id, title, pos, size, style) self.SetIcon(wx.Icon('wxWidgets.ico', wx.BITMAP_TYPE_ICO)) self.CreateStatusBar() self.Grid = wx.grid.Grid(self, -1) self.Grid.CreateGrid(6, 6) self.Grid.SetCellEditor(0, 0, wx.grid.GridCellNumberEditor(1, 1000)) self.Grid.SetCellValue(0, 0, '100') self.Grid.SetCellEditor(1, 0, wx.grid.GridCellFloatEditor()) self.Grid.SetCellValue(1, 0, '3.14') TextEditor = wx.grid.GridCellTextEditor() TextEditor.SetParameters('6') # What is meaning? self.Grid.SetCellEditor(2, 0, TextEditor) self.Grid.SetCellValue(2, 0, 'Python C++') self.Grid.SetCellEditor(3, 0, wx.grid.GridCellBoolEditor()) # self.Grid.SetCellValue(3, 0, 'True') Languages = ['C', 'C++', 'Python', 'Java', 'Perl', 'Ruby'] ChoiceEditor = wx.grid.GridCellChoiceEditor(Languages) self.Grid.SetCellEditor(4, 0, ChoiceEditor) self.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnCellLeftClick) self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnCellRightClick) self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnCellLeftDClick) self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_DCLICK, self.OnCellRightDClick) self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_CLICK, self.OnLabelLeftClick) self.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_CLICK, self.OnLabelRightClick) self.Bind(wx.grid.EVT_GRID_LABEL_LEFT_DCLICK, self.OnLabelLeftDClick) self.Bind(wx.grid.EVT_GRID_LABEL_RIGHT_DCLICK, self.OnLabelRightDClick) self.Bind(wx.grid.EVT_GRID_ROW_SIZE, self.OnRowSize) self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.OnColSize) self.Bind(wx.grid.EVT_GRID_RANGE_SELECT, self.OnRangeSelect) self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnCellChange) self.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnSelectCell) self.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnEditorShown) self.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.OnEditorHidden) self.Bind(wx.grid.EVT_GRID_EDITOR_CREATED, self.OnEditorCreated) def OnCellLeftClick(self, event): self.SetStatusText('You Have Left-Clicked On Cell(%d, %d)!' % (event.GetRow(), event.GetCol())) # Attention! # Normally event must skip to wx.grid.Grid # Of course event can veto. event.Skip() def OnCellRightClick(self, event): self.SetStatusText('You Have Right-Clicked One Cell(%d, %d)!' % (event.GetRow(), event.GetCol())) event.Skip() def OnCellLeftDClick(self, event): self.SetStatusText('You Have Left-Double-Clicked One Cell(%d, %d)!' % (event.GetRow(), event.GetCol())) event.Skip() def OnCellRightDClick(self, event): self.SetStatusText('You Have Right-Double-Clicked One Cell(%d, %d)!' % (event.GetRow(), event.GetCol())) event.Skip() def OnLabelLeftClick(self, event): self.SetStatusText('You Have Left-Clicked On Label "%s"!' % event.GetString()) event.Skip() def OnLabelRightClick(self, event): self.SetStatusText('You Have Right-Clicked On Label "%s"!' % event.GetString()) event.Skip() def OnLabelLeftDClick(self, event): self.SetStatusText('You Have Left-Double-Clicked On Label "%s"!' % event.GetString()) event.Skip() def OnLabelRightDClick(self, event): self.SetStatusText('You Have Right-Double-Clicked On Label "%s"!' % event.GetString()) event.Skip() def OnRowSize(self, event): self.SetStatusText('The Size of Row %d Has Been Changed!' % event.GetRowOrCol()) event.Skip() def OnColSize(self, event): self.SetStatusText('The Size of Col %d Has Been Changed!' % event.GetRowOrCol()) event.Skip() def OnRangeSelect(self, event): self.SetStatusText('Cell(%d, %d) ~ Cell(%d, %d) Has Been Selected!' %\ (event.GetTopRow(), event.GetLeftCol(), event.GetBottomRow(), event.GetRightCol())) event.Skip() def OnCellChange(self, event): self.SetStatusText('Cell(%d, %d) Has Been Changed!' % (event.GetRow(), event.GetCol())) event.Skip() def OnSelectCell(self, event): self.SetStatusText('Cell(%d, %d) Has Been Selected!' % (event.GetRow(), event.GetCol())) event.Skip() def OnEditorShown(self, event): self.SetStatusText('Editor Has Been Shown On Cell(%d, %d)' % (event.GetRow(), event.GetCol())) event.Skip() def OnEditorHidden(self, event): self.SetStatusText('Editor Has Been Hidden On Cell(%d, %d)' % (event.GetRow(), event.GetCol())) event.Skip() def OnEditorCreated(self, event): self.SetStatusText('Editor Has Been Created On Cell(%d, %d)' % (event.GetRow(), event.GetCol())) event.Skip() def TestFrame(): app = wx.PySimpleApp() frame = Frame(size=(640, 480)) frame.Centre() frame.Show() app.MainLoop() if __name__ == '__main__': TestFrame() |