Wxpython Control learning Wx.grid.Grid (including extensions to Gridcelleditor and Gridcelrender to support more grid cell styles, gridcellcoloreditor as an example)
Wx. A Grid and its associated classes are data used to display and edit the style of a class table. The control is displayed, and editing the data source mentions the interaction for rich features.
Wx. The Gridtablebase class controls the actual data to be displayed. You can call Creategrid () to produce an instance object of that class.
Wx. Gridcellrenderer the base class, which is responsible for painting the cells. Several of the default derivations are now available.
- Wxgridcellboolrenderer Show checkbox Style
- Wxgridcellfloatrenderer
- Wxgridcellnumberrenderer
- Wxgridcellstringrenderer
Wx. The Gridcelleditor base class, which is responsible for displaying the corresponding control in the cell editing state. Several of the default derivations are now available.
- Wxgridcellbooleditor
- Wxgridcellchoiceeditor
- Wxgridcellfloateditor
- Wxgridcellnumbereditor
- Wxgridcelltexteditor
How do I add, delete rows, columns, and cells?
In this example, settable () is used as the data source for the grid. Then focus on how the grid and data sources are being censored in this case.
The Gridtablemessage class, which can be used to send some message to the table, in this case, add and subtract rows, then we only need to use one of the 3 message:
Gridtable_notify_rows_inserted message inserted in line
Message for new line near Gridtable_notify_rows_appended
gridtable_notify_rows_deleted Delete a line message
Gridtable_request_view_get_values cell Value If there is a change in the message
1. Insert a new row at index
Grd. Gridtablemessage (Self,
Grd. gridtable_notify_rows_inserted
The index where the row is located
, 1 inserts a row of records
)
2. Delete rowindex lines
Grd. Gridtablemessage (SELF,GRD. Gridtable_notify_rows_deleted,
RowIndex, the index where the row is located
1 Delete Only one row
)
3. Attach a new row
Grd. Gridtablemessage (Self,
Grd. Gridtable_notify_rows_appended,
Number of new rows near 1
)
1 #-*-coding:utf-82 3 #-------------------------------------------------------------------------------4 #Name: Module 15 #Purpose:6 #7 #Author:ankier8 #9 #created:14/10/2012Ten #Copyright: (c) Ankier One #Licence: <your licence> A #------------------------------------------------------------------------------- - - ImportWX, Wx.grid as GRD the - #ordered grid cell ComboBox editor - classGridcellcomboboxeditor (GRD. Pygridcelleditor): - def __init__(Self, choices = []): +Grd. Pygridcelleditor.__init__(self) -Self.__choices=Choices + A defCreate (self, parent, ID, Evthandler): at """ - called to create the control, which must derive from WX. Control. - *must override* - """ -Self.__parent=Parent -Self.__comboboxdialog=None inSelf.__comboboxbutton= Wx.combobox (parent, id, value ="", Choices =self.__choices) -Self.__comboboxbutton. Seteditable (False) toSelf. Setcontrol (self.__comboboxbutton) + #Add new event handler to prevent pop-up window after cell auto editor -Neweventhandler =Wx._core. Evthandler () the ifEvthandler: *Self.__comboboxbutton. Pusheventhandler (Neweventhandler) $Self.__comboboxbutton. Bind (WX. Evt_combobox, self. OnClick)Panax Notoginseng - the defOnClick (Self, event): +Self.endvalue = self.__comboboxbutton. Getstringselection () A the + defSetSize (Self, rect): - """ $ called to position/size the edit control within the cell rectangle. $ If you don ' t fill the cell (the rect) then is sure to override - Paintbackground and do something meaningful there. - """ theSelf.__comboboxbutton. Setdimensions (rect.x,rect.y,rect.width+2,rect.height+2, WX. Size_allow_minus_one) - Wuyi defClone (self): the """ - Create a new object which is the copy of this one Wu *must override* - """ About returnGridcellcomboboxeditor () $ - defBeginEdit (self, row, col, grid): - """ - Fetch the value from the table and prepare the edit control A to begin editing. Set the focus to the edit control. + *must override* the """ -Self.startvalue =grid. GetTable (). GetValue (Row, col) $Self.endvalue =Self.startvalue theSelf.__comboboxbutton. Setstringselection (Self.startvalue) the the defEndEdit (self, row, col, grid): the """ - Complete the editing of the current cell. Returns True If the value in Has changed. If necessary, the control may be destroyed. the *must override* the """ AboutChanged =False the ifSelf.endvalue! =Self.startvalue: theChanged =True theGrid. GetTable (). SetValue (Row, col, Self.endvalue)#Update the table +Self.startvalue ="' - returnchanged the Bayi the the #Order Color cell colour column - classGridcellcomboboxrender (GRD. Gridcellstringrenderer): - def __init__(self): theGrd. Gridcellstringrenderer.__init__(self)
Transfer from http://www.cnblogs.com/ankier/archive/2012/10/14/2723364.html
Wxpython Control Learning Wx.grid.Grid Table control