Browse Source

Partially implement new UI mockup

The GiveBack flag now has a dedicated row with a switch, rather than a
toggle button the row labeled "Flags".  That GiveBack is one of several
flags seems like an implementation detail from the high level of a GUI.

There is now a combo box to select the dimension of the current-setting
value.  Changing this combo box automatically changes the value to keep
the current the same at the present voltage.  The correct item is
selected when a Sink is chosen from the list, and the unit label always
updates to match the dimension.
Clara Hobbs 6 years ago
parent
commit
54b055f762
2 changed files with 79 additions and 44 deletions
  1. 32
    40
      data/pd-buddy-gtk.ui
  2. 47
    4
      pd-buddy-gtk.py

+ 32
- 40
data/pd-buddy-gtk.ui View File

195
                                                 <property name="label" translatable="yes">_Voltage</property>
195
                                                 <property name="label" translatable="yes">_Voltage</property>
196
                                                 <property name="use_underline">True</property>
196
                                                 <property name="use_underline">True</property>
197
                                                 <property name="justify">right</property>
197
                                                 <property name="justify">right</property>
198
+                                                <property name="mnemonic_widget">voltage-spinbutton</property>
198
                                               </object>
199
                                               </object>
199
                                               <packing>
200
                                               <packing>
200
                                                 <property name="left_attach">0</property>
201
                                                 <property name="left_attach">0</property>
207
                                                 <property name="can_focus">False</property>
208
                                                 <property name="can_focus">False</property>
208
                                                 <property name="halign">start</property>
209
                                                 <property name="halign">start</property>
209
                                                 <property name="label" translatable="yes">V</property>
210
                                                 <property name="label" translatable="yes">V</property>
211
+                                                <property name="width_chars">2</property>
210
                                               </object>
212
                                               </object>
211
                                               <packing>
213
                                               <packing>
212
                                                 <property name="left_attach">2</property>
214
                                                 <property name="left_attach">2</property>
217
                                               <object class="GtkSpinButton" id="voltage-spinbutton">
219
                                               <object class="GtkSpinButton" id="voltage-spinbutton">
218
                                                 <property name="visible">True</property>
220
                                                 <property name="visible">True</property>
219
                                                 <property name="can_focus">True</property>
221
                                                 <property name="can_focus">True</property>
220
-                                                <property name="width_chars">5</property>
222
+                                                <property name="width_chars">6</property>
221
                                                 <property name="text" translatable="yes">0.00</property>
223
                                                 <property name="text" translatable="yes">0.00</property>
222
                                                 <property name="xalign">1</property>
224
                                                 <property name="xalign">1</property>
223
                                                 <property name="input_purpose">number</property>
225
                                                 <property name="input_purpose">number</property>
250
                                             <property name="margin_top">6</property>
252
                                             <property name="margin_top">6</property>
251
                                             <property name="margin_bottom">6</property>
253
                                             <property name="margin_bottom">6</property>
252
                                             <property name="column_spacing">12</property>
254
                                             <property name="column_spacing">12</property>
253
-                                            <child>
254
-                                              <object class="GtkLabel">
255
-                                                <property name="visible">True</property>
256
-                                                <property name="can_focus">False</property>
257
-                                                <property name="halign">start</property>
258
-                                                <property name="hexpand">True</property>
259
-                                                <property name="label" translatable="yes">_Current</property>
260
-                                                <property name="use_underline">True</property>
261
-                                                <property name="justify">right</property>
262
-                                                <property name="mnemonic_widget">current-spinbutton</property>
263
-                                              </object>
264
-                                              <packing>
265
-                                                <property name="left_attach">0</property>
266
-                                                <property name="top_attach">0</property>
267
-                                              </packing>
268
-                                            </child>
269
                                             <child>
255
                                             <child>
270
                                               <object class="GtkSpinButton" id="current-spinbutton">
256
                                               <object class="GtkSpinButton" id="current-spinbutton">
271
                                                 <property name="visible">True</property>
257
                                                 <property name="visible">True</property>
272
                                                 <property name="can_focus">True</property>
258
                                                 <property name="can_focus">True</property>
273
                                                 <property name="margin_left">12</property>
259
                                                 <property name="margin_left">12</property>
274
-                                                <property name="width_chars">5</property>
260
+                                                <property name="width_chars">6</property>
275
                                                 <property name="xalign">1</property>
261
                                                 <property name="xalign">1</property>
276
                                                 <property name="input_purpose">number</property>
262
                                                 <property name="input_purpose">number</property>
277
                                                 <property name="adjustment">current-adjustment</property>
263
                                                 <property name="adjustment">current-adjustment</property>
284
                                               </packing>
270
                                               </packing>
285
                                             </child>
271
                                             </child>
286
                                             <child>
272
                                             <child>
287
-                                              <object class="GtkLabel">
273
+                                              <object class="GtkLabel" id="current-unit">
288
                                                 <property name="visible">True</property>
274
                                                 <property name="visible">True</property>
289
                                                 <property name="can_focus">False</property>
275
                                                 <property name="can_focus">False</property>
290
                                                 <property name="halign">start</property>
276
                                                 <property name="halign">start</property>
291
                                                 <property name="label" translatable="yes">A</property>
277
                                                 <property name="label" translatable="yes">A</property>
278
+                                                <property name="width_chars">2</property>
292
                                               </object>
279
                                               </object>
293
                                               <packing>
280
                                               <packing>
294
                                                 <property name="left_attach">2</property>
281
                                                 <property name="left_attach">2</property>
295
                                                 <property name="top_attach">0</property>
282
                                                 <property name="top_attach">0</property>
296
                                               </packing>
283
                                               </packing>
297
                                             </child>
284
                                             </child>
285
+                                            <child>
286
+                                              <object class="GtkComboBoxText" id="current-dimension">
287
+                                                <property name="visible">True</property>
288
+                                                <property name="can_focus">False</property>
289
+                                                <property name="halign">start</property>
290
+                                                <property name="hexpand">True</property>
291
+                                                <property name="active_id">idim-current</property>
292
+                                                <items>
293
+                                                  <item id="idim-current" translatable="yes">Current</item>
294
+                                                  <item id="idim-power" translatable="yes">Power</item>
295
+                                                  <item id="idim-resistance" translatable="yes">Resistance</item>
296
+                                                </items>
297
+                                                <signal name="changed" handler="on_current_dimension_changed" swapped="no"/>
298
+                                              </object>
299
+                                              <packing>
300
+                                                <property name="left_attach">0</property>
301
+                                                <property name="top_attach">0</property>
302
+                                              </packing>
303
+                                            </child>
298
                                           </object>
304
                                           </object>
299
                                         </child>
305
                                         </child>
300
                                       </object>
306
                                       </object>
321
                                                 <property name="can_focus">False</property>
327
                                                 <property name="can_focus">False</property>
322
                                                 <property name="halign">start</property>
328
                                                 <property name="halign">start</property>
323
                                                 <property name="hexpand">True</property>
329
                                                 <property name="hexpand">True</property>
324
-                                                <property name="label" translatable="yes">Flags</property>
330
+                                                <property name="label" translatable="yes">_GiveBack</property>
331
+                                                <property name="use_underline">True</property>
325
                                                 <property name="justify">right</property>
332
                                                 <property name="justify">right</property>
333
+                                                <property name="mnemonic_widget">giveback-switch</property>
326
                                               </object>
334
                                               </object>
327
                                               <packing>
335
                                               <packing>
328
                                                 <property name="left_attach">0</property>
336
                                                 <property name="left_attach">0</property>
330
                                               </packing>
338
                                               </packing>
331
                                             </child>
339
                                             </child>
332
                                             <child>
340
                                             <child>
333
-                                              <object class="GtkButtonBox">
341
+                                              <object class="GtkSwitch" id="giveback-switch">
334
                                                 <property name="visible">True</property>
342
                                                 <property name="visible">True</property>
335
-                                                <property name="can_focus">False</property>
336
-                                                <property name="halign">start</property>
337
-                                                <property name="layout_style">expand</property>
338
-                                                <child>
339
-                                                  <object class="GtkToggleButton" id="giveback-toggle">
340
-                                                    <property name="label" translatable="yes">_GiveBack</property>
341
-                                                    <property name="visible">True</property>
342
-                                                    <property name="can_focus">True</property>
343
-                                                    <property name="receives_default">True</property>
344
-                                                    <property name="use_underline">True</property>
345
-                                                    <signal name="toggled" handler="on_giveback_toggle_toggled" swapped="no"/>
346
-                                                  </object>
347
-                                                  <packing>
348
-                                                    <property name="expand">True</property>
349
-                                                    <property name="fill">True</property>
350
-                                                    <property name="position">0</property>
351
-                                                  </packing>
352
-                                                </child>
343
+                                                <property name="can_focus">True</property>
344
+                                                <signal name="state-set" handler="on_giveback_switch_state_set" swapped="no"/>
353
                                               </object>
345
                                               </object>
354
                                               <packing>
346
                                               <packing>
355
                                                 <property name="left_attach">1</property>
347
                                                 <property name="left_attach">1</property>
468
                                                 <property name="visible">True</property>
460
                                                 <property name="visible">True</property>
469
                                                 <property name="can_focus">False</property>
461
                                                 <property name="can_focus">False</property>
470
                                                 <property name="halign">start</property>
462
                                                 <property name="halign">start</property>
471
-                                                <property name="label" translatable="yes">_Source Capabilities</property>
463
+                                                <property name="label" translatable="yes">Source _Capabilities</property>
472
                                                 <property name="use_underline">True</property>
464
                                                 <property name="use_underline">True</property>
473
                                                 <property name="justify">right</property>
465
                                                 <property name="justify">right</property>
474
                                                 <property name="mnemonic_widget">source-cap-row</property>
466
                                                 <property name="mnemonic_widget">source-cap-row</property>

+ 47
- 4
pd-buddy-gtk.py View File

286
         # Get relevant widgets
286
         # Get relevant widgets
287
         voltage = self.builder.get_object("voltage-adjustment")
287
         voltage = self.builder.get_object("voltage-adjustment")
288
         current = self.builder.get_object("current-adjustment")
288
         current = self.builder.get_object("current-adjustment")
289
-        giveback = self.builder.get_object("giveback-toggle")
289
+        current_dim = self.builder.get_object("current-dimension")
290
+        giveback = self.builder.get_object("giveback-switch")
290
         pd_frame = self.builder.get_object("power-delivery-frame")
291
         pd_frame = self.builder.get_object("power-delivery-frame")
291
         output = self.builder.get_object("output-switch")
292
         output = self.builder.get_object("output-switch")
292
         cap_row = self.builder.get_object("source-cap-row")
293
         cap_row = self.builder.get_object("source-cap-row")
317
         self._store_device_settings()
318
         self._store_device_settings()
318
         self._set_save_button_visibility()
319
         self._set_save_button_visibility()
319
 
320
 
320
-        # Set giveback button state
321
+        # Set giveback switch state
321
         giveback.set_active(bool(self.cfg.flags & pdbuddy.SinkFlags.GIVEBACK))
322
         giveback.set_active(bool(self.cfg.flags & pdbuddy.SinkFlags.GIVEBACK))
322
 
323
 
323
         # Get voltage and current from device and load them into the GUI
324
         # Get voltage and current from device and load them into the GUI
324
         voltage.set_value(self.cfg.v/1000)
325
         voltage.set_value(self.cfg.v/1000)
325
 
326
 
327
+        if self.cfg.idim == pdbuddy.SinkDimension.CURRENT:
328
+            current_dim.set_active_id("idim-current")
329
+        elif self.cfg.idim == pdbuddy.SinkDimension.POWER:
330
+            current_dim.set_active_id("idim-power")
331
+        elif self.cfg.idim == pdbuddy.SinkDimension.RESISTANCE:
332
+            current_dim.set_active_id("idim-resistance")
326
         current.set_value(self.cfg.i/1000)
333
         current.set_value(self.cfg.i/1000)
327
 
334
 
328
         # Set PD frame visibility and output switch state
335
         # Set PD frame visibility and output switch state
425
 
432
 
426
         self._set_save_button_visibility()
433
         self._set_save_button_visibility()
427
 
434
 
435
+    def on_current_dimension_changed(self, cb):
436
+        item = cb.get_active_id()
437
+        value = self.builder.get_object("current-adjustment")
438
+        unit = self.builder.get_object("current-unit")
439
+
440
+        if item == "idim-current":
441
+            if self.cfg.idim == pdbuddy.SinkDimension.POWER:
442
+                self.cfg = self.cfg._replace(i=self.cfg.i/self.cfg.v*1000.0)
443
+            elif self.cfg.idim == pdbuddy.SinkDimension.RESISTANCE:
444
+                self.cfg = self.cfg._replace(i=self.cfg.v/self.cfg.i*1000.0)
445
+            value.configure(self.cfg.i / 1000.0, 0, 5, 0.1, 1, 0)
446
+            idim = pdbuddy.SinkDimension.CURRENT
447
+            unit.set_text("A")
448
+        if item == "idim-power":
449
+            if self.cfg.idim == pdbuddy.SinkDimension.CURRENT:
450
+                self.cfg = self.cfg._replace(i=self.cfg.i*self.cfg.v/1000.0)
451
+            elif self.cfg.idim == pdbuddy.SinkDimension.RESISTANCE:
452
+                self.cfg = self.cfg._replace(
453
+                        i=self.cfg.v*self.cfg.v/self.cfg.i)
454
+            idim = pdbuddy.SinkDimension.POWER
455
+            value.configure(self.cfg.i / 1000.0, 0, 100, 1, 10, 0)
456
+            unit.set_text("W")
457
+        if item == "idim-resistance":
458
+            if self.cfg.idim == pdbuddy.SinkDimension.CURRENT:
459
+                self.cfg = self.cfg._replace(i=self.cfg.v/self.cfg.i*1000.0)
460
+            elif self.cfg.idim == pdbuddy.SinkDimension.POWER:
461
+                self.cfg = self.cfg._replace(
462
+                        i=self.cfg.v*self.cfg.v/self.cfg.i)
463
+            idim = pdbuddy.SinkDimension.RESISTANCE
464
+            value.configure(self.cfg.i / 1000.0, 0, 655.35, 1, 10, 0)
465
+            unit.set_text("\u03a9")
466
+
467
+        self.cfg = self.cfg._replace(idim=idim)
468
+
469
+        self._set_save_button_visibility()
470
+
428
     def on_current_adjustment_value_changed(self, adj):
471
     def on_current_adjustment_value_changed(self, adj):
429
         self.cfg = self.cfg._replace(i=int(adj.get_value() * 1000))
472
         self.cfg = self.cfg._replace(i=int(adj.get_value() * 1000))
430
 
473
 
431
         self._set_save_button_visibility()
474
         self._set_save_button_visibility()
432
 
475
 
433
-    def on_giveback_toggle_toggled(self, toggle):
434
-        if toggle.get_active():
476
+    def on_giveback_switch_state_set(self, switch, state):
477
+        if state:
435
             self.cfg = self.cfg._replace(flags=self.cfg.flags|pdbuddy.SinkFlags.GIVEBACK)
478
             self.cfg = self.cfg._replace(flags=self.cfg.flags|pdbuddy.SinkFlags.GIVEBACK)
436
         else:
479
         else:
437
             self.cfg = self.cfg._replace(flags=self.cfg.flags&~pdbuddy.SinkFlags.GIVEBACK)
480
             self.cfg = self.cfg._replace(flags=self.cfg.flags&~pdbuddy.SinkFlags.GIVEBACK)

Loading…
Cancel
Save