19 # |
19 # |
20 #You should have received a copy of the GNU General Public |
20 #You should have received a copy of the GNU General Public |
21 #License along with this library; if not, write to the Free Software |
21 #License along with this library; if not, write to the Free Software |
22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
23 |
24 import wx |
|
25 import re |
24 import re |
26 import datetime |
25 import datetime |
27 |
26 |
|
27 import wx |
|
28 |
28 #------------------------------------------------------------------------------- |
29 #------------------------------------------------------------------------------- |
29 # Force Variable Dialog |
30 # Helpers |
30 #------------------------------------------------------------------------------- |
31 #------------------------------------------------------------------------------- |
31 |
32 |
32 LOCATIONDATATYPES = {"X" : ["BOOL"], |
33 LOCATIONDATATYPES = {"X" : ["BOOL"], |
33 "B" : ["SINT", "USINT", "BYTE", "STRING"], |
34 "B" : ["SINT", "USINT", "BYTE", "STRING"], |
34 "W" : ["INT", "UINT", "WORD", "WSTRING"], |
35 "W" : ["INT", "UINT", "WORD", "WSTRING"], |
139 "TIME": gettime, |
140 "TIME": gettime, |
140 "DATE": getdate, |
141 "DATE": getdate, |
141 "DT": getdatetime, |
142 "DT": getdatetime, |
142 "TOD": gettimeofday} |
143 "TOD": gettimeofday} |
143 |
144 |
|
145 #------------------------------------------------------------------------------- |
|
146 # Force Variable Dialog |
|
147 #------------------------------------------------------------------------------- |
144 |
148 |
145 class ForceVariableDialog(wx.TextEntryDialog): |
149 class ForceVariableDialog(wx.TextEntryDialog): |
146 |
|
147 if wx.VERSION < (2, 6, 0): |
|
148 def Bind(self, event, function, id = None): |
|
149 if id is not None: |
|
150 event(self, id, function) |
|
151 else: |
|
152 event(self, function) |
|
153 |
150 |
154 def __init__(self, parent, iec_type, defaultValue=""): |
151 def __init__(self, parent, iec_type, defaultValue=""): |
155 wx.TextEntryDialog.__init__(self, parent, message = _("Forcing Variable Value"), |
152 wx.TextEntryDialog.__init__(self, parent, message = _("Forcing Variable Value"), |
156 caption = _("Please enter value for a \"%s\" variable:"%iec_type), defaultValue = defaultValue, |
153 caption = _("Please enter value for a \"%s\" variable:"%iec_type), defaultValue = defaultValue, |
157 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition) |
154 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition) |
158 |
155 |
159 self.IEC_Type = iec_type |
156 self.IEC_Type = iec_type |
160 if wx.VERSION >= (2, 8, 0): |
157 |
161 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId()) |
158 self.Bind(wx.EVT_BUTTON, self.OnOK, |
162 elif wx.VERSION >= (2, 6, 0): |
159 self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton()) |
163 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
160 |
164 else: |
|
165 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
|
166 |
|
167 def OnOK(self, event): |
161 def OnOK(self, event): |
|
162 message = None |
168 value = self.GetSizer().GetItem(1).GetWindow().GetValue() |
163 value = self.GetSizer().GetItem(1).GetWindow().GetValue() |
169 if value == "": |
164 if value == "": |
170 message = wx.MessageDialog(self, _("You must type a value!"), _("Error"), wx.OK|wx.ICON_ERROR) |
165 message = _("You must type a value!") |
171 message.ShowModal() |
|
172 message.Destroy() |
|
173 elif GetTypeValue[self.IEC_Type](value) is None: |
166 elif GetTypeValue[self.IEC_Type](value) is None: |
174 message = wx.MessageDialog(self, _("Invalid value \"%s\" for \"%s\" variable!")%(value, self.IEC_Type), _("Error"), wx.OK|wx.ICON_ERROR) |
167 message = _("Invalid value \"%s\" for \"%s\" variable!") % (value, self.IEC_Type) |
175 message.ShowModal() |
168 if message is not None: |
176 message.Destroy() |
169 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
170 dialog.ShowModal() |
|
171 dialog.Destroy() |
177 else: |
172 else: |
178 self.EndModal(wx.ID_OK) |
173 self.EndModal(wx.ID_OK) |
179 |
174 |
180 def GetValue(self): |
175 def GetValue(self): |
181 return GetTypeValue[self.IEC_Type](self.GetSizer().GetItem(1).GetWindow().GetValue()) |
176 return GetTypeValue[self.IEC_Type](wx.TextEntryDialog.GetValue(self)) |