Browse Source

Only show Save button when settings are different

Before now, the Save button appeared when the voltage and current
widgets changed their value.  If they were then changed back to the
original values, the Save button was still visible, allowing unnecessary
wear on the flash.  (the sarcastic horror!)

Now, the Save button is only shown when the voltage and current are not
both at their saved values.  A minor tweak, but we're closer to the
original design now.
Clara Hobbs 7 years ago
parent
commit
9efbee8180
1 changed files with 31 additions and 10 deletions
  1. 31
    10
      pd-buddy-gtk.py

+ 31
- 10
pd-buddy-gtk.py View File

@@ -146,6 +146,9 @@ class Handler:
146 146
 
147 147
     def __init__(self, builder):
148 148
         self.builder = builder
149
+        self.serial_port = None
150
+        self.voltage = None
151
+        self.current = None
149 152
 
150 153
     def on_pdb_window_realize(self, *args):
151 154
         # Get the list
@@ -172,7 +175,7 @@ class Handler:
172 175
         pdb_send_message(self.serial_port, 'load')
173 176
         tmpcfg = pdb_send_message(self.serial_port, 'get_tmpcfg')
174 177
 
175
-        # Get information
178
+        # Get voltage and current from device and load them into the GUI
176 179
         for line in tmpcfg:
177 180
             if line.startswith(b'v:'):
178 181
                 v = line.split()[1]
@@ -188,9 +191,8 @@ class Handler:
188 191
                 i = float(line.split()[1])
189 192
                 current.set_value(i)
190 193
 
191
-        # Hide the Save button
192
-        rev = self.builder.get_object("header-sink-save-revealer")
193
-        rev.set_reveal_child(False)
194
+        self._store_device_settings()
195
+        self._set_save_button_visibility()
194 196
 
195 197
         # Show the Sink page
196 198
         hst = self.builder.get_object("header-stack")
@@ -213,21 +215,40 @@ class Handler:
213 215
         st.set_visible_child(select)
214 216
 
215 217
     def on_header_sink_save_clicked(self, button):
216
-        rev = self.builder.get_object("header-sink-save-revealer")
217
-        rev.set_reveal_child(False)
218
+        self._store_device_settings()
219
+        self._set_save_button_visibility()
218 220
 
219 221
         pdb_send_message(self.serial_port, 'write')
220 222
 
221
-    def on_voltage_combobox_changed(self, combo):
223
+    def _store_device_settings(self):
224
+        """Store the settings that were loaded from the device"""
225
+        # Get voltage and current widgets
226
+        voltage = self.builder.get_object("voltage-combobox")
227
+        current = self.builder.get_object("current-spinbutton")
228
+
229
+        # Remember the loaded settings
230
+        self.voltage = voltage.get_active_id()
231
+        self.current = current.get_value()
232
+
233
+    def _set_save_button_visibility(self):
234
+        """Show the save button if there are new settings to save"""
235
+        # Get relevant widgets
236
+        voltage = self.builder.get_object("voltage-combobox")
237
+        current = self.builder.get_object("current-spinbutton")
222 238
         rev = self.builder.get_object("header-sink-save-revealer")
223
-        rev.set_reveal_child(True)
239
+
240
+        # Set visibility
241
+        rev.set_reveal_child(voltage.get_active_id() != self.voltage
242
+                             or current.get_value() != self.current)
243
+
244
+    def on_voltage_combobox_changed(self, combo):
245
+        self._set_save_button_visibility()
224 246
 
225 247
         pdb_send_message(self.serial_port,
226 248
                          'set_v {}'.format(int(combo.get_active_text())*1000))
227 249
 
228 250
     def on_current_spinbutton_changed(self, spin):
229
-        rev = self.builder.get_object("header-sink-save-revealer")
230
-        rev.set_reveal_child(True)
251
+        self._set_save_button_visibility()
231 252
 
232 253
         pdb_send_message(self.serial_port,
233 254
                          'set_i {}'.format(int(spin.get_value()*1000)))

Loading…
Cancel
Save