dialogs/PouNameDialog.py
changeset 814 5743cbdff669
child 1571 486f94a8032c
equal deleted inserted replaced
813:1460273f40ed 814:5743cbdff669
       
     1 # -*- coding: utf-8 -*-
       
     2 
       
     3 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
       
     4 #based on the plcopen standard. 
       
     5 #
       
     6 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
       
     7 #
       
     8 #See COPYING file for copyrights details.
       
     9 #
       
    10 #This library is free software; you can redistribute it and/or
       
    11 #modify it under the terms of the GNU General Public
       
    12 #License as published by the Free Software Foundation; either
       
    13 #version 2.1 of the License, or (at your option) any later version.
       
    14 #
       
    15 #This library is distributed in the hope that it will be useful,
       
    16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    18 #General Public License for more details.
       
    19 #
       
    20 #You should have received a copy of the GNU General Public
       
    21 #License along with this library; if not, write to the Free Software
       
    22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    23 
       
    24 import wx
       
    25 
       
    26 #-------------------------------------------------------------------------------
       
    27 #                                POU Name Dialog
       
    28 #-------------------------------------------------------------------------------
       
    29 
       
    30 class PouNameDialog(wx.TextEntryDialog):
       
    31 
       
    32     def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", 
       
    33                        style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
       
    34         wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
       
    35         
       
    36         self.PouNames = []
       
    37         
       
    38         self.Bind(wx.EVT_BUTTON, self.OnOK, 
       
    39               self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton())
       
    40         
       
    41     def OnOK(self, event):
       
    42         message = None
       
    43         step_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
       
    44         if step_name == "":
       
    45             message = _("You must type a name!")
       
    46         elif not TestIdentifier(step_name):
       
    47             message = _("\"%s\" is not a valid identifier!") % step_name
       
    48         elif step_name.upper() in IEC_KEYWORDS:
       
    49             message = _("\"%s\" is a keyword. It can't be used!") % step_name
       
    50         elif step_name.upper() in self.PouNames:
       
    51             message = _("A POU named \"%s\" already exists!") % step_name
       
    52         if message is not None:
       
    53             dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
       
    54             dialog.ShowModal()
       
    55             dialog.Destroy()
       
    56         else:
       
    57             self.EndModal(wx.ID_OK)
       
    58         event.Skip()
       
    59 
       
    60     def SetPouNames(self, pou_names):
       
    61         self.PouNames = [pou_name.upper() for pou_name in pou_names]
       
    62