Browse Source

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 years ago
parent
commit
72b6f50ca3
2 changed files with 25 additions and 30 deletions
  1. 21
    17
      data/pd-buddy-gtk.ui
  2. 4
    13
      pd-buddy-gtk.py

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

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<!-- Generated with glade 3.20.0 -->
2
+<!-- Generated with glade 3.20.2 -->
3
 <interface>
3
 <interface>
4
   <requires lib="gtk+" version="3.20"/>
4
   <requires lib="gtk+" version="3.20"/>
5
   <object class="GtkImage" id="back-image">
5
   <object class="GtkImage" id="back-image">
12
     <property name="step_increment">1</property>
12
     <property name="step_increment">1</property>
13
     <property name="page_increment">10</property>
13
     <property name="page_increment">10</property>
14
   </object>
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
   <object class="GtkApplicationWindow" id="pdb-window">
20
   <object class="GtkApplicationWindow" id="pdb-window">
16
     <property name="can_focus">False</property>
21
     <property name="can_focus">False</property>
17
     <property name="show_menubar">False</property>
22
     <property name="show_menubar">False</property>
188
                                                 <property name="label" translatable="yes">_Voltage</property>
193
                                                 <property name="label" translatable="yes">_Voltage</property>
189
                                                 <property name="use_underline">True</property>
194
                                                 <property name="use_underline">True</property>
190
                                                 <property name="justify">right</property>
195
                                                 <property name="justify">right</property>
191
-                                                <property name="mnemonic_widget">voltage-combobox</property>
192
                                               </object>
196
                                               </object>
193
                                               <packing>
197
                                               <packing>
194
                                                 <property name="left_attach">0</property>
198
                                                 <property name="left_attach">0</property>
196
                                               </packing>
200
                                               </packing>
197
                                             </child>
201
                                             </child>
198
                                             <child>
202
                                             <child>
199
-                                              <object class="GtkComboBoxText" id="voltage-combobox">
203
+                                              <object class="GtkLabel">
200
                                                 <property name="visible">True</property>
204
                                                 <property name="visible">True</property>
201
                                                 <property name="can_focus">False</property>
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
                                               </object>
208
                                               </object>
211
                                               <packing>
209
                                               <packing>
212
-                                                <property name="left_attach">1</property>
210
+                                                <property name="left_attach">2</property>
213
                                                 <property name="top_attach">0</property>
211
                                                 <property name="top_attach">0</property>
214
                                               </packing>
212
                                               </packing>
215
                                             </child>
213
                                             </child>
216
                                             <child>
214
                                             <child>
217
-                                              <object class="GtkLabel">
215
+                                              <object class="GtkSpinButton" id="voltage-spinbutton">
218
                                                 <property name="visible">True</property>
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
                                               </object>
225
                                               </object>
223
                                               <packing>
226
                                               <packing>
224
-                                                <property name="left_attach">2</property>
227
+                                                <property name="left_attach">1</property>
225
                                                 <property name="top_attach">0</property>
228
                                                 <property name="top_attach">0</property>
226
                                               </packing>
229
                                               </packing>
227
                                             </child>
230
                                             </child>
266
                                                 <property name="visible">True</property>
269
                                                 <property name="visible">True</property>
267
                                                 <property name="can_focus">True</property>
270
                                                 <property name="can_focus">True</property>
268
                                                 <property name="margin_left">12</property>
271
                                                 <property name="margin_left">12</property>
272
+                                                <property name="width_chars">5</property>
269
                                                 <property name="input_purpose">number</property>
273
                                                 <property name="input_purpose">number</property>
270
                                                 <property name="adjustment">current-adjustment</property>
274
                                                 <property name="adjustment">current-adjustment</property>
271
                                                 <property name="digits">2</property>
275
                                                 <property name="digits">2</property>

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

278
 
278
 
279
     def on_select_list_row_activated(self, selectlist, serport):
279
     def on_select_list_row_activated(self, selectlist, serport):
280
         # Get relevant widgets
280
         # Get relevant widgets
281
-        voltage = self.builder.get_object("voltage-combobox")
281
+        voltage = self.builder.get_object("voltage-spinbutton")
282
         current = self.builder.get_object("current-spinbutton")
282
         current = self.builder.get_object("current-spinbutton")
283
         giveback = self.builder.get_object("giveback-toggle")
283
         giveback = self.builder.get_object("giveback-toggle")
284
         pd_frame = self.builder.get_object("power-delivery-frame")
284
         pd_frame = self.builder.get_object("power-delivery-frame")
314
         giveback.set_active(bool(self.cfg.flags & pdbuddy.SinkFlags.GIVEBACK))
314
         giveback.set_active(bool(self.cfg.flags & pdbuddy.SinkFlags.GIVEBACK))
315
 
315
 
316
         # Get voltage and current from device and load them into the GUI
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
         current.set_value(self.cfg.i/1000)
319
         current.set_value(self.cfg.i/1000)
329
 
320
 
422
         # Set visibility
413
         # Set visibility
423
         rev.set_reveal_child(self.cfg != self.cfg_clean)
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
         self._set_save_button_visibility()
419
         self._set_save_button_visibility()
429
 
420
 

Loading…
Cancel
Save