Bladeren bron

Use SinkConfig objects for Save button visibility

Since I was clever enough to implement equality testing for SinkConfig,
the Save button's visibility can now be checked with a single comparison
of two SinkConfig objects.  Wonderful!
Clara Hobbs 7 jaren geleden
bovenliggende
commit
2fedef819f
1 gewijzigde bestanden met toevoegingen van 9 en 18 verwijderingen
  1. 9
    18
      pd-buddy-gtk.py

+ 9
- 18
pd-buddy-gtk.py Bestand weergeven

@@ -182,6 +182,9 @@ class Handler:
182 182
             comms_error_dialog(window, e)
183 183
             return
184 184
 
185
+        self._store_device_settings()
186
+        self._set_save_button_visibility()
187
+
185 188
         # Set giveback button state
186 189
         giveback.set_active(bool(self.cfg.flags & pdbuddy.SinkFlags.GIVEBACK))
187 190
 
@@ -197,9 +200,6 @@ class Handler:
197 200
 
198 201
         current.set_value(self.cfg.i/1000)
199 202
 
200
-        self._store_device_settings()
201
-        self._set_save_button_visibility()
202
-
203 203
         # Show the Sink page
204 204
         hst = self.builder.get_object("header-stack")
205 205
         hsink = self.builder.get_object("header-sink")
@@ -256,28 +256,19 @@ class Handler:
256 256
 
257 257
     def _store_device_settings(self):
258 258
         """Store the settings that were loaded from the device"""
259
-        # Get voltage and current widgets
260
-        voltage = self.builder.get_object("voltage-combobox")
261
-        current = self.builder.get_object("current-spinbutton")
262
-        giveback = self.builder.get_object("giveback-toggle")
263
-
264
-        # Remember the loaded settings
265
-        self.voltage = voltage.get_active_id()
266
-        self.current = current.get_value()
267
-        self.giveback = giveback.get_active()
259
+        self.cfg_clean = pdbuddy.SinkConfig(
260
+                status=self.cfg.status,
261
+                flags=self.cfg.flags,
262
+                v=self.cfg.v,
263
+                i=self.cfg.i)
268 264
 
269 265
     def _set_save_button_visibility(self):
270 266
         """Show the save button if there are new settings to save"""
271 267
         # Get relevant widgets
272
-        voltage = self.builder.get_object("voltage-combobox")
273
-        current = self.builder.get_object("current-spinbutton")
274
-        giveback = self.builder.get_object("giveback-toggle")
275 268
         rev = self.builder.get_object("header-sink-save-revealer")
276 269
 
277 270
         # Set visibility
278
-        rev.set_reveal_child(voltage.get_active_id() != self.voltage
279
-                             or current.get_value() != self.current
280
-                             or giveback.get_active() != self.giveback)
271
+        rev.set_reveal_child(self.cfg != self.cfg_clean)
281 272
 
282 273
     def on_voltage_combobox_changed(self, combo):
283 274
         self.cfg.v = int(combo.get_active_text()) * 1000

Laden…
Annuleren
Opslaan