Fix bug when drag'n dropping location with undefined direction on Windows default tip
authorLaurent Bessard
Wed, 05 Sep 2012 12:39:50 +0200
changeset 761 996515c4b394
parent 760 7cadc624cc74
Fix bug when drag'n dropping location with undefined direction on Windows
TextViewer.py
Viewer.py
controls/EditorPanel.py
controls/VariablePanel.py
--- a/TextViewer.py	Wed Sep 05 12:38:41 2012 +0200
+++ b/TextViewer.py	Wed Sep 05 12:39:50 2012 +0200
@@ -29,7 +29,7 @@
 import re
 
 from graphics.GraphicCommons import ERROR_HIGHLIGHT, SEARCH_RESULT_HIGHLIGHT, REFRESH_HIGHLIGHT_PERIOD
-from plcopen.structures import ST_BLOCK_START_KEYWORDS, ST_BLOCK_END_KEYWORDS, IEC_BLOCK_START_KEYWORDS, IEC_BLOCK_END_KEYWORDS
+from plcopen.structures import ST_BLOCK_START_KEYWORDS, ST_BLOCK_END_KEYWORDS, IEC_BLOCK_START_KEYWORDS, IEC_BLOCK_END_KEYWORDS, LOCATIONDATATYPES
 from controls import EditorPanel
 
 #-------------------------------------------------------------------------------
@@ -324,11 +324,31 @@
                     elif var_name.upper() in [name.upper() for name in self.Controler.GetEditedElementVariables(self.TagName, self.Debug)]:
                         message = _("\"%s\" element for this pou already exists!")%var_name
                     else:
+                        location = values[0]
+                        if not location.startswith("%"):
+                            dialog = wx.SingleChoiceDialog(self.ParentWindow, 
+                                  _("Select a variable class:"), _("Variable class"), 
+                                  ["Input", "Output", "Memory"], 
+                                  wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
+                            if dialog.ShowModal() == wx.ID_OK:
+                                selected = dialog.GetSelection()
+                            else:
+                                selected = None
+                            dialog.Destroy()
+                            if selected is None:
+                                event.SetDragText("")
+                                return
+                            if selected == 0:
+                                location = "%I" + location
+                            elif selected == 1:
+                                location = "%Q" + location
+                            else:
+                                location = "%M" + location
                         if values[2] is not None:
                             var_type = values[2]
                         else:
-                            var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0]
-                        self.Controler.AddEditedElementPouVar(self.TagName, var_type, var_name, values[0], values[4])
+                            var_type = LOCATIONDATATYPES.get(location[2], ["BOOL"])[0]
+                        self.Controler.AddEditedElementPouVar(self.TagName, var_type, var_name, location, values[4])
                         self.RefreshVariablePanel()
                         self.RefreshVariableTree()
                         event.SetDragText(var_name)
--- a/Viewer.py	Wed Sep 05 12:38:41 2012 +0200
+++ b/Viewer.py	Wed Sep 05 12:39:50 2012 +0200
@@ -207,6 +207,7 @@
         self.ParentWindow = parent
     
     def OnDropText(self, x, y, data):
+        self.ParentWindow.Select()
         tagname = self.ParentWindow.GetTagName()
         pou_name, pou_type = self.ParentWindow.Controler.GetEditedElementType(tagname, self.ParentWindow.Debug)
         x, y = self.ParentWindow.CalcUnscrolledPosition(x, y)
@@ -272,7 +273,7 @@
                 if pou_type == "program":
                     location = values[0]
                     if not location.startswith("%"):
-                        dialog = wx.SingleChoiceDialog(self.ParentWindow, 
+                        dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow, 
                               _("Select a variable class:"), _("Variable class"), 
                               ["Input", "Output", "Memory"], 
                               wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
@@ -630,9 +631,12 @@
         self.Editor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelWindow)
         self.Editor.Bind(wx.EVT_SIZE, self.OnMoveWindow)
         self.Editor.Bind(wx.EVT_MOUSE_EVENTS, self.OnViewerMouseEvent)
-        
+    
+    # Destructor
     def __del__(self):
         DebugViewer.__del__(self)
+        self.Flush()
+        self.ResetView()
         self.RefreshHighlightsTimer.Stop()
     
     def SetCurrentCursor(self, cursor):
@@ -671,13 +675,7 @@
     def GetNewId(self):
         self.current_id += 1
         return self.current_id
-    
-    # Destructor
-    def __del__(self):
-        DebugViewer.__del__(self)
-        self.Flush()
-        self.ResetView()
-    
+        
     def SetScale(self, scale_number, refresh=True, mouse_event=None):
         new_scale = max(0, min(scale_number, len(ZOOM_FACTORS) - 1))
         if self.CurrentScale != new_scale:
--- a/controls/EditorPanel.py	Wed Sep 05 12:38:41 2012 +0200
+++ b/controls/EditorPanel.py	Wed Sep 05 12:39:50 2012 +0200
@@ -76,6 +76,9 @@
     def GetTagName(self):
         return self.TagName
     
+    def Select(self):
+        self.ParentWindow.EditProjectElement(None, self.GetTagName(), True)
+    
     def GetTitle(self):
         return "-".join(self.TagName.split("::")[1:])
     
--- a/controls/VariablePanel.py	Wed Sep 05 12:38:41 2012 +0200
+++ b/controls/VariablePanel.py	Wed Sep 05 12:39:50 2012 +0200
@@ -232,6 +232,7 @@
         self.ParentWindow = parent
     
     def OnDropText(self, x, y, data):
+        self.ParentWindow.ParentWindow.Select()
         x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
         col = self.ParentWindow.VariablesGrid.XToCol(x)
         row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
@@ -272,22 +273,26 @@
                             elif base_type not in LOCATIONDATATYPES[location[0]]:
                                 message = _("Incompatible size of data between \"%s\" and \"%s\"")%(location, variable_type)
                             else:
-                                dialog = wx.SingleChoiceDialog(self.ParentWindow, 
+                                dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow.ParentWindow, 
                                       _("Select a variable class:"), _("Variable class"), 
                                       ["Input", "Output", "Memory"], 
                                       wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
                                 if dialog.ShowModal() == wx.ID_OK:
                                     selected = dialog.GetSelection()
-                                    if selected == 0:
-                                        location = "%I" + location
-                                    elif selected == 1:
-                                        location = "%Q" + location
-                                    else:
-                                        location = "%M" + location
-                                    self.ParentWindow.Table.SetValue(row, col, location)
-                                    self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
-                                    self.ParentWindow.SaveValues()
+                                else:
+                                    selected = None
                                 dialog.Destroy()
+                                if selected is None:
+                                    return
+                                if selected == 0:
+                                    location = "%I" + location
+                                elif selected == 1:
+                                    location = "%Q" + location
+                                else:
+                                    location = "%M" + location
+                                self.ParentWindow.Table.SetValue(row, col, location)
+                                self.ParentWindow.Table.ResetView(self.ParentWindow.VariablesGrid)
+                                self.ParentWindow.SaveValues()
                 elif colname == "Initial Value" and values[1] == "Constant":
                     if not self.ParentWindow.Table.GetValueByName(row, "Edit"):
                         message = _("Can't set an initial value to a function block instance")