add button to ForceVariableDialog to toggle forced boolean value
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 21 Jun 2017 17:08:52 +0300
changeset 1701 8337f6c169d0
parent 1700 df50e13a94d6
child 1702 bbb2c38969ca
add button to ForceVariableDialog to toggle forced boolean value

Button is added only for boolean variables.
dialogs/ForceVariableDialog.py
--- a/dialogs/ForceVariableDialog.py	Tue Jun 20 18:57:29 2017 +0300
+++ b/dialogs/ForceVariableDialog.py	Wed Jun 21 17:08:52 2017 +0300
@@ -167,10 +167,28 @@
         
         self.Bind(wx.EVT_BUTTON, self.OnOK, 
               self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton())
-        
+        self.ValueTextCtrl=self.GetSizer().GetItem(1).GetWindow()
+        if self.IEC_Type == "BOOL":
+            self.ToggleButton = wx.ToggleButton(self, label=_("Toggle value"))
+            value=GetTypeValue[self.IEC_Type](defaultValue)
+            if value is not None:
+                self.ToggleButton.SetValue(value)
+
+            border=self.GetSizer().GetItem(1).GetBorder()
+            self.GetSizer().Insert(before=2, item=self.ToggleButton,
+                                   border=border,
+                                   flag=wx.LEFT|wx.RIGHT|wx.EXPAND)
+            self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleBoolValue, self.ToggleButton)
+
+        self.Fit()
+
+    def ToggleBoolValue(self, event):
+        value=self.ToggleButton.GetValue()
+        self.ValueTextCtrl.SetValue(unicode(value))
+
     def OnOK(self, event):
         message = None
-        value = self.GetSizer().GetItem(1).GetWindow().GetValue()
+        value = self.ValueTextCtrl.GetValue()
         if value == "":
             message = _("You must type a value!")
         elif GetTypeValue[self.IEC_Type](value) is None: