Skip to content

Commit 3d530fe

Browse files
committed
Added pythonic wrappers for Topology and BlockRegistry
1 parent 18bd40a commit 3d530fe

7 files changed

Lines changed: 52 additions & 13 deletions

File tree

Changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
This this the changelog file for the Pothos Python toolkit.
22

3+
Release 0.2.0 (pending)
4+
==========================
5+
6+
- Added pythonic wrappers for Topology and BlockRegistry
7+
38
Release 0.1.3 (2016-03-06)
49
==========================
510

Pothos/Block.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
# Copyright (c) 2014-2014 Josh Blum
1+
# Copyright (c) 2014-2016 Josh Blum
22
# SPDX-License-Identifier: BSL-1.0
33

44
from . PothosModule import *
55
from . InputPort import InputPort
66
from . OutputPort import OutputPort
77
from . Label import Label, LabelIteratorRange
8+
from . BlockRegistry import BlockRegistry
89
import weakref
910

1011
class Block(object):
1112
def __init__(self):
12-
env = ProxyEnvironment("managed")
13-
reg = env.findProxy("Pothos/BlockRegistry")
14-
self._block = reg.callProxy("/blocks/python_block")
13+
self._block = BlockRegistry("/blocks/python_block")
1514
self._block._setPyBlock(weakref.proxy(self))
1615

1716
def __getattr__(self, name):

Pothos/BlockRegistry.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2016-2016 Josh Blum
2+
# SPDX-License-Identifier: BSL-1.0
3+
4+
from . PothosModule import *
5+
6+
def BlockRegistry(path, *args):
7+
env = ProxyEnvironment("managed")
8+
reg = env.findProxy("Pothos/BlockRegistry")
9+
return reg.callProxy(path, *args)

Pothos/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ install(FILES
4040
InputPort.py
4141
OutputPort.py
4242
TestPothos.py
43+
Topology.py
44+
BlockRegistry.py
4345
DESTINATION ${POTHOS_PYTHON_DIR}/Pothos)

Pothos/TestTopology.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,23 @@ def work(self):
2323
env = Pothos.ProxyEnvironment("managed")
2424

2525
#make a topology to connect and process
26-
topology = env.findProxy('Pothos/Topology').make()
27-
28-
#get the block registry
29-
reg = env.findProxy("Pothos/BlockRegistry")
26+
topology = Pothos.Topology()
3027

3128
#create feeder block and give it a message
32-
feeder = reg.callProxy("/blocks/feeder_source", "int")
29+
feeder = Pothos.BlockRegistry("/blocks/feeder_source", "int")
3330
feeder.feedMessage("hello")
3431
feeder.feedMessage("world")
3532
feeder.feedMessage(123)
3633

3734
#create a collector block to house the result
38-
collector = reg.callProxy("/blocks/collector_sink", "int")
35+
collector = Pothos.BlockRegistry("/blocks/collector_sink", "int")
3936

4037
#use an all in-python block thats not even in the block registry
4138
fwd = MessageForwarder()
4239

4340
#connect and run it
44-
topology.connect(feeder, "0", fwd, "0")
45-
topology.connect(fwd, "0", collector, "0")
41+
topology.connect(feeder, 0, fwd, 0)
42+
topology.connect(fwd, 0, collector, 0)
4643
topology.commit()
4744
topology.waitInactive()
4845

Pothos/Topology.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2016-2016 Josh Blum
2+
# SPDX-License-Identifier: BSL-1.0
3+
4+
from . PothosModule import *
5+
6+
class Topology(object):
7+
def __init__(self):
8+
env = ProxyEnvironment("managed")
9+
self._topology = env.findProxy('Pothos/Topology').make()
10+
11+
def connect(self, src, srcPort, dst, dstPort):
12+
return self._topology.connect(src, str(srcPort), dst, str(dstPort))
13+
14+
def disconnect(self, src, srcPort, dst, dstPort):
15+
return self._topology.disconnect(src, str(srcPort), dst, str(dstPort))
16+
17+
def __getattr__(self, name):
18+
return lambda *args: self._topology.call(name, *args)
19+
20+
def getInternalBlock(self):
21+
"""
22+
Get access to the underlying Pothos::Block handle.
23+
Topology uses this call to speak directly to the block.
24+
"""
25+
return self.self._topology

Pothos/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# Copyright (c) 2014-2014 Josh Blum
1+
# Copyright (c) 2014-2016 Josh Blum
22
# SPDX-License-Identifier: BSL-1.0
33

44
from . PothosModule import *
55
from . Block import Block
66
from . Label import Label, LabelIteratorRange
77
from . InputPort import InputPort
88
from . OutputPort import OutputPort
9+
from . Topology import Topology
10+
from . BlockRegistry import BlockRegistry

0 commit comments

Comments
 (0)