dialogs/PouNameDialog.py
changeset 1784 64beb9e9c749
parent 1782 5b6ad7a7fd9d
child 1799 9fd7bbf6ec45
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 import wx
    25 import wx
    26 
    26 
    27 #-------------------------------------------------------------------------------
    27 # -------------------------------------------------------------------------------
    28 #                                POU Name Dialog
    28 #                                POU Name Dialog
    29 #-------------------------------------------------------------------------------
    29 # -------------------------------------------------------------------------------
       
    30 
    30 
    31 
    31 class PouNameDialog(wx.TextEntryDialog):
    32 class PouNameDialog(wx.TextEntryDialog):
    32 
    33 
    33     def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", 
    34     def __init__(self, parent, message, caption="Please enter text", defaultValue="",
    34                        style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
    35                  style=wx.OK | wx.CANCEL | wx.CENTRE, pos=wx.DefaultPosition):
    35         wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
    36         wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
    36         
    37 
    37         self.PouNames = []
    38         self.PouNames = []
    38         
    39 
    39         self.Bind(wx.EVT_BUTTON, self.OnOK, 
    40         self.Bind(wx.EVT_BUTTON, self.OnOK,
    40               self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton())
    41                   self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton())
    41         
    42 
    42     def OnOK(self, event):
    43     def OnOK(self, event):
    43         message = None
    44         message = None
    44         step_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
    45         step_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
    45         if step_name == "":
    46         if step_name == "":
    46             message = _("You must type a name!")
    47             message = _("You must type a name!")
    49         elif step_name.upper() in IEC_KEYWORDS:
    50         elif step_name.upper() in IEC_KEYWORDS:
    50             message = _("\"%s\" is a keyword. It can't be used!") % step_name
    51             message = _("\"%s\" is a keyword. It can't be used!") % step_name
    51         elif step_name.upper() in self.PouNames:
    52         elif step_name.upper() in self.PouNames:
    52             message = _("A POU named \"%s\" already exists!") % step_name
    53             message = _("A POU named \"%s\" already exists!") % step_name
    53         if message is not None:
    54         if message is not None:
    54             dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
    55             dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
    55             dialog.ShowModal()
    56             dialog.ShowModal()
    56             dialog.Destroy()
    57             dialog.Destroy()
    57         else:
    58         else:
    58             self.EndModal(wx.ID_OK)
    59             self.EndModal(wx.ID_OK)
    59         event.Skip()
    60         event.Skip()
    60 
    61 
    61     def SetPouNames(self, pou_names):
    62     def SetPouNames(self, pou_names):
    62         self.PouNames = [pou_name.upper() for pou_name in pou_names]
    63         self.PouNames = [pou_name.upper() for pou_name in pou_names]
    63