Fixing bugs with latest changesets on Windows
authorlaurent
Fri, 04 May 2012 19:20:46 +0200
changeset 680 b693147fb2c3
parent 679 91e8ff268e96
child 681 c141dad94ff4
child 688 188906a7368c
Fixing bugs with latest changesets on Windows
PLCOpenEditor.py
controls/LibraryPanel.py
--- a/PLCOpenEditor.py	Fri May 04 11:12:08 2012 +0200
+++ b/PLCOpenEditor.py	Fri May 04 19:20:46 2012 +0200
@@ -306,6 +306,13 @@
             self.ShowErrorMessage(_("\"%s\" is used by one or more POUs. It can't be removed!")%name)
     return DeleteElementFunction
 
+if wx.Platform == '__WXMSW__':
+    TAB_BORDER = 6
+    NOTEBOOK_BORDER = 6
+else:
+    TAB_BORDER = 7
+    NOTEBOOK_BORDER = 2
+
 def SimplifyTabOrganization(tabs, rect):
     for tab in tabs:
         if tab["pos"][0] == rect.x:
@@ -314,9 +321,9 @@
             for other in others:
                 if (other["pos"][1] == tab["pos"][1] and 
                     other["size"][1] == tab["size"][1] and
-                    other["pos"][0] == tab["pos"][0] + tab["size"][0] + 7):
+                    other["pos"][0] == tab["pos"][0] + tab["size"][0] + TAB_BORDER):
                     
-                    tab["size"] = (tab["size"][0] + other["size"][0] + 7, tab["size"][1])
+                    tab["size"] = (tab["size"][0] + other["size"][0] + TAB_BORDER, tab["size"][1])
                     tab["pages"].extend(other["pages"])
                     tabs.remove(other)
                     
@@ -329,9 +336,9 @@
             for other in others:
                 if (other["pos"][0] == tab["pos"][0] and 
                     other["size"][0] == tab["size"][0] and
-                    other["pos"][1] == tab["pos"][1] + tab["size"][1] + 7):
+                    other["pos"][1] == tab["pos"][1] + tab["size"][1] + TAB_BORDER):
                     
-                    tab["size"] = (tab["size"][0], tab["size"][1] + other["size"][1] + 7)
+                    tab["size"] = (tab["size"][0], tab["size"][1] + other["size"][1] + TAB_BORDER)
                     tab["pages"].extend(other["pages"])
                     tabs.remove(other)
                     
@@ -346,25 +353,27 @@
         return tabs[0]
     split = None
     for idx, tab in enumerate(tabs):
+        if len(tab["pages"]) == 0:
+        	raise "Not possible"
         if tab["size"][0] == rect.width:
             if tab["pos"][1] == rect.y:
                 split = (wx.TOP, float(tab["size"][1]) / float(rect.height))
-                split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + 7, 
-                                     rect.width, rect.height - tab["size"][1] - 7)
+                split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER, 
+                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
             elif tab["pos"][1] == rect.height + 1 - tab["size"][1]:
                 split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height))
                 split_rect = wx.Rect(rect.x, rect.y, 
-                                     rect.width, rect.height - tab["size"][1] - 7)
+                                     rect.width, rect.height - tab["size"][1] - TAB_BORDER)
             break
         elif tab["size"][1] == rect.height:
             if tab["pos"][0] == rect.x:
                 split = (wx.LEFT, float(tab["size"][0]) / float(rect.width))
-                split_rect = wx.Rect(rect.x + tab["size"][0] + 7, rect.y, 
-                                     rect.width - tab["size"][0] - 7, rect.height)
+                split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y, 
+                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
             elif tab["pos"][0] == rect.width + 1 - tab["size"][0]:
                 split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width))
                 split_rect = wx.Rect(rect.x, rect.y, 
-                                     rect.width - tab["size"][0] - 7, rect.height)
+                                     rect.width - tab["size"][0] - TAB_BORDER, rect.height)
             break
     if split != None:
         split_tab = tabs.pop(idx)
@@ -384,6 +393,8 @@
 
 class IDEFrame(wx.Frame):
     
+    Starting = False
+    
     # Compatibility function for wx versions < 2.6
     if wx.VERSION < (2, 6, 0):
         def Bind(self, event, function, id = None):
@@ -805,7 +816,6 @@
         #self.DrawingMode = DRIVENDRAWING_MODE
         if USE_AUI:
             self.AuiTabCtrl = []
-        self.Starting = False
         self.DefaultPerspective = None
         
         # Initialize Printing configuring elements
@@ -818,6 +828,9 @@
         
         self.SetRefreshFunctions()
     
+    def ResetStarting(self):
+		self.Starting = False
+    
     def Show(self):
         wx.Frame.Show(self)
         wx.CallAfter(self.RestoreLastState)
@@ -834,8 +847,11 @@
     def OnResize(self, event):
         if self.Starting:
             self.RestoreLastOrganization()
-            self.Starting = False
-            self.RefreshEditor()
+            if wx.Platform == '__WXMSW__':
+                wx.CallAfter(self.ResetStarting)
+            else:
+                self.ResetStarting()
+            wx.CallAfter(self.RefreshEditor)
         event.Skip()
     
     def GetProjectConfiguration(self):
@@ -896,7 +912,7 @@
                 tabs.append(tab)
         tabs.sort(lambda x, y: cmp(x["pos"], y["pos"]))
         size = notebook.GetSize()
-        return ComputeTabsOrganization(tabs, wx.Rect(1, 1, size[0] - 2, size[1] - 2))
+        return ComputeTabsOrganization(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER))
     
     def LoadTab(self, notebook, page_infos):
         if page_infos[0] == "main":
--- a/controls/LibraryPanel.py	Fri May 04 11:12:08 2012 +0200
+++ b/controls/LibraryPanel.py	Fri May 04 19:20:46 2012 +0200
@@ -216,6 +216,9 @@
     
     def SearchInTree(self, value, mode="first"):
         root = self.Tree.GetRootItem()
+        if not root.IsOk():
+            return False
+        
         if mode == "first":
             item, item_cookie = self.Tree.GetFirstChild(root)
             selected = None
@@ -240,7 +243,10 @@
             else:
                 name = self.Tree.GetItemText(item)
                 if name.upper().startswith(value.upper()) and item != selected:
-                    self.Tree.CollapseAllChildren(root)
+                    child, child_cookie = self.Tree.GetFirstChild(root)
+                    while child.IsOk():
+                        self.Tree.CollapseAllChildren(child)
+                        child, child_cookie = self.Tree.GetNextChild(root, child_cookie)
                     self.Tree.SelectItem(item)
                     self.Tree.EnsureVisible(item)
                     return True