Bug on Project Tree with Windows fixed
authorlbessard
Mon, 10 Dec 2007 11:07:18 +0100
changeset 131 bc534997aecc
parent 130 38421cd7c8ff
child 132 3aaf349203bc
Bug on Project Tree with Windows fixed
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Mon Dec 10 11:06:46 2007 +0100
+++ b/PLCOpenEditor.py	Mon Dec 10 11:07:18 2007 +0100
@@ -361,12 +361,20 @@
                   size=wx.Size(200, -1),
                   style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER)
             self.AUIManager.AddPane(self.ProjectTree, wx.aui.AuiPaneInfo().Caption("Project Tree").Left().Layer(1).BestSize(wx.Size(200, 500)).CloseButton(False))
-        if wx.VERSION >= (2, 6, 0):
-            self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
-            self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp)
-        else:
-            wx.EVT_RIGHT_UP(self.ProjectTree, self.OnProjectTreeRightUp)
-            wx.EVT_LEFT_UP(self.ProjectTree, self.OnProjectTreeLeftUp)
+        if wx.Platform == '__WXMSW__':
+            self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnProjectTreeRightUp,
+                  id=ID_PLCOPENEDITORPROJECTTREE)
+            self.Bind(wx.EVT_TREE_ITEM_CHANGED, self.OnProjectTreeItemSelected,
+                  id=ID_PLCOPENEDITORPROJECTTREE)
+        else:
+            if wx.VERSION >= (2, 6, 0):
+                self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
+                self.ProjectTree.Bind(wx.EVT_LEFT_UP, self.OnProjectTreeLeftUp)
+            else:
+                wx.EVT_RIGHT_UP(self.ProjectTree, self.OnProjectTreeRightUp)
+                wx.EVT_LEFT_UP(self.ProjectTree, self.OnProjectTreeLeftUp)
+            self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging,
+                  id=ID_PLCOPENEDITORPROJECTTREE)
         self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnProjectTreeBeginDrag,
               id=ID_PLCOPENEDITORPROJECTTREE)
         self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnProjectTreeItemBeginEdit,
@@ -375,8 +383,6 @@
               id=ID_PLCOPENEDITORPROJECTTREE)
         self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnProjectTreeItemActivated,
               id=ID_PLCOPENEDITORPROJECTTREE)
-        self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnProjectTreeItemChanging,
-              id=ID_PLCOPENEDITORPROJECTTREE)
         
         if wx.VERSION < (2, 8, 0):
             self.ToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, 
@@ -1008,6 +1014,8 @@
         return found
 
     def OnProjectTreeBeginDrag(self, event):
+        if wx.Platform == '__WXMSW__':
+            self.SelectItem = event.Skip()
         if self.SelectedItem is not None and self.ProjectTree.GetPyData(self.SelectedItem) == ITEM_POU:
             block_name = self.ProjectTree.GetItemText(self.SelectedItem)
             block_type = self.Controler.GetPouType(block_name)
@@ -1191,40 +1199,47 @@
             self.EditProjectElement(data, tagname)
         event.Skip()
     
+    def ProjectTreeItemSelect(self, select_item):
+        name = self.ProjectTree.GetItemText(select_item)
+        data = self.ProjectTree.GetPyData(select_item)
+        if data == ITEM_DATATYPE:
+            self.EditProjectElement(data, self.Controler.ComputeDataTypeName(name), True)
+        elif data == ITEM_POU:
+            self.EditProjectElement(data, self.Controler.ComputePouName(name), True)
+        elif data == ITEM_CONFIGURATION:
+            self.EditProjectElement(data, self.Controler.ComputeConfigurationName(name), True)
+        elif data == ITEM_RESOURCE:
+            item = self.ProjectTree.GetItemParent(select_item)
+            item_type = self.ProjectTree.GetPyData(item)
+            while item_type != ITEM_CONFIGURATION:
+                item = self.ProjectTree.GetItemParent(item)
+                item_type = self.ProjectTree.GetPyData(item)
+            config_name = self.ProjectTree.GetItemText(item)
+            self.EditProjectElement(data, self.Controler.ComputeConfigurationResourceName(config_name, name), True)
+        elif data in [ITEM_TRANSITION, ITEM_ACTION]:
+            item = self.ProjectTree.GetItemParent(select_Item)
+            item_type = self.ProjectTree.GetPyData(item)
+            while item_type != ITEM_POU:
+                item = self.ProjectTree.GetItemParent(item)
+                item_type = self.ProjectTree.GetPyData(item)
+            pou_name = self.ProjectTree.GetItemText(item)
+            if data == ITEM_TRANSITION:
+                tagname = self.Controler.ComputePouTransitionName(pou_name, name)
+            elif data == ITEM_ACTION:
+                tagname = self.Controler.ComputePouActionName(pou_name, name)
+            self.EditProjectElement(data, tagname, True)
+    
     def OnProjectTreeLeftUp(self, event):
         if self.SelectedItem is not None:
             self.ProjectTree.SelectItem(self.SelectedItem)
-            name = self.ProjectTree.GetItemText(self.SelectedItem)
-            data = self.ProjectTree.GetPyData(self.SelectedItem)
-            if data == ITEM_DATATYPE:
-                self.EditProjectElement(data, self.Controler.ComputeDataTypeName(name), True)
-            elif data == ITEM_POU:
-                self.EditProjectElement(data, self.Controler.ComputePouName(name), True)
-            elif data == ITEM_CONFIGURATION:
-                self.EditProjectElement(data, self.Controler.ComputeConfigurationName(name), True)
-            elif data == ITEM_RESOURCE:
-                item = self.ProjectTree.GetItemParent(self.SelectedItem)
-                item_type = self.ProjectTree.GetPyData(item)
-                while item_type != ITEM_CONFIGURATION:
-                    item = self.ProjectTree.GetItemParent(item)
-                    item_type = self.ProjectTree.GetPyData(item)
-                config_name = self.ProjectTree.GetItemText(item)
-                self.EditProjectElement(data, self.Controler.ComputeConfigurationResourceName(config_name, name), True)
-            elif data in [ITEM_TRANSITION, ITEM_ACTION]:
-                item = self.ProjectTree.GetItemParent(self.SelectedItem)
-                item_type = self.ProjectTree.GetPyData(item)
-                while item_type != ITEM_POU:
-                    item = self.ProjectTree.GetItemParent(item)
-                    item_type = self.ProjectTree.GetPyData(item)
-                pou_name = self.ProjectTree.GetItemText(item)
-                if data == ITEM_TRANSITION:
-                    tagname = self.Controler.ComputePouTransitionName(pou_name, name)
-                elif data == ITEM_ACTION:
-                    tagname = self.Controler.ComputePouActionName(pou_name, name)
-                self.EditProjectElement(data, tagname, True)
+            self.ProjectTreeItemSelect(self.SelectedItem)
             wx.CallAfter(self.ResetSelectedItem)
         event.Skip()
     
+    def OnProjectTreeItemSelected(self, event):
+        self.ProjectTreeItemSelect(event.GetItem())
+        event.Skip()
+    
     def OnProjectTreeItemChanging(self, event):
         if self.ProjectTree.GetPyData(event.GetItem()) != ITEM_UNEDITABLE and self.SelectedItem is None:
             self.SelectedItem = event.GetItem()
@@ -3196,7 +3211,6 @@
             data = wx.TextDataObject(str((var_name, var_class, var_type, self.TagName)))
             dragSource = wx.DropSource(self.VariablesGrid)
             dragSource.SetData(data)
-            print dragSource.DoDragDrop()
         event.Skip()
     
     def OnVariablesGridSelectCell(self, event):