OK I might be close but as I see it I have a text control and a button side by side but my attempts, see below, continually gpf when I exit.
Can you tell me if I'm on the right track? Do I just need to clean up properly or is there an inherent problem with setting more than one control to this class?
···
#######################################################################
from wxPython.wx import *
from wxPython.grid import *
class CustomCellChoiceEditor(wxPyGridCellEditor):
def __init__(self):
wxPyGridCellEditor.__init__(self)
def Create(self, parent, id, evtHandler):
"""
Called to create the control, which must derive from wxControl.
"""
self._t = wxTextCtrl(parent, id, 'testing')
self._tc = wxButton(parent, id, '',size=wxSize(18,18))
EVT_BUTTON(self._tc, self._tc.GetId(), self.btnClick)
self.SetControl(self._tc)
self.SetControl(self._t)
if evtHandler:
self._tc.PushEventHandler(evtHandler)
def btnClick(self, evt):
print 'yay'
def SetSize(self, rect):
"""
Called to position/size the edit control within the cell rectangle.
If you don't fill the cell (the rect) then be sure to override
PaintBackground and do something meaningful there.
"""
self._t.SetDimensions(rect.x, rect.y, rect.width-25, rect.height+4,
wxSIZE_ALLOW_MINUS_ONE)
self._tc.SetDimensions(rect.x+rect.width-20, rect.y+1, 20, rect.height,wxSIZE_ALLOW_MINUS_ONE)
def BeginEdit(self, row, col, grid):
"""
Fetch the value from the table and prepare the edit control
to begin editing. Set the focus to the edit control.
"""
self.startValue = grid.GetTable().GetValue(row, col)
self._t.SetFocus()
def EndEdit(self, row, col, grid):
"""
Complete the editing of the current cell. Returns true if the value
has changed. If necessary, the control may be destroyed.
"""
changed = false
pclDescr = self._t.GetStringSelection()
print pclDescr
return true
def Reset(self):
"""
Reset the value in the control back to its starting value.
"""
pclDescr = self._t.SetStringSelection('bla')
def Clone(self):
"""
Create a new object which is the copy of this one
"""
return CustomCellChoiceEditor()
#---------------------------------------------------------------------------
class TestFrame(wxFrame):
def __init__(self, parent):
wxFrame.__init__(self, parent, -1, "Custom Grid Cell Editor Test",
size=(400,120))
grid = wxGrid(self, 2001, size = wxSize(360, 80))
grid.CreateGrid(2, 2)
grid.SetColLabelValue(0, 'Col 1')
grid.SetColLabelValue(1, 'Col 2')
grid.SetColLabelAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE)
grid.SetColSize(1, 280)
grid.SetRowLabelSize(0)
grid.SetCellValue(1, 1, 'A')
grid.SetCellEditor(1, 1, CustomCellChoiceEditor())
#---------------------------------------------------------------------------
if __name__ == '__main__':
import sys
app = wxPySimpleApp()
frame = TestFrame(None)
frame.Show(true)
app.MainLoop()
#######################################################################
Robin Dunn wrote:
Michael Beaulieu wrote:
Ya except I need more flexibility than what I found in the demo.
I want to have the ability to populate the control at the time of the user clicking on the down arrow, or perhaps throw up a dialog before populating the values in the drop down.
This widget is fine for small table lookups, but how can I deal with something like a product lookup, where I might want to throw a search dialog up instead of the list?
Create your own class derived from wxPyGridCellEditor