27 # Edit Step Name Dialog |
27 # Edit Step Name Dialog |
28 #------------------------------------------------------------------------------- |
28 #------------------------------------------------------------------------------- |
29 |
29 |
30 class SFCStepNameDialog(wx.TextEntryDialog): |
30 class SFCStepNameDialog(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 self.Variables = [] |
37 self.Variables = [] |
46 self.StepNames = [] |
38 self.StepNames = [] |
47 if wx.VERSION >= (2, 8, 0): |
39 |
48 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId()) |
40 self.Bind(wx.EVT_BUTTON, self.OnOK, |
49 elif wx.VERSION >= (2, 6, 0): |
41 self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton()) |
50 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
42 |
51 else: |
|
52 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
|
53 |
|
54 def OnOK(self, event): |
43 def OnOK(self, event): |
|
44 message = None |
55 step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
45 step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
56 if step_name == "": |
46 if step_name == "": |
57 message = wx.MessageDialog(self, _("You must type a name!"), _("Error"), wx.OK|wx.ICON_ERROR) |
47 message = _("You must type a name!") |
58 message.ShowModal() |
|
59 message.Destroy() |
|
60 elif not TestIdentifier(step_name): |
48 elif not TestIdentifier(step_name): |
61 message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) |
49 message = _("\"%s\" is not a valid identifier!") % step_name |
62 message.ShowModal() |
|
63 message.Destroy() |
|
64 elif step_name.upper() in IEC_KEYWORDS: |
50 elif step_name.upper() in IEC_KEYWORDS: |
65 message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) |
51 message = _("\"%s\" is a keyword. It can't be used!") % step_name |
66 message.ShowModal() |
|
67 message.Destroy() |
|
68 elif step_name.upper() in self.PouNames: |
52 elif step_name.upper() in self.PouNames: |
69 message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) |
53 message = _("A POU named \"%s\" already exists!") % step_name |
70 message.ShowModal() |
|
71 message.Destroy() |
|
72 elif step_name.upper() in self.Variables: |
54 elif step_name.upper() in self.Variables: |
73 message = wx.MessageDialog(self, _("A variable with \"%s\" as name already exists in this pou!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) |
55 message = _("A variable with \"%s\" as name already exists in this pou!") % step_name |
74 message.ShowModal() |
|
75 message.Destroy() |
|
76 elif step_name.upper() in self.StepNames: |
56 elif step_name.upper() in self.StepNames: |
77 message = wx.MessageDialog(self, _("\"%s\" step already exists!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) |
57 message = _("\"%s\" step already exists!") % step_name |
78 message.ShowModal() |
58 if message is not None: |
79 message.Destroy() |
59 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) |
|
60 dialog.ShowModal() |
|
61 dialog.Destroy() |
80 else: |
62 else: |
81 self.EndModal(wx.ID_OK) |
63 self.EndModal(wx.ID_OK) |
82 |
64 |
83 def SetPouNames(self, pou_names): |
65 def SetPouNames(self, pou_names): |
84 self.PouNames = [pou_name.upper() for pou_name in pou_names] |
66 self.PouNames = [pou_name.upper() for pou_name in pou_names] |