Imported Upstream version 3.2.2
[debian/gnuradio] / gr-wxgui / src / python / histosink_gl.py
1 #
2 # Copyright 2009 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 3, 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 ##################################################
23 # Imports
24 ##################################################
25 import histo_window
26 import common
27 from gnuradio import gr, blks2
28 from pubsub import pubsub
29 from constants import *
30
31 ##################################################
32 # histo sink block (wrapper for old wxgui)
33 ##################################################
34 class histo_sink_f(gr.hier_block2):
35         """
36         A histogram block and a gui window.
37         """
38
39         def __init__(
40                 self,
41                 parent,
42                 size=histo_window.DEFAULT_WIN_SIZE,
43                 title='',
44                 num_bins=11,
45                 frame_size=1000,
46         ):
47                 #init
48                 gr.hier_block2.__init__(
49                         self,
50                         "histo_sink",
51                         gr.io_signature(1, 1, gr.sizeof_float),
52                         gr.io_signature(0, 0, 0),
53                 )
54                 #blocks
55                 msgq = gr.msg_queue(2)
56                 histo = gr.histo_sink_f(msgq)
57                 histo.set_num_bins(num_bins)
58                 histo.set_frame_size(frame_size)
59                 #connect
60                 self.connect(self, histo)
61                 #controller
62                 self.controller = pubsub()
63                 self.controller.subscribe(NUM_BINS_KEY, histo.set_num_bins)
64                 self.controller.publish(NUM_BINS_KEY, histo.get_num_bins)
65                 self.controller.subscribe(FRAME_SIZE_KEY, histo.set_frame_size)
66                 self.controller.publish(FRAME_SIZE_KEY, histo.get_frame_size)
67                 #start input watcher
68                 common.input_watcher(msgq, self.controller, MSG_KEY, arg1_key=MINIMUM_KEY, arg2_key=MAXIMUM_KEY)
69                 #create window
70                 self.win = histo_window.histo_window(
71                         parent=parent,
72                         controller=self.controller,
73                         size=size,
74                         title=title,
75                         maximum_key=MAXIMUM_KEY,
76                         minimum_key=MINIMUM_KEY,
77                         num_bins_key=NUM_BINS_KEY,
78                         frame_size_key=FRAME_SIZE_KEY,
79                         msg_key=MSG_KEY,
80                 )
81                 common.register_access_methods(self, self.win)
82
83 # ----------------------------------------------------------------
84 # Standalone test app
85 # ----------------------------------------------------------------
86
87 import wx
88 from gnuradio.wxgui import stdgui2
89
90 class test_app_block (stdgui2.std_top_block):
91     def __init__(self, frame, panel, vbox, argv):
92         stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)
93
94         # build our flow graph
95         input_rate = 20.48e3
96
97         src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
98         #src2 = gr.sig_source_f (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1)
99         thr2 = gr.throttle(gr.sizeof_float, input_rate)
100         sink2 = histo_sink_f (panel, title="Data", num_bins=31, frame_size=1000)
101         vbox.Add (sink2.win, 1, wx.EXPAND)
102
103         self.connect(src2, thr2, sink2)
104
105 def main ():
106     app = stdgui2.stdapp (test_app_block, "Histo Sink Test App")
107     app.MainLoop ()
108
109 if __name__ == '__main__':
110     main ()