27 # POU Name Dialog |
27 # POU Name Dialog |
28 #------------------------------------------------------------------------------- |
28 #------------------------------------------------------------------------------- |
29 |
29 |
30 class PouNameDialog(wx.TextEntryDialog): |
30 class PouNameDialog(wx.TextEntryDialog): |
31 |
31 |
32 if wx.VERSION < (2, 6, 0): |
|
33 def Bind(self, event, function, id = None): |
|
34 if id is not None: |
|
35 event(self, id, function) |
|
36 else: |
|
37 event(self, function) |
|
38 |
|
39 |
|
40 def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
32 def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
41 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
33 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
42 wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
34 wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
43 |
35 |
44 self.PouNames = [] |
36 self.PouNames = [] |
45 if wx.VERSION >= (2, 8, 0): |
37 |
46 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId()) |
38 self.Bind(wx.EVT_BUTTON, self.OnOK, |
47 elif wx.VERSION >= (2, 6, 0): |
39 self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton()) |
48 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
40 |
49 else: |
|
50 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
|
51 |
|
52 def OnOK(self, event): |
41 def OnOK(self, event): |
|
42 message = None |
53 step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
43 step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
54 if step_name == "": |
44 if step_name == "": |
55 message = wx.MessageDialog(self, _("You must type a name!"), _("Error"), wx.OK|wx.ICON_ERROR) |
45 message = _("You must type a name!") |
56 message.ShowModal() |
|
57 message.Destroy() |
|
58 elif not TestIdentifier(step_name): |
46 elif not TestIdentifier(step_name): |
59 message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) |
47 message = _("\"%s\" is not a valid identifier!") % step_name |
60 message.ShowModal() |
|
61 message.Destroy() |
|
62 elif step_name.upper() in IEC_KEYWORDS: |
48 elif step_name.upper() in IEC_KEYWORDS: |
63 message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) |
49 message = _("\"%s\" is a keyword. It can't be used!") % step_name |
64 message.ShowModal() |
|
65 message.Destroy() |
|
66 elif step_name.upper() in self.PouNames: |
50 elif step_name.upper() in self.PouNames: |
67 message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) |
51 message = _("A POU named \"%s\" already exists!") % step_name |
68 message.ShowModal() |
52 if message is not None: |
69 message.Destroy() |
53 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
54 dialog.ShowModal() |
|
55 dialog.Destroy() |
70 else: |
56 else: |
71 self.EndModal(wx.ID_OK) |
57 self.EndModal(wx.ID_OK) |
72 |
58 |
73 def SetPouNames(self, pou_names): |
59 def SetPouNames(self, pou_names): |
74 self.PouNames = [pou_name.upper() for pou_name in pou_names] |
60 self.PouNames = [pou_name.upper() for pou_name in pou_names] |
75 |
61 |
76 def GetValue(self): |
|
77 return self.GetSizer().GetItem(1).GetWindow().GetValue() |
|