MQTT: Update available type choices when data types are changed in the IDE
authorEdouard Tisserant <edouard@beremiz.fr>
Tue, 17 Sep 2024 11:17:24 +0200
changeset 4014 da52eabd0e6d
parent 4013 7f4226b2f867
child 4015 ab96d56f9ae9
MQTT: Update available type choices when data types are changed in the IDE
mqtt/client.py
mqtt/mqtt_client_gen.py
--- a/mqtt/client.py	Fri Sep 13 14:28:07 2024 +0200
+++ b/mqtt/client.py	Tue Sep 17 11:17:24 2024 +0200
@@ -28,15 +28,24 @@
     CONFNODEEDITOR_TABS = [
         (_("MQTT Client"), "CreateMQTTClient_UI")]
 
+    MQTTClient_UI = None
+
     def Log(self, msg):
         self.Controler.GetCTRoot().logger.write(msg)
 
     def CreateMQTTClient_UI(self, parent):
-        return MQTTClientPanel(
+        self.MQTTClient_UI = MQTTClientPanel(
             parent,
             self.Controler.GetModelData(),
             self.Log,
             self.Controler.GetTypes)
+        return self.MQTTClient_UI
+
+    def RefreshView(self):
+        if(self.MQTTClient_UI):
+            self.MQTTClient_UI.RefreshView()
+        return ConfTreeNodeEditor.RefreshView(self)
+
 
 class MQTTClient(object):
     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
--- a/mqtt/mqtt_client_gen.py	Fri Sep 13 14:28:07 2024 +0200
+++ b/mqtt/mqtt_client_gen.py	Tue Sep 17 11:17:24 2024 +0200
@@ -152,14 +152,6 @@
     def ResetData(self):
         self.Reset(len(self.data))
 
-class MQQTTypeChoiceRenderer(dv.DataViewChoiceRenderer):
-    def __init__(self, types_getter):
-        dv.DataViewChoiceRenderer.__init__(self, types_getter())
-        self.types_getter = types_getter
-
-    def GetChoices(self):
-        return self.types_getter()
-
 class MQTTTopicListPanel(wx.Panel):
     def __init__(self, parent, log, model, direction, types_getter):
         self.log = log
@@ -177,19 +169,12 @@
 
         self.dvc.AssociateModel(self.model)
 
-        dsc = lstcoldsc[direction]
-        for idx,(colname,width) in enumerate(zip(dsc.lstcolnames,dsc.lstcolwidths)):
-            if colname == "Type":
-                choice_DV_render = MQQTTypeChoiceRenderer(types_getter)
-                choice_DV_col = dv.DataViewColumn(colname, choice_DV_render, idx, width=width)
-                self.dvc.AppendColumn(choice_DV_col)
-            else:
-                self.dvc.AppendTextColumn(colname,  idx, width=width, mode=dv.DATAVIEW_CELL_EDITABLE)
-
+        self.types_getter = types_getter
+        self.direction =  direction
+        self.CreateDVCColumns()
 
         self.Sizer = wx.BoxSizer(wx.VERTICAL)
 
-        self.direction =  direction
         titlestr = direction + " variables"
 
         title = wx.StaticText(self, label = titlestr)
@@ -207,6 +192,20 @@
         self.Sizer.Add(self.dvc, 1, wx.EXPAND)
 
 
+    def CreateDVCColumns(self):
+        dsc = lstcoldsc[self.direction]
+        for idx,(colname,width) in enumerate(zip(dsc.lstcolnames,dsc.lstcolwidths)):
+            if colname == "Type":
+                choice_DV_render = dv.DataViewChoiceRenderer(self.types_getter())
+                choice_DV_col = dv.DataViewColumn(colname, choice_DV_render, idx, width=width)
+                self.dvc.AppendColumn(choice_DV_col)
+            else:
+                self.dvc.AppendTextColumn(colname,  idx, width=width, mode=dv.DATAVIEW_CELL_EDITABLE)
+
+    def ResetDVCColumns(self):
+        self.dvc.ClearColumns()
+        self.CreateDVCColumns()
+
     def OnAddRow(self, evt):
         items = self.dvc.GetSelections()
         row = self.model.GetRow(items[0]) if items else 0
@@ -235,6 +234,10 @@
 
         self.SetAutoLayout(True)
 
+    def RefreshView(self):
+        for direction in directions:
+            self.selected_lists[direction].ResetDVCColumns()
+        
     def OnClose(self):
         pass