forked from sdr/gr-osmosdr
Import WX gain panel block
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
parent
cf9549485a
commit
6565f75487
|
@ -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
|
||||
)
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
<block>
|
||||
<name>WX Osmocom Sink/Source Gain Panel</name>
|
||||
<key>osmosdr_wx_gain_panel</key>
|
||||
<import>import osmosdr</import>
|
||||
<make>#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</make>
|
||||
<param>
|
||||
<name>Osmocom Sink/Source object</name>
|
||||
<key>osmoobj</key>
|
||||
<type>id</type>
|
||||
</param>
|
||||
<param>
|
||||
<name>Grid Position</name>
|
||||
<key>grid_pos</key>
|
||||
<value></value>
|
||||
<type>grid_pos</type>
|
||||
</param>
|
||||
<param>
|
||||
<name>Notebook</name>
|
||||
<key>notebook</key>
|
||||
<value></value>
|
||||
<type>notebook</type>
|
||||
</param>
|
||||
<doc>
|
||||
WRITE DOC !
|
||||
</doc>
|
||||
</block>
|
|
@ -31,6 +31,7 @@ endif()
|
|||
GR_PYTHON_INSTALL(
|
||||
FILES
|
||||
__init__.py
|
||||
wx_gain_panel.py
|
||||
DESTINATION ${GR_PYTHON_DIR}/osmosdr
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
Loading…
Reference in New Issue