Kaynağa Gözat

Partially fill the Source Capabilities dialog

Now it has the real PD Power and Information.  The list has separators
too.
Clara Hobbs 6 yıl önce
ebeveyn
işleme
572c140a74
2 değiştirilmiş dosya ile 49 ekleme ve 26 silme
  1. 8
    6
      data/src-cap-dialog.ui
  2. 41
    20
      pd-buddy-gtk.py

+ 8
- 6
data/src-cap-dialog.ui Dosyayı Görüntüle

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

+ 41
- 20
pd-buddy-gtk.py Dosyayı Görüntüle

339
         if row != sc_row:
339
         if row != sc_row:
340
             # If it's not the source-cap-row, leave
340
             # If it's not the source-cap-row, leave
341
             return
341
             return
342
+
342
         # Get the source capabilities
343
         # Get the source capabilities
343
         with pdbuddy.Sink(self.serial_port) as pdbs:
344
         with pdbuddy.Sink(self.serial_port) as pdbs:
344
             caps = pdbs.get_source_cap()
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
 class Application(Gtk.Application):
388
 class Application(Gtk.Application):

Loading…
İptal
Kaydet