From 6565f75487aefa54a59666b4a173908b890b1004 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Sun, 23 Apr 2017 22:52:14 +0200 Subject: [PATCH] Import WX gain panel block Signed-off-by: Sylvain Munaut --- grc/CMakeLists.txt | 1 + grc/wx_gain_panel.xml | 34 +++++++++++++++ python/CMakeLists.txt | 1 + python/__init__.py | 4 +- python/wx_gain_panel.py | 92 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 grc/wx_gain_panel.xml create mode 100644 python/wx_gain_panel.py diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 09838c1..427fd9a 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -40,6 +40,7 @@ add_custom_target(osmosdr_grc_xml_blocks ALL DEPENDS ${xml_blocks}) install(FILES ${xml_blocks} + wx_gain_panel.xml # DESTINATION ${GRC_BLOCKS_DIR} DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/wx_gain_panel.xml b/grc/wx_gain_panel.xml new file mode 100644 index 0000000..e2e7d68 --- /dev/null +++ b/grc/wx_gain_panel.xml @@ -0,0 +1,34 @@ + + + WX Osmocom Sink/Source Gain Panel + osmosdr_wx_gain_panel + import osmosdr + #set $parent = $notebook() and 'self.%s.GetPage(%s)'%$notebook() or 'self' +#set $win = '_%s_gain_panel'%$id +$win = osmosdr.wx_gain_panel($(parent).GetWin(), self.$osmoobj) +#if not $grid_pos() +$(parent).Add($win) +#else +$(parent).GridAdd($win, $(', '.join(map(str, $grid_pos())))) +#end if + + Osmocom Sink/Source object + osmoobj + id + + + Grid Position + grid_pos + + grid_pos + + + Notebook + notebook + + notebook + + +WRITE DOC ! + + diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 8841f36..4fe015d 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -31,6 +31,7 @@ endif() GR_PYTHON_INSTALL( FILES __init__.py + wx_gain_panel.py DESTINATION ${GR_PYTHON_DIR}/osmosdr ) diff --git a/python/__init__.py b/python/__init__.py index c7310e1..af2604b 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -25,5 +25,5 @@ This is the GNU Radio OsmoSDR module. # import swig generated symbols into the osmosdr namespace from osmosdr_swig import * -# import any pure python here -# +# import pure python here +from .wx_gain_panel import wx_gain_panel diff --git a/python/wx_gain_panel.py b/python/wx_gain_panel.py new file mode 100644 index 0000000..e76d653 --- /dev/null +++ b/python/wx_gain_panel.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import wx + +from gnuradio.gr.pubsub import pubsub +from gnuradio.wxgui import forms + + +GAIN_KEY = lambda x: 'gain:'+x + + +class wx_gain_panel(forms.static_box_sizer, pubsub): + + def __init__(self, parent, cobj, chan=0): + # Super init + pubsub.__init__(self) + forms.static_box_sizer.__init__(self, + parent = parent, + label = "Gain Settings", + orient = wx.VERTICAL, + bold = True, + ) + + # Save params + self.parent = parent + self.cobj = cobj + self.chan = 0 + + # Init gui + self._init_gui() + + def _init_gui(self): + # Top spacer + self.AddSpacer(3); + + # Space each gain + for g_name in self.cobj.get_gain_names(self.chan): + # Get range + g_range = self.cobj.get_gain_range(g_name, self.chan) + + # Skip invalid/non-configurable ones + if g_range.stop() <= g_range.start(): + continue + + # Current value + self[GAIN_KEY(g_name)] = self.cobj.get_gain(g_name, self.chan) + + # Subscribe + self.subscribe( + GAIN_KEY(g_name), + lambda gain,name=g_name,self=self: self.set_named_gain(name, gain) + ) + + # Create UI + g_hbox = wx.BoxSizer(wx.HORIZONTAL) + self.Add(g_hbox, 0, wx.EXPAND) + self.AddSpacer(3) + + g_hbox.AddSpacer(3) + forms.text_box( + parent = self.parent, + sizer = g_hbox, + proportion = 0, + converter = forms.float_converter(), + ps = self, + key = GAIN_KEY(g_name), + label = g_name + " Gain (dB)", + ) + g_hbox.AddSpacer(3) + forms.slider( + parent = self.parent, + sizer = g_hbox, + proportion = 1, + ps = self, + key = GAIN_KEY(g_name), + minimum = g_range.start(), + maximum = g_range.stop(), + step_size = g_range.step() or (g_range.stop() - g_range.start()) / 10.0, + ) + g_hbox.AddSpacer(3) + + def set_named_gain(self, name, gain): + if gain is None: + g_range = self.cobj.get_gain_range(name, self.chan) + self[GAIN_KEY(name)] = (g_range.start() + g_range.stop()) / 2.0 + else: + cur_gain = self.cobj.get_gain(name, self.chan) + if cur_gain != gain: + print "%s %f %f" % (name, cur_gain, gain) + self[GAIN_KEY(name)] = self.cobj.set_gain(gain, name, self.chan) +