Plugin Tree Drawing bug hacked
authorlbessard
Fri, 21 Dec 2007 18:06:11 +0100
changeset 84 8bc2669828e9
parent 83 ad4dafe7bfee
child 85 af97c60e759c
Plugin Tree Drawing bug hacked
Beremiz.py
--- a/Beremiz.py	Fri Dec 21 17:25:53 2007 +0100
+++ b/Beremiz.py	Fri Dec 21 18:06:11 2007 +0100
@@ -357,6 +357,8 @@
                   id=ID_BEREMIZPLUGINTREE)
             self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.OnPluginTreeItemChecked,
                   id=ID_BEREMIZPLUGINTREE)
+            self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnPluginTreeItemBeginEdit,
+                  id=ID_BEREMIZPLUGINTREE)
             self.Bind(CT.EVT_TREE_END_LABEL_EDIT, self.OnPluginTreeItemEndEdit,
                   id=ID_BEREMIZPLUGINTREE)
             self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnPluginTreeItemExpanded,
@@ -373,26 +375,6 @@
         
             self.AUIManager.Update()
 
-    def ShowChildrenWindows(self, root, show = True):
-        item, root_cookie = self.PluginTree.GetFirstChild(root)
-        while item is not None and item.IsOk():
-            window = self.PluginTree.GetItemWindow(item)
-            if show:
-                window.Show()
-            else:
-                window.Hide()
-            if self.PluginTree.IsExpanded(item):
-                self.ShowChildrenWindows(item, show)
-            item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
-
-    def OnPluginTreeItemExpanded(self, event):
-        self.ShowChildrenWindows(event.GetItem(), True)
-        event.Skip()
-
-    def OnPluginTreeItemCollapsed(self, event):
-        self.ShowChildrenWindows(event.GetItem(), False)
-        event.Skip()
-
     def __init__(self, parent, projectOpen):
         self._init_ctrls(parent)
         
@@ -597,6 +579,12 @@
                 wx.CallAfter(self.RefreshPluginTree)
         event.Skip()
     
+    def OnPluginTreeItemBeginEdit(self, event):
+        if event.GetItem() == self.PluginTree.GetRootItem():
+            event.Veto()
+        else:
+            event.Skip()
+    
     def OnPluginTreeItemEndEdit(self, event):
         if event.GetLabel() == "":
             event.Veto()
@@ -607,6 +595,26 @@
                 wx.CallAfter(self.RefreshPluginTree)
             event.Skip()
     
+    def ShowChildrenWindows(self, root, show = True):
+        item, root_cookie = self.PluginTree.GetFirstChild(root)
+        while item is not None and item.IsOk():
+            window = self.PluginTree.GetItemWindow(item)
+            if show:
+                window.Show()
+            else:
+                window.Hide()
+            if self.PluginTree.IsExpanded(item):
+                self.ShowChildrenWindows(item, show)
+            item, root_cookie = self.PluginTree.GetNextChild(root, root_cookie)
+
+    def OnPluginTreeItemExpanded(self, event):
+        self.ShowChildrenWindows(event.GetItem(), True)
+        event.Skip()
+
+    def OnPluginTreeItemCollapsed(self, event):
+        self.ShowChildrenWindows(event.GetItem(), False)
+        event.Skip()
+    
     def GetItemChannelChangedFunction(self, item):
         def OnPluginTreeItemChannelChanged(event):
             if not self.DisableEvents:
@@ -958,8 +966,8 @@
             dialog.Destroy()
             res = self.PluginRoot.NewProject(projectpath)
             if not res :
+                self.RefreshPluginToolBar()
                 self.RefreshPluginTree()
-                self.RefreshPluginToolBar()
                 self.RefreshButtons()
                 self.RefreshMainMenu()
             else:
@@ -978,11 +986,12 @@
             if os.path.isdir(projectpath):
                 result = self.PluginRoot.LoadProject(projectpath, self.Log)
                 if not result:
+                    self.RefreshPluginToolBar()
                     self.RefreshPluginTree()
-                    self.RefreshPluginToolBar()
                     self.PluginTree.SelectItem(self.PluginTree.GetRootItem())
                     self.RefreshButtons()
                     self.RefreshMainMenu()
+                    self.PluginTree.ScrollWindow(0, self.PluginTree.GetClientSize()[1])
                 else:
                     message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
                     message.ShowModal()
@@ -995,8 +1004,8 @@
         event.Skip()
     
     def OnCloseProjectMenu(self, event):
+        self.RefreshPluginToolBar()
         self.RefreshPluginTree()
-        self.RefreshPluginToolBar()
         self.RefreshButtons()
         self.RefreshMainMenu()
         event.Skip()