--- a/dialogs/ForceVariableDialog.py Fri Jun 15 18:03:25 2012 +0200
+++ b/dialogs/ForceVariableDialog.py Mon Jun 25 20:03:53 2012 +0200
@@ -21,12 +21,13 @@
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-import wx
import re
import datetime
+import wx
+
#-------------------------------------------------------------------------------
-# Force Variable Dialog
+# Helpers
#-------------------------------------------------------------------------------
LOCATIONDATATYPES = {"X" : ["BOOL"],
@@ -141,41 +142,35 @@
"DT": getdatetime,
"TOD": gettimeofday}
+#-------------------------------------------------------------------------------
+# Force Variable Dialog
+#-------------------------------------------------------------------------------
class ForceVariableDialog(wx.TextEntryDialog):
- if wx.VERSION < (2, 6, 0):
- def Bind(self, event, function, id = None):
- if id is not None:
- event(self, id, function)
- else:
- event(self, function)
-
def __init__(self, parent, iec_type, defaultValue=""):
wx.TextEntryDialog.__init__(self, parent, message = _("Forcing Variable Value"),
caption = _("Please enter value for a \"%s\" variable:"%iec_type), defaultValue = defaultValue,
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition)
self.IEC_Type = iec_type
- if wx.VERSION >= (2, 8, 0):
- self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId())
- elif wx.VERSION >= (2, 6, 0):
- self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
- else:
- self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
-
+
+ self.Bind(wx.EVT_BUTTON, self.OnOK,
+ self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton())
+
def OnOK(self, event):
+ message = None
value = self.GetSizer().GetItem(1).GetWindow().GetValue()
if value == "":
- message = wx.MessageDialog(self, _("You must type a value!"), _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("You must type a value!")
elif GetTypeValue[self.IEC_Type](value) is None:
- message = wx.MessageDialog(self, _("Invalid value \"%s\" for \"%s\" variable!")%(value, self.IEC_Type), _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
+ message = _("Invalid value \"%s\" for \"%s\" variable!") % (value, self.IEC_Type)
+ if message is not None:
+ dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
+ dialog.ShowModal()
+ dialog.Destroy()
else:
self.EndModal(wx.ID_OK)
def GetValue(self):
- return GetTypeValue[self.IEC_Type](self.GetSizer().GetItem(1).GetWindow().GetValue())
+ return GetTypeValue[self.IEC_Type](wx.TextEntryDialog.GetValue(self))