Adding Test when creating VariableBlock
authorlbessard
Wed, 18 Mar 2009 15:54:09 +0100
changeset 325 0a58f1625b6e
parent 324 9f240641e3f0
child 326 c82807b17128
Adding Test when creating VariableBlock
Dialogs.py
--- a/Dialogs.py	Wed Mar 18 10:17:48 2009 +0100
+++ b/Dialogs.py	Wed Mar 18 15:54:09 2009 +0100
@@ -547,10 +547,11 @@
         setattr(self.Preview, "IsOfType", ctrler.IsOfType)
 
         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
-
         if wx.VERSION >= (2, 5, 0):
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
             self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
         else:
+            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
             wx.EVT_PAINT(self.Preview, self.OnPaint)
         
         self._init_sizers()
@@ -642,6 +643,23 @@
         values["executionOrder"] = self.ExecutionOrder.GetValue()
         return values
 
+    def OnOK(self, event):
+        expression = self.Expression.GetValue()
+        if self.Expression.IsEnabled():
+            value = expression
+        else:
+            value = self.VariableName.GetStringSelection()
+        if value == "":
+            message = wx.MessageDialog(self, "At least a variable or aa expression must be selected!", "Error", wx.OK|wx.ICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+        elif value.upper() in IEC_KEYWORDS:
+            message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%value, "Error", wx.OK|wx.ICON_ERROR)
+            message.ShowModal()
+            message.Destroy()
+        else:
+            self.EndModal(wx.ID_OK)
+
     def OnClassChanged(self, event):
         self.RefreshNameList()
         if self.Class.GetStringSelection() == "Input":