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
         try:
177
         try:
178
             with pdbuddy.Sink(self.serial_port) as pdbs:
178
             with pdbuddy.Sink(self.serial_port) as pdbs:
179
                 pdbs.load()
179
                 pdbs.load()
180
-                tmpcfg = pdbs.get_tmpcfg()
180
+                self.cfg = pdbs.get_tmpcfg()
181
         except OSError as e:
181
         except OSError as e:
182
             comms_error_dialog(window, e)
182
             comms_error_dialog(window, e)
183
             return
183
             return
184
 
184
 
185
         # Set giveback button state
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
         # Get voltage and current from device and load them into the GUI
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
             voltage.set_active_id('voltage-five')
190
             voltage.set_active_id('voltage-five')
191
-        elif tmpcfg.v == 9000:
191
+        elif self.cfg.v == 9000:
192
             voltage.set_active_id('voltage-nine')
192
             voltage.set_active_id('voltage-nine')
193
-        elif tmpcfg.v == 15000:
193
+        elif self.cfg.v == 15000:
194
             voltage.set_active_id('voltage-fifteen')
194
             voltage.set_active_id('voltage-fifteen')
195
-        if tmpcfg.v == 20000:
195
+        if self.cfg.v == 20000:
196
             voltage.set_active_id('voltage-twenty')
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
         self._store_device_settings()
200
         self._store_device_settings()
201
         self._set_save_button_visibility()
201
         self._set_save_button_visibility()
245
         window = self.builder.get_object("pdb-window")
245
         window = self.builder.get_object("pdb-window")
246
         try:
246
         try:
247
             with pdbuddy.Sink(self.serial_port) as pdbs:
247
             with pdbuddy.Sink(self.serial_port) as pdbs:
248
+                pdbs.set_tmpcfg(self.cfg)
248
                 pdbs.write()
249
                 pdbs.write()
249
 
250
 
250
             self._store_device_settings()
251
             self._store_device_settings()
279
                              or giveback.get_active() != self.giveback)
280
                              or giveback.get_active() != self.giveback)
280
 
281
 
281
     def on_voltage_combobox_changed(self, combo):
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
     def on_current_spinbutton_changed(self, spin):
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
     def on_giveback_toggle_toggled(self, toggle):
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
 class Application(Gtk.Application):
301
 class Application(Gtk.Application):

Loading…
Cancel
Save