Random musings on random stuff.
I've added a PythonInterpreter component to Kamaelia in Kamaelia.Experimental.PythonInterpreter. The primary use for this is intended to assist with debugging, but there are other possible uses.
StandaloneInterpreter().run()Which you can run in the background on any console. For example you could do
ServerCore(protocol=myprotocol, port=1234).activate()Alternatively, you can use an embeddable component that speaks to inbox/outbox rather than stdin/stdout. Crudely you can do something like this:
StandaloneInterpreter().run()
Pipeline(But you can also put it inside a pygame application, reading & writing from a
ConsoleReader(),
InterpreterTransformer(),
ConsoleEchoer(),
).run()

from Kamaelia.Chassis.Pipeline import PipelineIn one console:
from Kamaelia.Chassis.ConnectedServer import ServerCore
from Kamaelia.Util.PureTransformer import PureTransformer
from Kamaelia.Experimental.PythonInterpreter import InterpreterTransformer
def NetInterpreter(*args, **argv):
return Pipeline(
PureTransformer(lambda x: str(x).rstrip()),
InterpreterTransformer(),
PureTransformer(lambda x: str(x)+"\r\n>>> "),
)
ServerCore(protocol=NetInterpreter, port=1236).run()
# ./ServerBasedPythonInterpreter.pyIn another:
~> telnet 127.0.0.1 1236
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
>>> self
Component
Kamaelia.Experimental.PythonInterpreter.InterpreterTransformer_21 [ inboxes :
{'control': [], 'inbox': []} outboxes : {'outbox': [], 'signal': []}
>>> "hello world"
hello world
>>> Axon
<module 'Axon'
from '/usr/local/lib/python2.5/site-packages/Axon/__init__.pyc'>
>>> dir(self)
['Inbox', 'Inboxes', 'Outboxes', 'Usescomponents', '_AxonObject_...
>>> self.scheduler
Axon.Scheduler.scheduler_1 :1 :1 :0 :
>>> self.scheduler.threads
{<Kamaelia.Internet.TCPServer.TCPServer object at 0xb7b972cc>: <object object
at 0xb7c92468>,
<Kamaelia.Internet.ConnectedSocketAdapter.ConnectedSocketAdapter object at
0xb7ba4acc>: <object object at 0xb7c92468>,
<Kamaelia.Experimental.PythonInterpreter.InterpreterTransformer object at
0xb7ba6bec>: <object object at 0xb7c92468>,
<Kamaelia.Chassis.Pipeline.Pipeline object at 0xb7bafc2c>: <object object at
0xb7c92468>, <Kamaelia.Experimental.PythonInterpreter.InterpreterTransformer
object at 0xb7b9dc4c>: <object object at 0xb7c92468>,
<Kamaelia.Util.PureTransformer.PureTransformer object at 0xb7baf86c>: <object
object at 0xb7c92460>, <Kamaelia.Chassis.ConnectedServer.ServerCore object at
0xb7b8acec>: <object object at 0xb7c92468>,
<Kamaelia.Chassis.Pipeline.Pipeline object at 0xb7ba1d0c>: <object object at
0xb7c92468>, <Kamaelia.Util.PureTransformer.PureTransformer object at
0xb7ba192c>: <object object at 0xb7c92468>,
<Kamaelia.Util.PureTransformer.PureTransformer object at 0xb7b9d96c>: <object
object at 0xb7c92468>, <Kamaelia.Internet.Selector.Selector object at
0xb7b979cc>: <object object at 0xb7c92468>}
etc.
if interactive_debug:And whilst the other forms naturally drop out as useful, this form is probably the safest of the bunch!
StandaloneInterpreter().activate()
MyMainApplication().run()
~/> ./BasicPythonInterpreter.py
> from Kamaelia.UI.Pygame.Ticker import Ticker
ok
> X=Ticker()
ok
Component Kamaelia.UI.Pygame.Ticker.Ticker_7 [ inboxes : {'control':
[], '_displaycontrol': [], 'unpausebox': [], 'pausebox': [], 'inbox':
[], 'alphacontrol': []} outboxes : {'outbox': <>, 'signal':
<>, '_displaysignal': <>}
> X.activate()
ok
Component Kamaelia.UI.Pygame.Ticker.Ticker_7 [ inboxes : {'control':
[], '_displaycontrol': [], 'unpausebox': [], 'pausebox': [], 'inbox':
[''], 'alphacontrol': []} outboxes : {'outbox': <>, 'signal':
<>, '_displaysignal': <>}
> self.link((self, "outbox"), (X,"inbox"))
ok
Link( source:
[Kamaelia.Experimental.PythonInterpreter.StandaloneInterpreter_5,outbox],
sink:[Kamaelia.UI.Pygame.Ticker.Ticker_7,inbox] )
> self.send("Hello", "outbox")
ok
./AxonVisualiser.py --port 1500And then in the enbedded interpreter do this:
> from Kamaelia.Util.Introspector import IntrospectorAnd that then adds an Axon visualisation/introspector to a running system - which looks like this:
ok
> from Kamaelia.Chassis.Pipeline import Pipeline
ok
> from Kamaelia.Internet.TCPClient import TCPClient
ok
> Pipeline(
Introspector(),
TCPClient("127.0.0.1", 1500),
).activate()
> > >
ok

This is really awesome. Very nice for visual programming.
cheers,
rene.
ps. comment body doesn't appear to work in FF OSX 3.0.7 anymore. It works after pressing preview, but then the rich text stuff doesn't appear.