summaryrefslogtreecommitdiff
path: root/gr-wxgui/src/python/histosink_gl.py
blob: 509f746be68a9e763c0d6c6f6ac83e073546d39d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#
# Copyright 2009 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#

##################################################
# Imports
##################################################
import histo_window
import common
from gnuradio import gr, blks2
from pubsub import pubsub
from constants import *

##################################################
# histo sink block (wrapper for old wxgui)
##################################################
class histo_sink_f(gr.hier_block2, common.wxgui_hb):
	"""
	A histogram block and a gui window.
	"""

	def __init__(
		self,
		parent,
		size=histo_window.DEFAULT_WIN_SIZE,
		title='',
		num_bins=11,
		frame_size=1000,
	):
		#init
		gr.hier_block2.__init__(
			self,
			"histo_sink",
			gr.io_signature(1, 1, gr.sizeof_float),
			gr.io_signature(0, 0, 0),
		)
		#blocks
		msgq = gr.msg_queue(2)
		histo = gr.histo_sink_f(msgq)
		histo.set_num_bins(num_bins)
		histo.set_frame_size(frame_size)
		#controller
		self.controller = pubsub()
		self.controller.subscribe(NUM_BINS_KEY, histo.set_num_bins)
		self.controller.publish(NUM_BINS_KEY, histo.get_num_bins)
		self.controller.subscribe(FRAME_SIZE_KEY, histo.set_frame_size)
		self.controller.publish(FRAME_SIZE_KEY, histo.get_frame_size)
		#start input watcher
		common.input_watcher(msgq, self.controller, MSG_KEY, arg1_key=MINIMUM_KEY, arg2_key=MAXIMUM_KEY)
		#create window
		self.win = histo_window.histo_window(
			parent=parent,
			controller=self.controller,
			size=size,
			title=title,
			maximum_key=MAXIMUM_KEY,
			minimum_key=MINIMUM_KEY,
			num_bins_key=NUM_BINS_KEY,
			frame_size_key=FRAME_SIZE_KEY,
			msg_key=MSG_KEY,
		)
		common.register_access_methods(self, self.win)
		#connect
		self.wxgui_connect(self, histo)

# ----------------------------------------------------------------
# Standalone test app
# ----------------------------------------------------------------

import wx
from gnuradio.wxgui import stdgui2

class test_app_block (stdgui2.std_top_block):
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)

        # build our flow graph
        input_rate = 20.48e3

        src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2e3, 1)
        #src2 = gr.sig_source_f (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1)
        thr2 = gr.throttle(gr.sizeof_float, input_rate)
        sink2 = histo_sink_f (panel, title="Data", num_bins=31, frame_size=1000)
        vbox.Add (sink2.win, 1, wx.EXPAND)

        self.connect(src2, thr2, sink2)

def main ():
    app = stdgui2.stdapp (test_app_block, "Histo Sink Test App")
    app.MainLoop ()

if __name__ == '__main__':
    main ()