Re: Close cell editor
ioprst <[email protected]>
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <[email protected]> |
It solved my problem
class GridCellColourEditor(wx.grid.GridCellEditor):
def Create(self, parent, id, evtHandler):
self._parent = parent
self._colourDialog = None
self._colourButton = wx.Button(parent, id, "")
self.SetControl(self._colourButton)
newEventHandler = wx.EvtHandler()
if evtHandler:
self._colourButton.PushEventHandler(newEventHandler)
self._colourButton.Bind(wx.EVT_BUTTON, self.OnClick)
def OnClick(self, event):
self._colourButton.SetFocus()
self.ShowColourDialog()
def SetSize(self, rect):
self._colourButton.SetSize(rect.x, rect.y,
rect.width + 2, rect.height + 2,
wx.SIZE_ALLOW_MINUS_ONE)
def Clone(self):
return GridCellColourEditor()
def BeginEdit(self, row, col, grid):
self.startValue = grid.GetTable().GetValue(row, col)
self.endValue = self.startValue
self._colourButton.SetBackgroundColour(self.startValue)
self._grid = grid
self._row = row
self._col = col
self._parent.Bind(wx.EVT_LEFT_DOWN, self.OnParentLeftDown)
self._parent.Bind(wx.EVT_KILL_FOCUS, self.OnParentKillFocus)
def EndEdit(self, row, col, grid, oldval):
self._parent.Unbind(wx.EVT_LEFT_DOWN)
self._parent.Unbind(wx.EVT_KILL_FOCUS)
if self.endValue != self.startValue:
return self.endValue
else:
return None
def ApplyEdit(self, row, col, grid):
val = self.endValue.GetAsString(wx.C2S_HTML_SYNTAX)
grid.GetTable().SetValue(row, col, val)
def Reset(self):
self._colourButton.SetBackgroundColour(self.startValue)
def ShowColourDialog(self):
colourDialog = wx.ColourDialog(self._parent)
self._colourDialog = colourDialog
colourDialog.GetColourData().SetColour(self.startValue)
if colourDialog.ShowModal() == wx.ID_OK:
data = colourDialog.GetColourData()
colour = data.GetColour()
self._colourButton.SetBackgroundColour(colour)
self.endValue = colour
self._parent.SetFocus()
del self._colourDialog
self._colourDialog = None
def OnParentLeftDown(self, event: wx.MouseEvent):
def CheckCellChange():
row = self._grid.GetGridCursorRow()
col = self._grid.GetGridCursorCol()
if self._row == row and self._col == col:
# клик в области сетки, но ячейка не изменилась
self._grid.CloseEditControl()
wx.CallAfter(CheckCellChange)
event.Skip()
def OnParentKillFocus(self, event: wx.FocusEvent):
if self._parent.FindFocus() != self._colourButton:
self._grid.CloseEditControl()
event.Skip()
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/866287f3-2afa-450b-8582-76d6301a39b9%40googlegroups.com.