PLCOpenEditor.py
changeset 705 1a343b239e9c
parent 703 1a14560e10ed
child 708 cf8f5749558d
equal deleted inserted replaced
704:aca0c83ed82e 705:1a343b239e9c
   107 from RessourceEditor import *
   107 from RessourceEditor import *
   108 from DataTypeEditor import *
   108 from DataTypeEditor import *
   109 from PLCControler import *
   109 from PLCControler import *
   110 from SearchResultPanel import SearchResultPanel
   110 from SearchResultPanel import SearchResultPanel
   111 from controls import CustomGrid, CustomTable, CustomTree, LibraryPanel, PouInstanceVariablesPanel
   111 from controls import CustomGrid, CustomTable, CustomTree, LibraryPanel, PouInstanceVariablesPanel
   112 from dialogs import ProjectDialog
   112 from dialogs import ProjectDialog, PouTransitionDialog, PouActionDialog
   113 
   113 
   114 # Define PLCOpenEditor controls id
   114 # Define PLCOpenEditor controls id
   115 [ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK, 
   115 [ID_PLCOPENEDITOR, ID_PLCOPENEDITORLEFTNOTEBOOK, 
   116  ID_PLCOPENEDITORBOTTOMNOTEBOOK, ID_PLCOPENEDITORRIGHTNOTEBOOK, 
   116  ID_PLCOPENEDITORBOTTOMNOTEBOOK, ID_PLCOPENEDITORRIGHTNOTEBOOK, 
   117  ID_PLCOPENEDITORPROJECTTREE, ID_PLCOPENEDITORMAINSPLITTER, 
   117  ID_PLCOPENEDITORPROJECTTREE, ID_PLCOPENEDITORMAINSPLITTER, 
   595             self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnProjectTreeRightUp,
   595             self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnProjectTreeRightUp,
   596                   id=ID_PLCOPENEDITORPROJECTTREE)
   596                   id=ID_PLCOPENEDITORPROJECTTREE)
   597             self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected,
   597             self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected,
   598                   id=ID_PLCOPENEDITORPROJECTTREE)
   598                   id=ID_PLCOPENEDITORPROJECTTREE)
   599         else:
   599         else:
   600             if wx.VERSION >= (2, 6, 0):
   600             self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
   601                 self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
   601             self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp)
   602                 self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp)
       
   603             else:
       
   604                 wx.EVT_RIGHT_UP(self.ProjectTree, self.OnProjectTreeRightUp)
       
   605                 wx.EVT_LEFT_UP(self.ProjectTree, self.OnProjectTreeLeftUp)
       
   606             self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging,
   602             self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging,
   607                   id=ID_PLCOPENEDITORPROJECTTREE)
   603                   id=ID_PLCOPENEDITORPROJECTTREE)
   608         self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag,
   604         self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag,
   609               id=ID_PLCOPENEDITORPROJECTTREE)
   605               id=ID_PLCOPENEDITORPROJECTTREE)
   610         self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit,
   606         self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit,
  2359 #-------------------------------------------------------------------------------
  2355 #-------------------------------------------------------------------------------
  2360 #                         Add Project Elements Functions
  2356 #                         Add Project Elements Functions
  2361 #-------------------------------------------------------------------------------
  2357 #-------------------------------------------------------------------------------
  2362 
  2358 
  2363     def OnAddDataTypeMenu(self, event):
  2359     def OnAddDataTypeMenu(self, event):
  2364         dialog = DataTypeDialog(self, _("Add a new data type"), _("Please enter data type name"), "", wx.OK|wx.CANCEL)
  2360         tagname = self.Controler.ProjectAddDataType()
  2365         dialog.SetDataTypeNames(self.Controler.GetProjectDataTypeNames())
  2361         if tagname is not None:
  2366         if dialog.ShowModal() == wx.ID_OK:
  2362             self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
  2367             tagname = self.Controler.ProjectAddDataType(dialog.GetValue())
  2363             self.EditProjectElement(ITEM_DATATYPE, tagname)
  2368             if tagname is not None:
  2364         
  2369                 self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
       
  2370                 self.EditProjectElement(ITEM_DATATYPE, tagname)
       
  2371         dialog.Destroy()
       
  2372 
       
  2373     def GenerateAddPouFunction(self, pou_type):
  2365     def GenerateAddPouFunction(self, pou_type):
  2374         def OnAddPouMenu(event):
  2366         def OnAddPouMenu(event):
  2375             dialog = PouDialog(self, pou_type)
  2367             dialog = PouDialog(self, pou_type)
  2376             dialog.SetPouNames(self.Controler.GetProjectPouNames())
  2368             dialog.SetPouNames(self.Controler.GetProjectPouNames())
  2377             dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
  2369             dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
       
  2370             dialog.SetValues({"pouName": self.Controler.GenerateNewName(None, None, "%s%%d" % pou_type)})
  2378             if dialog.ShowModal() == wx.ID_OK:
  2371             if dialog.ShowModal() == wx.ID_OK:
  2379                 values = dialog.GetValues()
  2372                 values = dialog.GetValues()
  2380                 tagname = self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
  2373                 tagname = self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
  2381                 if tagname is not None:
  2374                 if tagname is not None:
  2382                     self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
  2375                     self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
  2387     def GenerateAddTransitionFunction(self, pou_name):
  2380     def GenerateAddTransitionFunction(self, pou_name):
  2388         def OnAddTransitionMenu(event):
  2381         def OnAddTransitionMenu(event):
  2389             dialog = PouTransitionDialog(self)
  2382             dialog = PouTransitionDialog(self)
  2390             dialog.SetPouNames(self.Controler.GetProjectPouNames())
  2383             dialog.SetPouNames(self.Controler.GetProjectPouNames())
  2391             dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name))
  2384             dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name))
       
  2385             dialog.SetValues({"transitionName": self.Controler.GenerateNewName(None, None, "transition%d")})
  2392             if dialog.ShowModal() == wx.ID_OK: 
  2386             if dialog.ShowModal() == wx.ID_OK: 
  2393                 values = dialog.GetValues()
  2387                 values = dialog.GetValues()
  2394                 tagname = self.Controler.ProjectAddPouTransition(pou_name, values["transitionName"], values["language"])
  2388                 tagname = self.Controler.ProjectAddPouTransition(pou_name, values["transitionName"], values["language"])
  2395                 if tagname is not None:
  2389                 if tagname is not None:
  2396                     self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
  2390                     self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
  2401     def GenerateAddActionFunction(self, pou_name):
  2395     def GenerateAddActionFunction(self, pou_name):
  2402         def OnAddActionMenu(event):
  2396         def OnAddActionMenu(event):
  2403             dialog = PouActionDialog(self)
  2397             dialog = PouActionDialog(self)
  2404             dialog.SetPouNames(self.Controler.GetProjectPouNames())
  2398             dialog.SetPouNames(self.Controler.GetProjectPouNames())
  2405             dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name))
  2399             dialog.SetPouElementNames(self.Controler.GetProjectPouVariables(pou_name))
       
  2400             dialog.SetValues({"actionName": self.Controler.GenerateNewName(None, None, "action%d")})
  2406             if dialog.ShowModal() == wx.ID_OK:
  2401             if dialog.ShowModal() == wx.ID_OK:
  2407                 values = dialog.GetValues()
  2402                 values = dialog.GetValues()
  2408                 tagname = self.Controler.ProjectAddPouAction(pou_name, values["actionName"], values["language"])
  2403                 tagname = self.Controler.ProjectAddPouAction(pou_name, values["actionName"], values["language"])
  2409                 if tagname is not None:
  2404                 if tagname is not None:
  2410                     self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
  2405                     self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE)
  2411                     self.EditProjectElement(ITEM_ACTION, tagname)
  2406                     self.EditProjectElement(ITEM_ACTION, tagname)
  2412             dialog.Destroy()
  2407             dialog.Destroy()
  2413         return OnAddActionMenu
  2408         return OnAddActionMenu
  2414 
  2409 
  2415     def OnAddConfigurationMenu(self, event):
  2410     def OnAddConfigurationMenu(self, event):
  2416         dialog = ConfigurationNameDialog(self, _("Please enter configuration name"), _("Add new configuration"))
  2411         tagname = self.Controler.ProjectAddConfiguration()
  2417         dialog.SetPouNames(self.Controler.GetProjectPouNames())
  2412         if tagname is not None:
  2418         dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
  2413             self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
  2419         if dialog.ShowModal() == wx.ID_OK:
  2414             self.EditProjectElement(ITEM_CONFIGURATION, tagname)
  2420             value = dialog.GetValue()
  2415         dialog.Destroy()
  2421             tagname = self.Controler.ProjectAddConfiguration(value)
  2416 
       
  2417     def GenerateAddResourceFunction(self, config_name):
       
  2418         def OnAddResourceMenu(event):
       
  2419             tagname = self.Controler.ProjectAddConfigurationResource(config_name)
  2422             if tagname is not None:
  2420             if tagname is not None:
  2423                 self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
  2421                 self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
  2424                 self.EditProjectElement(ITEM_CONFIGURATION, tagname)
  2422                 self.EditProjectElement(ITEM_RESOURCE, tagname)
  2425         dialog.Destroy()
       
  2426 
       
  2427     def GenerateAddResourceFunction(self, config_name):
       
  2428         def OnAddResourceMenu(event):
       
  2429             dialog = ResourceNameDialog(self, _("Please enter resource name"), _("Add new resource"))
       
  2430             dialog.SetPouNames(self.Controler.GetProjectPouNames())
       
  2431             dialog.SetPouElementNames(self.Controler.GetProjectPouVariables())
       
  2432             if dialog.ShowModal() == wx.ID_OK:
       
  2433                 value = dialog.GetValue()
       
  2434                 tagname = self.Controler.ProjectAddConfigurationResource(config_name, value)
       
  2435                 if tagname is not None:
       
  2436                     self._Refresh(TITLE, FILEMENU, EDITMENU, PROJECTTREE, POUINSTANCEVARIABLESPANEL)
       
  2437                     self.EditProjectElement(ITEM_RESOURCE, tagname)
       
  2438             dialog.Destroy()
       
  2439         return OnAddResourceMenu
  2423         return OnAddResourceMenu
  2440 
  2424 
  2441     def GenerateChangePouTypeFunction(self, name, new_type):
  2425     def GenerateChangePouTypeFunction(self, name, new_type):
  2442         def OnChangePouTypeMenu(event):
  2426         def OnChangePouTypeMenu(event):
  2443             selected = self.ProjectTree.GetSelection()
  2427             selected = self.ProjectTree.GetSelection()
  2891                 self.ShowErrorMessage(_("\"%s\" is not a valid folder!")%os.path.dirname(filepath))
  2875                 self.ShowErrorMessage(_("\"%s\" is not a valid folder!")%os.path.dirname(filepath))
  2892             self._Refresh(TITLE, FILEMENU, PAGETITLES)
  2876             self._Refresh(TITLE, FILEMENU, PAGETITLES)
  2893         dialog.Destroy()
  2877         dialog.Destroy()
  2894 
  2878 
  2895 #-------------------------------------------------------------------------------
  2879 #-------------------------------------------------------------------------------
  2896 #                          Edit Step Name Dialog
       
  2897 #-------------------------------------------------------------------------------
       
  2898 
       
  2899 class DataTypeDialog(wx.TextEntryDialog):
       
  2900 
       
  2901     if wx.VERSION < (2, 6, 0):
       
  2902         def Bind(self, event, function, id = None):
       
  2903             if id is not None:
       
  2904                 event(self, id, function)
       
  2905             else:
       
  2906                 event(self, function)
       
  2907     
       
  2908     def __init__(self, parent, message, caption = _("Please enter text"), defaultValue = "", 
       
  2909                        style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
       
  2910         wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
       
  2911         
       
  2912         self.DataTypeNames = []
       
  2913         if wx.VERSION >= (2, 8, 0):
       
  2914             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId())
       
  2915         elif wx.VERSION >= (2, 6, 0):
       
  2916             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
       
  2917         else:
       
  2918             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
       
  2919     
       
  2920     def OnOK(self, event):
       
  2921         datatype_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
       
  2922         if datatype_name == "":
       
  2923             message = wx.MessageDialog(self, _("You must type a name!"), _("Error"), wx.OK|wx.ICON_ERROR)
       
  2924             message.ShowModal()
       
  2925             message.Destroy()
       
  2926         elif not TestIdentifier(datatype_name):
       
  2927             message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%datatype_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  2928             message.ShowModal()
       
  2929             message.Destroy()
       
  2930         elif datatype_name.upper() in IEC_KEYWORDS:
       
  2931             message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%datatype_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  2932             message.ShowModal()
       
  2933             message.Destroy()
       
  2934         elif datatype_name.upper() in self.DataTypeNames:
       
  2935             message = wx.MessageDialog(self, _("\"%s\" data type already exists!")%datatype_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  2936             message.ShowModal()
       
  2937             message.Destroy()
       
  2938         else:
       
  2939             self.EndModal(wx.ID_OK)
       
  2940 
       
  2941     def SetDataTypeNames(self, datatype_names):
       
  2942         self.DataTypeNames = [datatype_name.upper() for datatype_name in datatype_names]
       
  2943 
       
  2944     def GetValue(self):
       
  2945         return self.GetSizer().GetItem(1).GetWindow().GetValue()
       
  2946 
       
  2947 #-------------------------------------------------------------------------------
       
  2948 #                            Create Pou Dialog
       
  2949 #-------------------------------------------------------------------------------
       
  2950 
       
  2951 [ID_POUDIALOG, ID_POUDIALOGPOUNAME, 
       
  2952  ID_POUDIALOGPOUTYPE, ID_POUDIALOGLANGUAGE, ID_POUDIALOGSTATICTEXT1,
       
  2953  ID_POUDIALOGSTATICTEXT2, ID_POUDIALOGSTATICTEXT3, 
       
  2954 ] = [wx.NewId() for _init_ctrls in range(7)]
       
  2955 
       
  2956 def GetPouTypes():
       
  2957     _ = lambda x : x
       
  2958     return [_("function"), _("functionBlock"), _("program")]
       
  2959 POU_TYPES_DICT = dict([(_(pou_type), pou_type) for pou_type in GetPouTypes()])
       
  2960 
       
  2961 def GetPouLanguages():
       
  2962     _ = lambda x : x
       
  2963     return [_("IL"), _("ST"), _("LD"), _("FBD"), _("SFC")]
       
  2964 POU_LANGUAGES_DICT = dict([(_(language), language) for language in GetPouLanguages()])
       
  2965 
       
  2966 class PouDialog(wx.Dialog):
       
  2967     if wx.VERSION < (2, 6, 0):
       
  2968         def Bind(self, event, function, id = None):
       
  2969             if id is not None:
       
  2970                 event(self, id, function)
       
  2971             else:
       
  2972                 event(self, function)
       
  2973     
       
  2974     def _init_coll_flexGridSizer1_Items(self, parent):
       
  2975         parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
       
  2976         parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
       
  2977         
       
  2978     def _init_coll_flexGridSizer1_Growables(self, parent):
       
  2979         parent.AddGrowableCol(0)
       
  2980         parent.AddGrowableRow(0)
       
  2981     
       
  2982     def _init_coll_MainSizer_Items(self, parent):
       
  2983         parent.AddWindow(self.staticText1, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
       
  2984         parent.AddWindow(self.PouName, 0, border=0, flag=wx.GROW)
       
  2985         parent.AddWindow(self.staticText2, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
       
  2986         parent.AddWindow(self.PouType, 0, border=0, flag=wx.GROW)
       
  2987         parent.AddWindow(self.staticText3, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
       
  2988         parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW)
       
  2989         
       
  2990     def _init_coll_MainSizer_Growables(self, parent):
       
  2991         parent.AddGrowableCol(1)
       
  2992         
       
  2993     def _init_sizers(self):
       
  2994         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
       
  2995         self.MainSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=3, vgap=15)
       
  2996 
       
  2997         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
       
  2998         self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
       
  2999         self._init_coll_MainSizer_Items(self.MainSizer)
       
  3000         self._init_coll_MainSizer_Growables(self.MainSizer)
       
  3001 
       
  3002         self.SetSizer(self.flexGridSizer1)
       
  3003         
       
  3004     def _init_ctrls(self, prnt):
       
  3005         wx.Dialog.__init__(self, id=ID_POUDIALOG,
       
  3006               name='PouDialog', parent=prnt,
       
  3007               size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE,
       
  3008               title=_('Create a new POU'))
       
  3009         self.SetClientSize(wx.Size(300, 200))
       
  3010 
       
  3011         self.staticText1 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT1,
       
  3012               label=_('POU Name:'), name='staticText1', parent=self,
       
  3013               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
       
  3014 
       
  3015         self.PouName = wx.TextCtrl(id=ID_POUDIALOGPOUNAME,
       
  3016               name='POUName', parent=self, pos=wx.Point(0, 0), 
       
  3017               size=wx.Size(0, 24), style=0)
       
  3018 
       
  3019         self.staticText2 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT2,
       
  3020               label=_('POU Type:'), name='staticText2', parent=self,
       
  3021               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
       
  3022 
       
  3023         self.PouType = wx.ComboBox(id=ID_POUDIALOGPOUTYPE,
       
  3024               name='POUType', parent=self, pos=wx.Point(0, 0),
       
  3025               size=wx.Size(0, 28), style=wx.CB_READONLY)
       
  3026         self.Bind(wx.EVT_COMBOBOX, self.OnTypeChanged, id=ID_POUDIALOGPOUTYPE)
       
  3027 
       
  3028         self.staticText3 = wx.StaticText(id=ID_POUDIALOGSTATICTEXT3,
       
  3029               label=_('Language:'), name='staticText3', parent=self,
       
  3030               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
       
  3031 
       
  3032         self.Language = wx.ComboBox(id=ID_POUDIALOGLANGUAGE,
       
  3033               name='Language', parent=self, pos=wx.Point(0, 0),
       
  3034               size=wx.Size(0, 28), style=wx.CB_READONLY)
       
  3035         
       
  3036         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
       
  3037         self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
       
  3038             
       
  3039         self._init_sizers()
       
  3040 
       
  3041     def __init__(self, parent, pou_type = None):
       
  3042         self._init_ctrls(parent)
       
  3043         
       
  3044         for option in GetPouTypes():
       
  3045             self.PouType.Append(_(option))
       
  3046         if pou_type is not None:
       
  3047             self.PouType.SetStringSelection(_(pou_type))
       
  3048         self.RefreshLanguage()
       
  3049 
       
  3050         self.PouNames = []
       
  3051         self.PouElementNames = []
       
  3052 
       
  3053     def OnOK(self, event):
       
  3054         error = []
       
  3055         pou_name = self.PouName.GetValue()
       
  3056         if pou_name == "":
       
  3057             error.append(_("POU Name"))
       
  3058         if self.PouType.GetSelection() == -1:
       
  3059             error.append(_("POU Type"))
       
  3060         if self.Language.GetSelection() == -1:
       
  3061             error.append(_("Language"))
       
  3062         if len(error) > 0:
       
  3063             text = ""
       
  3064             for i, item in enumerate(error):
       
  3065                 if i == 0:
       
  3066                     text += item
       
  3067                 elif i == len(error) - 1:
       
  3068                     text += _(" and %s")%item
       
  3069                 else:
       
  3070                     text += _(", %s")%item 
       
  3071             message = wx.MessageDialog(self, _("Form isn't complete. %s must be filled!")%text, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3072             message.ShowModal()
       
  3073             message.Destroy()
       
  3074         elif not TestIdentifier(pou_name):
       
  3075             message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%pou_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3076             message.ShowModal()
       
  3077             message.Destroy()
       
  3078         elif pou_name.upper() in IEC_KEYWORDS:
       
  3079             message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%pou_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3080             message.ShowModal()
       
  3081             message.Destroy()
       
  3082         elif pou_name.upper() in self.PouNames:
       
  3083             message = wx.MessageDialog(self, _("\"%s\" pou already exists!")%pou_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3084             message.ShowModal()
       
  3085             message.Destroy()
       
  3086         elif pou_name.upper() in self.PouElementNames:
       
  3087             message = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%pou_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
       
  3088             result = message.ShowModal()
       
  3089             message.Destroy()
       
  3090             if result == wx.ID_YES:
       
  3091                 self.EndModal(wx.ID_OK)
       
  3092         else:
       
  3093             self.EndModal(wx.ID_OK)
       
  3094 
       
  3095     def RefreshLanguage(self):
       
  3096         selection = POU_LANGUAGES_DICT.get(self.Language.GetStringSelection(), "")
       
  3097         self.Language.Clear()
       
  3098         for language in GetPouLanguages():
       
  3099             if language != "SFC" or POU_TYPES_DICT[self.PouType.GetStringSelection()] != "function":
       
  3100                 self.Language.Append(_(language))
       
  3101         if self.Language.FindString(_(selection)) != wx.NOT_FOUND:
       
  3102             self.Language.SetStringSelection(_(selection))
       
  3103 
       
  3104     def OnTypeChanged(self, event):
       
  3105         self.RefreshLanguage()
       
  3106         event.Skip()
       
  3107 
       
  3108     def SetPouNames(self, pou_names):
       
  3109         self.PouNames = [pou_name.upper() for pou_name in pou_names]
       
  3110 
       
  3111     def SetPouElementNames(self, element_names):
       
  3112         self.PouElementNames = [element_name.upper() for element_name in element_names]
       
  3113 
       
  3114     def SetValues(self, values):
       
  3115         for item, value in values.items():
       
  3116             if item == "pouName":
       
  3117                 self.PouName.SetValue(value)
       
  3118             elif item == "pouType":
       
  3119                 self.PouType.SetStringSelection(_(value))
       
  3120             elif item == "language":
       
  3121                 self.Language.SetStringSelection(_(value))
       
  3122                 
       
  3123     def GetValues(self):
       
  3124         values = {}
       
  3125         values["pouName"] = self.PouName.GetValue()
       
  3126         values["pouType"] = POU_TYPES_DICT[self.PouType.GetStringSelection()]
       
  3127         values["language"] = POU_LANGUAGES_DICT[self.Language.GetStringSelection()]
       
  3128         return values
       
  3129 
       
  3130 
       
  3131 #-------------------------------------------------------------------------------
       
  3132 #                          Create Pou Transition Dialog
       
  3133 #-------------------------------------------------------------------------------
       
  3134 
       
  3135 [ID_POUTRANSITIONDIALOG, ID_POUTRANSITIONDIALOGTRANSITIONNAME, 
       
  3136  ID_POUTRANSITIONDIALOGLANGUAGE, ID_POUTRANSITIONDIALOGSTATICTEXT1, 
       
  3137  ID_POUTRANSITIONDIALOGSTATICTEXT2,
       
  3138 ] = [wx.NewId() for _init_ctrls in range(5)]
       
  3139 
       
  3140 def GetTransitionLanguages():
       
  3141     _ = lambda x : x
       
  3142     return [_("IL"), _("ST"), _("LD"), _("FBD")]
       
  3143 TRANSITION_LANGUAGES_DICT = dict([(_(language), language) for language in GetTransitionLanguages()])
       
  3144 
       
  3145 class PouTransitionDialog(wx.Dialog):
       
  3146     if wx.VERSION < (2, 6, 0):
       
  3147         def Bind(self, event, function, id = None):
       
  3148             if id is not None:
       
  3149                 event(self, id, function)
       
  3150             else:
       
  3151                 event(self, function)
       
  3152     
       
  3153     def _init_coll_flexGridSizer1_Items(self, parent):
       
  3154         parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
       
  3155         parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
       
  3156         
       
  3157     def _init_coll_flexGridSizer1_Growables(self, parent):
       
  3158         parent.AddGrowableCol(0)
       
  3159         parent.AddGrowableRow(0)
       
  3160     
       
  3161     def _init_coll_MainSizer_Items(self, parent):
       
  3162         parent.AddWindow(self.staticText1, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
       
  3163         parent.AddWindow(self.TransitionName, 0, border=0, flag=wx.GROW)
       
  3164         parent.AddWindow(self.staticText2, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
       
  3165         parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW)
       
  3166         
       
  3167     def _init_coll_MainSizer_Growables(self, parent):
       
  3168         parent.AddGrowableCol(1)
       
  3169         
       
  3170     def _init_sizers(self):
       
  3171         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
       
  3172         self.MainSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=15)
       
  3173 
       
  3174         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
       
  3175         self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
       
  3176         self._init_coll_MainSizer_Items(self.MainSizer)
       
  3177         self._init_coll_MainSizer_Growables(self.MainSizer)
       
  3178 
       
  3179         self.SetSizer(self.flexGridSizer1)
       
  3180 
       
  3181     def _init_ctrls(self, prnt):
       
  3182         wx.Dialog.__init__(self, id=ID_POUTRANSITIONDIALOG,
       
  3183               name='PouTransitionDialog', parent=prnt,
       
  3184               size=wx.Size(350, 200), style=wx.DEFAULT_DIALOG_STYLE,
       
  3185               title=_('Create a new transition'))
       
  3186         self.SetClientSize(wx.Size(350, 160))
       
  3187 
       
  3188         self.staticText1 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT1,
       
  3189               label=_('Transition Name:'), name='staticText1', parent=self,
       
  3190               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
       
  3191 
       
  3192         self.TransitionName = wx.TextCtrl(id=ID_POUTRANSITIONDIALOGTRANSITIONNAME,
       
  3193               name='TransitionName', parent=self, pos=wx.Point(0, 0),
       
  3194               size=wx.Size(0, 24), style=0)
       
  3195 
       
  3196         self.staticText2 = wx.StaticText(id=ID_POUTRANSITIONDIALOGSTATICTEXT2,
       
  3197               label=_('Language:'), name='staticText2', parent=self,
       
  3198               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
       
  3199 
       
  3200         self.Language = wx.ComboBox(id=ID_POUTRANSITIONDIALOGLANGUAGE,
       
  3201               name='Language', parent=self, pos=wx.Point(0, 0),
       
  3202               size=wx.Size(0, 28), style=wx.CB_READONLY)
       
  3203         
       
  3204         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
       
  3205         self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
       
  3206         
       
  3207         self._init_sizers()
       
  3208 
       
  3209     def __init__(self, parent):
       
  3210         self._init_ctrls(parent)
       
  3211         
       
  3212         for language in GetTransitionLanguages():
       
  3213             self.Language.Append(_(language))
       
  3214             
       
  3215         self.PouNames = []
       
  3216         self.PouElementNames = []
       
  3217         
       
  3218     def OnOK(self, event):
       
  3219         error = []
       
  3220         transition_name = self.TransitionName.GetValue()
       
  3221         if self.TransitionName.GetValue() == "":
       
  3222             error.append(_("Transition Name"))
       
  3223         if self.Language.GetSelection() == -1:
       
  3224             error.append(_("Language"))
       
  3225         if len(error) > 0:
       
  3226             text = ""
       
  3227             for i, item in enumerate(error):
       
  3228                 if i == 0:
       
  3229                     text += item
       
  3230                 elif i == len(error) - 1:
       
  3231                     text += _(" and %s")%item
       
  3232                 else:
       
  3233                     text += _(", %s")%item 
       
  3234             message = wx.MessageDialog(self, _("Form isn't complete. %s must be filled!")%text, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3235             message.ShowModal()
       
  3236             message.Destroy()
       
  3237         elif not TestIdentifier(transition_name):
       
  3238             message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3239             message.ShowModal()
       
  3240             message.Destroy()
       
  3241         elif transition_name.upper() in IEC_KEYWORDS:
       
  3242             message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3243             message.ShowModal()
       
  3244             message.Destroy()
       
  3245         elif transition_name.upper() in self.PouNames:
       
  3246             message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3247             message.ShowModal()
       
  3248             message.Destroy()
       
  3249         elif transition_name.upper() in self.PouElementNames:
       
  3250             message = wx.MessageDialog(self, _("\"%s\" element for this pou already exists!")%transition_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3251             message.ShowModal()
       
  3252             message.Destroy()
       
  3253         else:
       
  3254             self.EndModal(wx.ID_OK)
       
  3255     
       
  3256     def SetPouNames(self, pou_names):
       
  3257         self.PouNames = [pou_name.upper() for pou_name in pou_names]
       
  3258     
       
  3259     def SetPouElementNames(self, pou_names):
       
  3260         self.PouElementNames = [pou_name.upper() for pou_name in pou_names]
       
  3261     
       
  3262     def SetValues(self, values):
       
  3263         for item, value in values.items():
       
  3264             if item == "transitionName":
       
  3265                 self.TransitionName.SetValue(value)
       
  3266             elif item == "language":
       
  3267                 self.Language.SetSelection(_(value))
       
  3268                 
       
  3269     def GetValues(self):
       
  3270         values = {}
       
  3271         values["transitionName"] = self.TransitionName.GetValue()
       
  3272         values["language"] = TRANSITION_LANGUAGES_DICT[self.Language.GetStringSelection()]
       
  3273         return values
       
  3274 
       
  3275 #-------------------------------------------------------------------------------
       
  3276 #                          Create Pou Action Dialog
       
  3277 #-------------------------------------------------------------------------------
       
  3278 
       
  3279 [ID_POUACTIONDIALOG, ID_POUACTIONDIALOGACTIONNAME, 
       
  3280  ID_POUACTIONDIALOGLANGUAGE, ID_POUACTIONDIALOGSTATICTEXT1, 
       
  3281  ID_POUACTIONDIALOGSTATICTEXT2, 
       
  3282 ] = [wx.NewId() for _init_ctrls in range(5)]
       
  3283 
       
  3284 def GetActionLanguages():
       
  3285     _ = lambda x : x
       
  3286     return [_("IL"), _("ST"), _("LD"), _("FBD")]
       
  3287 ACTION_LANGUAGES_DICT = dict([(_(language), language) for language in GetActionLanguages()])
       
  3288 
       
  3289 class PouActionDialog(wx.Dialog):
       
  3290     if wx.VERSION < (2, 6, 0):
       
  3291         def Bind(self, event, function, id = None):
       
  3292             if id is not None:
       
  3293                 event(self, id, function)
       
  3294             else:
       
  3295                 event(self, function)
       
  3296     
       
  3297     def _init_coll_flexGridSizer1_Items(self, parent):
       
  3298         parent.AddSizer(self.MainSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
       
  3299         parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
       
  3300         
       
  3301     def _init_coll_flexGridSizer1_Growables(self, parent):
       
  3302         parent.AddGrowableCol(0)
       
  3303         parent.AddGrowableRow(0)
       
  3304     
       
  3305     def _init_coll_MainSizer_Items(self, parent):
       
  3306         parent.AddWindow(self.staticText1, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
       
  3307         parent.AddWindow(self.ActionName, 0, border=0, flag=wx.GROW)
       
  3308         parent.AddWindow(self.staticText2, 0, border=4, flag=wx.ALIGN_CENTER_VERTICAL|wx.TOP)
       
  3309         parent.AddWindow(self.Language, 0, border=0, flag=wx.GROW)
       
  3310         
       
  3311     def _init_coll_MainSizer_Growables(self, parent):
       
  3312         parent.AddGrowableCol(1)
       
  3313         
       
  3314     def _init_sizers(self):
       
  3315         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
       
  3316         self.MainSizer = wx.FlexGridSizer(cols=2, hgap=5, rows=2, vgap=15)
       
  3317 
       
  3318         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
       
  3319         self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
       
  3320         self._init_coll_MainSizer_Items(self.MainSizer)
       
  3321         self._init_coll_MainSizer_Growables(self.MainSizer)
       
  3322 
       
  3323         self.SetSizer(self.flexGridSizer1)
       
  3324 
       
  3325     def _init_ctrls(self, prnt):
       
  3326         wx.Dialog.__init__(self, id=ID_POUACTIONDIALOG,
       
  3327               name='PouActionDialog', parent=prnt,
       
  3328               size=wx.Size(320, 200), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
       
  3329               title=_('Create a new action'))
       
  3330         self.SetClientSize(wx.Size(320, 160))
       
  3331 
       
  3332         self.staticText1 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT1,
       
  3333               label=_('Action Name:'), name='staticText1', parent=self,
       
  3334               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
       
  3335 
       
  3336         self.ActionName = wx.TextCtrl(id=ID_POUACTIONDIALOGACTIONNAME,
       
  3337               name='ActionName', parent=self, pos=wx.Point(0, 0),
       
  3338               size=wx.Size(0, 24), style=0)
       
  3339 
       
  3340         self.staticText2 = wx.StaticText(id=ID_POUACTIONDIALOGSTATICTEXT2,
       
  3341               label=_('Language:'), name='staticText2', parent=self,
       
  3342               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
       
  3343 
       
  3344         self.Language = wx.ComboBox(id=ID_POUACTIONDIALOGLANGUAGE,
       
  3345               name='Language', parent=self, pos=wx.Point(0, 0),
       
  3346               size=wx.Size(0, 28), style=wx.CB_READONLY)
       
  3347         
       
  3348         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
       
  3349         self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
       
  3350         
       
  3351         self._init_sizers()
       
  3352 
       
  3353     def __init__(self, parent):
       
  3354         self._init_ctrls(parent)
       
  3355         
       
  3356         for option in GetActionLanguages():
       
  3357             self.Language.Append(_(option))
       
  3358         
       
  3359         self.PouNames = []
       
  3360         self.PouElementNames = []
       
  3361     
       
  3362     def OnOK(self, event):
       
  3363         error = []
       
  3364         action_name = self.ActionName.GetValue()
       
  3365         if action_name == "":
       
  3366             error.append(_("Action Name"))
       
  3367         if self.Language.GetSelection() == -1:
       
  3368             error.append(_("Language"))
       
  3369         if len(error) > 0:
       
  3370             text = ""
       
  3371             for i, item in enumerate(error):
       
  3372                 if i == 0:
       
  3373                     text += item
       
  3374                 elif i == len(error) - 1:
       
  3375                     text += _(" and %s")%item
       
  3376                 else:
       
  3377                     text += _(", %s")%item 
       
  3378             message = wx.MessageDialog(self, _("Form isn't complete. %s must be filled!")%text, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3379             message.ShowModal()
       
  3380             message.Destroy()
       
  3381         elif not TestIdentifier(action_name):
       
  3382             message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3383             message.ShowModal()
       
  3384             message.Destroy()
       
  3385         elif action_name.upper() in IEC_KEYWORDS:
       
  3386             message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3387             message.ShowModal()
       
  3388             message.Destroy()
       
  3389         elif action_name.upper() in self.PouNames:
       
  3390             message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3391             message.ShowModal()
       
  3392             message.Destroy()
       
  3393         elif action_name.upper() in self.PouElementNames:
       
  3394             message = wx.MessageDialog(self, _("\"%s\" element for this pou already exists!")%action_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3395             message.ShowModal()
       
  3396             message.Destroy()
       
  3397         else:
       
  3398             self.EndModal(wx.ID_OK)
       
  3399     
       
  3400     def SetPouNames(self, pou_names):
       
  3401         self.PouNames = [pou_name.upper() for pou_name in pou_names]
       
  3402         
       
  3403     def SetPouElementNames(self, element_names):
       
  3404         self.PouElementNames = [element_name.upper() for element_name in element_names]
       
  3405         
       
  3406     def SetValues(self, values):
       
  3407         for item, value in values.items():
       
  3408             if item == "actionName":
       
  3409                 self.ActionName.SetValue(value)
       
  3410             elif item == "language":
       
  3411                 self.Language.SetStringSelection(_(value))
       
  3412                 
       
  3413     def GetValues(self):
       
  3414         values = {}
       
  3415         values["actionName"] = self.ActionName.GetValue()
       
  3416         values["language"] = ACTION_LANGUAGES_DICT[self.Language.GetStringSelection()]
       
  3417         return values
       
  3418 
       
  3419 #-------------------------------------------------------------------------------
       
  3420 #                          Configuration Name Dialog
       
  3421 #-------------------------------------------------------------------------------
       
  3422 
       
  3423 class ConfigurationNameDialog(wx.TextEntryDialog):
       
  3424 
       
  3425     if wx.VERSION < (2, 6, 0):
       
  3426         def Bind(self, event, function, id = None):
       
  3427             if id is not None:
       
  3428                 event(self, id, function)
       
  3429             else:
       
  3430                 event(self, function)
       
  3431 
       
  3432     def __init__(self, parent, message, caption = _("Please enter configuration name"), defaultValue = "", 
       
  3433                        style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
       
  3434         wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
       
  3435         
       
  3436         self.PouNames = []
       
  3437         self.PouElementNames = []
       
  3438         
       
  3439         if wx.VERSION >= (2, 8, 0):
       
  3440             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId())
       
  3441         elif wx.VERSION >= (2, 6, 0):
       
  3442             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
       
  3443         else:
       
  3444             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
       
  3445     
       
  3446     def OnOK(self, event):
       
  3447         config_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
       
  3448         if config_name == "":
       
  3449             message = wx.MessageDialog(self, _("You must type a name!"), _("Error"), wx.OK|wx.ICON_ERROR)
       
  3450             message.ShowModal()
       
  3451             message.Destroy()
       
  3452         elif not TestIdentifier(config_name):
       
  3453             message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%config_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3454             message.ShowModal()
       
  3455             message.Destroy()
       
  3456         elif config_name.upper() in IEC_KEYWORDS:
       
  3457             message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%config_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3458             message.ShowModal()
       
  3459             message.Destroy()
       
  3460         elif config_name.upper() in self.PouNames:
       
  3461             message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%config_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3462             message.ShowModal()
       
  3463             message.Destroy()
       
  3464         elif config_name.upper() in self.PouElementNames:
       
  3465             message = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%config_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
       
  3466             result = message.ShowModal()
       
  3467             message.Destroy()
       
  3468             if result == wx.ID_YES:
       
  3469                 self.EndModal(wx.ID_OK)
       
  3470         else:
       
  3471             self.EndModal(wx.ID_OK)
       
  3472 
       
  3473     def SetPouNames(self, pou_names):
       
  3474         self.PouNames = [pou_name.upper() for pou_name in pou_names]
       
  3475     
       
  3476     def SetPouElementNames(self, pou_names):
       
  3477         self.PouElementNames = [pou_name.upper() for pou_name in pou_names]
       
  3478     
       
  3479     def GetValue(self):
       
  3480         return self.GetSizer().GetItem(1).GetWindow().GetValue()
       
  3481 
       
  3482 #-------------------------------------------------------------------------------
       
  3483 #                          Resource Name Dialog
       
  3484 #-------------------------------------------------------------------------------
       
  3485 
       
  3486 class ResourceNameDialog(wx.TextEntryDialog):
       
  3487 
       
  3488     if wx.VERSION < (2, 6, 0):
       
  3489         def Bind(self, event, function, id = None):
       
  3490             if id is not None:
       
  3491                 event(self, id, function)
       
  3492             else:
       
  3493                 event(self, function)
       
  3494 
       
  3495     def __init__(self, parent, message, caption = _("Please enter resource name"), defaultValue = "", 
       
  3496                        style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition):
       
  3497         wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos)
       
  3498         
       
  3499         self.PouNames = []
       
  3500         self.PouElementNames = []
       
  3501         
       
  3502         if wx.VERSION >= (2, 8, 0):
       
  3503             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(2).GetSizer().GetItem(1).GetSizer().GetAffirmativeButton().GetId())
       
  3504         elif wx.VERSION >= (2, 6, 0):
       
  3505             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId())
       
  3506         else:
       
  3507             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
       
  3508 
       
  3509     def OnOK(self, event):
       
  3510         resource_name = self.GetSizer().GetItem(1).GetWindow().GetValue()
       
  3511         if resource_name == "":
       
  3512             message = wx.MessageDialog(self, _("You must type a name!"), _("Error"), wx.OK|wx.ICON_ERROR)
       
  3513             message.ShowModal()
       
  3514             message.Destroy()
       
  3515         elif not TestIdentifier(resource_name):
       
  3516             message = wx.MessageDialog(self, _("\"%s\" is not a valid identifier!")%resource_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3517             message.ShowModal()
       
  3518             message.Destroy()
       
  3519         elif resource_name.upper() in IEC_KEYWORDS:
       
  3520             message = wx.MessageDialog(self, _("\"%s\" is a keyword. It can't be used!")%resource_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3521             message.ShowModal()
       
  3522             message.Destroy()
       
  3523         elif resource_name.upper() in self.PouNames:
       
  3524             message = wx.MessageDialog(self, _("A POU named \"%s\" already exists!")%resource_name, _("Error"), wx.OK|wx.ICON_ERROR)
       
  3525             message.ShowModal()
       
  3526             message.Destroy()
       
  3527         elif resource_name.upper() in self.PouElementNames:
       
  3528             message = wx.MessageDialog(self, _("A POU has an element named \"%s\". This could cause a conflict. Do you wish to continue?")%resource_name, _("Warning"), wx.YES_NO|wx.ICON_EXCLAMATION)
       
  3529             result = message.ShowModal()
       
  3530             message.Destroy()
       
  3531             if result == wx.ID_YES:
       
  3532                 self.EndModal(wx.ID_OK)
       
  3533         else:
       
  3534             self.EndModal(wx.ID_OK)
       
  3535 
       
  3536     def SetPouNames(self, pou_names):
       
  3537         self.PouNames = [pou_name.upper() for pou_name in pou_names]
       
  3538     
       
  3539     def SetPouElementNames(self, pou_names):
       
  3540         self.PouElementNames = [pou_name.upper() for pou_name in pou_names]
       
  3541     
       
  3542     def GetValue(self):
       
  3543         return self.GetSizer().GetItem(1).GetWindow().GetValue()
       
  3544 
       
  3545 #-------------------------------------------------------------------------------
       
  3546 #                            Debug Variables Panel
  2880 #                            Debug Variables Panel
  3547 #-------------------------------------------------------------------------------
  2881 #-------------------------------------------------------------------------------
  3548 
  2882 
  3549 def GetDebugVariablesTableColnames():
  2883 def GetDebugVariablesTableColnames():
  3550     _ = lambda x : x
  2884     _ = lambda x : x