Преглед на файлове

Populate the PDO list

Now the PDO list in the new Source Capabilities dialog actually gets
populated.  It looks great, too, as per the mockup.
Clara Hobbs преди 6 години
родител
ревизия
db10144e7f
променени са 2 файла, в които са добавени 102 реда и са изтрити 184 реда
  1. 1
    176
      data/src-cap-dialog.ui
  2. 101
    8
      pd-buddy-gtk.py

+ 1
- 176
data/src-cap-dialog.ui Целия файл

@@ -108,9 +108,7 @@
108 108
                             <property name="can_focus">False</property>
109 109
                             <property name="halign">start</property>
110 110
                             <property name="valign">start</property>
111
-                            <property name="label" translatable="yes">label
112
-test
113
-asdf</property>
111
+                            <property name="label" translatable="yes">label</property>
114 112
                           </object>
115 113
                           <packing>
116 114
                             <property name="left_attach">1</property>
@@ -142,179 +140,6 @@ asdf</property>
142 140
                                 <property name="can_focus">False</property>
143 141
                                 <property name="selection_mode">none</property>
144 142
                                 <property name="activate_on_single_click">False</property>
145
-                                <child>
146
-                                  <object class="GtkListBoxRow">
147
-                                    <property name="visible">True</property>
148
-                                    <property name="can_focus">False</property>
149
-                                    <property name="activatable">False</property>
150
-                                    <property name="selectable">False</property>
151
-                                    <child>
152
-                                      <object class="GtkBox">
153
-                                        <property name="visible">True</property>
154
-                                        <property name="can_focus">False</property>
155
-                                        <property name="margin_left">12</property>
156
-                                        <property name="margin_right">12</property>
157
-                                        <property name="margin_top">6</property>
158
-                                        <property name="margin_bottom">6</property>
159
-                                        <property name="spacing">12</property>
160
-                                        <property name="homogeneous">True</property>
161
-                                        <child>
162
-                                          <object class="GtkLabel" id="pdo-type">
163
-                                            <property name="visible">True</property>
164
-                                            <property name="can_focus">False</property>
165
-                                            <property name="halign">start</property>
166
-                                            <property name="label" translatable="yes">Fixed</property>
167
-                                          </object>
168
-                                          <packing>
169
-                                            <property name="expand">True</property>
170
-                                            <property name="fill">True</property>
171
-                                            <property name="position">0</property>
172
-                                          </packing>
173
-                                        </child>
174
-                                        <child>
175
-                                          <object class="GtkLabel" id="pdo-center">
176
-                                            <property name="visible">True</property>
177
-                                            <property name="can_focus">False</property>
178
-                                            <property name="halign">end</property>
179
-                                            <property name="label" translatable="yes">5 V</property>
180
-                                          </object>
181
-                                          <packing>
182
-                                            <property name="expand">True</property>
183
-                                            <property name="fill">True</property>
184
-                                            <property name="position">1</property>
185
-                                          </packing>
186
-                                        </child>
187
-                                        <child>
188
-                                          <object class="GtkBox">
189
-                                            <property name="visible">True</property>
190
-                                            <property name="can_focus">False</property>
191
-                                            <property name="halign">end</property>
192
-                                            <property name="spacing">6</property>
193
-                                            <child>
194
-                                              <object class="GtkLabel" id="pdo-right">
195
-                                                <property name="visible">True</property>
196
-                                                <property name="can_focus">False</property>
197
-                                                <property name="label" translatable="yes">3 A</property>
198
-                                              </object>
199
-                                              <packing>
200
-                                                <property name="expand">False</property>
201
-                                                <property name="fill">True</property>
202
-                                                <property name="pack_type">end</property>
203
-                                                <property name="position">0</property>
204
-                                              </packing>
205
-                                            </child>
206
-                                            <child>
207
-                                              <object class="GtkImage" id="pdo-icon">
208
-                                                <property name="visible">True</property>
209
-                                                <property name="can_focus">False</property>
210
-                                                <property name="tooltip_text" translatable="yes">Something something peak current
211
-another line about peak current</property>
212
-                                                <property name="icon_name">dialog-information-symbolic</property>
213
-                                              </object>
214
-                                              <packing>
215
-                                                <property name="expand">False</property>
216
-                                                <property name="fill">True</property>
217
-                                                <property name="pack_type">end</property>
218
-                                                <property name="position">1</property>
219
-                                              </packing>
220
-                                            </child>
221
-                                          </object>
222
-                                          <packing>
223
-                                            <property name="expand">True</property>
224
-                                            <property name="fill">True</property>
225
-                                            <property name="pack_type">end</property>
226
-                                            <property name="position">2</property>
227
-                                          </packing>
228
-                                        </child>
229
-                                      </object>
230
-                                    </child>
231
-                                  </object>
232
-                                </child>
233
-                                <child>
234
-                                  <object class="GtkListBoxRow">
235
-                                    <property name="visible">True</property>
236
-                                    <property name="can_focus">False</property>
237
-                                    <property name="activatable">False</property>
238
-                                    <property name="selectable">False</property>
239
-                                    <child>
240
-                                      <object class="GtkBox">
241
-                                        <property name="visible">True</property>
242
-                                        <property name="can_focus">False</property>
243
-                                        <property name="margin_left">12</property>
244
-                                        <property name="margin_right">12</property>
245
-                                        <property name="margin_top">6</property>
246
-                                        <property name="margin_bottom">6</property>
247
-                                        <property name="spacing">12</property>
248
-                                        <property name="homogeneous">True</property>
249
-                                        <child>
250
-                                          <object class="GtkLabel" id="pdo-type1">
251
-                                            <property name="visible">True</property>
252
-                                            <property name="can_focus">False</property>
253
-                                            <property name="halign">start</property>
254
-                                            <property name="label" translatable="yes">Battery</property>
255
-                                          </object>
256
-                                          <packing>
257
-                                            <property name="expand">True</property>
258
-                                            <property name="fill">True</property>
259
-                                            <property name="position">0</property>
260
-                                          </packing>
261
-                                        </child>
262
-                                        <child>
263
-                                          <object class="GtkLabel" id="pdo-center1">
264
-                                            <property name="visible">True</property>
265
-                                            <property name="can_focus">False</property>
266
-                                            <property name="halign">end</property>
267
-                                            <property name="label" translatable="yes">6–8.4 V</property>
268
-                                          </object>
269
-                                          <packing>
270
-                                            <property name="expand">True</property>
271
-                                            <property name="fill">True</property>
272
-                                            <property name="position">1</property>
273
-                                          </packing>
274
-                                        </child>
275
-                                        <child>
276
-                                          <object class="GtkBox">
277
-                                            <property name="visible">True</property>
278
-                                            <property name="can_focus">False</property>
279
-                                            <property name="halign">end</property>
280
-                                            <property name="spacing">6</property>
281
-                                            <child>
282
-                                              <object class="GtkLabel" id="pdo-right1">
283
-                                                <property name="visible">True</property>
284
-                                                <property name="can_focus">False</property>
285
-                                                <property name="label" translatable="yes">18 W</property>
286
-                                              </object>
287
-                                              <packing>
288
-                                                <property name="expand">False</property>
289
-                                                <property name="fill">True</property>
290
-                                                <property name="pack_type">end</property>
291
-                                                <property name="position">0</property>
292
-                                              </packing>
293
-                                            </child>
294
-                                            <child>
295
-                                              <object class="GtkImage" id="pdo-icon1">
296
-                                                <property name="can_focus">False</property>
297
-                                                <property name="icon_name">dialog-information-symbolic</property>
298
-                                              </object>
299
-                                              <packing>
300
-                                                <property name="expand">False</property>
301
-                                                <property name="fill">True</property>
302
-                                                <property name="pack_type">end</property>
303
-                                                <property name="position">1</property>
304
-                                              </packing>
305
-                                            </child>
306
-                                          </object>
307
-                                          <packing>
308
-                                            <property name="expand">True</property>
309
-                                            <property name="fill">True</property>
310
-                                            <property name="pack_type">end</property>
311
-                                            <property name="position">2</property>
312
-                                          </packing>
313
-                                        </child>
314
-                                      </object>
315
-                                    </child>
316
-                                  </object>
317
-                                </child>
318 143
                               </object>
319 144
                             </child>
320 145
                           </object>

+ 101
- 8
pd-buddy-gtk.py Целия файл

@@ -17,7 +17,7 @@ def comms_error_dialog(parent, e):
17 17
     dialog.destroy()
18 18
 
19 19
 
20
-class ListRowModel(GObject.GObject):
20
+class SelectListRowModel(GObject.GObject):
21 21
 
22 22
     def __init__(self, serport):
23 23
         GObject.GObject.__init__(self)
@@ -49,7 +49,7 @@ class SelectListStore(Gio.ListStore):
49 49
         # Add any new ports
50 50
         for port in serports:
51 51
             if port is not None:
52
-                self.append(ListRowModel(port))
52
+                self.append(SelectListRowModel(port))
53 53
 
54 54
 
55 55
 def list_box_update_header_func(row, before, data):
@@ -114,7 +114,6 @@ class SelectListRow(Gtk.ListBoxRow):
114 114
 
115 115
     def __init__(self, model):
116 116
         Gtk.EventBox.__init__(self)
117
-
118 117
         self.model = model
119 118
 
120 119
         self._builder = Gtk.Builder()
@@ -142,6 +141,97 @@ class SelectListRow(Gtk.ListBoxRow):
142 141
             return
143 142
 
144 143
 
144
+class PDOListRowModel(GObject.GObject):
145
+
146
+    def __init__(self, pdo):
147
+        GObject.GObject.__init__(self)
148
+        self.pdo = pdo
149
+
150
+
151
+class PDOListStore(Gio.ListStore):
152
+
153
+    def update_items(self, pdo_list):
154
+        # Clear the list
155
+        self.remove_all()
156
+
157
+        # Add everything from the new list
158
+        for pdo in pdo_list:
159
+            self.append(PDOListRowModel(pdo))
160
+
161
+
162
+class PDOListRow(Gtk.ListBoxRow):
163
+    oc_tooltips = [
164
+        "I<sub>Peak</sub> = I<sub>OC</sub> (default)",
165
+        """Overload Capabilities:
166
+1. I<sub>Peak</sub> = 150% I<sub>OC</sub> for 1 ms @ 5% duty cycle (I<sub>Low</sub> = 97% I<sub>OC</sub> for 19 ms)
167
+2. I<sub>Peak</sub> = 125% I<sub>OC</sub> for 2 ms @ 10% duty cycle (I<sub>Low</sub> = 97% I<sub>OC</sub> for 18 ms)
168
+3. I<sub>Peak</sub> = 110% I<sub>OC</sub> for 10 ms @ 50% duty cycle (I<sub>Low</sub> = 90% I<sub>OC</sub> for 10 ms)""",
169
+        """Overload Capabilities:
170
+1. I<sub>Peak</sub> = 200% I<sub>OC</sub> for 1 ms @ 5% duty cycle (I<sub>Low</sub> = 95% I<sub>OC</sub> for 19 ms)
171
+2. I<sub>Peak</sub> = 150% I<sub>OC</sub> for 2 ms @ 10% duty cycle (I<sub>Low</sub> = 94% I<sub>OC</sub> for 18 ms)
172
+3. I<sub>Peak</sub> = 125% I<sub>OC</sub> for 10 ms @ 50% duty cycle (I<sub>Low</sub> = 75% I<sub>OC</sub> for 10 ms)""",
173
+        """Overload Capabilities:
174
+1. I<sub>Peak</sub> = 200% I<sub>OC</sub> for 1 ms @ 5% duty cycle (I<sub>Low</sub> = 95% I<sub>OC</sub> for 19 ms)
175
+2. I<sub>Peak</sub> = 175% I<sub>OC</sub> for 2 ms @ 10% duty cycle (I<sub>Low</sub> = 92% I<sub>OC</sub> for 18 ms)
176
+3. I<sub>Peak</sub> = 150% I<sub>OC</sub> for 10 ms @ 50% duty cycle (I<sub>Low</sub> = 50% I<sub>OC</sub> for 10 ms)"""
177
+    ]
178
+
179
+    def __init__(self, model):
180
+        Gtk.ListBoxRow.__init__(self)
181
+        self.model = model
182
+
183
+        self.set_activatable(False)
184
+        self.set_selectable(False)
185
+        self.set_can_focus(False)
186
+
187
+        # Make the widgets and populate them with info from the model
188
+        # Main box
189
+        box = Gtk.Box(Gtk.Orientation.HORIZONTAL, 12)
190
+        box.set_homogeneous(True)
191
+        box.set_margin_left(12)
192
+        box.set_margin_right(12)
193
+        box.set_margin_top(6)
194
+        box.set_margin_bottom(6)
195
+
196
+        # Type label
197
+        type_label = Gtk.Label(model.pdo.pdo_type.capitalize())
198
+        type_label.set_halign(Gtk.Align.START)
199
+        box.pack_start(type_label, True, True, 0)
200
+
201
+        # Voltage label
202
+        if model.pdo.pdo_type != "unknown":
203
+            voltage_label = Gtk.Label("{:g} V".format(model.pdo.v / 1000.0))
204
+            voltage_label.set_halign(Gtk.Align.END)
205
+            box.pack_start(voltage_label, True, True, 0)
206
+
207
+        # Right box
208
+        right_box = Gtk.Box(Gtk.Orientation.HORIZONTAL, 6)
209
+        right_box.set_halign(Gtk.Align.END)
210
+        if model.pdo.pdo_type != "unknown":
211
+            # Current label
212
+            current_label = Gtk.Label("{:g} A".format(model.pdo.i / 1000.0))
213
+            current_label.set_halign(Gtk.Align.END)
214
+            right_box.pack_end(current_label, True, False, 0)
215
+
216
+            # 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)
223
+        else:
224
+            # PDO value
225
+            text_label = Gtk.Label()
226
+            text_label.set_markup("<tt>{}</tt>".format(model.pdo))
227
+            right_box.pack_end(text_label, True, False, 0)
228
+
229
+        box.pack_end(right_box, True, True, 0)
230
+
231
+        self.add(box)
232
+        self.show_all()
233
+
234
+
145 235
 class Handler:
146 236
 
147 237
     def __init__(self, builder):
@@ -359,15 +449,15 @@ class Handler:
359 449
         d_info = dialog_builder.get_object("info-label")
360 450
         # Make the string to display
361 451
         info_str = ""
362
-        if not caps[0].dual_role_pwr:
452
+        if caps[0].dual_role_pwr:
363 453
             info_str += "Dual-Role Power\n"
364
-        if not caps[0].usb_suspend:
454
+        if caps[0].usb_suspend:
365 455
             info_str += "USB Suspend Supported\n"
366 456
         if caps[0].unconstrained_pwr:
367 457
             info_str += "Unconstrained Power\n"
368
-        if not caps[0].usb_comms:
458
+        if caps[0].usb_comms:
369 459
             info_str += "USB Communications Capable\n"
370
-        if not caps[0].dual_role_data:
460
+        if caps[0].dual_role_data:
371 461
             info_str += "Dual-Role Data\n"
372 462
         info_str = info_str[:-1]
373 463
         # Set the text and label visibility
@@ -378,7 +468,10 @@ class Handler:
378 468
         # PDO list
379 469
         d_list = dialog_builder.get_object("src-cap-list")
380 470
         d_list.set_header_func(list_box_update_header_func, None)
381
-        # TODO
471
+
472
+        model = PDOListStore()
473
+        d_list.bind_model(model, PDOListRow)
474
+        model.update_items(caps)
382 475
 
383 476
         # Show the dialog
384 477
         dialog.run()

Loading…
Отказ
Запис