laurent@409: # -*- coding: utf-8 -*- laurent@409: laurent@409: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor laurent@409: #based on the plcopen standard. laurent@409: # laurent@409: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD laurent@409: # laurent@409: #See COPYING file for copyrights details. laurent@409: # laurent@409: #This library is free software; you can redistribute it and/or laurent@409: #modify it under the terms of the GNU General Public laurent@409: #License as published by the Free Software Foundation; either laurent@409: #version 2.1 of the License, or (at your option) any later version. laurent@409: # laurent@409: #This library is distributed in the hope that it will be useful, laurent@409: #but WITHOUT ANY WARRANTY; without even the implied warranty of laurent@409: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU laurent@409: #General Public License for more details. laurent@409: # laurent@409: #You should have received a copy of the GNU General Public laurent@409: #License along with this library; if not, write to the Free Software laurent@409: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA laurent@409: laurent@409: import wx laurent@409: laurent@409: #------------------------------------------------------------------------------- laurent@409: # Edit Step Name Dialog laurent@409: #------------------------------------------------------------------------------- laurent@409: laurent@409: class SFCStepNameDialog(wx.TextEntryDialog): laurent@409: laurent@409: def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", laurent@409: style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): laurent@409: wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) laurent@409: laurent@409: self.PouNames = [] laurent@409: self.Variables = [] laurent@409: self.StepNames = [] Laurent@714: Laurent@714: self.Bind(wx.EVT_BUTTON, self.OnOK, Laurent@714: self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton()) Laurent@714: laurent@409: def OnOK(self, event): Laurent@714: message = None laurent@409: step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() laurent@409: if step_name == "": Laurent@714: message = _("You must type a name!") laurent@409: elif not TestIdentifier(step_name): Laurent@714: message = _("\"%s\" is not a valid identifier!") % step_name laurent@409: elif step_name.upper() in IEC_KEYWORDS: Laurent@714: message = _("\"%s\" is a keyword. It can't be used!") % step_name laurent@409: elif step_name.upper() in self.PouNames: Laurent@714: message = _("A POU named \"%s\" already exists!") % step_name laurent@409: elif step_name.upper() in self.Variables: Laurent@714: message = _("A variable with \"%s\" as name already exists in this pou!") % step_name laurent@409: elif step_name.upper() in self.StepNames: Laurent@714: message = _("\"%s\" step already exists!") % step_name Laurent@714: if message is not None: Laurent@714: dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR) Laurent@714: dialog.ShowModal() Laurent@714: dialog.Destroy() laurent@409: else: laurent@409: self.EndModal(wx.ID_OK) Laurent@732: event.Skip() laurent@409: laurent@409: def SetPouNames(self, pou_names): laurent@409: self.PouNames = [pou_name.upper() for pou_name in pou_names] laurent@409: laurent@409: def SetVariables(self, variables): laurent@409: self.Variables = [var["Name"].upper() for var in variables] laurent@409: laurent@409: def SetStepNames(self, step_names): laurent@409: self.StepNames = [step_name.upper() for step_name in step_names]