PLCOpenEditor.py
changeset 712 c11b54730a7b
parent 711 5f6a743dcde5
child 714 131ea7f237b9
equal deleted inserted replaced
711:5f6a743dcde5 712:c11b54730a7b
  1922         self.ProjectTreeItemSelect(item)
  1922         self.ProjectTreeItemSelect(item)
  1923         name = self.ProjectTree.GetItemText(item)
  1923         name = self.ProjectTree.GetItemText(item)
  1924         item_infos = self.ProjectTree.GetPyData(item)
  1924         item_infos = self.ProjectTree.GetPyData(item)
  1925         
  1925         
  1926         menu = None
  1926         menu = None
  1927         if item_infos["type"] in ITEMS_UNEDITABLE:
  1927         if item_infos["type"] in ITEMS_UNEDITABLE + [ITEM_PROJECT]:
  1928             name = UNEDITABLE_NAMES_DICT[name]
  1928             if item_infos["type"] == ITEM_PROJECT:
       
  1929                 name = "Project"
       
  1930             else:
       
  1931                 name = UNEDITABLE_NAMES_DICT[name]
  1929             
  1932             
  1930             if name == "Data Types":
  1933             if name == "Data Types":
  1931                 menu = wx.Menu(title='')
  1934                 menu = wx.Menu(title='')
  1932                 new_id = wx.NewId()
  1935                 new_id = wx.NewId()
  1933                 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add DataType"))
  1936                 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add DataType"))
  1934                 self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, id=new_id)
  1937                 self.Bind(wx.EVT_MENU, self.OnAddDataTypeMenu, id=new_id)
  1935             
  1938             
  1936             elif name in ["Functions", "Function Blocks", "Programs"]:
  1939             elif name in ["Functions", "Function Blocks", "Programs", "Project"]:
  1937                 menu = wx.Menu(title='')
  1940                 menu = wx.Menu(title='')
  1938 
  1941                 
  1939                 new_id = wx.NewId()
  1942                 if name != "Project":
  1940                 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add POU"))
  1943                     new_id = wx.NewId()
  1941                 self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction({"Functions" : "function", "Function Blocks" : "functionBlock", "Programs" : "program"}[name]), id=new_id)
  1944                     AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Add POU"))
       
  1945                     self.Bind(wx.EVT_MENU, self.GenerateAddPouFunction({"Functions" : "function", "Function Blocks" : "functionBlock", "Programs" : "program"}[name]), id=new_id)
  1942 
  1946 
  1943                 new_id = wx.NewId()
  1947                 new_id = wx.NewId()
  1944                 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Paste POU"))
  1948                 AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Paste POU"))
  1945                 self.Bind(wx.EVT_MENU, self.OnPastePou, id=new_id)
  1949                 self.Bind(wx.EVT_MENU, self.OnPastePou, id=new_id)
  1946                 if self.GetCopyBuffer() is None:
  1950                 if self.GetCopyBuffer() is None:
  2447             self.SetCopyBuffer(pou_xml)
  2451             self.SetCopyBuffer(pou_xml)
  2448             self._Refresh(EDITMENU)
  2452             self._Refresh(EDITMENU)
  2449 
  2453 
  2450     def OnPastePou(self, event):
  2454     def OnPastePou(self, event):
  2451         selected = self.ProjectTree.GetSelection()
  2455         selected = self.ProjectTree.GetSelection()
  2452 
  2456         
  2453         pou_type = self.ProjectTree.GetItemText(selected)
  2457         if self.ProjectTree.GetPyData(selected)["type"] != ITEM_PROJECT: 
  2454         pou_type = UNEDITABLE_NAMES_DICT[pou_type] # one of 'Functions', 'Function Blocks' or 'Programs'
  2458             pou_type = self.ProjectTree.GetItemText(selected)
  2455         pou_type = {'Functions': 'function', 'Function Blocks': 'functionBlock', 'Programs': 'program'}[pou_type]
  2459             pou_type = UNEDITABLE_NAMES_DICT[pou_type] # one of 'Functions', 'Function Blocks' or 'Programs'
  2456 
  2460             pou_type = {'Functions': 'function', 'Function Blocks': 'functionBlock', 'Programs': 'program'}[pou_type]
       
  2461         else:
       
  2462             pou_type = None
       
  2463         
  2457         pou_xml = self.GetCopyBuffer()
  2464         pou_xml = self.GetCopyBuffer()
  2458 
  2465 
  2459         result = self.Controler.PastePou(pou_type, pou_xml)
  2466         result = self.Controler.PastePou(pou_type, pou_xml)
  2460 
  2467 
  2461         if result is not None:
  2468         if not isinstance(result, TupleType):
  2462             message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
  2469             message = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
  2463             message.ShowModal()
  2470             message.ShowModal()
  2464             message.Destroy()
  2471             message.Destroy()
  2465         else:
  2472         else:
  2466             self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
  2473             self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, PROJECTTREE, LIBRARYTREE)
       
  2474             self.EditProjectElement(ITEM_POU, result[0])
  2467 
  2475 
  2468 #-------------------------------------------------------------------------------
  2476 #-------------------------------------------------------------------------------
  2469 #                        Remove Project Elements Functions
  2477 #                        Remove Project Elements Functions
  2470 #-------------------------------------------------------------------------------
  2478 #-------------------------------------------------------------------------------
  2471 
  2479