Imported Upstream version 3.0
[debian/gnuradio] / gr-wxgui / src / python / stdgui.py
1 #
2 # Copyright 2004 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
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 2, or (at your option)
9 # any later version.
10
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.
15
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.
20
21
22 '''A simple wx gui for GNU Radio applications'''
23
24 import wx
25 import sys
26 from gnuradio import gr
27
28
29 class stdapp (wx.App):
30     def __init__ (self, flow_graph_maker, title="GNU Radio", nstatus=2):
31         self.flow_graph_maker = flow_graph_maker
32         self.title = title
33         self._nstatus = nstatus
34         # All our initialization must come before calling wx.App.__init__.
35         # OnInit is called from somewhere in the guts of __init__.
36         wx.App.__init__ (self, redirect=False)
37
38     def OnInit (self):
39         frame = stdframe (self.flow_graph_maker, self.title, self._nstatus)
40         frame.Show (True)
41         self.SetTopWindow (frame)
42         return True
43
44
45 class stdframe (wx.Frame):
46     def __init__ (self, flow_graph_maker, title="GNU Radio", nstatus=2):
47         # print "stdframe.__init__"
48         wx.Frame.__init__(self, None, -1, title)
49
50         self.CreateStatusBar (nstatus)
51         mainmenu = wx.MenuBar ()
52
53         menu = wx.Menu ()
54         item = menu.Append (200, 'E&xit', 'Exit')
55         self.Bind (wx.EVT_MENU, self.OnCloseWindow, item)
56         mainmenu.Append (menu, "&File")
57         self.SetMenuBar (mainmenu)
58
59         self.Bind (wx.EVT_CLOSE, self.OnCloseWindow)
60         self.panel = stdpanel (self, self, flow_graph_maker)
61         vbox = wx.BoxSizer(wx.VERTICAL)
62         vbox.Add(self.panel, 1, wx.EXPAND)
63         self.SetSizer(vbox)
64         self.SetAutoLayout(True)
65         vbox.Fit(self)
66
67     def OnCloseWindow (self, event):
68         self.flow_graph().stop()
69         self.Destroy ()
70
71     def flow_graph (self):
72         return self.panel.fg
73     
74 class stdpanel (wx.Panel):
75     def __init__ (self, parent, frame, flow_graph_maker):
76         # print "stdpanel.__init__"
77         wx.Panel.__init__ (self, parent, -1)
78         self.frame = frame
79
80         vbox = wx.BoxSizer (wx.VERTICAL)
81         self.fg = flow_graph_maker (frame, self, vbox, sys.argv)
82         self.SetSizer (vbox)
83         self.SetAutoLayout (True)
84         vbox.Fit (self)
85
86         self.fg.start ()
87
88 class gui_flow_graph (gr.flow_graph):
89     def __init__ (self, *ignore):
90         gr.flow_graph.__init__ (self)