Procházet zdrojové kódy

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 před 6 roky
rodič
revize
54b055f762
2 změnil soubory, kde provedl 79 přidání a 44 odebrání
  1. 32
    40
      data/pd-buddy-gtk.ui
  2. 47
    4
      pd-buddy-gtk.py

+ 32
- 40
data/pd-buddy-gtk.ui Zobrazit soubor

@@ -195,6 +195,7 @@
195 195
                                                 <property name="label" translatable="yes">_Voltage</property>
196 196
                                                 <property name="use_underline">True</property>
197 197
                                                 <property name="justify">right</property>
198
+                                                <property name="mnemonic_widget">voltage-spinbutton</property>
198 199
                                               </object>
199 200
                                               <packing>
200 201
                                                 <property name="left_attach">0</property>
@@ -207,6 +208,7 @@
207 208
                                                 <property name="can_focus">False</property>
208 209
                                                 <property name="halign">start</property>
209 210
                                                 <property name="label" translatable="yes">V</property>
211
+                                                <property name="width_chars">2</property>
210 212
                                               </object>
211 213
                                               <packing>
212 214
                                                 <property name="left_attach">2</property>
@@ -217,7 +219,7 @@
217 219
                                               <object class="GtkSpinButton" id="voltage-spinbutton">
218 220
                                                 <property name="visible">True</property>
219 221
                                                 <property name="can_focus">True</property>
220
-                                                <property name="width_chars">5</property>
222
+                                                <property name="width_chars">6</property>
221 223
                                                 <property name="text" translatable="yes">0.00</property>
222 224
                                                 <property name="xalign">1</property>
223 225
                                                 <property name="input_purpose">number</property>
@@ -250,28 +252,12 @@
250 252
                                             <property name="margin_top">6</property>
251 253
                                             <property name="margin_bottom">6</property>
252 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 255
                                             <child>
270 256
                                               <object class="GtkSpinButton" id="current-spinbutton">
271 257
                                                 <property name="visible">True</property>
272 258
                                                 <property name="can_focus">True</property>
273 259
                                                 <property name="margin_left">12</property>
274
-                                                <property name="width_chars">5</property>
260
+                                                <property name="width_chars">6</property>
275 261
                                                 <property name="xalign">1</property>
276 262
                                                 <property name="input_purpose">number</property>
277 263
                                                 <property name="adjustment">current-adjustment</property>
@@ -284,17 +270,37 @@
284 270
                                               </packing>
285 271
                                             </child>
286 272
                                             <child>
287
-                                              <object class="GtkLabel">
273
+                                              <object class="GtkLabel" id="current-unit">
288 274
                                                 <property name="visible">True</property>
289 275
                                                 <property name="can_focus">False</property>
290 276
                                                 <property name="halign">start</property>
291 277
                                                 <property name="label" translatable="yes">A</property>
278
+                                                <property name="width_chars">2</property>
292 279
                                               </object>
293 280
                                               <packing>
294 281
                                                 <property name="left_attach">2</property>
295 282
                                                 <property name="top_attach">0</property>
296 283
                                               </packing>
297 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 304
                                           </object>
299 305
                                         </child>
300 306
                                       </object>
@@ -321,8 +327,10 @@
321 327
                                                 <property name="can_focus">False</property>
322 328
                                                 <property name="halign">start</property>
323 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 332
                                                 <property name="justify">right</property>
333
+                                                <property name="mnemonic_widget">giveback-switch</property>
326 334
                                               </object>
327 335
                                               <packing>
328 336
                                                 <property name="left_attach">0</property>
@@ -330,26 +338,10 @@
330 338
                                               </packing>
331 339
                                             </child>
332 340
                                             <child>
333
-                                              <object class="GtkButtonBox">
341
+                                              <object class="GtkSwitch" id="giveback-switch">
334 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 345
                                               </object>
354 346
                                               <packing>
355 347
                                                 <property name="left_attach">1</property>
@@ -468,7 +460,7 @@
468 460
                                                 <property name="visible">True</property>
469 461
                                                 <property name="can_focus">False</property>
470 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 464
                                                 <property name="use_underline">True</property>
473 465
                                                 <property name="justify">right</property>
474 466
                                                 <property name="mnemonic_widget">source-cap-row</property>

+ 47
- 4
pd-buddy-gtk.py Zobrazit soubor

@@ -286,7 +286,8 @@ class Handler:
286 286
         # Get relevant widgets
287 287
         voltage = self.builder.get_object("voltage-adjustment")
288 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 291
         pd_frame = self.builder.get_object("power-delivery-frame")
291 292
         output = self.builder.get_object("output-switch")
292 293
         cap_row = self.builder.get_object("source-cap-row")
@@ -317,12 +318,18 @@ class Handler:
317 318
         self._store_device_settings()
318 319
         self._set_save_button_visibility()
319 320
 
320
-        # Set giveback button state
321
+        # Set giveback switch state
321 322
         giveback.set_active(bool(self.cfg.flags & pdbuddy.SinkFlags.GIVEBACK))
322 323
 
323 324
         # Get voltage and current from device and load them into the GUI
324 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 333
         current.set_value(self.cfg.i/1000)
327 334
 
328 335
         # Set PD frame visibility and output switch state
@@ -425,13 +432,49 @@ class Handler:
425 432
 
426 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 471
     def on_current_adjustment_value_changed(self, adj):
429 472
         self.cfg = self.cfg._replace(i=int(adj.get_value() * 1000))
430 473
 
431 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 478
             self.cfg = self.cfg._replace(flags=self.cfg.flags|pdbuddy.SinkFlags.GIVEBACK)
436 479
         else:
437 480
             self.cfg = self.cfg._replace(flags=self.cfg.flags&~pdbuddy.SinkFlags.GIVEBACK)

Loading…
Zrušit
Uložit