2 # Copyright 2009 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
23 from gnuradio import gr
26 # Top-level display panel with vertical box sizer. User does not create or
27 # subclass this class; rather, the user supplies his own class constructor
28 # that gets invoked with needed parameters.
30 class top_panel(wx.Panel):
31 def __init__(self, frame, top_block, gui, options, args):
32 wx.Panel.__init__(self, frame, -1)
33 vbox = wx.BoxSizer(wx.VERTICAL)
35 # Create the user's GUI class
37 self.gui = gui(frame, # Top-level window frame
38 self, # Parent class for user created windows
39 vbox, # Sizer for user to add windows to
40 top_block, # GUI-unaware flowgraph to manipulate
41 options, # Command-line options
42 args) # Command-line arguments
45 # User hasn't made their own GUI, create our default
46 # We don't have a default GUI yet either :)
49 vbox.Add(p, 1, wx.EXPAND)
52 self.SetAutoLayout(True)
58 except AttributeError:
62 # Top-level window frame with menu and status bars.
64 class top_frame(wx.Frame):
65 def __init__ (self, top_block, gui, options, args,
66 title, nstatus, start, realtime):
68 wx.Frame.__init__(self, None, -1, title)
69 self.top_block = top_block
71 self.CreateStatusBar(nstatus)
72 mainmenu = wx.MenuBar()
73 self.SetMenuBar(mainmenu)
77 item = menu.Append(200, 'E&xit', 'Exit Application') # FIXME magic ID
78 self.Bind(wx.EVT_MENU, self.OnCloseWindow, item)
79 mainmenu.Append(menu, "&File")
80 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
82 # Create main panel, creates user GUI class with supplied parameters
83 self.panel = top_panel(self, top_block, gui, options, args)
85 vbox = wx.BoxSizer(wx.VERTICAL)
86 vbox.Add(self.panel, 1, wx.EXPAND)
88 self.SetAutoLayout(True)
92 if gr.enable_realtime_scheduling() != gr.RT_OK:
93 self.SetStatusText("Failed to enable realtime scheduling")
95 if start and self.top_block is not None:
96 self.top_block.start()
98 def OnCloseWindow(self, event):
99 # Give user API a chance to do something
100 self.panel.shutdown()
102 # Stop flowgraph as a convenience
103 self.SetStatusText("Ensuring flowgraph has completed before exiting...")
104 if self.top_block is not None:
105 self.top_block.stop()
106 self.top_block.wait()
112 # Top-level wxPython application object. User creates or subclasses this
113 # in their GUI script.
116 def __init__ (self, top_block=None, gui=None, options=None, args=None,
117 title="GNU Radio", nstatus=1, start=False, realtime=False):
118 self.top_block = top_block
120 self.options = options
123 self.nstatus = nstatus
125 self.realtime = realtime
127 wx.App.__init__ (self, redirect=False)
130 # Pass user parameters to top window frame
131 frame = top_frame(self.top_block, self.gui, self.options, self.args,
132 self.title, self.nstatus, self.start, self.realtime)
134 self.SetTopWindow(frame)