Sfoglia il codice sorgente

Voltage spinbutton instead of combobox

Now that the firmware is able to make requests from programmable power
supplies, it's important that the GUI allows setting arbitrary voltages.
This commit makes it do that.
Clara Hobbs 7 anni fa
parent
commit
72b6f50ca3
2 ha cambiato i file con 25 aggiunte e 30 eliminazioni
  1. 21
    17
      data/pd-buddy-gtk.ui
  2. 4
    13
      pd-buddy-gtk.py

+ 21
- 17
data/pd-buddy-gtk.ui Vedi File

@@ -1,5 +1,5 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<!-- Generated with glade 3.20.0 -->
2
+<!-- Generated with glade 3.20.2 -->
3 3
 <interface>
4 4
   <requires lib="gtk+" version="3.20"/>
5 5
   <object class="GtkImage" id="back-image">
@@ -12,6 +12,11 @@
12 12
     <property name="step_increment">1</property>
13 13
     <property name="page_increment">10</property>
14 14
   </object>
15
+  <object class="GtkAdjustment" id="voltage-adjustment">
16
+    <property name="upper">20</property>
17
+    <property name="step_increment">0.01</property>
18
+    <property name="page_increment">1</property>
19
+  </object>
15 20
   <object class="GtkApplicationWindow" id="pdb-window">
16 21
     <property name="can_focus">False</property>
17 22
     <property name="show_menubar">False</property>
@@ -188,7 +193,6 @@
188 193
                                                 <property name="label" translatable="yes">_Voltage</property>
189 194
                                                 <property name="use_underline">True</property>
190 195
                                                 <property name="justify">right</property>
191
-                                                <property name="mnemonic_widget">voltage-combobox</property>
192 196
                                               </object>
193 197
                                               <packing>
194 198
                                                 <property name="left_attach">0</property>
@@ -196,32 +200,31 @@
196 200
                                               </packing>
197 201
                                             </child>
198 202
                                             <child>
199
-                                              <object class="GtkComboBoxText" id="voltage-combobox">
203
+                                              <object class="GtkLabel">
200 204
                                                 <property name="visible">True</property>
201 205
                                                 <property name="can_focus">False</property>
202
-                                                <items>
203
-                                                  <item id="voltage-five" translatable="yes">5</item>
204
-                                                  <item id="voltage-nine" translatable="yes">9</item>
205
-                                                  <item id="voltage-twelve" translatable="yes">12</item>
206
-                                                  <item id="voltage-fifteen" translatable="yes">15</item>
207
-                                                  <item id="voltage-twenty" translatable="yes">20</item>
208
-                                                </items>
209
-                                                <signal name="changed" handler="on_voltage_combobox_changed" swapped="no"/>
206
+                                                <property name="halign">start</property>
207
+                                                <property name="label" translatable="yes">V</property>
210 208
                                               </object>
211 209
                                               <packing>
212
-                                                <property name="left_attach">1</property>
210
+                                                <property name="left_attach">2</property>
213 211
                                                 <property name="top_attach">0</property>
214 212
                                               </packing>
215 213
                                             </child>
216 214
                                             <child>
217
-                                              <object class="GtkLabel">
215
+                                              <object class="GtkSpinButton" id="voltage-spinbutton">
218 216
                                                 <property name="visible">True</property>
219
-                                                <property name="can_focus">False</property>
220
-                                                <property name="halign">start</property>
221
-                                                <property name="label" translatable="yes">V</property>
217
+                                                <property name="can_focus">True</property>
218
+                                                <property name="width_chars">5</property>
219
+                                                <property name="text" translatable="yes">0.00</property>
220
+                                                <property name="input_purpose">number</property>
221
+                                                <property name="adjustment">voltage-adjustment</property>
222
+                                                <property name="digits">2</property>
223
+                                                <property name="numeric">True</property>
224
+                                                <signal name="value-changed" handler="on_voltage_spinbutton_changed" swapped="no"/>
222 225
                                               </object>
223 226
                                               <packing>
224
-                                                <property name="left_attach">2</property>
227
+                                                <property name="left_attach">1</property>
225 228
                                                 <property name="top_attach">0</property>
226 229
                                               </packing>
227 230
                                             </child>
@@ -266,6 +269,7 @@
266 269
                                                 <property name="visible">True</property>
267 270
                                                 <property name="can_focus">True</property>
268 271
                                                 <property name="margin_left">12</property>
272
+                                                <property name="width_chars">5</property>
269 273
                                                 <property name="input_purpose">number</property>
270 274
                                                 <property name="adjustment">current-adjustment</property>
271 275
                                                 <property name="digits">2</property>

+ 4
- 13
pd-buddy-gtk.py Vedi File

@@ -278,7 +278,7 @@ class Handler:
278 278
 
279 279
     def on_select_list_row_activated(self, selectlist, serport):
280 280
         # Get relevant widgets
281
-        voltage = self.builder.get_object("voltage-combobox")
281
+        voltage = self.builder.get_object("voltage-spinbutton")
282 282
         current = self.builder.get_object("current-spinbutton")
283 283
         giveback = self.builder.get_object("giveback-toggle")
284 284
         pd_frame = self.builder.get_object("power-delivery-frame")
@@ -314,16 +314,7 @@ class Handler:
314 314
         giveback.set_active(bool(self.cfg.flags & pdbuddy.SinkFlags.GIVEBACK))
315 315
 
316 316
         # Get voltage and current from device and load them into the GUI
317
-        if self.cfg.v == 5000:
318
-            voltage.set_active_id('voltage-five')
319
-        elif self.cfg.v == 9000:
320
-            voltage.set_active_id('voltage-nine')
321
-        elif self.cfg.v == 12000:
322
-            voltage.set_active_id('voltage-twelve')
323
-        elif self.cfg.v == 15000:
324
-            voltage.set_active_id('voltage-fifteen')
325
-        if self.cfg.v == 20000:
326
-            voltage.set_active_id('voltage-twenty')
317
+        voltage.set_value(self.cfg.v/1000)
327 318
 
328 319
         current.set_value(self.cfg.i/1000)
329 320
 
@@ -422,8 +413,8 @@ class Handler:
422 413
         # Set visibility
423 414
         rev.set_reveal_child(self.cfg != self.cfg_clean)
424 415
 
425
-    def on_voltage_combobox_changed(self, combo):
426
-        self.cfg = self.cfg._replace(v=int(combo.get_active_text()) * 1000)
416
+    def on_voltage_spinbutton_changed(self, spin):
417
+        self.cfg = self.cfg._replace(v=int(spin.get_value() * 1000))
427 418
 
428 419
         self._set_save_button_visibility()
429 420
 

Loading…
Annulla
Salva