BeremizIDE.py
changeset 1768 691083b5682a
parent 1767 c74815729afd
child 1769 4665ba25a0ba
equal deleted inserted replaced
1767:c74815729afd 1768:691083b5682a
   226 
   226 
   227         IDEFrame._init_utils(self)
   227         IDEFrame._init_utils(self)
   228 
   228 
   229     def _init_coll_FileMenu_Items(self, parent):
   229     def _init_coll_FileMenu_Items(self, parent):
   230         AppendMenu(parent, help='', id=wx.ID_NEW,
   230         AppendMenu(parent, help='', id=wx.ID_NEW,
   231               kind=wx.ITEM_NORMAL, text=_(u'New') + '\tCTRL+N')
   231                    kind=wx.ITEM_NORMAL, text=_(u'New') + '\tCTRL+N')
   232         AppendMenu(parent, help='', id=wx.ID_OPEN,
   232         AppendMenu(parent, help='', id=wx.ID_OPEN,
   233               kind=wx.ITEM_NORMAL, text=_(u'Open') + '\tCTRL+O')
   233                    kind=wx.ITEM_NORMAL, text=_(u'Open') + '\tCTRL+O')
   234         parent.AppendMenu(ID_FILEMENURECENTPROJECTS, _("&Recent Projects"), self.RecentProjectsMenu)
   234         parent.AppendMenu(ID_FILEMENURECENTPROJECTS, _("&Recent Projects"), self.RecentProjectsMenu)
   235         parent.AppendSeparator()
   235         parent.AppendSeparator()
   236         AppendMenu(parent, help='', id=wx.ID_SAVE,
   236         AppendMenu(parent, help='', id=wx.ID_SAVE,
   237               kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S')
   237                    kind=wx.ITEM_NORMAL, text=_(u'Save') + '\tCTRL+S')
   238         AppendMenu(parent, help='', id=wx.ID_SAVEAS,
   238         AppendMenu(parent, help='', id=wx.ID_SAVEAS,
   239               kind=wx.ITEM_NORMAL, text=_(u'Save as') + '\tCTRL+SHIFT+S')
   239                    kind=wx.ITEM_NORMAL, text=_(u'Save as') + '\tCTRL+SHIFT+S')
   240         AppendMenu(parent, help='', id=wx.ID_CLOSE,
   240         AppendMenu(parent, help='', id=wx.ID_CLOSE,
   241               kind=wx.ITEM_NORMAL, text=_(u'Close Tab') + '\tCTRL+W')
   241                    kind=wx.ITEM_NORMAL, text=_(u'Close Tab') + '\tCTRL+W')
   242         AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
   242         AppendMenu(parent, help='', id=wx.ID_CLOSE_ALL,
   243               kind=wx.ITEM_NORMAL, text=_(u'Close Project') + '\tCTRL+SHIFT+W')
   243                    kind=wx.ITEM_NORMAL, text=_(u'Close Project') + '\tCTRL+SHIFT+W')
   244         parent.AppendSeparator()
   244         parent.AppendSeparator()
   245         AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
   245         AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
   246               kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P')
   246                    kind=wx.ITEM_NORMAL, text=_(u'Page Setup') + '\tCTRL+ALT+P')
   247         AppendMenu(parent, help='', id=wx.ID_PREVIEW,
   247         AppendMenu(parent, help='', id=wx.ID_PREVIEW,
   248               kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P')
   248                    kind=wx.ITEM_NORMAL, text=_(u'Preview') + '\tCTRL+SHIFT+P')
   249         AppendMenu(parent, help='', id=wx.ID_PRINT,
   249         AppendMenu(parent, help='', id=wx.ID_PRINT,
   250               kind=wx.ITEM_NORMAL, text=_(u'Print') + '\tCTRL+P')
   250                    kind=wx.ITEM_NORMAL, text=_(u'Print') + '\tCTRL+P')
   251         parent.AppendSeparator()
   251         parent.AppendSeparator()
   252         AppendMenu(parent, help='', id=wx.ID_EXIT,
   252         AppendMenu(parent, help='', id=wx.ID_EXIT,
   253               kind=wx.ITEM_NORMAL, text=_(u'Quit') + '\tCTRL+Q')
   253                    kind=wx.ITEM_NORMAL, text=_(u'Quit') + '\tCTRL+Q')
   254 
   254 
   255         self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
   255         self.Bind(wx.EVT_MENU, self.OnNewProjectMenu, id=wx.ID_NEW)
   256         self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
   256         self.Bind(wx.EVT_MENU, self.OnOpenProjectMenu, id=wx.ID_OPEN)
   257         self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
   257         self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
   258         self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
   258         self.Bind(wx.EVT_MENU, self.OnSaveProjectAsMenu, id=wx.ID_SAVEAS)
   276                 new_menu = wx.Menu(title='')
   276                 new_menu = wx.Menu(title='')
   277                 menu.AppendMenu(new_id, text, new_menu)
   277                 menu.AppendMenu(new_id, text, new_menu)
   278                 self._RecursiveAddMenuItems(new_menu, children)
   278                 self._RecursiveAddMenuItems(new_menu, children)
   279             else:
   279             else:
   280                 AppendMenu(menu, help=help, id=new_id,
   280                 AppendMenu(menu, help=help, id=new_id,
   281                        kind=wx.ITEM_NORMAL, text=text)
   281                            kind=wx.ITEM_NORMAL, text=text)
   282                 self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name),
   282                 self.Bind(wx.EVT_MENU, self.GetAddConfNodeFunction(name),
   283                           id=new_id)
   283                           id=new_id)
   284 
   284 
   285     def _init_coll_AddMenu_Items(self, parent):
   285     def _init_coll_AddMenu_Items(self, parent):
   286         IDEFrame._init_coll_AddMenu_Items(self, parent, False)
   286         IDEFrame._init_coll_AddMenu_Items(self, parent, False)
   296         id = wx.NewId()
   296         id = wx.NewId()
   297         parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support'))
   297         parent.Append(help='', id=id, kind=wx.ITEM_NORMAL, text=_(u'Community support'))
   298         self.Bind(wx.EVT_MENU, handler, id=id)
   298         self.Bind(wx.EVT_MENU, handler, id=id)
   299 
   299 
   300         parent.Append(help='', id=wx.ID_ABOUT,
   300         parent.Append(help='', id=wx.ID_ABOUT,
   301               kind=wx.ITEM_NORMAL, text=_(u'About'))
   301                       kind=wx.ITEM_NORMAL, text=_(u'About'))
   302         self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
   302         self.Bind(wx.EVT_MENU, self.OnAboutMenu, id=wx.ID_ABOUT)
   303 
   303 
   304     def _init_coll_ConnectionStatusBar_Fields(self, parent):
   304     def _init_coll_ConnectionStatusBar_Fields(self, parent):
   305         parent.SetFieldsCount(3)
   305         parent.SetFieldsCount(3)
   306 
   306 
   373         self.MainTabs["LogViewer"] = (self.LogViewer, _("PLC Log"))
   373         self.MainTabs["LogViewer"] = (self.LogViewer, _("PLC Log"))
   374         self.BottomNoteBook.AddPage(*self.MainTabs["LogViewer"])
   374         self.BottomNoteBook.AddPage(*self.MainTabs["LogViewer"])
   375         #self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogViewer), wx.RIGHT)
   375         #self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogViewer), wx.RIGHT)
   376 
   376 
   377         StatusToolBar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
   377         StatusToolBar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
   378                 wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
   378                                    wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
   379         StatusToolBar.SetToolBitmapSize(wx.Size(25, 25))
   379         StatusToolBar.SetToolBitmapSize(wx.Size(25, 25))
   380         StatusToolBar.Realize()
   380         StatusToolBar.Realize()
   381         self.Panes["StatusToolBar"] = StatusToolBar
   381         self.Panes["StatusToolBar"] = StatusToolBar
   382         self.AUIManager.AddPane(StatusToolBar, wx.aui.AuiPaneInfo().
   382         self.AUIManager.AddPane(StatusToolBar, wx.aui.AuiPaneInfo().
   383                   Name("StatusToolBar").Caption(_("Status ToolBar")).
   383                                 Name("StatusToolBar").Caption(_("Status ToolBar")).
   384                   ToolbarPane().Top().Position(1).
   384                                 ToolbarPane().Top().Position(1).
   385                   LeftDockable(False).RightDockable(False))
   385                                 LeftDockable(False).RightDockable(False))
   386 
   386 
   387         self.AUIManager.Update()
   387         self.AUIManager.Update()
   388 
   388 
   389         self.ConnectionStatusBar = esb.EnhancedStatusBar(self, style=wx.ST_SIZEGRIP)
   389         self.ConnectionStatusBar = esb.EnhancedStatusBar(self, style=wx.ST_SIZEGRIP)
   390         self._init_coll_ConnectionStatusBar_Fields(self.ConnectionStatusBar)
   390         self._init_coll_ConnectionStatusBar_Fields(self.ConnectionStatusBar)
   483             # create temporary directory for runtime working directory
   483             # create temporary directory for runtime working directory
   484             self.local_runtime_tmpdir = tempfile.mkdtemp()
   484             self.local_runtime_tmpdir = tempfile.mkdtemp()
   485             # choose an arbitrary random port for runtime
   485             # choose an arbitrary random port for runtime
   486             self.runtime_port = int(random.random() * 1000) + 61131
   486             self.runtime_port = int(random.random() * 1000) + 61131
   487             # launch local runtime
   487             # launch local runtime
   488             self.local_runtime = ProcessLogger(self.Log,
   488             self.local_runtime = ProcessLogger(
       
   489                 self.Log,
   489                 "\"%s\" \"%s\" -p %s -i localhost %s %s" % (
   490                 "\"%s\" \"%s\" -p %s -i localhost %s %s" % (
   490                     sys.executable,
   491                     sys.executable,
   491                     Bpath("Beremiz_service.py"),
   492                     Bpath("Beremiz_service.py"),
   492                     self.runtime_port,
   493                     self.runtime_port,
   493                     {False: "-x 0", True: "-x 1"}[taskbaricon],
   494                     {False: "-x 0", True: "-x 1"}[taskbaricon],
   733         if self.CTR is not None:
   734         if self.CTR is not None:
   734 
   735 
   735             for confnode_method in self.CTR.StatusMethods:
   736             for confnode_method in self.CTR.StatusMethods:
   736                 if "method" in confnode_method and confnode_method.get("shown", True):
   737                 if "method" in confnode_method and confnode_method.get("shown", True):
   737                     id = wx.NewId()
   738                     id = wx.NewId()
   738                     StatusToolBar.AddSimpleTool(id,
   739                     StatusToolBar.AddSimpleTool(
   739                         GetBitmap(confnode_method.get("bitmap", "Unknown")),
   740                         id, GetBitmap(confnode_method.get("bitmap", "Unknown")),
   740                         confnode_method["tooltip"])
   741                         confnode_method["tooltip"])
   741                     self.Bind(wx.EVT_MENU, self.GetMenuCallBackFunction(confnode_method["method"]), id=id)
   742                     self.Bind(wx.EVT_MENU, self.GetMenuCallBackFunction(confnode_method["method"]), id=id)
   742 
   743 
   743             StatusToolBar.Realize()
   744             StatusToolBar.Realize()
   744             self.AUIManager.GetPane("StatusToolBar").BestSize(StatusToolBar.GetBestSize()).Show()
   745             self.AUIManager.GetPane("StatusToolBar").BestSize(StatusToolBar.GetBestSize()).Show()
  1031                     if tagname == "Project":
  1032                     if tagname == "Project":
  1032                         self.SelectedItem = root
  1033                         self.SelectedItem = root
  1033                         self.ProjectTree.SelectItem(root)
  1034                         self.ProjectTree.SelectItem(root)
  1034                         self.ResetSelectedItem()
  1035                         self.ResetSelectedItem()
  1035                     else:
  1036                     else:
  1036                         return self.RecursiveProjectTreeItemSelection(root,
  1037                         return self.RecursiveProjectTreeItemSelection(
  1037                               [(word, ITEM_CONFNODE) for word in tagname.split(".")])
  1038                             root,
       
  1039                             [(word, ITEM_CONFNODE) for word in tagname.split(".")])
  1038                 elif words[0] == "R":
  1040                 elif words[0] == "R":
  1039                     return self.RecursiveProjectTreeItemSelection(root, [(words[2], ITEM_RESOURCE)])
  1041                     return self.RecursiveProjectTreeItemSelection(root, [(words[2], ITEM_RESOURCE)])
  1040                 elif not os.path.exists(words[0]):
  1042                 elif not os.path.exists(words[0]):
  1041                     IDEFrame.SelectProjectTreeItem(self, tagname)
  1043                     IDEFrame.SelectProjectTreeItem(self, tagname)
  1042 
  1044 
  1059                 self.CTR.CTNAddChild(ConfNodeName, ConfNodeType)
  1061                 self.CTR.CTNAddChild(ConfNodeName, ConfNodeType)
  1060             self._Refresh(TITLE, FILEMENU, PROJECTTREE)
  1062             self._Refresh(TITLE, FILEMENU, PROJECTTREE)
  1061 
  1063 
  1062     def DeleteConfNode(self, confnode):
  1064     def DeleteConfNode(self, confnode):
  1063         if self.CTR.CheckProjectPathPerm():
  1065         if self.CTR.CheckProjectPathPerm():
  1064             dialog = wx.MessageDialog(self,
  1066             dialog = wx.MessageDialog(
       
  1067                 self,
  1065                 _("Really delete node '%s'?") % confnode.CTNName(),
  1068                 _("Really delete node '%s'?") % confnode.CTNName(),
  1066                 _("Remove %s node") % confnode.CTNType,
  1069                 _("Remove %s node") % confnode.CTNType,
  1067                 wx.YES_NO | wx.NO_DEFAULT)
  1070                 wx.YES_NO | wx.NO_DEFAULT)
  1068             if dialog.ShowModal() == wx.ID_YES:
  1071             if dialog.ShowModal() == wx.ID_YES:
  1069                 confnode.CTNRemove()
  1072                 confnode.CTNRemove()
  1110     # Allow clicking....
  1113     # Allow clicking....
  1111     cap = wx.Window_GetCapture()
  1114     cap = wx.Window_GetCapture()
  1112     if cap:
  1115     if cap:
  1113         cap.ReleaseMouse()
  1116         cap.ReleaseMouse()
  1114 
  1117 
  1115     dlg = wx.SingleChoiceDialog(None,
  1118     dlg = wx.SingleChoiceDialog(
       
  1119         None,
  1116         _("""
  1120         _("""
  1117 An unhandled exception (bug) occured. Bug report saved at :
  1121 An unhandled exception (bug) occured. Bug report saved at :
  1118 (%s)
  1122 (%s)
  1119 
  1123 
  1120 Please be kind enough to send this file to:
  1124 Please be kind enough to send this file to: