Просмотр исходного кода

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 лет назад
Родитель
Сommit
65f79f8ea3
2 измененных файлов: 72 добавлений и 3 удалений
  1. 48
    1
      data/pd-buddy-gtk.ui
  2. 24
    2
      pd-buddy-gtk.py

+ 48
- 1
data/pd-buddy-gtk.ui Просмотреть файл

@@ -21,7 +21,7 @@
21 21
       <object class="GtkStack" id="stack">
22 22
         <property name="visible">True</property>
23 23
         <property name="can_focus">False</property>
24
-        <property name="transition_type">slide-left-right</property>
24
+        <property name="transition_type">crossfade</property>
25 25
         <child>
26 26
           <object class="GtkScrolledWindow" id="select">
27 27
             <property name="visible">True</property>
@@ -93,6 +93,7 @@
93 93
                                   <object class="GtkLabel">
94 94
                                     <property name="visible">True</property>
95 95
                                     <property name="can_focus">False</property>
96
+                                    <property name="halign">end</property>
96 97
                                     <property name="label" translatable="yes">Voltage</property>
97 98
                                     <property name="justify">right</property>
98 99
                                     <style>
@@ -108,6 +109,7 @@
108 109
                                   <object class="GtkLabel">
109 110
                                     <property name="visible">True</property>
110 111
                                     <property name="can_focus">False</property>
112
+                                    <property name="halign">end</property>
111 113
                                     <property name="label" translatable="yes">Current</property>
112 114
                                     <property name="justify">right</property>
113 115
                                     <style>
@@ -173,6 +175,50 @@
173 175
                                     <property name="top_attach">0</property>
174 176
                                   </packing>
175 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 222
                               </object>
177 223
                             </child>
178 224
                           </object>
@@ -204,6 +250,7 @@
204 250
       <object class="GtkStack" id="header-stack">
205 251
         <property name="visible">True</property>
206 252
         <property name="can_focus">False</property>
253
+        <property name="transition_type">crossfade</property>
207 254
         <child>
208 255
           <object class="GtkHeaderBar" id="header-select">
209 256
             <property name="visible">True</property>

+ 24
- 2
pd-buddy-gtk.py Просмотреть файл

@@ -162,6 +162,7 @@ class Handler:
162 162
         self.serial_port = None
163 163
         self.voltage = None
164 164
         self.current = None
165
+        self.giveback = None
165 166
         self.selectlist = None
166 167
 
167 168
     def on_pdb_window_realize(self, *args):
@@ -183,6 +184,7 @@ class Handler:
183 184
         # Get voltage and current widgets
184 185
         voltage = self.builder.get_object("voltage-combobox")
185 186
         current = self.builder.get_object("current-spinbutton")
187
+        giveback = self.builder.get_object("giveback-toggle")
186 188
 
187 189
         self.serial_port = serport
188 190
 
@@ -195,7 +197,14 @@ class Handler:
195 197
 
196 198
         # Get voltage and current from device and load them into the GUI
197 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 208
                 v = line.split()[1]
200 209
                 if v == b'5.00':
201 210
                     voltage.set_active_id('voltage-five')
@@ -266,21 +275,25 @@ class Handler:
266 275
         # Get voltage and current widgets
267 276
         voltage = self.builder.get_object("voltage-combobox")
268 277
         current = self.builder.get_object("current-spinbutton")
278
+        giveback = self.builder.get_object("giveback-toggle")
269 279
 
270 280
         # Remember the loaded settings
271 281
         self.voltage = voltage.get_active_id()
272 282
         self.current = current.get_value()
283
+        self.giveback = giveback.get_active()
273 284
 
274 285
     def _set_save_button_visibility(self):
275 286
         """Show the save button if there are new settings to save"""
276 287
         # Get relevant widgets
277 288
         voltage = self.builder.get_object("voltage-combobox")
278 289
         current = self.builder.get_object("current-spinbutton")
290
+        giveback = self.builder.get_object("giveback-toggle")
279 291
         rev = self.builder.get_object("header-sink-save-revealer")
280 292
 
281 293
         # Set visibility
282 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 298
     def on_voltage_combobox_changed(self, combo):
286 299
         window = self.builder.get_object("pdb-window")
@@ -304,6 +317,15 @@ class Handler:
304 317
         except:
305 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 329
 class Application(Gtk.Application):
308 330
 
309 331
     def __init__(self, *args, **kwargs):

Загрузка…
Отмена
Сохранить