PLCOpenEditor.py
changeset 500 b3499ff87178
parent 498 5f90349529c9
child 503 52689bda4686
equal deleted inserted replaced
499:cecb4369fa42 500:b3499ff87178
  2502     #  @param fileOpen The filepath to open if no controler defined (default: None).
  2502     #  @param fileOpen The filepath to open if no controler defined (default: None).
  2503     #  @param debug The filepath to open if no controler defined (default: False).
  2503     #  @param debug The filepath to open if no controler defined (default: False).
  2504     def __init__(self, parent, fileOpen = None):
  2504     def __init__(self, parent, fileOpen = None):
  2505         IDEFrame.__init__(self, parent)
  2505         IDEFrame.__init__(self, parent)
  2506         
  2506         
       
  2507         result = None
       
  2508         
  2507         # Open the filepath if defined
  2509         # Open the filepath if defined
  2508         if fileOpen is not None and os.path.isfile(fileOpen):
  2510         if fileOpen is not None and os.path.isfile(fileOpen):
  2509             # Create a new controller
  2511             # Create a new controller
  2510             self.Controler = PLCControler()
  2512             self.Controler = PLCControler()
  2511             self.Controler.OpenXMLFile(fileOpen)
  2513             result = self.Controler.OpenXMLFile(fileOpen)
  2512             self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  2514             if result is None:
       
  2515                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  2513         
  2516         
  2514         # Define PLCOpenEditor icon
  2517         # Define PLCOpenEditor icon
  2515         self.SetIcon(wx.Icon(os.path.join(CWD,"Images", "poe.ico"),wx.BITMAP_TYPE_ICO))
  2518         self.SetIcon(wx.Icon(os.path.join(CWD,"Images", "poe.ico"),wx.BITMAP_TYPE_ICO))
  2516 
  2519 
  2517         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
  2520         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
  2518         
  2521         
  2519         self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
  2522         self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
       
  2523         
       
  2524         if result is not None:
       
  2525             self.ShowErrorMessage(result)
  2520 
  2526 
  2521     def OnCloseFrame(self, event):
  2527     def OnCloseFrame(self, event):
  2522         if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")):
  2528         if self.Controler is None or self.CheckSaveBeforeClosing(_("Close Application")):
  2523             if USE_AUI:
  2529             if USE_AUI:
  2524                 self.AUIManager.UnInit()
  2530                 self.AUIManager.UnInit()
  2593             filepath = self.Controler.GetFilePath()
  2599             filepath = self.Controler.GetFilePath()
  2594         if filepath != "":
  2600         if filepath != "":
  2595             directory = os.path.dirname(filepath)
  2601             directory = os.path.dirname(filepath)
  2596         else:
  2602         else:
  2597             directory = os.getcwd()
  2603             directory = os.getcwd()
       
  2604         
       
  2605         result = None
       
  2606         
  2598         dialog = wx.FileDialog(self, _("Choose a file"), directory, "",  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
  2607         dialog = wx.FileDialog(self, _("Choose a file"), directory, "",  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
  2599         if dialog.ShowModal() == wx.ID_OK:
  2608         if dialog.ShowModal() == wx.ID_OK:
  2600             filepath = dialog.GetPath()
  2609             filepath = dialog.GetPath()
  2601             if os.path.isfile(filepath):
  2610             if os.path.isfile(filepath):
  2602                 self.ResetView()
  2611                 self.ResetView()
  2603                 self.Controler = PLCControler()
  2612                 self.Controler = PLCControler()
  2604                 self.Controler.OpenXMLFile(filepath)
  2613                 result = self.Controler.OpenXMLFile(filepath)
  2605                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  2614                 if result is None:
       
  2615                     self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  2606             self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
  2616             self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
  2607         dialog.Destroy()
  2617         dialog.Destroy()
       
  2618         
       
  2619         if result is not None:
       
  2620             self.ShowErrorMessage(result)
  2608     
  2621     
  2609     def OnCloseProjectMenu(self, event):
  2622     def OnCloseProjectMenu(self, event):
  2610         if not self.CheckSaveBeforeClosing():
  2623         if not self.CheckSaveBeforeClosing():
  2611             return
  2624             return
  2612         self.ResetView()
  2625         self.ResetView()