Skip to content

Commit 40d929c

Browse files
committed
checklist: added scrollbar for long lists
1 parent f82fc33 commit 40d929c

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

MAVProxy/modules/lib/mp_checklist.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ChecklistFrame(wx.Frame):
6565

6666
def __init__(self, state, title):
6767
self.state = state
68-
wx.Frame.__init__(self, None, title=title, size=(600,600), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)
68+
wx.Frame.__init__(self, None, title=title, size=(600,600), style=wx.DEFAULT_FRAME_STYLE)
6969

7070
#use tabs for the individual checklists
7171
self.createLists()
@@ -77,7 +77,6 @@ def __init__(self, state, title):
7777

7878
#add in the pipe from MAVProxy
7979
self.timer = wx.Timer(self)
80-
#self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
8180
self.Bind(wx.EVT_TIMER, lambda evt, notebook=self.nb: self.on_timer(evt, notebook), self.timer)
8281
self.timer.Start(100)
8382

@@ -137,34 +136,52 @@ def createWidgets(self):
137136
#create the panels for the tabs
138137

139138
for name in self.lists.keys():
139+
# Create the panel for this tab
140140
panel = wx.Panel(self.nb)
141+
142+
# Create a scrolled window within the panel
143+
scrolled_window = wx.ScrolledWindow(panel, wx.ID_ANY, style=wx.VSCROLL)
144+
scrolled_window.SetScrollRate(0, 10)
145+
146+
# Create a vertical box sizer for the scrolled window
141147
box = wx.BoxSizer(wx.VERTICAL)
142-
panel.SetAutoLayout(True)
143-
panel.SetSizer(box)
148+
scrolled_window.SetSizer(box)
144149

150+
# Add each checkbox to the scrolled window
145151
for key in self.lists[name]:
146-
CheckBox = wx.CheckBox(panel, wx.ID_ANY, key)
147-
box.Add(CheckBox)
148-
149-
panel.Layout()
152+
CheckBox = wx.CheckBox(scrolled_window, wx.ID_ANY, key)
153+
box.Add(CheckBox, 0, wx.ALL, 5)
154+
155+
# Create a sizer for the panel and add the scrolled window to it
156+
panel_sizer = wx.BoxSizer(wx.VERTICAL)
157+
panel_sizer.Add(scrolled_window, 1, wx.EXPAND|wx.ALL, 0)
158+
panel.SetSizer(panel_sizer)
159+
160+
# Add the panel to the notebook
150161
self.nb.AddPage(panel, name)
151162

152163
#Receive messages from MAVProxy and process them
153164
def on_timer(self, event, notebook):
154165
state = self.state
155-
win = notebook.GetPage(notebook.GetSelection())
166+
page = notebook.GetPage(notebook.GetSelection())
167+
156168
if state.close_event.wait(0.001):
157169
self.timer.Stop()
158170
self.Destroy()
159171
return
172+
160173
while state.child_pipe.poll():
161174
obj = state.child_pipe.recv()
162175
if isinstance(obj, CheckItem):
163-
#go through each item in the current tab and (un)check as needed
164-
#print(obj.name + ", " + str(obj.state))
165-
for widget in win.GetChildren():
166-
if type(widget) is wx.CheckBox and widget.GetLabel() == obj.name:
167-
widget.SetValue(obj.state)
176+
# Find the scrolled window which is the first child of the page
177+
for child in page.GetChildren():
178+
if isinstance(child, wx.ScrolledWindow):
179+
scrolled_window = child
180+
# Go through each item in the current tab and (un)check as needed
181+
for widget in scrolled_window.GetChildren():
182+
if isinstance(widget, wx.CheckBox) and widget.GetLabel() == obj.name:
183+
widget.SetValue(obj.state)
184+
break
168185

169186

170187
if __name__ == "__main__":

0 commit comments

Comments
 (0)