OPC-UA: Update CTN "ChangesToSave" status when variable selection change. wxPython4
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Fri, 11 Nov 2022 16:07:38 +0100
branchwxPython4
changeset 3674 d10a7907fb43
parent 3673 6a04e7a90ceb
child 3675 d331eb981b44
OPC-UA: Update CTN "ChangesToSave" status when variable selection change.

- fixes changes not being saved when no other changes happening to configuration
- added CTNMarkModified to ConfigTreeNode in order to generalize
ConfigTreeNode.py
opc_ua/client.py
opc_ua/opcua_client_maker.py
--- a/ConfigTreeNode.py	Fri Nov 11 08:26:15 2022 +0100
+++ b/ConfigTreeNode.py	Fri Nov 11 16:07:38 2022 +0100
@@ -133,6 +133,15 @@
     def CTNTestModified(self):
         return self.ChangesToSave
 
+    def CTNMarkModified(self):
+        oldChangesToSave = self.ChangesToSave
+        self.ChangesToSave = True
+        if not oldChangesToSave:
+            appframe = self.GetCTRoot().AppFrame
+            if appframe is not None:
+                appframe.RefreshTitle()
+                appframe.RefreshPageTitles()
+
     def ProjectTestModified(self):
         """
         recursively check modified status
--- a/opc_ua/client.py	Fri Nov 11 08:26:15 2022 +0100
+++ b/opc_ua/client.py	Fri Nov 11 16:07:38 2022 +0100
@@ -88,7 +88,7 @@
     EditorType = OPCUAClientEditor
 
     def __init__(self):
-        self.modeldata = OPCUAClientModel(self.Log)
+        self.modeldata = OPCUAClientModel(self.Log, self.CTNMarkModified)
 
         filepath = self.GetFileName()
         if os.path.isfile(filepath):
@@ -99,7 +99,7 @@
 
     def GetModelData(self):
         return self.modeldata
-    
+
     def GetConfig(self):
         cfg = lambda path: self.GetParamsAttributes("OPCUAClient."+path)["value"]
         AuthType = cfg("AuthType")
--- a/opc_ua/opcua_client_maker.py	Fri Nov 11 08:26:15 2022 +0100
+++ b/opc_ua/opcua_client_maker.py	Fri Nov 11 16:07:38 2022 +0100
@@ -447,9 +447,10 @@
         
 
 class OPCUAClientList(list):
-    def __init__(self, log = lambda m:None):
+    def __init__(self, log, change_callback):
         super(OPCUAClientList, self).__init__(self)
         self.log = log
+        self.change_callback = change_callback
 
     def append(self, value):
         v = dict(zip(lstcolnames, value))
@@ -480,13 +481,19 @@
 
         list.append(self, [v[n] for n in lstcolnames])
 
+        self.change_callback()
+
         return True
 
+    def __delitem__(self, index):
+        list.__delitem__(self, index)
+        self.change_callback()
+
 class OPCUAClientModel(dict):
-    def __init__(self, log = lambda m:None):
+    def __init__(self, log, change_callback = lambda : None):
         super(OPCUAClientModel, self).__init__()
         for direction in directions:
-            self[direction] = OPCUAClientList(log)
+            self[direction] = OPCUAClientList(log, change_callback)
 
     def LoadCSV(self,path):
         with open(path, 'rb') as csvfile:
@@ -496,7 +503,8 @@
                 self[direction][:] = []
             for row in reader:
                 direction = row[0]
-                self[direction].append(row[1:])
+                # avoids calling change callback whe loading CSV
+                list.append(self[direction],row[1:])
 
     def SaveCSV(self,path):
         with open(path, 'wb') as csvfile: