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: # POU Name Dialog laurent@409: #------------------------------------------------------------------------------- laurent@409: laurent@409: class PouNameDialog(wx.TextEntryDialog): laurent@409: laurent@409: if wx.VERSION < (2, 6, 0): laurent@409: def Bind(self, event, function, id = None): laurent@409: if id is not None: laurent@409: event(self, id, function) laurent@409: else: laurent@409: event(self, function) laurent@409: 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: if wx.VERSION >= (2, 8, 0): laurent@409: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId()) laurent@409: elif wx.VERSION >= (2, 6, 0): laurent@409: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) laurent@409: else: laurent@409: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) laurent@409: laurent@409: def OnOK(self, event): laurent@409: step_name = self.GetSizer().GetItem(1).GetWindow().GetValue() laurent@409: if step_name == "": laurent@409: message = wx.MessageDialog(self, _("You must type a name!"), _("Error"), wx.OK|wx.ICON_ERROR) laurent@409: message.ShowModal() laurent@409: message.Destroy() laurent@409: elif not TestIdentifier(step_name): laurent@409: message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) laurent@409: message.ShowModal() laurent@409: message.Destroy() laurent@409: elif step_name.upper() in IEC_KEYWORDS: laurent@409: message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) laurent@409: message.ShowModal() laurent@409: message.Destroy() laurent@409: elif step_name.upper() in self.PouNames: laurent@446: message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%step_name, _("Error"), wx.OK|wx.ICON_ERROR) laurent@409: message.ShowModal() laurent@409: message.Destroy() laurent@409: else: laurent@409: self.EndModal(wx.ID_OK) 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 GetValue(self): laurent@409: return self.GetSizer().GetItem(1).GetWindow().GetValue()