I sent this a month ago, but got no reply...so I'll try once more:
Can anyone figure out what I'm doing wrong here?
···
I can't undo my grid editing by pressing escape in my
grid cells. Nothing happens on the escape key. It works
without the custom cell editor (but then I loose some
required features) and my cell editor is basically copied
from the demo. Escaping editing works in the demo...I have a feeling this is a trivial oversight, but I can't
see what I'm doing wrong here...Snippets attached.
From my grid class __init__()
attr2 = wxGridCellAttr()
cellEditor = NameCellEditor()
cellEditor.grid = self # Since BeginEdit needs stuff...
attr2.SetEditor(cellEditor) # <= Remove this line, and ESC works...
self.SetColAttr(2, attr2)
self.Refresh()And then my cell editor where I've basically copied GridCustEditor.py
from the Demo. I've skipped __init__, Show, PaintBackground, StartingClick
and Destroy. Then I've changed BeginEdit and EndEdit to add my features.class NameCellEditor(wxPyGridCellEditor):
"""
This is the editor for catalog item names.
Its reason for existence is to make sure that the extra information
shown after the item name is removed before we edit, and returned
when we have left the cell. (OnIdle--since other code actually update
our data.)This class is based on MyCellEditor in GridCustEditor.py in the Demo.
"""def Create(self, parent, id, evtHandler):
"""Copy of Demo GridCustEditor.py"""
self._tc = wxTextCtrl(parent, id, "")
self._tc.SetInsertionPoint(0)
self.SetControl(self._tc)
if evtHandler:
self._tc.PushEventHandler(evtHandler)def SetSize(self, rect):
"""Copy of Demo GridCustEditor.py"""
self._tc.SetDimensions(rect.x, rect.y, rect.width+2, rect.height+2,
wxSIZE_ALLOW_MINUS_ONE)def BeginEdit(self, row, col, grid):
"""
Fetch mainName attribute from the underlying item and prepare
the edit control to begin editing. Set the focus to the edit control.
"""# Note that we don't use startValue from the Grid but from the
# logic layer. (SystemMatrix class.)
item = self.grid.getMatrix().getItem(self.grid.itemType, row)
if item:
self.startValue = item.mainName
else:
self.startValue = ""
self._tc.SetValue(self.startValue)
self._tc.SetInsertionPointEnd()
self._tc.SetFocus()def EndEdit(self, row, col, grid):
"""
Do the ususal, stuff, then ask OnIdle to refill the grid from
the logic layer (SystemMatrix class) to get back the tail on the text.
"""
changed = falseval = self._tc.GetValue()
if val != self.startValue:
changed = true
grid.GetTable().SetValue(row, col, val)
# Make sure that the "tail" is added to the grid cell after
# the new value has been processed.
self.grid.doRefill = 1self.startValue = ''
self._tc.SetValue('')
return changeddef Reset(self):
"""Copy of Demo GridCustEditor.py"""
self._tc.SetValue(self.startValue)
self._tc.SetInsertionPointEnd()def IsAcceptedKey(self, evt):
"""Copy of Demo GridCustEditor.py"""
return (not (evt.ControlDown() or evt.AltDown()) and
evt.GetKeyCode() != WXK_SHIFT)def StartingKey(self, evt):
"""Copy of Demo GridCustEditor.py"""
key = evt.GetKeyCode()
ch = None
if key in [WXK_NUMPAD0, WXK_NUMPAD1, WXK_NUMPAD2, WXK_NUMPAD3, WXK_NUMPAD4,
WXK_NUMPAD5, WXK_NUMPAD6, WXK_NUMPAD7, WXK_NUMPAD8, WXK_NUMPAD9]:
ch = ch = chr(ord('0') + key - WXK_NUMPAD0)elif key < 256 and key >= 0 and chr(key) in string.printable:
ch = chr(key)
if not evt.ShiftDown():
ch = string.lower(ch)if ch is not None:
self._tc.SetValue(ch)
else:
evt.Skip()def Clone(self):
"""Copy of Demo GridCustEditor.py"""
return NameCellEditor(self.log)
--
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se