Browse Source

Added GiveBack flag GtkToggleButton

Since the firmware supports GiveBack now, the GUI should as well.  This
commit adds a toggle button for toggling the GiveBack flag on a PD Buddy
Sink.
Clara Hobbs 7 years ago
parent
commit
65f79f8ea3
2 changed files with 72 additions and 3 deletions
  1. 48
    1
      data/pd-buddy-gtk.ui
  2. 24
    2
      pd-buddy-gtk.py

+ 48
- 1
data/pd-buddy-gtk.ui View File

21
       <object class="GtkStack" id="stack">
21
       <object class="GtkStack" id="stack">
22
         <property name="visible">True</property>
22
         <property name="visible">True</property>
23
         <property name="can_focus">False</property>
23
         <property name="can_focus">False</property>
24
-        <property name="transition_type">slide-left-right</property>
24
+        <property name="transition_type">crossfade</property>
25
         <child>
25
         <child>
26
           <object class="GtkScrolledWindow" id="select">
26
           <object class="GtkScrolledWindow" id="select">
27
             <property name="visible">True</property>
27
             <property name="visible">True</property>
93
                                   <object class="GtkLabel">
93
                                   <object class="GtkLabel">
94
                                     <property name="visible">True</property>
94
                                     <property name="visible">True</property>
95
                                     <property name="can_focus">False</property>
95
                                     <property name="can_focus">False</property>
96
+                                    <property name="halign">end</property>
96
                                     <property name="label" translatable="yes">Voltage</property>
97
                                     <property name="label" translatable="yes">Voltage</property>
97
                                     <property name="justify">right</property>
98
                                     <property name="justify">right</property>
98
                                     <style>
99
                                     <style>
108
                                   <object class="GtkLabel">
109
                                   <object class="GtkLabel">
109
                                     <property name="visible">True</property>
110
                                     <property name="visible">True</property>
110
                                     <property name="can_focus">False</property>
111
                                     <property name="can_focus">False</property>
112
+                                    <property name="halign">end</property>
111
                                     <property name="label" translatable="yes">Current</property>
113
                                     <property name="label" translatable="yes">Current</property>
112
                                     <property name="justify">right</property>
114
                                     <property name="justify">right</property>
113
                                     <style>
115
                                     <style>
173
                                     <property name="top_attach">0</property>
175
                                     <property name="top_attach">0</property>
174
                                   </packing>
176
                                   </packing>
175
                                 </child>
177
                                 </child>
178
+                                <child>
179
+                                  <object class="GtkLabel">
180
+                                    <property name="visible">True</property>
181
+                                    <property name="can_focus">False</property>
182
+                                    <property name="halign">end</property>
183
+                                    <property name="label" translatable="yes">Flags</property>
184
+                                    <property name="justify">right</property>
185
+                                    <style>
186
+                                      <class name="dim-label"/>
187
+                                    </style>
188
+                                  </object>
189
+                                  <packing>
190
+                                    <property name="left_attach">0</property>
191
+                                    <property name="top_attach">2</property>
192
+                                  </packing>
193
+                                </child>
194
+                                <child>
195
+                                  <object class="GtkButtonBox">
196
+                                    <property name="visible">True</property>
197
+                                    <property name="can_focus">False</property>
198
+                                    <property name="halign">start</property>
199
+                                    <property name="orientation">vertical</property>
200
+                                    <property name="layout_style">end</property>
201
+                                    <child>
202
+                                      <object class="GtkToggleButton" id="giveback-toggle">
203
+                                        <property name="label" translatable="yes">GiveBack</property>
204
+                                        <property name="visible">True</property>
205
+                                        <property name="can_focus">True</property>
206
+                                        <property name="receives_default">True</property>
207
+                                        <signal name="toggled" handler="on_giveback_toggle_toggled" swapped="no"/>
208
+                                      </object>
209
+                                      <packing>
210
+                                        <property name="expand">True</property>
211
+                                        <property name="fill">True</property>
212
+                                        <property name="position">0</property>
213
+                                      </packing>
214
+                                    </child>
215
+                                  </object>
216
+                                  <packing>
217
+                                    <property name="left_attach">1</property>
218
+                                    <property name="top_attach">2</property>
219
+                                    <property name="width">2</property>
220
+                                  </packing>
221
+                                </child>
176
                               </object>
222
                               </object>
177
                             </child>
223
                             </child>
178
                           </object>
224
                           </object>
204
       <object class="GtkStack" id="header-stack">
250
       <object class="GtkStack" id="header-stack">
205
         <property name="visible">True</property>
251
         <property name="visible">True</property>
206
         <property name="can_focus">False</property>
252
         <property name="can_focus">False</property>
253
+        <property name="transition_type">crossfade</property>
207
         <child>
254
         <child>
208
           <object class="GtkHeaderBar" id="header-select">
255
           <object class="GtkHeaderBar" id="header-select">
209
             <property name="visible">True</property>
256
             <property name="visible">True</property>

+ 24
- 2
pd-buddy-gtk.py View File

162
         self.serial_port = None
162
         self.serial_port = None
163
         self.voltage = None
163
         self.voltage = None
164
         self.current = None
164
         self.current = None
165
+        self.giveback = None
165
         self.selectlist = None
166
         self.selectlist = None
166
 
167
 
167
     def on_pdb_window_realize(self, *args):
168
     def on_pdb_window_realize(self, *args):
183
         # Get voltage and current widgets
184
         # Get voltage and current widgets
184
         voltage = self.builder.get_object("voltage-combobox")
185
         voltage = self.builder.get_object("voltage-combobox")
185
         current = self.builder.get_object("current-spinbutton")
186
         current = self.builder.get_object("current-spinbutton")
187
+        giveback = self.builder.get_object("giveback-toggle")
186
 
188
 
187
         self.serial_port = serport
189
         self.serial_port = serport
188
 
190
 
195
 
197
 
196
         # Get voltage and current from device and load them into the GUI
198
         # Get voltage and current from device and load them into the GUI
197
         for line in tmpcfg:
199
         for line in tmpcfg:
198
-            if line.startswith(b'v:'):
200
+            if line.startswith(b'flags:'):
201
+                line = line.split()[1:]
202
+                try:
203
+                    line.index(b'GiveBack')
204
+                    giveback.set_active(True)
205
+                except:
206
+                    giveback.set_active(False)
207
+            elif line.startswith(b'v:'):
199
                 v = line.split()[1]
208
                 v = line.split()[1]
200
                 if v == b'5.00':
209
                 if v == b'5.00':
201
                     voltage.set_active_id('voltage-five')
210
                     voltage.set_active_id('voltage-five')
266
         # Get voltage and current widgets
275
         # Get voltage and current widgets
267
         voltage = self.builder.get_object("voltage-combobox")
276
         voltage = self.builder.get_object("voltage-combobox")
268
         current = self.builder.get_object("current-spinbutton")
277
         current = self.builder.get_object("current-spinbutton")
278
+        giveback = self.builder.get_object("giveback-toggle")
269
 
279
 
270
         # Remember the loaded settings
280
         # Remember the loaded settings
271
         self.voltage = voltage.get_active_id()
281
         self.voltage = voltage.get_active_id()
272
         self.current = current.get_value()
282
         self.current = current.get_value()
283
+        self.giveback = giveback.get_active()
273
 
284
 
274
     def _set_save_button_visibility(self):
285
     def _set_save_button_visibility(self):
275
         """Show the save button if there are new settings to save"""
286
         """Show the save button if there are new settings to save"""
276
         # Get relevant widgets
287
         # Get relevant widgets
277
         voltage = self.builder.get_object("voltage-combobox")
288
         voltage = self.builder.get_object("voltage-combobox")
278
         current = self.builder.get_object("current-spinbutton")
289
         current = self.builder.get_object("current-spinbutton")
290
+        giveback = self.builder.get_object("giveback-toggle")
279
         rev = self.builder.get_object("header-sink-save-revealer")
291
         rev = self.builder.get_object("header-sink-save-revealer")
280
 
292
 
281
         # Set visibility
293
         # Set visibility
282
         rev.set_reveal_child(voltage.get_active_id() != self.voltage
294
         rev.set_reveal_child(voltage.get_active_id() != self.voltage
283
-                             or current.get_value() != self.current)
295
+                             or current.get_value() != self.current
296
+                             or giveback.get_active() != self.giveback)
284
 
297
 
285
     def on_voltage_combobox_changed(self, combo):
298
     def on_voltage_combobox_changed(self, combo):
286
         window = self.builder.get_object("pdb-window")
299
         window = self.builder.get_object("pdb-window")
304
         except:
317
         except:
305
             self.on_header_sink_back_clicked(None)
318
             self.on_header_sink_back_clicked(None)
306
 
319
 
320
+    def on_giveback_toggle_toggled(self, toggle):
321
+        window = self.builder.get_object("pdb-window")
322
+        try:
323
+            pdb_send_message(self.serial_port, 'toggle_giveback', window)
324
+
325
+            self._set_save_button_visibility()
326
+        except:
327
+            self.on_header_sink_back_clicked(None)
328
+
307
 class Application(Gtk.Application):
329
 class Application(Gtk.Application):
308
 
330
 
309
     def __init__(self, *args, **kwargs):
331
     def __init__(self, *args, **kwargs):

Loading…
Cancel
Save