IDEFrame.py
branchwxPython4
changeset 3303 0ffb41625592
parent 2737 38afed869ff6
child 3309 446b2c3da6e6
equal deleted inserted replaced
3302:c89fc366bebd 3303:0ffb41625592
   113         path = base64.decodestring(path)
   113         path = base64.decodestring(path)
   114     return text(path, sys.getfilesystemencoding())
   114     return text(path, sys.getfilesystemencoding())
   115 
   115 
   116 
   116 
   117 def AppendMenu(parent, help, kind, text, id=wx.ID_ANY):
   117 def AppendMenu(parent, help, kind, text, id=wx.ID_ANY):
   118     return parent.Append(help=help, kind=kind, text=text, id=id)
   118     return parent.Append(wx.MenuItem(helpString=help, kind=kind, text=text, id=id))
   119 
   119 
   120 
   120 
   121 [
   121 [
   122     TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
   122     TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
   123     POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
   123     POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
   389         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT,
   389         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT,
   390                    kind=wx.ITEM_NORMAL, text=_(u'Search in Project') + '\tCTRL+SHIFT+F')
   390                    kind=wx.ITEM_NORMAL, text=_(u'Search in Project') + '\tCTRL+SHIFT+F')
   391         parent.AppendSeparator()
   391         parent.AppendSeparator()
   392         add_menu = wx.Menu(title='')
   392         add_menu = wx.Menu(title='')
   393         self._init_coll_AddMenu_Items(add_menu)
   393         self._init_coll_AddMenu_Items(add_menu)
   394         parent.AppendMenu(wx.ID_ADD, _(u"&Add Element"), add_menu)
   394         parent.Append(wx.ID_ADD, _(u"&Add Element"), add_menu)
   395         AppendMenu(parent, help='', id=wx.ID_SELECTALL,
   395         AppendMenu(parent, help='', id=wx.ID_SELECTALL,
   396                    kind=wx.ITEM_NORMAL, text=_(u'Select All') + '\tCTRL+A')
   396                    kind=wx.ITEM_NORMAL, text=_(u'Select All') + '\tCTRL+A')
   397         AppendMenu(parent, help='', id=wx.ID_DELETE,
   397         AppendMenu(parent, help='', id=wx.ID_DELETE,
   398                    kind=wx.ITEM_NORMAL, text=_(u'&Delete'))
   398                    kind=wx.ITEM_NORMAL, text=_(u'&Delete'))
   399         self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
   399         self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
   440         if self.EnableDebug:
   440         if self.EnableDebug:
   441             AppendMenu(parent, help='', id=wx.ID_CLEAR,
   441             AppendMenu(parent, help='', id=wx.ID_CLEAR,
   442                        kind=wx.ITEM_NORMAL, text=_(u'Clear Errors') + '\tCTRL+K')
   442                        kind=wx.ITEM_NORMAL, text=_(u'Clear Errors') + '\tCTRL+K')
   443         parent.AppendSeparator()
   443         parent.AppendSeparator()
   444         zoommenu = wx.Menu(title='')
   444         zoommenu = wx.Menu(title='')
   445         parent.AppendMenu(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu)
   445         parent.Append(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu)
   446         for idx, value in enumerate(ZOOM_FACTORS):
   446         for idx, value in enumerate(ZOOM_FACTORS):
   447             new_item = AppendMenu(zoommenu, help='',
   447             new_item = AppendMenu(zoommenu, help='',
   448                        kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%")
   448                        kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%")
   449             self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), new_item)
   449             self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), new_item)
   450 
   450 
   567 
   567 
   568         self.MainTabs = {}
   568         self.MainTabs = {}
   569 
   569 
   570         self.ProjectPanel = wx.SplitterWindow(
   570         self.ProjectPanel = wx.SplitterWindow(
   571             id=ID_PLCOPENEDITORPROJECTPANEL,
   571             id=ID_PLCOPENEDITORPROJECTPANEL,
   572             name='ProjectPanel', parent=self.LeftNoteBook, point=wx.Point(0, 0),
   572             name='ProjectPanel', parent=self.LeftNoteBook,
   573             size=wx.Size(0, 0), style=wx.SP_3D)
   573             size=wx.Size(0, 0))
   574 
   574 
   575         self.ProjectTree = CustomTree(id=ID_PLCOPENEDITORPROJECTTREE,
   575         self.ProjectTree = CustomTree(id=ID_PLCOPENEDITORPROJECTTREE,
   576                                       name='ProjectTree',
   576                                       name='ProjectTree',
   577                                       parent=self.ProjectPanel,
   577                                       parent=self.ProjectPanel,
   578                                       pos=wx.Point(0, 0), size=wx.Size(0, 0),
   578                                       pos=wx.Point(0, 0), size=wx.Size(0, 0),
   629         EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR,
   629         EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR,
   630                                    wx.DefaultPosition, wx.DefaultSize,
   630                                    wx.DefaultPosition, wx.DefaultSize,
   631                                    wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
   631                                    wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
   632         EditorToolBar.SetToolBitmapSize(wx.Size(25, 25))
   632         EditorToolBar.SetToolBitmapSize(wx.Size(25, 25))
   633         EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION,
   633         EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION,
       
   634                                    _("Select an object"),
   634                                    GetBitmap("select"),
   635                                    GetBitmap("select"),
   635                                    wx.NullBitmap,
   636                                    wx.NullBitmap)
   636                                    _("Select an object"))
       
   637         EditorToolBar.Realize()
   637         EditorToolBar.Realize()
   638         self.Panes["EditorToolBar"] = EditorToolBar
   638         self.Panes["EditorToolBar"] = EditorToolBar
   639         self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo().
   639         self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo().
   640                                 Name("EditorToolBar").Caption(_("Editor ToolBar")).
   640                                 Name("EditorToolBar").Caption(_("Editor ToolBar")).
   641                                 ToolbarPane().Top().Position(1).
   641                                 ToolbarPane().Top().Position(1).
   917     def _Refresh(self, *elements):
   917     def _Refresh(self, *elements):
   918         """Call Editor refresh functions.
   918         """Call Editor refresh functions.
   919 
   919 
   920         :param elements: List of elements to refresh.
   920         :param elements: List of elements to refresh.
   921         """
   921         """
   922         try:
   922         for element in elements:
   923             for element in elements:
   923             self.RefreshFunctions[element]()
   924                 self.RefreshFunctions[element]()
       
   925         except wx.PyDeadObjectError:
       
   926             # ignore exceptions caused by refresh while quitting
       
   927             pass
       
   928 
   924 
   929     def OnPageClose(self, event):
   925     def OnPageClose(self, event):
   930         """Callback function when AUINotebook Page closed with CloseButton
   926         """Callback function when AUINotebook Page closed with CloseButton
   931 
   927 
   932         :param event: AUINotebook Event.
   928         :param event: AUINotebook Event.
  1801                     elif item_infos["type"] == ITEM_TRANSITION:
  1797                     elif item_infos["type"] == ITEM_TRANSITION:
  1802                         block_type = "Transition"
  1798                         block_type = "Transition"
  1803                     else:
  1799                     else:
  1804                         block_type = "Action"
  1800                         block_type = "Action"
  1805                     self.LastToolTipItem = item
  1801                     self.LastToolTipItem = item
  1806                     wx.CallAfter(self.ProjectTree.SetToolTipString,
  1802                     wx.CallAfter(self.ProjectTree.SetToolTip,
  1807                                  "%s : %s : %s" % (
  1803                                  "%s : %s : %s" % (
  1808                                      block_type, bodytype, item_infos["name"]))
  1804                                      block_type, bodytype, item_infos["name"]))
  1809             elif self.LastToolTipItem is not None:
  1805             elif self.LastToolTipItem is not None:
  1810                 self.ProjectTree.SetToolTip(None)
  1806                 self.ProjectTree.SetToolTip(None)
  1811                 self.LastToolTipItem = None
  1807                 self.LastToolTipItem = None
  2111         for toolbar_item in items:
  2107         for toolbar_item in items:
  2112             if toolbar_item is None:
  2108             if toolbar_item is None:
  2113                 MenuToolBar.AddSeparator()
  2109                 MenuToolBar.AddSeparator()
  2114             else:
  2110             else:
  2115                 id, bitmap, help, callback = toolbar_item
  2111                 id, bitmap, help, callback = toolbar_item
  2116                 MenuToolBar.AddSimpleTool(id=id, shortHelpString=help, bitmap=GetBitmap(bitmap))
  2112                 MenuToolBar.AddTool(id, help, GetBitmap(bitmap))
  2117                 if callback is not None:
  2113                 if callback is not None:
  2118                     self.Bind(wx.EVT_TOOL, callback, id=id)
  2114                     self.Bind(wx.EVT_TOOL, callback, id=id)
  2119         MenuToolBar.Realize()
  2115         MenuToolBar.Realize()
  2120         self.AUIManager.GetPane("MenuToolBar").BestSize(MenuToolBar.GetBestSize())
  2116         self.AUIManager.GetPane("MenuToolBar").BestSize(MenuToolBar.GetBestSize())
  2121 
  2117 
  2151             EditorToolBar = self.Panes["EditorToolBar"]
  2147             EditorToolBar = self.Panes["EditorToolBar"]
  2152             if EditorToolBar:
  2148             if EditorToolBar:
  2153                 for radio, modes, id, method, picture, help in self.EditorToolBarItems[menu]:
  2149                 for radio, modes, id, method, picture, help in self.EditorToolBarItems[menu]:
  2154                     if modes & self.DrawingMode:
  2150                     if modes & self.DrawingMode:
  2155                         if radio or self.DrawingMode == FREEDRAWING_MODE:
  2151                         if radio or self.DrawingMode == FREEDRAWING_MODE:
  2156                             EditorToolBar.AddRadioTool(id, GetBitmap(picture), wx.NullBitmap, help)
  2152                             EditorToolBar.AddRadioTool(id, help, GetBitmap(picture), wx.NullBitmap)
  2157                         else:
  2153                         else:
  2158                             EditorToolBar.AddSimpleTool(id, GetBitmap(picture), help)
  2154                             EditorToolBar.AddTool(id, help, GetBitmap(picture))
  2159                         self.Bind(wx.EVT_MENU, getattr(self, method), id=id)
  2155                         self.Bind(wx.EVT_MENU, getattr(self, method), id=id)
  2160                         self.CurrentEditorToolBar.append(id)
  2156                         self.CurrentEditorToolBar.append(id)
  2161                 EditorToolBar.Realize()
  2157                 EditorToolBar.Realize()
  2162                 self.AUIManager.GetPane("EditorToolBar").Show()
  2158                 self.AUIManager.GetPane("EditorToolBar").Show()
  2163                 self.AUIManager.Update()
  2159                 self.AUIManager.Update()