Beremiz.py
changeset 715 135566ab0807
parent 714 f8ee6fd01f7c
child 716 180e4a7d945c
equal deleted inserted replaced
714:f8ee6fd01f7c 715:135566ab0807
   148 import types, time, re, platform, time, traceback, commands
   148 import types, time, re, platform, time, traceback, commands
   149 from plugger import PluginsRoot, MATIEC_ERROR_MODEL
   149 from plugger import PluginsRoot, MATIEC_ERROR_MODEL
   150 from wxPopen import ProcessLogger
   150 from wxPopen import ProcessLogger
   151 
   151 
   152 from docutils import *
   152 from docutils import *
   153 from PLCOpenEditor import IDEFrame, Viewer, AppendMenu, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, INSTANCESTREE, LIBRARYTREE, SCALING, PAGETITLES, USE_AUI
   153 from PLCOpenEditor import IDEFrame, AppendMenu, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, INSTANCESTREE, LIBRARYTREE, SCALING, PAGETITLES, USE_AUI
       
   154 from PLCOpenEditor import EditorPanel, Viewer, TextViewer, GraphicViewer, ResourceEditor, ConfigurationEditor, DataTypeEditor
   154 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
   155 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
   155 
   156 
   156 SCROLLBAR_UNIT = 10
   157 SCROLLBAR_UNIT = 10
   157 WINDOW_COLOUR = wx.Colour(240,240,240)
   158 WINDOW_COLOUR = wx.Colour(240,240,240)
   158 TITLE_COLOUR = wx.Colour(200,200,220)
   159 TITLE_COLOUR = wx.Colour(200,200,220)
   499               size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
   500               size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
   500         self.PLCConfig.SetBackgroundColour(wx.WHITE)
   501         self.PLCConfig.SetBackgroundColour(wx.WHITE)
   501         self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
   502         self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
   502         self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
   503         self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
   503         self.PLCConfig.Bind(wx.EVT_MOUSEWHEEL, self.OnPLCConfigScroll)
   504         self.PLCConfig.Bind(wx.EVT_MOUSEWHEEL, self.OnPLCConfigScroll)
       
   505         self.MainTabs["PLCConfig"] = (self.PLCConfig, _("Topology"))
   504         self.BottomNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True)
   506         self.BottomNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True)
   505         
   507         
   506         self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
   508         self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
   507                   name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
   509                   name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
   508                   size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
   510                   size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
   509         self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
   511         self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
   510         self.BottomNoteBook.AddPage(self.LogConsole, _("Log Console"))
   512         self.MainTabs["LogConsole"] = (self.LogConsole, _("Log Console"))
       
   513         self.BottomNoteBook.AddPage(*self.MainTabs["LogConsole"])
   511         if USE_AUI:
   514         if USE_AUI:
   512             self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogConsole), wx.RIGHT)
   515             self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogConsole), wx.RIGHT)
   513         
   516         
   514         self._init_beremiz_sizers()
   517         self._init_beremiz_sizers()
   515 
   518 
   543             ("VAR_LOCAL",     LOCATION_VAR_MEMORY)]:
   546             ("VAR_LOCAL",     LOCATION_VAR_MEMORY)]:
   544             self.LocationImageDict[itemtype]=self.LocationImageList.Add(wx.Bitmap(os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png'%imgname)))
   547             self.LocationImageDict[itemtype]=self.LocationImageList.Add(wx.Bitmap(os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png'%imgname)))
   545         
   548         
   546         # Add beremiz's icon in top left corner of the frame
   549         # Add beremiz's icon in top left corner of the frame
   547         self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO))
   550         self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO))
       
   551         
       
   552         if projectOpen is None and self.Config.HasEntry("currenteditedproject"):
       
   553             projectOpen = str(self.Config.Read("currenteditedproject"))
       
   554             if projectOpen == "":
       
   555                 projectOpen = None
   548         
   556         
   549         if projectOpen is not None and os.path.isdir(projectOpen):
   557         if projectOpen is not None and os.path.isdir(projectOpen):
   550             self.PluginRoot = PluginsRoot(self, self.Log)
   558             self.PluginRoot = PluginsRoot(self, self.Log)
   551             self.Controler = self.PluginRoot
   559             self.Controler = self.PluginRoot
   552             result = self.PluginRoot.LoadProject(projectOpen, buildpath)
   560             result = self.PluginRoot.LoadProject(projectOpen, buildpath)
   654                 self.PluginRoot.SaveProject()
   662                 self.PluginRoot.SaveProject()
   655             elif answer == wx.ID_CANCEL:
   663             elif answer == wx.ID_CANCEL:
   656                 return False
   664                 return False
   657         return True
   665         return True
   658     
   666     
       
   667     def GetTabInfos(self, tab):
       
   668         if (isinstance(tab, EditorPanel) and 
       
   669             not isinstance(tab, (Viewer, 
       
   670                                  TextViewer, 
       
   671                                  GraphicViewer, 
       
   672                                  ResourceEditor, 
       
   673                                  ConfigurationEditor, 
       
   674                                  DataTypeEditor))):
       
   675             return ("plugin", tab.Controler.PlugFullName())
       
   676         else:
       
   677             return IDEFrame.GetTabInfos(self, tab)
       
   678     
       
   679     def LoadTab(self, notebook, page_infos):
       
   680         if page_infos[0] == "plugin":
       
   681             plugin = self.PluginRoot.GetChildByName(page_infos[1])
       
   682             return notebook.GetPageIndex(plugin._OpenView())
       
   683         else:
       
   684             return IDEFrame.LoadTab(self, notebook, page_infos)
       
   685     
   659     def OnCloseFrame(self, event):
   686     def OnCloseFrame(self, event):
   660         if self.PluginRoot is None or self.CheckSaveBeforeClosing(_("Close Application")):
   687         if self.PluginRoot is None or self.CheckSaveBeforeClosing(_("Close Application")):
   661             if self.PluginRoot is not None:
   688             if self.PluginRoot is not None:
   662                 self.PluginRoot.KillDebugThread()
   689                 self.PluginRoot.KillDebugThread()
   663             self.KillLocalRuntime()
   690             self.KillLocalRuntime()
   664             
   691             
   665             self.SaveFrameSize()
   692             self.SaveLastState()
       
   693             
       
   694             if self.PluginRoot is not None:
       
   695                 project_path = os.path.realpath(self.PluginRoot.GetProjectPath())
       
   696             else:
       
   697                 project_path = ""
       
   698             self.Config.Write("currenteditedproject", project_path)    
       
   699             self.Config.Flush()
   666             
   700             
   667             event.Skip()
   701             event.Skip()
   668         else:
   702         else:
   669             event.Veto()
   703             event.Veto()
   670     
   704     
  1674             result = self.PluginRoot.LoadProject(projectpath)
  1708             result = self.PluginRoot.LoadProject(projectpath)
  1675             if not result:
  1709             if not result:
  1676                 self.RefreshConfigRecentProjects(projectpath)
  1710                 self.RefreshConfigRecentProjects(projectpath)
  1677                 if self.EnableDebug:
  1711                 if self.EnableDebug:
  1678                     self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
  1712                     self.DebugVariablePanel.SetDataProducer(self.PluginRoot)
       
  1713                 self.LoadProjectOrganization()
  1679                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  1714                 self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
  1680                 self.RefreshAll()
  1715                 self.RefreshAll()
  1681             else:
  1716             else:
  1682                 self.ResetView()
  1717                 self.ResetView()
  1683                 self.ShowErrorMessage(result)
  1718                 self.ShowErrorMessage(result)
  1687     
  1722     
  1688     def OnCloseProjectMenu(self, event):
  1723     def OnCloseProjectMenu(self, event):
  1689         if self.PluginRoot is not None and not self.CheckSaveBeforeClosing():
  1724         if self.PluginRoot is not None and not self.CheckSaveBeforeClosing():
  1690             return
  1725             return
  1691         
  1726         
       
  1727         self.SaveProjectOrganization()
  1692         self.ResetView()
  1728         self.ResetView()
  1693         self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
  1729         self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
  1694         self.RefreshAll()
  1730         self.RefreshAll()
  1695     
  1731     
  1696     def OnSaveProjectMenu(self, event):
  1732     def OnSaveProjectMenu(self, event):