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.
22 ##################################################
24 ##################################################
31 from constants import *
32 from gnuradio import gr #for gr.prefs
35 ##################################################
37 ##################################################
38 DEFAULT_WIN_SIZE = (600, 300)
40 ##################################################
41 # histo window control panel
42 ##################################################
43 class control_panel(wx.Panel):
45 A control panel with wx widgits to control the plotter and histo sink.
48 def __init__(self, parent):
50 Create a new control panel.
51 @param parent the wx parent window
54 wx.Panel.__init__(self, parent, style=wx.SUNKEN_BORDER)
55 parent[SHOW_CONTROL_PANEL_KEY] = True
56 parent.subscribe(SHOW_CONTROL_PANEL_KEY, self.Show)
57 control_box = wx.BoxSizer(wx.VERTICAL)
59 control_box = forms.static_box_sizer(
60 parent=self, label='Options',
61 bold=True, orient=wx.VERTICAL,
64 control_box.AddStretchSpacer()
66 sizer=control_box, parent=self, label='Num Bins',
67 converter=forms.int_converter(),
68 ps=parent, key=NUM_BINS_KEY,
71 control_box.AddStretchSpacer()
73 sizer=control_box, parent=self, label='Frame Size',
74 converter=forms.int_converter(),
75 ps=parent, key=FRAME_SIZE_KEY,
78 control_box.AddStretchSpacer()
80 sizer=control_box, parent=self,
81 true_label='Stop', false_label='Run',
82 ps=parent, key=RUNNING_KEY,
85 self.SetSizerAndFit(control_box)
87 ##################################################
88 # histo window with plotter and control panel
89 ##################################################
90 class histo_window(wx.Panel, pubsub.pubsub):
103 pubsub.pubsub.__init__(self)
105 self.samples = list()
107 self.proxy(MAXIMUM_KEY, controller, maximum_key)
108 self.proxy(MINIMUM_KEY, controller, minimum_key)
109 self.proxy(NUM_BINS_KEY, controller, num_bins_key)
110 self.proxy(FRAME_SIZE_KEY, controller, frame_size_key)
111 self.proxy(MSG_KEY, controller, msg_key)
113 self[RUNNING_KEY] = True
117 wx.Panel.__init__(self, parent, style=wx.SIMPLE_BORDER)
118 self.plotter = plotter.bar_plotter(self)
119 self.plotter.SetSize(wx.Size(*size))
120 self.plotter.set_title(title)
121 self.plotter.enable_point_label(True)
122 self.plotter.enable_grid_lines(False)
123 #setup the box with plot and controls
124 self.control_panel = control_panel(self)
125 main_box = wx.BoxSizer(wx.HORIZONTAL)
126 main_box.Add(self.plotter, 1, wx.EXPAND)
127 main_box.Add(self.control_panel, 0, wx.EXPAND)
128 self.SetSizerAndFit(main_box)
130 self.subscribe(MSG_KEY, self.handle_msg)
131 self.subscribe(X_DIVS_KEY, self.update_grid)
132 self.subscribe(Y_DIVS_KEY, self.update_grid)
134 def handle_msg(self, msg):
136 Handle the message from the fft sink message queue.
137 @param msg the frame as a character array
139 if not self[RUNNING_KEY]: return
140 #convert to floating point numbers
141 self.samples = 100*numpy.fromstring(msg, numpy.float32)[:self[NUM_BINS_KEY]] #only take first frame
142 self.plotter.set_bars(
145 color_spec=(0, 0, 1),
149 def update_grid(self):
150 if not len(self.samples): return
151 #calculate the maximum y value
152 y_off = math.ceil(numpy.max(self.samples))
153 y_off = min(max(y_off, 1.0), 100.0) #between 1% and 100%
155 self.plotter.set_x_grid(
156 self[MINIMUM_KEY], self[MAXIMUM_KEY],
157 common.get_clean_num((self[MAXIMUM_KEY] - self[MINIMUM_KEY])/self[X_DIVS_KEY]),
159 self.plotter.set_x_label('Counts')
161 self.plotter.set_y_grid(0, y_off, y_off/self[Y_DIVS_KEY])
162 self.plotter.set_y_label('Frequency', '%')
163 self.plotter.update()