switch source package format to 3.0 quilt
[debian/gnuradio] / grc / grc_gnuradio / wxgui / top_block_gui.py
1 # Copyright 2008, 2009 Free Software Foundation, Inc.
2 #
3 # This file is part of GNU Radio
4 #
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)
8 # any later version.
9 #
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.
14 #
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.
19 #
20
21 import wx
22 from gnuradio import gr
23 import panel
24
25 default_gui_size = (200, 100)
26
27 class top_block_gui(gr.top_block):
28         """gr top block with wx gui app and grid sizer."""
29
30         def __init__(self, title='', size=default_gui_size):
31                 """
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
37                 """
38                 #initialize
39                 gr.top_block.__init__(self)
40                 self._size = size
41                 #create gui elements
42                 self._app = wx.App()
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
48
49         def SetIcon(self, *args, **kwargs): self._frame.SetIcon(*args, **kwargs)
50
51         def Run(self, start=True):
52                 """
53                 Setup the wx gui elements.
54                 Start the gr top block.
55                 Block with the wx main loop.
56                 """
57                 #set minimal window size
58                 self._frame.SetSizeHints(*self._size)
59                 #create callback for quit
60                 def _quit(event):
61                         self.stop(); self.wait()
62                         self._frame.Destroy()
63                 #setup app
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)
71                 #start flow graph
72                 if start: self.start()
73                 #blocking main loop
74                 self._app.MainLoop()