def OnJsonEditor(self, event=None): if event: event.Skip() dialog = Dialog() dialog.SetTitle('JSON Editor') dialog.SetSizer(wx.BoxSizer(wx.HORIZONTAL)) okBtn = wx.Button(dialog, wx.ID_OK, "Save") cnlBtn = wx.Button(dialog, wx.ID_CANCEL, "Cancel") richText = wx.TextCtrl(dialog, wx.ID_ANY, "If supported by the native " "control, this is reversed, " "and this is a different " "font.", size=(400, 475), style=wx.HSCROLL | wx.TE_MULTILINE | wx.TE_NOHIDESEL) dialog.Sizer.Add(richText, flag=wx.GROW, proportion=1) dialog.Sizer.Add(okBtn, flag=wx.ALIGN_RIGHT | wx.ALL) dialog.Sizer.Add(cnlBtn, flag=wx.ALL) # Get cell value of parent grid if self.is_json(self._current_cell_value()): jsonStr = json.loads(self._current_cell_value()) richText.SetValue(json.dumps(jsonStr, indent=4, ensure_ascii=False)) else: richText.SetValue(self._current_cell_value()) dialog.SetSize((650, 550)) # If click Save, then save the value in richText into the original # grid cell, and clear all indent. if dialog.ShowModal() == wx.ID_OK: try: strJson = json.loads(richText.GetValue()) self.cell_value_edited(self.selection.cell[0], self.selection.cell[1], json.dumps(strJson, ensure_ascii=False)) except ValueError or json.JSONDecodeError as e: res = wx.MessageDialog( dialog, "Error in JSON: {}\n\n" "Save anyway?".format(e), "Validation Error!", wx.YES_NO).ShowModal() if res == wx.ID_YES: self.cell_value_edited(self.selection.cell[0], self.selection.cell[1], richText.GetValue()) else: pass