|
@@ -57,12 +57,29 @@ class SelectListStore(Gio.ListStore):
|
57
|
57
|
GLib.timeout_add(1000, self.update_items)
|
58
|
58
|
|
59
|
59
|
def update_items(self):
|
60
|
|
- # Clear the old entries
|
61
|
|
- self.remove_all()
|
62
|
|
-
|
63
|
|
- # Search for the serial ports
|
64
|
|
- for serport in serial.tools.list_ports.grep("1209:0001"):
|
65
|
|
- self.append(ListRowModel(serport))
|
|
60
|
+ # Get a list of serial ports
|
|
61
|
+ serports = list(serial.tools.list_ports.grep("1209:0001"))
|
|
62
|
+
|
|
63
|
+ # Mark ports to remove or add
|
|
64
|
+ remove_list = []
|
|
65
|
+ list_len = self.get_n_items()
|
|
66
|
+ for i in range(list_len):
|
|
67
|
+ remove = True
|
|
68
|
+ for j in range(len(serports)):
|
|
69
|
+ if serports[j] is not None and self.get_item(i).serport == serports[j]:
|
|
70
|
+ serports[j] = None
|
|
71
|
+ remove = False
|
|
72
|
+ if remove:
|
|
73
|
+ remove_list.append(i)
|
|
74
|
+
|
|
75
|
+ # Remove the missing ones
|
|
76
|
+ for i in remove_list:
|
|
77
|
+ self.remove(i)
|
|
78
|
+
|
|
79
|
+ # Add any new ports
|
|
80
|
+ for port in serports:
|
|
81
|
+ if port is not None:
|
|
82
|
+ self.append(ListRowModel(port))
|
66
|
83
|
|
67
|
84
|
# Set the visible child
|
68
|
85
|
# FIXME: This is rather poor organization
|