Browse Source

wxGUI Manage color rules interactively (vector map): fix number of LoadTable method calls (#444)

Tomas Zigo 5 năm trước cách đây
mục cha
commit
9b7398c00b
1 tập tin đã thay đổi với 33 bổ sung5 xóa
  1. 33 5
      gui/wxpython/modules/colorrules.py

+ 33 - 5
gui/wxpython/modules/colorrules.py

@@ -1090,9 +1090,7 @@ class VectorColorTable(ColorTable):
         # additional bindings for vector color management
         self.Bind(wx.EVT_COMBOBOX, self.OnLayerSelection, self.layerSelect)
 
-        self.sourceColumn.Bind(wx.EVT_TEXT, self.OnSourceColumnSelection)
-        self.fromColumn.Bind(wx.EVT_TEXT, self.OnFromColSelection)
-        self.toColumn.Bind(wx.EVT_TEXT, self.OnToColSelection)
+        self._columnWidgetEvtHandler()
         self.Bind(wx.EVT_BUTTON, self.OnAddColumn, self.addColumn)
 
         self._initLayer()
@@ -1396,8 +1394,8 @@ class VectorColorTable(ColorTable):
             self.useColumn.SetValue(False)
             self.OnCheckColumn(event=None)
             self.useColumn.Enable(self.CheckMapset())
-
-        self.LoadTable()
+        else:
+            self.LoadTable()
 
         self.btnPreview.Enable(enable)
         self.btnOK.Enable(enable)
@@ -1447,6 +1445,7 @@ class VectorColorTable(ColorTable):
     def OnLayerSelection(self, event):
         # reset choices in column selection comboboxes if layer changes
         vlayer = int(self.layerSelect.GetStringSelection())
+        self._columnWidgetEvtHandler(bind=False)
         self.sourceColumn.InsertColumns(
             vector=self.inmap, layer=vlayer,
             type=['integer', 'double precision'],
@@ -1485,6 +1484,8 @@ class VectorColorTable(ColorTable):
             self.properties['loadColumn'] = ''
             self.properties['storeColumn'] = ''
 
+        self._columnWidgetEvtHandler()
+
         if event:
             self.LoadTable()
         self.Update()
@@ -1867,6 +1868,33 @@ class VectorColorTable(ColorTable):
 
         return ColorTable._apply(self, updatePreview)
 
+    def _columnWidgetEvtHandler(self, bind=True):
+        """Bind/Unbind Column widgets handlers"""
+        widgets = [
+            {
+                'widget': self.sourceColumn,
+                'event': wx.EVT_TEXT,
+                'handler': self.OnSourceColumnSelection,
+            },
+            {
+                'widget': self.fromColumn,
+                'event': wx.EVT_TEXT,
+                'handler': self.OnFromColSelection,
+            },
+            {
+                'widget': self.toColumn,
+                'event': wx.EVT_TEXT,
+                'handler': self.OnToColSelection,
+            },
+        ]
+        for widget in widgets:
+            if bind is True:
+                getattr(widget['widget'], 'Bind')(
+                    widget['event'], widget['handler'],
+                )
+            else:
+                getattr(widget['widget'], 'Unbind')(widget['event'])
+
 
 class ThematicVectorTable(VectorColorTable):