PLCOpenEditor.py
changeset 599 4bb7b132e15d
parent 587 98445f90f45d
child 604 5b42b4401e6b
equal deleted inserted replaced
598:510647310137 599:4bb7b132e15d
   271 ] = range(10)
   271 ] = range(10)
   272 
   272 
   273 def GetShortcutKeyCallbackFunction(viewer_function):
   273 def GetShortcutKeyCallbackFunction(viewer_function):
   274     def ShortcutKeyFunction(self, event):
   274     def ShortcutKeyFunction(self, event):
   275         control = self.FindFocus()
   275         control = self.FindFocus()
   276         if control.GetName() in ["Viewer", "TextViewer"]:
   276         if control is not None and control.GetName() in ["Viewer", "TextViewer"]:
   277             getattr(control.Parent, viewer_function)()
   277             getattr(control.Parent, viewer_function)()
   278         elif isinstance(control, wx.stc.StyledTextCtrl):
   278         elif isinstance(control, wx.stc.StyledTextCtrl):
   279             getattr(control, viewer_function)()
   279             getattr(control, viewer_function)()
   280         elif isinstance(control, wx.TextCtrl):
   280         elif isinstance(control, wx.TextCtrl):
   281             control.ProcessEvent(event)
   281             control.ProcessEvent(event)
   616         self.LibraryPanel = wx.Panel(id=ID_PLCOPENEDITORLIBRARYPANEL,
   616         self.LibraryPanel = wx.Panel(id=ID_PLCOPENEDITORLIBRARYPANEL,
   617               name='LibraryPanel', parent=self.RightNoteBook, pos=wx.Point(0,
   617               name='LibraryPanel', parent=self.RightNoteBook, pos=wx.Point(0,
   618               0), size=wx.Size(0, 0), style=0)
   618               0), size=wx.Size(0, 0), style=0)
   619         self.RightNoteBook.AddPage(self.LibraryPanel, _("Library"))
   619         self.RightNoteBook.AddPage(self.LibraryPanel, _("Library"))
   620         
   620         
   621         if wx.Platform == '__WXMSW__':
       
   622             librarytreestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER
       
   623         else:
       
   624             librarytreestyle = wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_SINGLE|wx.SUNKEN_BORDER
       
   625         self.LibraryTree = wx.TreeCtrl(id=ID_PLCOPENEDITORLIBRARYTREE,
   621         self.LibraryTree = wx.TreeCtrl(id=ID_PLCOPENEDITORLIBRARYTREE,
   626                   name='LibraryTree', parent=self.LibraryPanel, 
   622                   name='LibraryTree', parent=self.LibraryPanel, 
   627                   pos=wx.Point(0, 0), size=wx.Size(0, 0),
   623                   pos=wx.Point(0, 0), size=wx.Size(0, 0),
   628                   style=librarytreestyle)
   624                   style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT)
   629         self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnLibraryTreeItemSelected,
   625         self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnLibraryTreeItemSelected,
   630               id=ID_PLCOPENEDITORLIBRARYTREE)
   626               id=ID_PLCOPENEDITORLIBRARYTREE)
   631         self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnLibraryTreeBeginDrag,
   627         self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnLibraryTreeBeginDrag,
   632               id=ID_PLCOPENEDITORLIBRARYTREE)
   628               id=ID_PLCOPENEDITORLIBRARYTREE)
   633         
   629         
  1062     OnCopyMenu = GetShortcutKeyCallbackFunction("Copy")
  1058     OnCopyMenu = GetShortcutKeyCallbackFunction("Copy")
  1063     OnPasteMenu = GetShortcutKeyCallbackFunction("Paste")
  1059     OnPasteMenu = GetShortcutKeyCallbackFunction("Paste")
  1064 
  1060 
  1065     def OnSelectAllMenu(self, event):
  1061     def OnSelectAllMenu(self, event):
  1066         control = self.FindFocus()
  1062         control = self.FindFocus()
  1067         if control.GetName() == "Viewer":
  1063         if control is not None and control.GetName() == "Viewer":
  1068             control.Parent.SelectAll()
  1064             control.Parent.SelectAll()
  1069         elif isinstance(control, wx.stc.StyledTextCtrl):
  1065         elif isinstance(control, wx.stc.StyledTextCtrl):
  1070             control.SelectAll()
  1066             control.SelectAll()
  1071         elif isinstance(control, wx.TextCtrl):
  1067         elif isinstance(control, wx.TextCtrl):
  1072             control.SetSelection(0, control.GetLastPosition())
  1068             control.SetSelection(0, control.GetLastPosition())
  1918     def RefreshLibraryTree(self):
  1914     def RefreshLibraryTree(self):
  1919         to_delete = []
  1915         to_delete = []
  1920         blocktypes = self.Controler.GetBlockTypes()
  1916         blocktypes = self.Controler.GetBlockTypes()
  1921         root = self.LibraryTree.GetRootItem()
  1917         root = self.LibraryTree.GetRootItem()
  1922         if not root.IsOk():
  1918         if not root.IsOk():
  1923             if wx.Platform == '__WXMSW__':
  1919             root = self.LibraryTree.AddRoot("")
  1924                 root = self.LibraryTree.AddRoot(_("Block Types"))
       
  1925                 self.LibraryTree.SetPyData(root, {"type" : CATEGORY})
       
  1926             else:
       
  1927                 root = self.LibraryTree.AddRoot("")
       
  1928         if wx.VERSION >= (2, 6, 0):
  1920         if wx.VERSION >= (2, 6, 0):
  1929             category_item, root_cookie = self.LibraryTree.GetFirstChild(root)
  1921             category_item, root_cookie = self.LibraryTree.GetFirstChild(root)
  1930         else:
  1922         else:
  1931             category_item, root_cookie = self.LibraryTree.GetFirstChild(root, 0)
  1923             category_item, root_cookie = self.LibraryTree.GetFirstChild(root, 0)
  1932         for category in blocktypes:
  1924         for category in blocktypes:
  1958         while category_item.IsOk():
  1950         while category_item.IsOk():
  1959             to_delete.append(category_item)
  1951             to_delete.append(category_item)
  1960             category_item, root_cookie = self.LibraryTree.GetNextChild(root, root_cookie)
  1952             category_item, root_cookie = self.LibraryTree.GetNextChild(root, root_cookie)
  1961         for item in to_delete:
  1953         for item in to_delete:
  1962             self.LibraryTree.Delete(item)
  1954             self.LibraryTree.Delete(item)
  1963         if wx.Platform == '__WXMSW__':        
       
  1964             self.LibraryTree.Expand(root)
       
  1965 
  1955 
  1966     def OnLibraryTreeItemSelected(self, event):
  1956     def OnLibraryTreeItemSelected(self, event):
  1967         selected = event.GetItem()
  1957         selected = event.GetItem()
  1968         pydata = self.LibraryTree.GetPyData(selected)
  1958         pydata = self.LibraryTree.GetPyData(selected)
  1969         if pydata is not None and pydata["type"] != CATEGORY:
  1959         if pydata is not None and pydata["type"] != CATEGORY:
  1990 #-------------------------------------------------------------------------------
  1980 #-------------------------------------------------------------------------------
  1991 #                          ToolBar Management Functions
  1981 #                          ToolBar Management Functions
  1992 #-------------------------------------------------------------------------------
  1982 #-------------------------------------------------------------------------------
  1993 
  1983 
  1994     def ResetToolBar(self):
  1984     def ResetToolBar(self):
       
  1985         if USE_AUI:
       
  1986             ToolBar = self.Panes["ToolBar"]
       
  1987         else:
       
  1988             ToolBar = self.ToolBar
       
  1989         
  1995         for item in self.CurrentToolBar:
  1990         for item in self.CurrentToolBar:
  1996             if wx.VERSION >= (2, 6, 0):
  1991             if wx.VERSION >= (2, 6, 0):
  1997                 self.Unbind(wx.EVT_MENU, id=item)
  1992                 self.Unbind(wx.EVT_MENU, id=item)
  1998             else:
  1993             else:
  1999                 self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) 
  1994                 self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) 
  2000             
  1995         
  2001             if USE_AUI:
       
  2002                 ToolBar = self.Panes["ToolBar"]
       
  2003             else:
       
  2004                 ToolBar = self.ToolBar
       
  2005             if ToolBar:
  1996             if ToolBar:
  2006                 ToolBar.DeleteTool(item)
  1997                 ToolBar.DeleteTool(item)
  2007                 ToolBar.Realize()
  1998         
  2008                 if USE_AUI:
  1999         if ToolBar:
  2009                     self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
  2000             ToolBar.Realize()
  2010                     self.AUIManager.Update()
  2001             if USE_AUI:
       
  2002                 self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
       
  2003                 self.AUIManager.Update()
  2011 
  2004 
  2012     def RefreshToolBar(self):
  2005     def RefreshToolBar(self):
  2013         selected = self.TabsOpened.GetSelection()
  2006         selected = self.TabsOpened.GetSelection()
  2014         language = None
  2007         language = None
  2015         if selected != -1:
  2008         if selected != -1: