2476 def SetStepNames(self, step_names): |
2476 def SetStepNames(self, step_names): |
2477 self.StepNames = [step_name.upper() for step_name in step_names] |
2477 self.StepNames = [step_name.upper() for step_name in step_names] |
2478 |
2478 |
2479 def GetValue(self): |
2479 def GetValue(self): |
2480 return self.GetSizer().GetItem(1).GetWindow().GetValue() |
2480 return self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2481 |
|
2482 #------------------------------------------------------------------------------- |
|
2483 # POU Name Dialog |
|
2484 #------------------------------------------------------------------------------- |
|
2485 |
|
2486 class PouNameDialog(wx.TextEntryDialog): |
|
2487 |
|
2488 if wx.VERSION < (2, 6, 0): |
|
2489 def Bind(self, event, function, id = None): |
|
2490 if id is not None: |
|
2491 event(self, id, function) |
|
2492 else: |
|
2493 event(self, function) |
|
2494 |
|
2495 |
|
2496 def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
|
2497 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
|
2498 wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
2499 |
|
2500 self.PouNames = [] |
|
2501 if wx.VERSION >= (2, 8, 0): |
|
2502 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId()) |
|
2503 elif wx.VERSION >= (2, 6, 0): |
|
2504 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
|
2505 else: |
|
2506 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
|
2507 |
|
2508 def OnOK(self, event): |
|
2509 step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
2510 if step_name == "": |
|
2511 message = wx.MessageDialog(self, "You must type a name!", "Error", wx.OK|wx.ICON_ERROR) |
|
2512 message.ShowModal() |
|
2513 message.Destroy() |
|
2514 elif not TestIdentifier(step_name): |
|
2515 message = wx.MessageDialog(self, "\"%s\" is not a valid identifier!"%step_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2516 message.ShowModal() |
|
2517 message.Destroy() |
|
2518 elif step_name.upper() in IEC_KEYWORDS: |
|
2519 message = wx.MessageDialog(self, "\"%s\" is a keyword. It can't be used!"%step_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2520 message.ShowModal() |
|
2521 message.Destroy() |
|
2522 elif step_name.upper() in self.PouNames: |
|
2523 message = wx.MessageDialog(self, "A pou with \"%s\" as name exists!"%step_name, "Error", wx.OK|wx.ICON_ERROR) |
|
2524 message.ShowModal() |
|
2525 message.Destroy() |
|
2526 else: |
|
2527 self.EndModal(wx.ID_OK) |
|
2528 |
|
2529 def SetPouNames(self, pou_names): |
|
2530 self.PouNames = [pou_name.upper() for pou_name in pou_names] |
|
2531 |
|
2532 def GetValue(self): |
|
2533 return self.GetSizer().GetItem(1).GetWindow().GetValue() |