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
                                                 <property name="visible">True</property>
455
                                                 <property name="visible">True</property>
456
                                                 <property name="can_focus">False</property>
456
                                                 <property name="can_focus">False</property>
457
                                                 <property name="halign">start</property>
457
                                                 <property name="halign">start</property>
458
-                                                <property name="hexpand">True</property>
459
                                                 <property name="label" translatable="yes">Source Capabilities</property>
458
                                                 <property name="label" translatable="yes">Source Capabilities</property>
460
                                                 <property name="justify">right</property>
459
                                                 <property name="justify">right</property>
461
                                               </object>
460
                                               </object>
464
                                                 <property name="top_attach">0</property>
463
                                                 <property name="top_attach">0</property>
465
                                               </packing>
464
                                               </packing>
466
                                             </child>
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
                                             <child>
477
                                             <child>
468
                                               <object class="GtkLabel" id="short-source-cap-label">
478
                                               <object class="GtkLabel" id="short-source-cap-label">
469
                                                 <property name="visible">True</property>
479
                                                 <property name="visible">True</property>
470
                                                 <property name="can_focus">False</property>
480
                                                 <property name="can_focus">False</property>
481
+                                                <property name="halign">end</property>
482
+                                                <property name="hexpand">True</property>
471
                                                 <property name="label" translatable="yes">label</property>
483
                                                 <property name="label" translatable="yes">label</property>
472
                                                 <style>
484
                                                 <style>
473
                                                   <class name="dim-label"/>
485
                                                   <class name="dim-label"/>
474
                                                 </style>
486
                                                 </style>
475
                                               </object>
487
                                               </object>
476
                                               <packing>
488
                                               <packing>
477
-                                                <property name="left_attach">1</property>
489
+                                                <property name="left_attach">2</property>
478
                                                 <property name="top_attach">0</property>
490
                                                 <property name="top_attach">0</property>
479
                                               </packing>
491
                                               </packing>
480
                                             </child>
492
                                             </child>
481
                                             <child>
493
                                             <child>
482
-                                              <object class="GtkImage">
483
-                                                <property name="visible">True</property>
494
+                                              <object class="GtkImage" id="source-cap-warning">
484
                                                 <property name="can_focus">False</property>
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
                                               </object>
499
                                               </object>
487
                                               <packing>
500
                                               <packing>
488
-                                                <property name="left_attach">2</property>
501
+                                                <property name="left_attach">1</property>
489
                                                 <property name="top_attach">0</property>
502
                                                 <property name="top_attach">0</property>
490
                                               </packing>
503
                                               </packing>
491
                                             </child>
504
                                             </child>

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

181
         giveback = self.builder.get_object("giveback-toggle")
181
         giveback = self.builder.get_object("giveback-toggle")
182
         pd_frame = self.builder.get_object("power-delivery-frame")
182
         pd_frame = self.builder.get_object("power-delivery-frame")
183
         output = self.builder.get_object("output-switch")
183
         output = self.builder.get_object("output-switch")
184
+        cap_warning = self.builder.get_object("source-cap-warning")
184
         cap_label = self.builder.get_object("short-source-cap-label")
185
         cap_label = self.builder.get_object("short-source-cap-label")
185
 
186
 
186
         self.serial_port = serport
187
         self.serial_port = serport
231
         else:
232
         else:
232
             pd_frame.set_visible(True)
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
             with pdbuddy.Sink(self.serial_port) as pdbs:
237
             with pdbuddy.Sink(self.serial_port) as pdbs:
237
                 caps = pdbs.get_source_cap()
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
             cap_label.set_text('{:g} W'.format(pdbuddy.calculate_pdp(caps)))
244
             cap_label.set_text('{:g} W'.format(pdbuddy.calculate_pdp(caps)))
239
 
245
 
240
         # Show the Sink page
246
         # Show the Sink page

Loading…
Cancel
Save