IDE: Add a "undo" button for each field in CTN config panel to reset to default value.
--- a/editors/ConfTreeNodeEditor.py Thu Jul 22 12:03:34 2021 +0200
+++ b/editors/ConfTreeNodeEditor.py Fri Jul 23 13:15:19 2021 +0200
@@ -385,7 +385,7 @@
element_infos["children"],
element_path)
else:
- boxsizer = wx.FlexGridSizer(cols=3, rows=1)
+ boxsizer = wx.FlexGridSizer(cols=4, rows=1)
boxsizer.AddGrowableCol(1)
flags = (wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)
if first:
@@ -472,8 +472,9 @@
else:
if element_infos["type"] == "boolean":
- checkbox = wx.CheckBox(self.ParamsEditor, size=wx.Size(17, 25))
- boxsizer.AddWindow(checkbox)
+ checkbox = wx.CheckBox(self.ParamsEditor)
+ boxsizer.AddWindow(checkbox, border=5,
+ flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT)
if element_infos["value"] is not None:
checkbox.SetValue(element_infos["value"])
checkbox.Bind(wx.EVT_CHECKBOX,
@@ -526,6 +527,16 @@
textctrl.Bind(wx.EVT_TEXT_ENTER, callback)
textctrl.Bind(wx.EVT_TEXT, callback)
textctrl.Bind(wx.EVT_KILL_FOCUS, callback)
+
+ if not isinstance(element_infos["type"], list) and element_infos["use"] == "optional":
+ bt = wx.BitmapButton(self.ParamsEditor,
+ bitmap=wx.ArtProvider.GetBitmap(wx.ART_UNDO, wx.ART_TOOLBAR, (16,16)),
+ style=wx.BORDER_NONE)
+ self.Bind(wx.EVT_BUTTON,
+ self.GetResetFunction(element_path),
+ bt)
+
+ boxsizer.AddWindow(bt)
first = False
sizer.Layout()
self.RefreshScrollbars()
@@ -590,6 +601,13 @@
event.Skip()
return OnTextCtrlChanged
+ def GetResetFunction(self, path):
+ def OnResetBt(event):
+ res = self.SetConfNodeParamsAttribute(path, None)
+ wx.CallAfter(self.RefreshView)
+ event.Skip()
+ return OnResetBt
+
def GetCheckBoxCallBackFunction(self, chkbx, path):
def OnCheckBoxChanged(event):
res = self.SetConfNodeParamsAttribute(path, chkbx.IsChecked())
--- a/xmlclass/xmlclass.py Thu Jul 22 12:03:34 2021 +0200
+++ b/xmlclass/xmlclass.py Fri Jul 23 13:15:19 2021 +0200
@@ -1522,7 +1522,7 @@
raise ValueError("Wrong path!")
if attributes[parts[0]]["attr_type"]["basename"] == "boolean":
setattr(self, parts[0], value)
- elif attributes[parts[0]]["use"] == "optional" and value == "":
+ elif attributes[parts[0]]["use"] == "optional" and value == None:
if "default" in attributes[parts[0]]:
setattr(self, parts[0],
attributes[parts[0]]["attr_type"]["extract"](