dialogs/PouDialog.py
changeset 1784 64beb9e9c749
parent 1768 691083b5682a
child 1881 091005ec69c4
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    25 
    25 
    26 import wx
    26 import wx
    27 
    27 
    28 from plcopen.structures import TestIdentifier, IEC_KEYWORDS
    28 from plcopen.structures import TestIdentifier, IEC_KEYWORDS
       
    29 from util.TranslationCatalogs import NoTranslate
       
    30 
    29 
    31 
    30 def GetPouTypes():
    32 def GetPouTypes():
    31     _ = lambda x : x
    33     _ = NoTranslate
    32     return [_("function"), _("functionBlock"), _("program")]
    34     return [_("function"), _("functionBlock"), _("program")]
       
    35 
       
    36 
    33 POU_TYPES_DICT = dict([(_(pou_type), pou_type) for pou_type in GetPouTypes()])
    37 POU_TYPES_DICT = dict([(_(pou_type), pou_type) for pou_type in GetPouTypes()])
    34 
    38 
       
    39 
    35 def GetPouLanguages():
    40 def GetPouLanguages():
    36     _ = lambda x : x
    41     _ = NoTranslate
    37     return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")]
    42     return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")]
       
    43 
    38 
    44 
    39 class PouDialog(wx.Dialog):
    45 class PouDialog(wx.Dialog):
    40 
    46 
    41     POU_LANGUAGES = GetPouLanguages()
    47     POU_LANGUAGES = GetPouLanguages()
    42     POU_LANGUAGES_DICT = dict([(_(language), language) for language in POU_LANGUAGES])
    48     POU_LANGUAGES_DICT = dict([(_(language), language) for language in POU_LANGUAGES])
    43 
    49 
    44     def __init__(self, parent, pou_type=None, type_readonly=False):
    50     def __init__(self, parent, pou_type=None, type_readonly=False):
    45         wx.Dialog.__init__(self, id=-1, parent=parent,
    51         wx.Dialog.__init__(self, id=-1, parent=parent,
    46               name='PouDialog', title=_('Create a new POU'),
    52                            name='PouDialog', title=_('Create a new POU'),
    47               style=wx.DEFAULT_DIALOG_STYLE)
    53                            style=wx.DEFAULT_DIALOG_STYLE)
    48 
    54 
    49         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
    55         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
    50         main_sizer.AddGrowableCol(0)
    56         main_sizer.AddGrowableCol(0)
    51         main_sizer.AddGrowableRow(0)
    57         main_sizer.AddGrowableRow(0)
    52 
    58 
    53         infos_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15)
    59         infos_sizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15)
    54         infos_sizer.AddGrowableCol(1)
    60         infos_sizer.AddGrowableCol(1)
    55         main_sizer.AddSizer(infos_sizer, border=20,
    61         main_sizer.AddSizer(infos_sizer, border=20,
    56               flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
    62                             flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT)
    57 
    63 
    58         pouname_label = wx.StaticText(self, label=_('POU Name:'))
    64         pouname_label = wx.StaticText(self, label=_('POU Name:'))
    59         infos_sizer.AddWindow(pouname_label, border=4,
    65         infos_sizer.AddWindow(pouname_label, border=4,
    60               flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
    66                               flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP)
    61 
    67 
    62         self.PouName = wx.TextCtrl(self)
    68         self.PouName = wx.TextCtrl(self)
    63         infos_sizer.AddWindow(self.PouName, flag=wx.GROW)
    69         infos_sizer.AddWindow(self.PouName, flag=wx.GROW)
    64 
    70 
    65         poutype_label = wx.StaticText(self, label=_('POU Type:'))
    71         poutype_label = wx.StaticText(self, label=_('POU Type:'))
    66         infos_sizer.AddWindow(poutype_label, border=4,
    72         infos_sizer.AddWindow(poutype_label, border=4,
    67               flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
    73                               flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP)
    68 
    74 
    69         self.PouType = wx.ComboBox(self, style=wx.CB_READONLY)
    75         self.PouType = wx.ComboBox(self, style=wx.CB_READONLY)
    70         self.Bind(wx.EVT_COMBOBOX, self.OnTypeChanged, self.PouType)
    76         self.Bind(wx.EVT_COMBOBOX, self.OnTypeChanged, self.PouType)
    71         infos_sizer.AddWindow(self.PouType, flag=wx.GROW)
    77         infos_sizer.AddWindow(self.PouType, flag=wx.GROW)
    72 
    78 
    73         language_label = wx.StaticText(self, label=_('Language:'))
    79         language_label = wx.StaticText(self, label=_('Language:'))
    74         infos_sizer.AddWindow(language_label, border=4,
    80         infos_sizer.AddWindow(language_label, border=4,
    75               flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
    81                               flag=wx.ALIGN_CENTER_VERTICAL | wx.TOP)
    76 
    82 
    77         self.Language = wx.ComboBox(self, style=wx.CB_READONLY)
    83         self.Language = wx.ComboBox(self, style=wx.CB_READONLY)
    78         infos_sizer.AddWindow(self.Language, flag=wx.GROW)
    84         infos_sizer.AddWindow(self.Language, flag=wx.GROW)
    79 
    85 
    80         button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
    86         button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTRE)
    81         self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
    87         self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
    82         main_sizer.AddSizer(button_sizer, border=20,
    88         main_sizer.AddSizer(button_sizer, border=20,
    83               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
    89                             flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT)
    84 
    90 
    85         self.SetSizer(main_sizer)
    91         self.SetSizer(main_sizer)
    86 
    92 
    87         for option in GetPouTypes():
    93         for option in GetPouTypes():
    88             if not type_readonly or _(option) == _(pou_type):
    94             if not type_readonly or _(option) == _(pou_type):
   109             text = ""
   115             text = ""
   110             for i, item in enumerate(error):
   116             for i, item in enumerate(error):
   111                 if i == 0:
   117                 if i == 0:
   112                     text += item
   118                     text += item
   113                 elif i == len(error) - 1:
   119                 elif i == len(error) - 1:
   114                     text += _(" and %s")%item
   120                     text += _(" and %s") % item
   115                 else:
   121                 else:
   116                     text += _(", %s")%item
   122                     text += _(", %s") % item
   117             message = _("Form isn't complete. %s must be filled!") % text
   123             message = _("Form isn't complete. %s must be filled!") % text
   118         elif not TestIdentifier(pou_name):
   124         elif not TestIdentifier(pou_name):
   119             message = _("\"%s\" is not a valid identifier!") % pou_name
   125             message = _("\"%s\" is not a valid identifier!") % pou_name
   120         elif pou_name.upper() in IEC_KEYWORDS:
   126         elif pou_name.upper() in IEC_KEYWORDS:
   121             message = _("\"%s\" is a keyword. It can't be used!") % pou_name
   127             message = _("\"%s\" is a keyword. It can't be used!") % pou_name
   124         elif pou_name.upper() in self.PouElementNames:
   130         elif pou_name.upper() in self.PouElementNames:
   125             message = _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?") % pou_name
   131             message = _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?") % pou_name
   126             question = True
   132             question = True
   127         if message is not None:
   133         if message is not None:
   128             if question:
   134             if question:
   129                 dialog = wx.MessageDialog(self, message, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
   135                 dialog = wx.MessageDialog(self, message, _("Warning"), wx.YES_NO | wx.ICON_EXCLAMATION)
   130                 result = dialog.ShowModal()
   136                 result = dialog.ShowModal()
   131                 dialog.Destroy()
   137                 dialog.Destroy()
   132                 if result == wx.ID_YES:
   138                 if result == wx.ID_YES:
   133                     self.EndModal(wx.ID_OK)
   139                     self.EndModal(wx.ID_OK)
   134             else:
   140             else:
   135                 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK|wx.ICON_ERROR)
   141                 dialog = wx.MessageDialog(self, message, _("Error"), wx.OK | wx.ICON_ERROR)
   136                 dialog.ShowModal()
   142                 dialog.ShowModal()
   137                 dialog.Destroy()
   143                 dialog.Destroy()
   138         else:
   144         else:
   139             self.EndModal(wx.ID_OK)
   145             self.EndModal(wx.ID_OK)
   140 
   146