SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Wed, 09 Jun 2021 10:06:23 +0200
branchsvghmi
changeset 3251 6d4ff271ebf1
parent 3250 22da8e0b07b8
child 3252 352b2111ca66
child 3253 9233e60a8317
SVGHMI: UI Updates validity indicator when DnD HMI tree node in text field, according to node type
svghmi/ui.py
--- a/svghmi/ui.py	Mon May 31 16:06:00 2021 +0200
+++ b/svghmi/ui.py	Wed Jun 09 10:06:23 2021 +0200
@@ -200,6 +200,17 @@
         self.SetSizer(self.main_sizer)
         self.main_sizer.Fit(self)
 
+    def setValidityNOK(self):
+        self.validity_sbmp.SetBitmap(self.invalid_bmp)
+        self.validity_sbmp.Show(True)
+
+    def setValidityOK(self):
+        self.validity_sbmp.SetBitmap(self.valid_bmp)
+        self.validity_sbmp.Show(True)
+
+    def setValidityUnknown(self):
+        self.validity_sbmp.Show(False)
+
 class ArgEditor(ParamEditor):
     pass
 
@@ -207,18 +218,25 @@
     def __init__(self, parent, pathdesc):
         ParamEditor.__init__(self, parent, pathdesc)
         self.ParentObj = parent
+        self.pathdesc = pathdesc
         DropTarget = PathDropTarget(self)
         self.edit.SetDropTarget(DropTarget)
-        self.Bind(wx.EVT_TEXT_ENTER, self.OnPathChanged, self.edit)
+        self.Bind(wx.EVT_TEXT, self.OnPathChanged, self.edit)
 
     def OnHMITreeDnD(self):
         self.ParentObj.GotPathDnDOn(self)
 
-    def SetPath(self, value):
-        self.edit.SetValue(value)
+    def SetPath(self, hmitree_node):
+        self.edit.ChangeValue(hmitree_node.hmi_path())
+        if hmitree_node.nodetype in self.pathdesc.get("accepts").split(","):
+            self.setValidityOK()
+        else:
+            self.setValidityNOK()
 
     def OnPathChanged(self, event):
-        # TODO : update validity
+        # TODO : find corresponding hmitre node and type to update validity
+        # Lazy way : hide validity
+        self.setValidityUnknown()
         event.Skip()
     
 
@@ -328,9 +346,9 @@
     def GotPathDnDOn(self, target_editor):
         dndindex = self.paths_editors.index(target_editor)
 
-        for selected,editor in zip(self.hmitree_nodes,
+        for hmitree_node,editor in zip(self.hmitree_nodes,
                                    self.paths_editors[dndindex:]):
-            editor.SetPath(selected.hmi_path())
+            editor.SetPath(hmitree_node)
 
     def RecallLibDir(self):
         conf = self.Config.Read(_conf_key)