Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
authorlaurent
Wed, 09 Dec 2009 10:19:35 +0100
changeset 479 2fab0eefa66e
parent 478 dc403c47af54
child 480 5389728644a5
Adding support for getting current value in ForceVariableDialog default value and adding variable in DebugVariablePanel when forced
PLCOpenEditor.py
Viewer.py
dialogs/ForceVariableDialog.py
--- a/PLCOpenEditor.py	Tue Dec 08 17:10:30 2009 +0100
+++ b/PLCOpenEditor.py	Wed Dec 09 10:19:35 2009 +0100
@@ -1009,16 +1009,6 @@
                     self.VariablePanelIndexer.RemoveVariablePanel(tagname)
                     self.TabsOpened.DeletePage(idx)
 
-    def CloseDebugTabs(self):
-        if self.EnableDebug:
-            idxs = range(self.TabsOpened.GetPageCount())
-            idxs.reverse()
-            for idx in idxs:
-                window = self.TabsOpened.GetPage(idx)
-                if window.IsDebugging():
-                    self.TabsOpened.DeletePage(idx)
-            self.DebugVariablePanel.ResetGrid()
-
     def OnUndoMenu(self, event):
         self.Controler.LoadPrevious()
         self.CloseTabsWithoutModel()
@@ -1872,6 +1862,20 @@
             if isinstance(editor, GraphicViewer):
                 editor.ResetView()
 
+    def CloseDebugTabs(self):
+        if self.EnableDebug:
+            idxs = range(self.TabsOpened.GetPageCount())
+            idxs.reverse()
+            for idx in idxs:
+                window = self.TabsOpened.GetPage(idx)
+                if window.IsDebugging():
+                    self.TabsOpened.DeletePage(idx)
+            self.DebugVariablePanel.ResetGrid()
+    
+    def AddDebugVariable(self, iec_path):
+        if self.EnableDebug:
+            self.DebugVariablePanel.InsertValue(iec_path)
+            
 #-------------------------------------------------------------------------------
 #                         Library Tree Management Functions
 #-------------------------------------------------------------------------------
@@ -4029,7 +4033,7 @@
             message = _("Invalid value \"%s\" for debug variable")%data
             values = None
         if values is not None and values[1] == "debug":
-            self.ParentWindow.InsertValue(row, values[0])
+            self.ParentWindow.InsertValue(values[0], row)
         if message is not None:
             wx.CallAfter(self.ShowMessage, message)
             
@@ -4144,11 +4148,11 @@
         self.Table.ResetView(self.VariablesGrid)
         self.Thaw()
     
-    def GetForceVariableMenuFunction(self, iec_path):
+    def GetForceVariableMenuFunction(self, iec_path, item):
         iec_type = self.GetDataType(iec_path)
         def ForceVariableFunction(event):
             if iec_type is not None:
-                dialog = ForceVariableDialog(self, iec_type)
+                dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
                 if dialog.ShowModal() == wx.ID_OK:
                     self.ForceDataValue(iec_path, dialog.GetValue())
         return ForceVariableFunction
@@ -4166,7 +4170,7 @@
             menu = wx.Menu(title='')
             new_id = wx.NewId()
             AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value"))
-            self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper()), id=new_id)
+            self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.Table.GetItem(row)), id=new_id)
             new_id = wx.NewId()
             AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value"))
             self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id)
@@ -4193,7 +4197,9 @@
         self.MoveValue(self.VariablesGrid.GetGridCursorRow(), 1)
         event.Skip()
 
-    def InsertValue(self, idx, iec_path):
+    def InsertValue(self, iec_path, idx = None):
+        if idx is None:
+            idx = self.Table.GetNumberRows()
         for item in self.Table.GetData():
             if iec_path == item.GetVariable():
                 return
--- a/Viewer.py	Tue Dec 08 17:10:30 2009 +0100
+++ b/Viewer.py	Wed Dec 09 10:19:35 2009 +0100
@@ -1106,12 +1106,13 @@
 #                           Popup menu functions
 #-------------------------------------------------------------------------------
 
-    def GetForceVariableMenuFunction(self, iec_path):
+    def GetForceVariableMenuFunction(self, iec_path, element):
         iec_type = self.GetDataType(iec_path)
         def ForceVariableFunction(event):
             if iec_type is not None:
-                dialog = ForceVariableDialog(self.ParentWindow, iec_type)
+                dialog = ForceVariableDialog(self.ParentWindow, iec_type, str(element.GetValue()))
                 if dialog.ShowModal() == wx.ID_OK:
+                    self.ParentWindow.AddDebugVariable(iec_path)
                     self.ForceDataValue(iec_path, dialog.GetValue())
         return ForceVariableFunction
 
@@ -1126,7 +1127,7 @@
             menu = wx.Menu(title='')
             new_id = wx.NewId()
             AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value"))
-            self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper()), id=new_id)
+            self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.SelectedElement), id=new_id)
             new_id = wx.NewId()
             AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value"))
             self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id)
--- a/dialogs/ForceVariableDialog.py	Tue Dec 08 17:10:30 2009 +0100
+++ b/dialogs/ForceVariableDialog.py	Wed Dec 09 10:19:35 2009 +0100
@@ -45,7 +45,7 @@
 getfloat = gen_get_function(float)
 getstring = gen_get_function(str)
 
-GetTypeValue = {"BOOL": lambda x: {"TRUE": True, "FALSE": False}.get(x, None),
+GetTypeValue = {"BOOL": lambda x: {"TRUE": True, "FALSE": False}.get(x.upper(), None),
                 "SINT": getinteger,
                 "INT": getinteger,
                 "DINT": getinteger,
@@ -73,9 +73,9 @@
             else:
                 event(self, function)
 
-    def __init__(self, parent, iec_type):
+    def __init__(self, parent, iec_type, defaultValue=""):
         wx.TextEntryDialog.__init__(self, parent, message = _("Forcing Variable Value"), 
-                caption = _("Please enter value for a \"%s\" variable:"%iec_type), defaultValue = "", 
+                caption = _("Please enter value for a \"%s\" variable:"%iec_type), defaultValue = defaultValue, 
                 style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition)
         
         self.IEC_Type = iec_type