|
@@ -9,17 +9,6 @@ gi.require_version('Gtk', '3.0')
|
9
|
9
|
from gi.repository import Gtk, Gio, GObject, GLib
|
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
|
|
-
|
23
|
12
|
def pdb_send_message(sp, message):
|
24
|
13
|
"""Send a message over the serial port and return the response"""
|
25
|
14
|
# Open the serial port
|
|
@@ -46,16 +35,6 @@ class ListRowModel(GObject.GObject):
|
46
|
35
|
|
47
|
36
|
class SelectListStore(Gio.ListStore):
|
48
|
37
|
|
49
|
|
- def __init__(self, stack, list_empty, list_frame):
|
50
|
|
- Gio.ListStore.__init__(self)
|
51
|
|
-
|
52
|
|
- self.stack = stack
|
53
|
|
- self.list_empty = list_empty
|
54
|
|
- self.list_frame = list_frame
|
55
|
|
-
|
56
|
|
- self.update_items()
|
57
|
|
- GLib.timeout_add(1000, self.update_items)
|
58
|
|
-
|
59
|
38
|
def update_items(self):
|
60
|
39
|
# Get a list of serial ports
|
61
|
40
|
serports = list(serial.tools.list_ports.grep("1209:0001"))
|
|
@@ -81,38 +60,86 @@ class SelectListStore(Gio.ListStore):
|
81
|
60
|
if port is not None:
|
82
|
61
|
self.append(ListRowModel(port))
|
83
|
62
|
|
|
63
|
+
|
|
64
|
+class SelectList(Gtk.Box):
|
|
65
|
+ __gsignals__ = {
|
|
66
|
+ 'row-activated': (GObject.SIGNAL_RUN_FIRST, None,
|
|
67
|
+ (object,))
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ def __init__(self):
|
|
71
|
+ Gtk.Box.__init__(self)
|
|
72
|
+
|
|
73
|
+ self._model = None
|
|
74
|
+
|
|
75
|
+ self._builder = Gtk.Builder()
|
|
76
|
+ self._builder.add_from_file("data/select-stack.ui")
|
|
77
|
+ self._builder.connect_signals(self)
|
|
78
|
+
|
|
79
|
+ sl = self._builder.get_object("select-list")
|
|
80
|
+
|
|
81
|
+ # Add separators to the list
|
|
82
|
+ sl.set_header_func(self._update_header_func, None)
|
|
83
|
+
|
|
84
|
+ self.pack_start(self._builder.get_object("select-stack"), True, True, 0)
|
|
85
|
+ self.show_all()
|
|
86
|
+
|
|
87
|
+ def _update_header_func(self, row, before, data):
|
|
88
|
+ """Add a separator header to all rows but the first one"""
|
|
89
|
+ if before is None:
|
|
90
|
+ row.set_header(None)
|
|
91
|
+ return
|
|
92
|
+
|
|
93
|
+ current = row.get_header()
|
|
94
|
+ if current is None:
|
|
95
|
+ current = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
|
|
96
|
+ row.set_header(current)
|
|
97
|
+
|
|
98
|
+ def bind_model(self, model, func):
|
|
99
|
+ self._builder.get_object("select-list").bind_model(model, func)
|
|
100
|
+ self._model = model
|
|
101
|
+
|
|
102
|
+ self._reload()
|
|
103
|
+ GLib.timeout_add(1000, self._reload)
|
|
104
|
+
|
|
105
|
+ def _reload(self):
|
|
106
|
+ self._model.update_items()
|
|
107
|
+
|
84
|
108
|
# Set the visible child
|
85
|
|
- # FIXME: This is rather poor organization
|
86
|
|
- if self.get_n_items():
|
87
|
|
- self.stack.set_visible_child(self.list_frame)
|
|
109
|
+ stack = self._builder.get_object("select-stack")
|
|
110
|
+ if self._model.get_n_items():
|
|
111
|
+ stack.set_visible_child(self._builder.get_object("select-frame"))
|
88
|
112
|
else:
|
89
|
|
- self.stack.set_visible_child(self.list_empty)
|
|
113
|
+ stack.set_visible_child(self._builder.get_object("select-none"))
|
90
|
114
|
|
91
|
115
|
return True
|
92
|
116
|
|
|
117
|
+ def on_select_list_row_activated(self, box, row):
|
|
118
|
+ self.emit("row-activated", row.model.serport)
|
|
119
|
+
|
93
|
120
|
|
94
|
121
|
class SelectListRow(Gtk.ListBoxRow):
|
95
|
122
|
|
96
|
|
- def __init__(self, lrm):
|
|
123
|
+ def __init__(self, model):
|
97
|
124
|
Gtk.EventBox.__init__(self)
|
98
|
125
|
|
99
|
|
- self.serial_port = lrm.serport
|
|
126
|
+ self.model = model
|
100
|
127
|
|
101
|
128
|
self._builder = Gtk.Builder()
|
102
|
129
|
self._builder.add_from_file("data/select-list-row.ui")
|
103
|
130
|
self._builder.connect_signals(self)
|
104
|
131
|
|
105
|
132
|
name = self._builder.get_object("name")
|
106
|
|
- name.set_text(self.serial_port.description)
|
|
133
|
+ name.set_text(self.model.serport.description)
|
107
|
134
|
|
108
|
135
|
device = self._builder.get_object("device")
|
109
|
|
- device.set_text(self.serial_port.device)
|
|
136
|
+ device.set_text(self.model.serport.device)
|
110
|
137
|
|
111
|
138
|
self.add(self._builder.get_object("grid"))
|
112
|
139
|
self.show_all()
|
113
|
140
|
|
114
|
141
|
def on_identify_clicked(self, button):
|
115
|
|
- pdb_send_message(self.serial_port, 'identify')
|
|
142
|
+ pdb_send_message(self.model.serport, 'identify')
|
116
|
143
|
|
117
|
144
|
|
118
|
145
|
class Handler:
|
|
@@ -122,27 +149,25 @@ class Handler:
|
122
|
149
|
|
123
|
150
|
def on_pdb_window_realize(self, *args):
|
124
|
151
|
# Get the list
|
125
|
|
- sl = self.builder.get_object("select-list")
|
126
|
|
- ss = self.builder.get_object("select-stack")
|
127
|
|
- se = self.builder.get_object("select-none")
|
128
|
|
- sf = self.builder.get_object("select-frame")
|
|
152
|
+ sb = self.builder.get_object("select-box")
|
|
153
|
+ sl = SelectList()
|
|
154
|
+ sb.pack_start(sl, True, True, 0)
|
129
|
155
|
|
130
|
|
- liststore = SelectListStore(ss, se, sf)
|
|
156
|
+ liststore = SelectListStore()
|
131
|
157
|
|
132
|
158
|
sl.bind_model(liststore, SelectListRow)
|
133
|
159
|
|
134
|
|
- # Add separators to the list
|
135
|
|
- sl.set_header_func(update_header_func, None)
|
|
160
|
+ sl.connect("row-activated", self.on_select_list_row_activated)
|
136
|
161
|
|
137
|
162
|
def on_pdb_window_delete_event(self, *args):
|
138
|
163
|
Gtk.main_quit(*args)
|
139
|
164
|
|
140
|
|
- def on_select_list_row_activated(self, box, row):
|
|
165
|
+ def on_select_list_row_activated(self, selectlist, serport):
|
141
|
166
|
# Get voltage and current widgets
|
142
|
167
|
voltage = self.builder.get_object("voltage-combobox")
|
143
|
168
|
current = self.builder.get_object("current-spinbutton")
|
144
|
169
|
|
145
|
|
- self.serial_port = row.serial_port
|
|
170
|
+ self.serial_port = serport
|
146
|
171
|
|
147
|
172
|
pdb_send_message(self.serial_port, 'load')
|
148
|
173
|
tmpcfg = pdb_send_message(self.serial_port, 'get_tmpcfg')
|
|
@@ -170,7 +195,7 @@ class Handler:
|
170
|
195
|
# Show the Sink page
|
171
|
196
|
hst = self.builder.get_object("header-stack")
|
172
|
197
|
hsink = self.builder.get_object("header-sink")
|
173
|
|
- hsink.set_subtitle(row.serial_port.device)
|
|
198
|
+ hsink.set_subtitle(serport.device)
|
174
|
199
|
hst.set_visible_child(hsink)
|
175
|
200
|
|
176
|
201
|
st = self.builder.get_object("stack")
|