Fwd: Re:

Matt Jones matt.walker.jones at gmail.com
Thu Feb 14 15:00:02 EST 2013


Sending back to the maillist

*Matt Jones*


---------- Forwarded message ----------
From: <md123 at nycap.rr.com>
Date: Thu, Feb 14, 2013 at 1:42 PM
Subject: Re: Re:
To: Matt Jones <matt.walker.jones at gmail.com>


thanks for replying Matt.  I am using version 2.7.3.  im not sure  if this
is right but here is the code from
"/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py"



# Copyright 2006,2007 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.
#

from gnuradio_core import hier_block2_swig
try:
    import pmt
except ImportError:
    from gruel import pmt

#
# This hack forces a 'has-a' relationship to look like an 'is-a' one.
#
# It allows Python classes to subclass this one, while passing through
# method calls to the C++ class shared pointer from SWIG.
#
# It also allows us to intercept method calls if needed
#
class hier_block2(object):
    """
    Python wrapper around the C++ hierarchical block implementation.
    Provides convenience functions and allows proper Python subclassing.
    """

    def __init__(self, name, input_signature, output_signature):
        """
        Create a hierarchical block with a given name and I/O signatures.
        """
        self._hb = hier_block2_swig(name, input_signature, output_signature)

    def __getattr__(self, name):
        """
        Pass-through member requests to the C++ object.
        """
        if not hasattr(self, "_hb"):
            raise RuntimeError("hier_block2: invalid state--did you forget
to call gr.hier_block2.__init__ in a derived class?")
        return getattr(self._hb, name)

    def connect(self, *points):
        """
        Connect two or more block endpoints.  An endpoint is either a
(block, port)
        tuple or a block instance.  In the latter case, the port number is
assumed
        to be zero.

        To connect the hierarchical block external inputs or outputs to
internal block
        inputs or outputs, use 'self' in the connect call.

        If multiple arguments are provided, connect will attempt to wire
them in series,
        interpreting the endpoints as inputs or outputs as appropriate.
        """

        if len (points) < 1:
            raise ValueError, ("connect requires at least one endpoint; %d
provided." % (len (points),))
        else:
            if len(points) == 1:
                self._hb.primitive_connect(points[0].to_basic_block())
            else:
                for i in range (1, len (points)):
                    self._connect(points[i-1], points[i])

    def _connect(self, src, dst):
        (src_block, src_port) = self._coerce_endpoint(src)
        (dst_block, dst_port) = self._coerce_endpoint(dst)
        self._hb.primitive_connect(src_block.to_basic_block(), src_port,
                                   dst_block.to_basic_block(), dst_port)

    def _coerce_endpoint(self, endp):
        if hasattr(endp, 'to_basic_block'):
            return (endp, 0)
        else:
            if hasattr(endp, "__getitem__") and len(endp) == 2:
                return endp # Assume user put (block, port)
            else:
                raise ValueError("unable to coerce endpoint")

    def disconnect(self, *points):
        """
        Disconnect two endpoints in the flowgraph.

        To disconnect the hierarchical block external inputs or outputs to
internal block
        inputs or outputs, use 'self' in the connect call.

        If more than two arguments are provided, they are disconnected
successively.
        """

        if len (points) < 1:
            raise ValueError, ("disconnect requires at least one endpoint;
%d provided." % (len (points),))
        else:
            if len (points) == 1:
                self._hb.primitive_disconnect(points[0].to_basic_block())
            else:
                for i in range (1, len (points)):
                    self._disconnect(points[i-1], points[i])

    def _disconnect(self, src, dst):
        (src_block, src_port) = self._coerce_endpoint(src)
        (dst_block, dst_port) = self._coerce_endpoint(dst)
        self._hb.primitive_disconnect(src_block.to_basic_block(), src_port,
                                      dst_block.to_basic_block(), dst_port)

    def msg_connect(self, src, srcport, dst, dstport):
        self.primitive_msg_connect(src.to_basic_block(), srcport,
dst.to_basic_block(), dstport);

    def msg_disconnect(self, src, srcport, dst, dstport):
        self.primitive_msg_disconnect(src.to_basic_block(), srcport,
dst.to_basic_block(), dstport);

    def message_port_register_hier_in(self, portname):

self.primitive_message_port_register_hier_in(pmt.pmt_intern(portname));

    def message_port_register_hier_out(self, portname):

self.primitive_message_port_register_hier_out(pmt.pmt_intern(portname));


Thank you very much!
----------------------------------------------------------------------------------------

---- Matt Jones <matt.walker.jones at gmail.com> wrote:
> Please post the code, or a link to the code...
>
> Also, what version of python are you running this code over?
>
> *Matt Jones*
>
>
> On Thu, Feb 14, 2013 at 12:26 PM, <md123 at nycap.rr.com> wrote:
>
> >   using ubuntu 12.10 i am trying to run a python block, namely OP25, in
> > GNU Radio Companion v3.6.3-35-g4435082f. i get the following error:
> >
> > Executing: "/home/matt/op25_grc.py"
> >
> > Imported legacy fsk4
> > Using Volk machine: ssse3_32
> > Traceback (most recent call last):
> > File "/home/matt/op25_grc.py", line 493, in <module>
> > tb = op25_grc()
> > File "/home/matt/op25_grc.py", line 231, in __init__
> > self.wxgui_fftsink2_0_0.set_callback(wxgui_fftsink2_0_0_callback)
> > File
"/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py",
> > line 54, in __getattr__
> > return getattr(self._hb, name)
> > AttributeError: 'gr_hier_block2_sptr' object has no attribute
> > 'set_callback'
> >
> > i cannot find any sort of solution on the web anywhere. any sort of help
> > will be much appreciated. thanks in advance.
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130214/fac0ecea/attachment.html>


More information about the Python-list mailing list