Fix block connection with wire problems
authorLaurent Bessard
Wed, 01 Aug 2012 12:43:23 +0200
changeset 735 99699ca6eda4
parent 734 eeac14463bcf
child 736 eb6b13d87bfc
Fix block connection with wire problems
Viewer.py
--- a/Viewer.py	Tue Jul 31 17:45:33 2012 +0200
+++ b/Viewer.py	Wed Aug 01 12:43:23 2012 +0200
@@ -1666,8 +1666,11 @@
                 elif connector is None or self.SelectedElement.GetDragging():
                     self.DrawingWire = False
                     rect = self.SelectedElement.GetRedrawRect()
-                    self.SelectedElement.Delete()
-                    self.SelectedElement = None
+                    wire = self.SelectedElement
+                    self.SelectedElement = self.SelectedElement.StartConnected.GetParentBlock()
+                    self.SelectedElement.SetSelected(True)
+                    rect.Union(self.SelectedElement.GetRedrawRect())
+                    wire.Delete()
                     self.RefreshRect(self.GetScrolledRect(rect), False)
             else:
                 if self.Debug:
@@ -1704,7 +1707,7 @@
             if self.SelectedElement is not None and self.SelectedElement != element:
                 self.SelectedElement.SetSelected(False)
                 self.SelectedElement = None
-            if element:
+            if element is not None:
                 self.SelectedElement = element
                 if self.Debug:
                     Graphic_Element.OnRightDown(self.SelectedElement, event, self.GetLogicalDC(), self.Scaling)
@@ -1731,7 +1734,17 @@
         event.Skip()
     
     def OnViewerLeftDClick(self, event):
-        if self.Mode == MODE_SELECTION and self.SelectedElement is not None:
+        element = self.FindElement(event, connectors=False)
+        if self.Mode == MODE_SELECTION and element is not None:
+            if self.SelectedElement is not None and self.SelectedElement != element:
+                self.SelectedElement.SetSelected(False)
+            if self.HighlightedElement is not None and self.HighlightedElement != element:
+                self.HighlightedElement.SetHighlighted(False)
+                    
+            self.SelectedElement = element
+            self.HighlightedElement = element
+            self.SelectedElement.SetHighlighted(True)
+            
             if self.Debug:
                 if self.IsBlock(self.SelectedElement):
                     instance_type = self.SelectedElement.GetType()