Browse Source

Partially fill the Source Capabilities dialog

Now it has the real PD Power and Information.  The list has separators
too.
Clara Hobbs 6 years ago
parent
commit
572c140a74
2 changed files with 49 additions and 26 deletions
  1. 8
    6
      data/src-cap-dialog.ui
  2. 41
    20
      pd-buddy-gtk.py

+ 8
- 6
data/src-cap-dialog.ui View File

@@ -48,8 +48,6 @@
48 48
                     <property name="margin_right">50</property>
49 49
                     <property name="margin_top">22</property>
50 50
                     <property name="margin_bottom">22</property>
51
-                    <property name="hexpand">True</property>
52
-                    <property name="vexpand">False</property>
53 51
                     <property name="orientation">vertical</property>
54 52
                     <property name="spacing">18</property>
55 53
                     <child>
@@ -60,11 +58,12 @@
60 58
                         <property name="row_spacing">6</property>
61 59
                         <property name="column_spacing">12</property>
62 60
                         <child>
63
-                          <object class="GtkLabel">
61
+                          <object class="GtkLabel" id="power-header">
64 62
                             <property name="visible">True</property>
65 63
                             <property name="can_focus">False</property>
66 64
                             <property name="halign">end</property>
67
-                            <property name="label" translatable="yes">PDO Power</property>
65
+                            <property name="valign">start</property>
66
+                            <property name="label" translatable="yes">PD Power</property>
68 67
                             <style>
69 68
                               <class name="dim-label"/>
70 69
                             </style>
@@ -75,7 +74,7 @@
75 74
                           </packing>
76 75
                         </child>
77 76
                         <child>
78
-                          <object class="GtkLabel">
77
+                          <object class="GtkLabel" id="info-header">
79 78
                             <property name="visible">True</property>
80 79
                             <property name="can_focus">False</property>
81 80
                             <property name="halign">end</property>
@@ -95,7 +94,7 @@
95 94
                             <property name="visible">True</property>
96 95
                             <property name="can_focus">False</property>
97 96
                             <property name="halign">start</property>
98
-                            <property name="valign">center</property>
97
+                            <property name="valign">start</property>
99 98
                             <property name="label" translatable="yes">label</property>
100 99
                           </object>
101 100
                           <packing>
@@ -107,6 +106,8 @@
107 106
                           <object class="GtkLabel" id="info-label">
108 107
                             <property name="visible">True</property>
109 108
                             <property name="can_focus">False</property>
109
+                            <property name="halign">start</property>
110
+                            <property name="valign">start</property>
110 111
                             <property name="label" translatable="yes">label
111 112
 test
112 113
 asdf</property>
@@ -127,6 +128,7 @@ asdf</property>
127 128
                       <object class="GtkFrame">
128 129
                         <property name="visible">True</property>
129 130
                         <property name="can_focus">False</property>
131
+                        <property name="halign">center</property>
130 132
                         <property name="label_xalign">0</property>
131 133
                         <property name="shadow_type">in</property>
132 134
                         <child>

+ 41
- 20
pd-buddy-gtk.py View File

@@ -339,29 +339,50 @@ class Handler:
339 339
         if row != sc_row:
340 340
             # If it's not the source-cap-row, leave
341 341
             return
342
+
342 343
         # Get the source capabilities
343 344
         with pdbuddy.Sink(self.serial_port) as pdbs:
344 345
             caps = pdbs.get_source_cap()
345
-            s = ""
346
-            for i, cap in enumerate(caps):
347
-                s += "PDO {}: {}".format(i+1, cap)
348
-                if i < len(caps) - 1:
349
-                    s += "\n"
350
-            if not s:
351
-                s = "No Source_Capabilities"
352
-            flags = Gtk.DialogFlags.DESTROY_WITH_PARENT;
353
-            window = self.builder.get_object("pdb-window")
354
-            dialog_builder = Gtk.Builder.new_from_file("data/src-cap-dialog.ui")
355
-            dialog = dialog_builder.get_object("src-cap-dialog")
356
-            dialog.set_transient_for(window)
357
-            #dialog = Gtk.MessageDialog(window,
358
-            #                 flags,
359
-            #                 Gtk.MessageType.INFO,
360
-            #                 Gtk.ButtonsType.CLOSE,
361
-            #                 None)
362
-            #dialog.set_markup("<span font_family='monospace'>{}</span>".format(s))
363
-            dialog.run()
364
-            dialog.destroy()
346
+
347
+        # Create the dialog
348
+        window = self.builder.get_object("pdb-window")
349
+        dialog_builder = Gtk.Builder.new_from_file("data/src-cap-dialog.ui")
350
+        dialog = dialog_builder.get_object("src-cap-dialog")
351
+        dialog.set_transient_for(window)
352
+
353
+        # Populate PD Power
354
+        d_power = dialog_builder.get_object("power-label")
355
+        d_power.set_text("{:g} W".format(pdbuddy.calculate_pdp(caps)))
356
+
357
+        # Populate Information
358
+        d_info_header = dialog_builder.get_object("info-header")
359
+        d_info = dialog_builder.get_object("info-label")
360
+        # Make the string to display
361
+        info_str = ""
362
+        if not caps[0].dual_role_pwr:
363
+            info_str += "Dual-Role Power\n"
364
+        if not caps[0].usb_suspend:
365
+            info_str += "USB Suspend Supported\n"
366
+        if caps[0].unconstrained_pwr:
367
+            info_str += "Unconstrained Power\n"
368
+        if not caps[0].usb_comms:
369
+            info_str += "USB Communications Capable\n"
370
+        if not caps[0].dual_role_data:
371
+            info_str += "Dual-Role Data\n"
372
+        info_str = info_str[:-1]
373
+        # Set the text and label visibility
374
+        d_info.set_text(info_str)
375
+        d_info_header.set_visible(info_str)
376
+        d_info.set_visible(info_str)
377
+
378
+        # PDO list
379
+        d_list = dialog_builder.get_object("src-cap-list")
380
+        d_list.set_header_func(list_box_update_header_func, None)
381
+        # TODO
382
+
383
+        # Show the dialog
384
+        dialog.run()
385
+        dialog.destroy()
365 386
 
366 387
 
367 388
 class Application(Gtk.Application):

Loading…
Cancel
Save