Browse Source

Implement the Power Rule violation icon

Now when there's a violation of the USB PD power rules, an icon appears
to alert the user to their charger's noncompliance.  The icon has a
tooltip explaining its meaning.
Clara Hobbs 7 years ago
parent
commit
21b6d5a544
2 changed files with 27 additions and 8 deletions
  1. 19
    6
      data/pd-buddy-gtk.ui
  2. 8
    2
      pd-buddy-gtk.py

+ 19
- 6
data/pd-buddy-gtk.ui View File

@@ -455,7 +455,6 @@
455 455
                                                 <property name="visible">True</property>
456 456
                                                 <property name="can_focus">False</property>
457 457
                                                 <property name="halign">start</property>
458
-                                                <property name="hexpand">True</property>
459 458
                                                 <property name="label" translatable="yes">Source Capabilities</property>
460 459
                                                 <property name="justify">right</property>
461 460
                                               </object>
@@ -464,28 +463,42 @@
464 463
                                                 <property name="top_attach">0</property>
465 464
                                               </packing>
466 465
                                             </child>
466
+                                            <child>
467
+                                              <object class="GtkImage">
468
+                                                <property name="visible">True</property>
469
+                                                <property name="can_focus">False</property>
470
+                                                <property name="icon_name">go-next-symbolic</property>
471
+                                              </object>
472
+                                              <packing>
473
+                                                <property name="left_attach">3</property>
474
+                                                <property name="top_attach">0</property>
475
+                                              </packing>
476
+                                            </child>
467 477
                                             <child>
468 478
                                               <object class="GtkLabel" id="short-source-cap-label">
469 479
                                                 <property name="visible">True</property>
470 480
                                                 <property name="can_focus">False</property>
481
+                                                <property name="halign">end</property>
482
+                                                <property name="hexpand">True</property>
471 483
                                                 <property name="label" translatable="yes">label</property>
472 484
                                                 <style>
473 485
                                                   <class name="dim-label"/>
474 486
                                                 </style>
475 487
                                               </object>
476 488
                                               <packing>
477
-                                                <property name="left_attach">1</property>
489
+                                                <property name="left_attach">2</property>
478 490
                                                 <property name="top_attach">0</property>
479 491
                                               </packing>
480 492
                                             </child>
481 493
                                             <child>
482
-                                              <object class="GtkImage">
483
-                                                <property name="visible">True</property>
494
+                                              <object class="GtkImage" id="source-cap-warning">
484 495
                                                 <property name="can_focus">False</property>
485
-                                                <property name="icon_name">go-next-symbolic</property>
496
+                                                <property name="tooltip_text" translatable="yes">Source violates the USB PD Power Rules</property>
497
+                                                <property name="halign">start</property>
498
+                                                <property name="icon_name">dialog-warning-symbolic</property>
486 499
                                               </object>
487 500
                                               <packing>
488
-                                                <property name="left_attach">2</property>
501
+                                                <property name="left_attach">1</property>
489 502
                                                 <property name="top_attach">0</property>
490 503
                                               </packing>
491 504
                                             </child>

+ 8
- 2
pd-buddy-gtk.py View File

@@ -181,6 +181,7 @@ class Handler:
181 181
         giveback = self.builder.get_object("giveback-toggle")
182 182
         pd_frame = self.builder.get_object("power-delivery-frame")
183 183
         output = self.builder.get_object("output-switch")
184
+        cap_warning = self.builder.get_object("source-cap-warning")
184 185
         cap_label = self.builder.get_object("short-source-cap-label")
185 186
 
186 187
         self.serial_port = serport
@@ -231,10 +232,15 @@ class Handler:
231 232
         else:
232 233
             pd_frame.set_visible(True)
233 234
 
234
-            # Update the text in the capability label
235
-            # TODO: do this repeatedly
235
+            # TODO: do these next things repeatedly
236
+            # Get the Source_Capabilities
236 237
             with pdbuddy.Sink(self.serial_port) as pdbs:
237 238
                 caps = pdbs.get_source_cap()
239
+
240
+            # Update the warning icon
241
+            cap_warning.set_visible(not pdbuddy.follows_power_rules(caps))
242
+
243
+            # Update the text in the capability label
238 244
             cap_label.set_text('{:g} W'.format(pdbuddy.calculate_pdp(caps)))
239 245
 
240 246
         # Show the Sink page

Loading…
Cancel
Save