Browse Source

Support typec_virtual PDOs

When there's a single typec_virtual PDO returned by the get_source_cap
command, the GUI now handles it wonderfully.  It shows the available
power and the advertised Type-C Current just like it's the regular info
from Power Delivery.  There's no voltage listed in a Type-C Current row
in the Source Capabilities dialog, since it's just a maximum current,
with no voltage information.
Clara Hobbs 6 years ago
parent
commit
efcf7047bc
1 changed files with 36 additions and 19 deletions
  1. 36
    19
      pd-buddy-gtk.py

+ 36
- 19
pd-buddy-gtk.py View File

@@ -194,12 +194,19 @@ class PDOListRow(Gtk.ListBoxRow):
194 194
         box.set_margin_bottom(6)
195 195
 
196 196
         # Type label
197
-        type_label = Gtk.Label(model.pdo.pdo_type.capitalize())
197
+        if model.pdo.pdo_type == "fixed":
198
+            type_text = "Fixed"
199
+        elif model.pdo.pdo_type == "unknown":
200
+            type_text = "Unknown"
201
+        elif model.pdo.pdo_type == "typec_virtual":
202
+            type_text = "Type-C Current"
203
+        type_label = Gtk.Label(type_text)
198 204
         type_label.set_halign(Gtk.Align.START)
199 205
         box.pack_start(type_label, True, True, 0)
200 206
 
201 207
         # Voltage label
202
-        if model.pdo.pdo_type != "unknown":
208
+        if (model.pdo.pdo_type != "unknown"
209
+                and model.pdo.pdo_type != "typec_virtual"):
203 210
             voltage_label = Gtk.Label("{:g} V".format(model.pdo.v / 1000.0))
204 211
             voltage_label.set_halign(Gtk.Align.END)
205 212
             box.pack_start(voltage_label, True, True, 0)
@@ -214,12 +221,17 @@ class PDOListRow(Gtk.ListBoxRow):
214 221
             right_box.pack_end(current_label, True, False, 0)
215 222
 
216 223
             # Over-current image(?)
217
-            if model.pdo.peak_i > 0:
218
-                oc_image = Gtk.Image.new_from_icon_name(
219
-                        "dialog-information-symbolic", Gtk.IconSize.BUTTON)
220
-                oc_image.set_tooltip_markup(
221
-                        PDOListRow.oc_tooltips[model.pdo.peak_i])
222
-                right_box.pack_end(oc_image, True, False, 0)
224
+            try:
225
+                if model.pdo.peak_i > 0:
226
+                    oc_image = Gtk.Image.new_from_icon_name(
227
+                            "dialog-information-symbolic", Gtk.IconSize.BUTTON)
228
+                    oc_image.set_tooltip_markup(
229
+                            PDOListRow.oc_tooltips[model.pdo.peak_i])
230
+                    right_box.pack_end(oc_image, True, False, 0)
231
+            except AttributeError:
232
+                # If this is a typec_virtual PDO, there's no peak_i attribute.
233
+                # Not a problem, so just ignore the error.
234
+                pass
223 235
         else:
224 236
             # PDO value
225 237
             text_label = Gtk.Label()
@@ -465,17 +477,22 @@ class Handler:
465 477
         d_info = dialog_builder.get_object("info-label")
466 478
         # Make the string to display
467 479
         info_str = ""
468
-        if caps[0].dual_role_pwr:
469
-            info_str += "Dual-Role Power\n"
470
-        if caps[0].usb_suspend:
471
-            info_str += "USB Suspend Supported\n"
472
-        if caps[0].unconstrained_pwr:
473
-            info_str += "Unconstrained Power\n"
474
-        if caps[0].usb_comms:
475
-            info_str += "USB Communications Capable\n"
476
-        if caps[0].dual_role_data:
477
-            info_str += "Dual-Role Data\n"
478
-        info_str = info_str[:-1]
480
+        try:
481
+            if caps[0].dual_role_pwr:
482
+                info_str += "Dual-Role Power\n"
483
+            if caps[0].usb_suspend:
484
+                info_str += "USB Suspend Supported\n"
485
+            if caps[0].unconstrained_pwr:
486
+                info_str += "Unconstrained Power\n"
487
+            if caps[0].usb_comms:
488
+                info_str += "USB Communications Capable\n"
489
+            if caps[0].dual_role_data:
490
+                info_str += "Dual-Role Data\n"
491
+            info_str = info_str[:-1]
492
+        except AttributeError:
493
+            # If we have a typec_virtual PDO, there will be AttributeErrors
494
+            # from the above.  Not a problem, so just pass.
495
+            pass
479 496
         # Set the text and label visibility
480 497
         d_info.set_text(info_str)
481 498
         d_info_header.set_visible(info_str)

Loading…
Cancel
Save