Browse Source

Manipulate configuration locally

Now instead of editing configuration on the device, we keep a SinkConfig
locally and manipulate it there.  Much less error-prone, and things can
still get even better than they are now.
Clara Hobbs 7 years ago
parent
commit
b0e03062c3
1 changed files with 17 additions and 31 deletions
  1. 17
    31
      pd-buddy-gtk.py

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

@@ -177,25 +177,25 @@ class Handler:
177 177
         try:
178 178
             with pdbuddy.Sink(self.serial_port) as pdbs:
179 179
                 pdbs.load()
180
-                tmpcfg = pdbs.get_tmpcfg()
180
+                self.cfg = pdbs.get_tmpcfg()
181 181
         except OSError as e:
182 182
             comms_error_dialog(window, e)
183 183
             return
184 184
 
185 185
         # Set giveback button state
186
-        giveback.set_active(bool(tmpcfg.flags & pdbuddy.SinkFlags.GIVEBACK))
186
+        giveback.set_active(bool(self.cfg.flags & pdbuddy.SinkFlags.GIVEBACK))
187 187
 
188 188
         # Get voltage and current from device and load them into the GUI
189
-        if tmpcfg.v == 5000:
189
+        if self.cfg.v == 5000:
190 190
             voltage.set_active_id('voltage-five')
191
-        elif tmpcfg.v == 9000:
191
+        elif self.cfg.v == 9000:
192 192
             voltage.set_active_id('voltage-nine')
193
-        elif tmpcfg.v == 15000:
193
+        elif self.cfg.v == 15000:
194 194
             voltage.set_active_id('voltage-fifteen')
195
-        if tmpcfg.v == 20000:
195
+        if self.cfg.v == 20000:
196 196
             voltage.set_active_id('voltage-twenty')
197 197
 
198
-        current.set_value(tmpcfg.i/1000)
198
+        current.set_value(self.cfg.i/1000)
199 199
 
200 200
         self._store_device_settings()
201 201
         self._set_save_button_visibility()
@@ -245,6 +245,7 @@ class Handler:
245 245
         window = self.builder.get_object("pdb-window")
246 246
         try:
247 247
             with pdbuddy.Sink(self.serial_port) as pdbs:
248
+                pdbs.set_tmpcfg(self.cfg)
248 249
                 pdbs.write()
249 250
 
250 251
             self._store_device_settings()
@@ -279,37 +280,22 @@ class Handler:
279 280
                              or giveback.get_active() != self.giveback)
280 281
 
281 282
     def on_voltage_combobox_changed(self, combo):
282
-        window = self.builder.get_object("pdb-window")
283
-        try:
284
-            with pdbuddy.Sink(self.serial_port) as pdbs:
285
-                pdbs.set_v(int(combo.get_active_text())*1000)
283
+        self.cfg.v = int(combo.get_active_text()) * 1000
286 284
 
287
-            self._set_save_button_visibility()
288
-        except OSError as e:
289
-            comms_error_dialog(window, e)
290
-            self.on_header_sink_back_clicked(None)
285
+        self._set_save_button_visibility()
291 286
 
292 287
     def on_current_spinbutton_changed(self, spin):
293
-        window = self.builder.get_object("pdb-window")
294
-        try:
295
-            with pdbuddy.Sink(self.serial_port) as pdbs:
296
-                pdbs.set_i(int(spin.get_value())*1000)
288
+        self.cfg.i = int(spin.get_value() * 1000)
297 289
 
298
-            self._set_save_button_visibility()
299
-        except OSError as e:
300
-            comms_error_dialog(window, e)
301
-            self.on_header_sink_back_clicked(None)
290
+        self._set_save_button_visibility()
302 291
 
303 292
     def on_giveback_toggle_toggled(self, toggle):
304
-        window = self.builder.get_object("pdb-window")
305
-        try:
306
-            with pdbuddy.Sink(self.serial_port) as pdbs:
307
-                pdbs.toggle_giveback()
293
+        if toggle.get_active():
294
+            self.cfg.flags |= pdbuddy.SinkFlags.GIVEBACK
295
+        else:
296
+            self.cfg.flags &= ~pdbuddy.SinkFlags.GIVEBACK
308 297
 
309
-            self._set_save_button_visibility()
310
-        except OSError as e:
311
-            comms_error_dialog(window, e)
312
-            self.on_header_sink_back_clicked(None)
298
+        self._set_save_button_visibility()
313 299
 
314 300
 
315 301
 class Application(Gtk.Application):

Loading…
Cancel
Save