Selaa lähdekoodia

A bit of cleanup

Clara Hobbs 7 vuotta sitten
vanhempi
commit
92f9b8059c
1 muutettua tiedostoa jossa 25 lisäystä ja 24 poistoa
  1. 25
    24
      pd-buddy-gtk.py

+ 25
- 24
pd-buddy-gtk.py Näytä tiedosto

9
 from gi.repository import Gtk
9
 from gi.repository import Gtk
10
 
10
 
11
 
11
 
12
+def update_header_func(row, before, data):
13
+    """Add a separator header to all rows but the first one"""
14
+    if before is None:
15
+        row.set_header(None)
16
+        return
17
+
18
+    current = row.get_header()
19
+    if current is None:
20
+        current = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
21
+        row.set_header(current)
22
+
12
 def pdb_send_message(sp, message):
23
 def pdb_send_message(sp, message):
13
-        # Open the serial port
14
-        # FIXME handle exceptions
15
-        sp = serial.Serial(sp.device, baudrate=115200, timeout=0.01)
24
+    """Send a message over the serial port and return the response"""
25
+    # Open the serial port
26
+    # FIXME handle exceptions
27
+    sp = serial.Serial(sp.device, baudrate=115200, timeout=0.01)
28
+
29
+    sp.write(bytes(message, 'utf-8') + b'\r\n')
30
+    sp.flush()
31
+    answer = sp.readlines()
16
 
32
 
17
-        sp.write(bytes(message, 'utf-8') + b'\r\n')
18
-        sp.flush()
19
-        answer = sp.readlines()
33
+    sp.close()
20
 
34
 
21
-        sp.close()
35
+    # Remove the echoed command and prompt
36
+    answer = answer[1:-1]
37
+    return answer
22
 
38
 
23
-        # Remove the echoed command and prompt
24
-        answer = answer[1:-1]
25
-        return answer
26
 
39
 
27
 class SelectListRow(Gtk.ListBoxRow):
40
 class SelectListRow(Gtk.ListBoxRow):
28
 
41
 
65
             ss.set_visible_child(sf)
78
             ss.set_visible_child(sf)
66
             sl.insert(SelectListRow(serport), -1)
79
             sl.insert(SelectListRow(serport), -1)
67
 
80
 
68
-        def update_header_func(row, before, data):
69
-            """Add a separator header to all rows but the first one"""
70
-            if before is None:
71
-                row.set_header(None)
72
-                return
73
-
74
-            current = row.get_header()
75
-            if current is None:
76
-                current = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
77
-                current.show()
78
-                row.set_header(current)
79
-
80
         # Add separators to the list
81
         # Add separators to the list
81
         sl.set_header_func(update_header_func, None)
82
         sl.set_header_func(update_header_func, None)
82
 
83
 
91
         self.serial_port = row.serial_port
92
         self.serial_port = row.serial_port
92
 
93
 
93
         pdb_send_message(self.serial_port, 'load')
94
         pdb_send_message(self.serial_port, 'load')
94
-        lines = pdb_send_message(self.serial_port, 'get_tmpcfg')
95
+        tmpcfg = pdb_send_message(self.serial_port, 'get_tmpcfg')
95
 
96
 
96
         # Get information
97
         # Get information
97
-        for line in lines:
98
+        for line in tmpcfg:
98
             if line.startswith(b'v:'):
99
             if line.startswith(b'v:'):
99
                 v = line.split()[1]
100
                 v = line.split()[1]
100
                 if v == b'5.00':
101
                 if v == b'5.00':

Loading…
Peruuta
Tallenna