ソースを参照

Add interface for setting voltage range

There's a switch to toggle whether the range is enabled at all, two
spinbuttons for the range itself which automatically maintain their
ordering, and a button to toggle between high and low voltages
preferred.  What more could a gal ask for?
Clara Hobbs 6年前
コミット
dac9d5ddff
2個のファイルの変更226行の追加5行の削除
  1. 154
    1
      data/pd-buddy-gtk.ui
  2. 72
    4
      pd-buddy-gtk.py

+ 154
- 1
data/pd-buddy-gtk.ui ファイルの表示

@@ -13,6 +13,23 @@
13 13
     <property name="page_increment">1</property>
14 14
     <signal name="value-changed" handler="on_current_adjustment_value_changed" swapped="no"/>
15 15
   </object>
16
+  <object class="GtkImage" id="order-image">
17
+    <property name="visible">True</property>
18
+    <property name="can_focus">False</property>
19
+    <property name="icon_name">go-next-symbolic</property>
20
+  </object>
21
+  <object class="GtkAdjustment" id="vmax-adjustment">
22
+    <property name="upper">21</property>
23
+    <property name="step_increment">0.10000000000000001</property>
24
+    <property name="page_increment">1</property>
25
+    <signal name="value-changed" handler="on_vmax_adjustment_value_changed" swapped="no"/>
26
+  </object>
27
+  <object class="GtkAdjustment" id="vmin-adjustment">
28
+    <property name="upper">21</property>
29
+    <property name="step_increment">0.10000000000000001</property>
30
+    <property name="page_increment">1</property>
31
+    <signal name="value-changed" handler="on_vmin_adjustment_value_changed" swapped="no"/>
32
+  </object>
16 33
   <object class="GtkAdjustment" id="voltage-adjustment">
17 34
     <property name="upper">21</property>
18 35
     <property name="step_increment">0.10000000000000001</property>
@@ -165,7 +182,7 @@
165 182
                                 <property name="label_xalign">0</property>
166 183
                                 <child>
167 184
                                   <object class="GtkListBox" id="sink-config-list">
168
-                                    <property name="width_request">342</property>
185
+                                    <property name="width_request">360</property>
169 186
                                     <property name="visible">True</property>
170 187
                                     <property name="can_focus">False</property>
171 188
                                     <property name="selection_mode">none</property>
@@ -236,6 +253,142 @@
236 253
                                         </child>
237 254
                                       </object>
238 255
                                     </child>
256
+                                    <child>
257
+                                      <object class="GtkListBoxRow">
258
+                                        <property name="width_request">100</property>
259
+                                        <property name="visible">True</property>
260
+                                        <property name="can_focus">True</property>
261
+                                        <property name="activatable">False</property>
262
+                                        <child>
263
+                                          <object class="GtkGrid">
264
+                                            <property name="visible">True</property>
265
+                                            <property name="can_focus">False</property>
266
+                                            <property name="margin_left">12</property>
267
+                                            <property name="margin_right">6</property>
268
+                                            <property name="margin_top">6</property>
269
+                                            <property name="margin_bottom">6</property>
270
+                                            <property name="column_spacing">12</property>
271
+                                            <child>
272
+                                              <object class="GtkLabel">
273
+                                                <property name="visible">True</property>
274
+                                                <property name="can_focus">False</property>
275
+                                                <property name="halign">start</property>
276
+                                                <property name="hexpand">True</property>
277
+                                                <property name="label" translatable="yes">Voltage _Range</property>
278
+                                                <property name="use_underline">True</property>
279
+                                                <property name="mnemonic_widget">vrange-switch</property>
280
+                                              </object>
281
+                                              <packing>
282
+                                                <property name="left_attach">0</property>
283
+                                                <property name="top_attach">0</property>
284
+                                              </packing>
285
+                                            </child>
286
+                                            <child>
287
+                                              <object class="GtkSwitch" id="vrange-switch">
288
+                                                <property name="visible">True</property>
289
+                                                <property name="can_focus">True</property>
290
+                                                <property name="halign">end</property>
291
+                                                <property name="active">True</property>
292
+                                                <signal name="state-set" handler="on_vrange_switch_state_set" swapped="no"/>
293
+                                              </object>
294
+                                              <packing>
295
+                                                <property name="left_attach">1</property>
296
+                                                <property name="top_attach">0</property>
297
+                                              </packing>
298
+                                            </child>
299
+                                          </object>
300
+                                        </child>
301
+                                      </object>
302
+                                    </child>
303
+                                    <child>
304
+                                      <object class="GtkListBoxRow" id="vrange-row">
305
+                                        <property name="name">S</property>
306
+                                        <property name="width_request">100</property>
307
+                                        <property name="visible">True</property>
308
+                                        <property name="can_focus">True</property>
309
+                                        <property name="activatable">False</property>
310
+                                        <child>
311
+                                          <object class="GtkGrid">
312
+                                            <property name="visible">True</property>
313
+                                            <property name="can_focus">False</property>
314
+                                            <property name="halign">end</property>
315
+                                            <property name="margin_left">12</property>
316
+                                            <property name="margin_right">6</property>
317
+                                            <property name="margin_bottom">6</property>
318
+                                            <property name="column_spacing">12</property>
319
+                                            <child>
320
+                                              <object class="GtkLabel">
321
+                                                <property name="visible">True</property>
322
+                                                <property name="can_focus">False</property>
323
+                                                <property name="label" translatable="yes">V</property>
324
+                                                <property name="width_chars">2</property>
325
+                                              </object>
326
+                                              <packing>
327
+                                                <property name="left_attach">1</property>
328
+                                                <property name="top_attach">0</property>
329
+                                              </packing>
330
+                                            </child>
331
+                                            <child>
332
+                                              <object class="GtkBox">
333
+                                                <property name="visible">True</property>
334
+                                                <property name="can_focus">False</property>
335
+                                                <child>
336
+                                                  <object class="GtkSpinButton" id="vmin-spinbutton">
337
+                                                    <property name="visible">True</property>
338
+                                                    <property name="can_focus">True</property>
339
+                                                    <property name="width_chars">6</property>
340
+                                                    <property name="input_purpose">number</property>
341
+                                                    <property name="adjustment">vmin-adjustment</property>
342
+                                                    <property name="digits">2</property>
343
+                                                  </object>
344
+                                                  <packing>
345
+                                                    <property name="expand">False</property>
346
+                                                    <property name="fill">True</property>
347
+                                                    <property name="position">0</property>
348
+                                                  </packing>
349
+                                                </child>
350
+                                                <child>
351
+                                                  <object class="GtkButton" id="hv-preferred-button">
352
+                                                    <property name="visible">True</property>
353
+                                                    <property name="can_focus">True</property>
354
+                                                    <property name="receives_default">True</property>
355
+                                                    <property name="image">order-image</property>
356
+                                                    <signal name="clicked" handler="on_hv_preferred_button_clicked" swapped="no"/>
357
+                                                  </object>
358
+                                                  <packing>
359
+                                                    <property name="expand">False</property>
360
+                                                    <property name="fill">True</property>
361
+                                                    <property name="position">1</property>
362
+                                                  </packing>
363
+                                                </child>
364
+                                                <child>
365
+                                                  <object class="GtkSpinButton" id="vmax-spinbutton">
366
+                                                    <property name="visible">True</property>
367
+                                                    <property name="can_focus">True</property>
368
+                                                    <property name="width_chars">6</property>
369
+                                                    <property name="input_purpose">number</property>
370
+                                                    <property name="adjustment">vmax-adjustment</property>
371
+                                                    <property name="digits">2</property>
372
+                                                  </object>
373
+                                                  <packing>
374
+                                                    <property name="expand">False</property>
375
+                                                    <property name="fill">True</property>
376
+                                                    <property name="position">2</property>
377
+                                                  </packing>
378
+                                                </child>
379
+                                                <style>
380
+                                                  <class name="linked"/>
381
+                                                </style>
382
+                                              </object>
383
+                                              <packing>
384
+                                                <property name="left_attach">0</property>
385
+                                                <property name="top_attach">0</property>
386
+                                              </packing>
387
+                                            </child>
388
+                                          </object>
389
+                                        </child>
390
+                                      </object>
391
+                                    </child>
239 392
                                     <child>
240 393
                                       <object class="GtkListBoxRow">
241 394
                                         <property name="width_request">100</property>

+ 72
- 4
pd-buddy-gtk.py ファイルの表示

@@ -54,7 +54,9 @@ class SelectListStore(Gio.ListStore):
54 54
 
55 55
 def list_box_update_header_func(row, before, data):
56 56
     """Add a separator header to all rows but the first one"""
57
-    if before is None:
57
+    name = Gtk.Buildable.get_name(row)
58
+    # No header over the vrange-row to make it look like part of the row above
59
+    if before is None or name == "vrange-row":
58 60
         row.set_header(None)
59 61
         return
60 62
 
@@ -255,9 +257,7 @@ class Handler:
255 257
     def __init__(self, builder):
256 258
         self.builder = builder
257 259
         self.serial_port = None
258
-        self.voltage = None
259
-        self.current = None
260
-        self.giveback = None
260
+        self.vrange_set = False
261 261
         self.selectlist = None
262 262
 
263 263
     def on_pdb_window_realize(self, *args):
@@ -285,6 +285,9 @@ class Handler:
285 285
     def on_select_list_row_activated(self, selectlist, serport):
286 286
         # Get relevant widgets
287 287
         voltage = self.builder.get_object("voltage-adjustment")
288
+        vr_switch = self.builder.get_object("vrange-switch")
289
+        vmin_adj = self.builder.get_object("vmin-adjustment")
290
+        vmax_adj = self.builder.get_object("vmax-adjustment")
288 291
         current = self.builder.get_object("current-adjustment")
289 292
         current_dim = self.builder.get_object("current-dimension")
290 293
         giveback = self.builder.get_object("giveback-switch")
@@ -311,6 +314,10 @@ class Handler:
311 314
                             i=0, idim=pdbuddy.SinkDimension.CURRENT)
312 315
                 else:
313 316
                     self.cfg = pdbs.get_tmpcfg()
317
+                    if self.cfg.vmin is None:
318
+                        self.cfg = self.cfg._replace(vmin=0)
319
+                    if self.cfg.vmax is None:
320
+                        self.cfg = self.cfg._replace(vmax=0)
314 321
         except OSError as e:
315 322
             comms_error_dialog(window, e)
316 323
             return
@@ -324,6 +331,13 @@ class Handler:
324 331
         # Get voltage and current from device and load them into the GUI
325 332
         voltage.set_value(self.cfg.v/1000)
326 333
 
334
+        vr_switch.set_active(self.cfg.vmin != 0 or self.cfg.vmax != 0)
335
+        self.vrange_set = True
336
+        vmin_adj.set_value(self.cfg.vmin/1000)
337
+        self._set_hv_pref_image()
338
+        vmax_adj.set_value(self.cfg.vmax/1000)
339
+        self.vrange_set = False
340
+
327 341
         if self.cfg.idim == pdbuddy.SinkDimension.CURRENT:
328 342
             current_dim.set_active_id("idim-current")
329 343
         elif self.cfg.idim == pdbuddy.SinkDimension.POWER:
@@ -432,6 +446,60 @@ class Handler:
432 446
 
433 447
         self._set_save_button_visibility()
434 448
 
449
+    def on_vrange_switch_state_set(self, switch, state):
450
+        row = self.builder.get_object("vrange-row")
451
+        vmin_adj = self.builder.get_object("vmin-adjustment")
452
+        vmax_adj = self.builder.get_object("vmax-adjustment")
453
+
454
+        row.set_visible(state)
455
+        if not state:
456
+            self.cfg = self.cfg._replace(vmin=0, vmax=0)
457
+        self.vrange_set = True
458
+        vmin_adj.set_value(self.cfg.vmin/1000)
459
+        vmax_adj.set_value(self.cfg.vmax/1000)
460
+        self.vrange_set = False
461
+
462
+        self._set_save_button_visibility()
463
+
464
+    def on_vmin_adjustment_value_changed(self, adj):
465
+        if not self.vrange_set:
466
+            self.cfg = self.cfg._replace(vmin=int(adj.get_value() * 1000))
467
+
468
+            # Update vmax if necessary
469
+            vmax_adj = self.builder.get_object("vmax-adjustment")
470
+            if adj.get_value() > vmax_adj.get_value():
471
+                vmax_adj.set_value(adj.get_value())
472
+
473
+            self._set_save_button_visibility()
474
+
475
+    def on_vmax_adjustment_value_changed(self, adj):
476
+        if not self.vrange_set:
477
+            self.cfg = self.cfg._replace(vmax=int(adj.get_value() * 1000))
478
+
479
+            # Update vmin if necessary
480
+            vmin_adj = self.builder.get_object("vmin-adjustment")
481
+            if adj.get_value() < vmin_adj.get_value():
482
+                vmin_adj.set_value(adj.get_value())
483
+
484
+            self._set_save_button_visibility()
485
+
486
+    def on_hv_preferred_button_clicked(self, button):
487
+        self.cfg = self.cfg._replace(
488
+                flags=self.cfg.flags^pdbuddy.SinkFlags.HV_PREFERRED)
489
+
490
+        self._set_hv_pref_image()
491
+        self._set_save_button_visibility()
492
+
493
+    def _set_hv_pref_image(self):
494
+        hv_pref = self.builder.get_object("hv-preferred-button")
495
+        image = self.builder.get_object("order-image")
496
+
497
+        if self.cfg.flags & pdbuddy.SinkFlags.HV_PREFERRED:
498
+            image.set_from_icon_name("go-previous-symbolic",
499
+                    Gtk.IconSize.BUTTON)
500
+        else:
501
+            image.set_from_icon_name("go-next-symbolic", Gtk.IconSize.BUTTON)
502
+
435 503
     def on_current_dimension_changed(self, cb):
436 504
         item = cb.get_active_id()
437 505
         value = self.builder.get_object("current-adjustment")

読み込み中…
キャンセル
保存