1 # Copyright 2008, 2009 Free Software Foundation, Inc.
3 # This file is part of GNU Radio
5 # GNU Radio is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3, or (at your option)
10 # GNU Radio is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with GNU Radio; see the file COPYING. If not, write to
17 # the Free Software Foundation, Inc., 51 Franklin Street,
18 # Boston, MA 02110-1301, USA.
22 from gnuradio import gr
25 default_gui_size = (200, 100)
27 class top_block_gui(gr.top_block):
28 """gr top block with wx gui app and grid sizer."""
30 def __init__(self, title='', size=default_gui_size):
32 Initialize the gr top block.
33 Create the wx gui elements.
34 @param title the main window title
35 @param size the main window size tuple in pixels
36 @param icon the file path to an icon or None
39 gr.top_block.__init__(self)
43 self._frame = wx.Frame(None, title=title)
44 self._panel = panel.Panel(self._frame)
45 self.Add = self._panel.Add
46 self.GridAdd = self._panel.GridAdd
47 self.GetWin = self._panel.GetWin
49 def SetIcon(self, *args, **kwargs): self._frame.SetIcon(*args, **kwargs)
51 def Run(self, start=True):
53 Setup the wx gui elements.
54 Start the gr top block.
55 Block with the wx main loop.
57 #set minimal window size
58 self._frame.SetSizeHints(*self._size)
59 #create callback for quit
61 self.stop(); self.wait()
64 self._frame.Bind(wx.EVT_CLOSE, _quit)
65 self._sizer = wx.BoxSizer(wx.VERTICAL)
66 self._sizer.Add(self._panel, 0, wx.EXPAND)
67 self._frame.SetSizerAndFit(self._sizer)
68 self._frame.SetAutoLayout(True)
69 self._frame.Show(True)
70 self._app.SetTopWindow(self._frame)
72 if start: self.start()