Fixing library treectrl in order to make it similar on all platforms
authorlaurent
Fri, 09 Dec 2011 10:11:42 +0100
changeset 596 ce33d72f6df7
parent 595 15df411e9463
child 597 7b17e3c8dbed
Fixing library treectrl in order to make it similar on all platforms
dialogs/FBDBlockDialog.py
--- a/dialogs/FBDBlockDialog.py	Fri Dec 09 10:09:50 2011 +0100
+++ b/dialogs/FBDBlockDialog.py	Fri Dec 09 10:11:42 2011 +0100
@@ -137,13 +137,9 @@
               label=_('Preview:'), name='staticText6', parent=self,
               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
 
-        if wx.Platform == '__WXMSW__':
-            treestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER
-        else:
-            treestyle = wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_SINGLE|wx.SUNKEN_BORDER
         self.TypeTree = wx.TreeCtrl(id=ID_FBDBLOCKDIALOGTYPETREE,
               name='TypeTree', parent=self, pos=wx.Point(0, 0),
-              size=wx.Size(0, 0), style=treestyle)
+              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.OnTypeTreeItemSelected,
               id=ID_FBDBLOCKDIALOGTYPETREE)
 
@@ -211,16 +207,17 @@
     def FindTreeItem(self, root, name, inputs = None):
         if root.IsOk():
             pydata = self.TypeTree.GetPyData(root)
-            type_inputs = pydata.get("inputs", None)
-            type_extension = pydata.get("extension", None)
-            if inputs is not None and type_inputs is not None:
-                if type_extension is not None:
-                    same_inputs = type_inputs == inputs[:type_extension]
+            if pydata is not None:
+                type_inputs = pydata.get("inputs", None)
+                type_extension = pydata.get("extension", None)
+                if inputs is not None and type_inputs is not None:
+                    if type_extension is not None:
+                        same_inputs = type_inputs == inputs[:type_extension]
+                    else:
+                        same_inputs = type_inputs == inputs
                 else:
-                    same_inputs = type_inputs == inputs
-            else:
-                same_inputs = True
-            if self.TypeTree.GetItemText(root) == name and same_inputs:
+                    same_inputs = True
+            if pydata is not None and self.TypeTree.GetItemText(root) == name and same_inputs:
                 return root
             else:
                 if wx.VERSION < (2, 6, 0):
@@ -266,11 +263,7 @@
             self.EndModal(wx.ID_OK)
 
     def SetBlockList(self, blocktypes):
-        if wx.Platform == '__WXMSW__':
-            root = self.TypeTree.AddRoot(_("Block Types"))
-        else:
-            root = self.TypeTree.AddRoot("")
-        self.TypeTree.SetPyData(root, {"type" : CATEGORY})
+        root = self.TypeTree.AddRoot("")
         for category in blocktypes:
             category_name = category["name"]
             category_item = self.TypeTree.AppendItem(root, _(category_name))
@@ -283,9 +276,7 @@
                 if blocktype["extensible"]:
                     block_data["extension"] = len(blocktype["inputs"])
                 self.TypeTree.SetPyData(blocktype_item, block_data)
-        if wx.Platform == '__WXMSW__':
-            self.TypeTree.Expand(root)
-
+        
     def SetMinBlockSize(self, size):
         self.MinBlockSize = size
 
@@ -302,6 +293,7 @@
             item = self.FindTreeItem(self.TypeTree.GetRootItem(), blocktype, inputs)
             if item:
                 self.TypeTree.SelectItem(item)
+                self.TypeTree.EnsureVisible(item)
         for name, value in values.items():
             if name == "name":
                 self.BlockName.SetValue(value)