controls/LibraryPanel.py
changeset 714 131ea7f237b9
parent 680 b693147fb2c3
child 741 330f578e228d
--- a/controls/LibraryPanel.py	Fri Jun 15 18:03:25 2012 +0200
+++ b/controls/LibraryPanel.py	Mon Jun 25 20:03:53 2012 +0200
@@ -24,78 +24,61 @@
 
 import wx
 
+#-------------------------------------------------------------------------------
+#                                 Helpers
+#-------------------------------------------------------------------------------
+
 [CATEGORY, BLOCK] = range(2)
 
-[ID_LIBRARYPANEL, ID_LIBRARYSEARCHCTRL, 
- ID_LIBRARYTREE, ID_LIBRARYCOMMENT, 
-] = [wx.NewId() for _init_ctrls in range(4)]
+#-------------------------------------------------------------------------------
+#                              Library Panel
+#-------------------------------------------------------------------------------
 
 class LibraryPanel(wx.Panel):
     
-    def _init_coll_MainSizer_Items(self, parent):
-        parent.AddWindow(self.SearchCtrl, 0, border=0, flag=wx.GROW)
-        parent.AddWindow(self.Tree, 0, border=0, flag=wx.GROW)
-        parent.AddWindow(self.Comment, 0, border=0, flag=wx.GROW)
-
-    def _init_coll_MainSizer_Growables(self, parent):
-        parent.AddGrowableCol(0)
-        parent.AddGrowableRow(1)
-    
-    def _init_sizers(self):
-        self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=0)
-        
-        self._init_coll_MainSizer_Growables(self.MainSizer)
-        self._init_coll_MainSizer_Items(self.MainSizer)
-        
-        self.SetSizer(self.MainSizer)
-    
-    def _init_ctrls(self, prnt, enable_drag=False):
-        wx.Panel.__init__(self, id=ID_LIBRARYPANEL,
-                  name='LibraryPanel', parent=prnt,
-                  pos=wx.Point(0, 0), size=wx.Size(0, 0), 
-                  style=wx.TAB_TRAVERSAL)
-        
-        self.SearchCtrl = wx.SearchCtrl(id=ID_LIBRARYSEARCHCTRL, 
-                  name='SearchCtrl', parent=self,
-                  pos=wx.Point(0, 0), size=wx.Size(0, 28), style=0)
+    def __init__(self, parent, enable_drag=False):
+        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
+        
+        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=0)
+        main_sizer.AddGrowableCol(0)
+        main_sizer.AddGrowableRow(1)
+        
+        self.SearchCtrl = wx.SearchCtrl(self)
         self.SearchCtrl.ShowSearchButton(True)
-        self.Bind(wx.EVT_TEXT, self.OnSearchCtrlChanged,
-              id=ID_LIBRARYSEARCHCTRL)
-        self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.OnSearchButtonClick,
-              id=ID_LIBRARYSEARCHCTRL)
+        self.Bind(wx.EVT_TEXT, self.OnSearchCtrlChanged, self.SearchCtrl)
+        self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, 
+              self.OnSearchButtonClick, self.SearchCtrl)
         search_textctrl = self.SearchCtrl.GetChildren()[0]
         search_textctrl.Bind(wx.EVT_CHAR, self.OnKeyDown)
-        
-        self.Tree = wx.TreeCtrl(id=ID_LIBRARYTREE,
-                  name='Tree', parent=self, 
-                  pos=wx.Point(0, 0), size=wx.Size(0, 0),
-                  style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT)
-        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemSelected,
-              id=ID_LIBRARYTREE)
+        main_sizer.AddWindow(self.SearchCtrl, flag=wx.GROW)
+        
+        self.Tree = wx.TreeCtrl(self, 
+              style=wx.TR_HAS_BUTTONS|
+                    wx.TR_SINGLE|
+                    wx.SUNKEN_BORDER|
+                    wx.TR_HIDE_ROOT|
+                    wx.TR_LINES_AT_ROOT)
+        self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnTreeItemSelected, self.Tree)
         self.Tree.Bind(wx.EVT_CHAR, self.OnKeyDown)
         if enable_drag:
-            self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnTreeBeginDrag,
-                  id=ID_LIBRARYTREE)
-        
-        self.Comment = wx.TextCtrl(id=ID_LIBRARYCOMMENT,
-              name='Comment', parent=self, 
-              pos=wx.Point(0, 0), size=wx.Size(0, 80), 
+            self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnTreeBeginDrag, self.Tree)
+        main_sizer.AddWindow(self.Tree, flag=wx.GROW)
+        
+        self.Comment = wx.TextCtrl(self, size=wx.Size(0, 80), 
               style=wx.TE_READONLY|wx.TE_MULTILINE)
-        
-        self._init_sizers()
-    
-    def __init__(self, parent, enable_drag=False):
-        self._init_ctrls(parent, enable_drag)
-        
-        self.Controler = None
+        main_sizer.AddWindow(self.Comment, flag=wx.GROW)
+        
+        self.SetSizer(main_sizer)
+            
+        self.Controller = None
     
         self.BlockList = None
     
     def __del__(self):
-        self.Controler = None
-    
-    def SetControler(self, controler):
-        self.Controler = controler
+        self.Controller = None
+    
+    def SetController(self, controller):
+        self.Controller = controller
     
     def SetBlockList(self, blocklist):
         self.BlockList = blocklist
@@ -110,7 +93,7 @@
         self.Comment.SetValue("")
     
     def RefreshTree(self):
-        if self.Controler is not None:
+        if self.Controller is not None:
             to_delete = []
             selected_name = None
             selected = self.Tree.GetSelection()
@@ -121,14 +104,11 @@
             if self.BlockList is not None:
                 blocktypes = self.BlockList
             else:
-                blocktypes = self.Controler.GetBlockTypes()
+                blocktypes = self.Controller.GetBlockTypes()
             root = self.Tree.GetRootItem()
             if not root.IsOk():
                 root = self.Tree.AddRoot("")
-            if wx.VERSION >= (2, 6, 0):
-                category_item, root_cookie = self.Tree.GetFirstChild(root)
-            else:
-                category_item, root_cookie = self.Tree.GetFirstChild(root, 0)
+            category_item, root_cookie = self.Tree.GetFirstChild(root)
             for category in blocktypes:
                 category_name = category["name"]
                 if not category_item.IsOk():
@@ -138,10 +118,7 @@
                 else:
                     self.Tree.SetItemText(category_item, _(category_name))
                 self.Tree.SetPyData(category_item, {"type" : CATEGORY})
-                if wx.VERSION >= (2, 6, 0):
-                    blocktype_item, category_cookie = self.Tree.GetFirstChild(category_item)
-                else:
-                    blocktype_item, category_cookie = self.Tree.GetFirstChild(category_item, 0)        
+                blocktype_item, category_cookie = self.Tree.GetFirstChild(category_item)
                 for blocktype in category["list"]:
                     if not blocktype_item.IsOk():
                         blocktype_item = self.Tree.AppendItem(category_item, blocktype["name"])
@@ -280,7 +257,7 @@
         selected = event.GetItem()
         pydata = self.Tree.GetPyData(selected)
         if pydata is not None and pydata["type"] != CATEGORY:
-            blocktype = self.Controler.GetBlockType(self.Tree.GetItemText(selected), pydata["inputs"])
+            blocktype = self.Controller.GetBlockType(self.Tree.GetItemText(selected), pydata["inputs"])
             if blocktype:
                 comment = blocktype["comment"]
                 self.Comment.SetValue(_(comment) + blocktype.get("usage", ""))