Example #1
0
from Axon.likefile import LikeFile, schedulerThread
import time, Axon
from Sprites.BasicSprite import BasicSprite
from Sprites.SpriteScheduler import SpriteScheduler
from Simplegame import *


class catMaker(Axon.Component.component):
    """discards input, makes one cat per item on inbox."""
    def main(self):
        self.spritescheduler = SpriteScheduler(cat_args, cat_sprites, background, screen_surface, MyGamesEvents).activate()
        yield 1 # to make sure spritescheduler's main gets called once - there's code outside the loop there that needs to run.
        while True:
            while self.dataReady("inbox"):
                discardedfornow = self.recv("inbox")
                cat_appear_wav.play()
                self.spritescheduler.allsprites.add(make_cat(*self.spritescheduler.cat_args))
            self.pause()
            yield 1

bg = schedulerThread(slowmo=0.01).start()
catmaker = LikeFile(catMaker())
catmaker.activate()

max_cats = 10
for i in xrange(0, max_cats):
    time.sleep(0.5)
    catmaker.put(i)
print "cats over!"
time.sleep(5)
Example #2
0
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# a slightly more complicated example of a TCP client, where we define an echo.

from Kamaelia.Chassis.ConnectedServer import SimpleServer
from Kamaelia.Protocol.EchoProtocol import EchoProtocol
from Kamaelia.Internet.TCPClient import TCPClient
from Axon.likefile import LikeFile, schedulerThread
import time

schedulerThread(slowmo=0.01).start()

PORT = 1900
# This starts an echo server in the background.
SimpleServer(protocol=EchoProtocol, port=PORT).activate()

# give the component time to commence listening on a port.
time.sleep(0.5)

echoClient = LikeFile(TCPClient(host="localhost", port=PORT))
while True:
    echoClient.put(raw_input(">>> "))
    print echoClient.get()
Example #3
0
# Copyright 2010 British Broadcasting Corporation and Kamaelia Contributors(1)
#
# (1) Kamaelia Contributors are listed in the AUTHORS file and at
#     http://www.kamaelia.org/AUTHORS - please extend this file,
#     not this notice.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from Axon.likefile import LikeFile, schedulerThread
from Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
background = schedulerThread().start()
p = LikeFile(SimpleHTTPClient())
p.put("http://google.com")
p.put("http://slashdot.org")
p.put("http://whatismyip.org")
google = p.get()
slashdot = p.get()
whatismyip = p.get()
p.shutdown()
print "google is", len(google), "bytes long, and slashdot is", len(slashdot), "bytes long. Also, our IP address is:", whatismyip
Example #4
0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from Axon.likefile import LikeFile, schedulerThread
from Kamaelia.Codec.Vorbis import VorbisDecode, AOAudioPlaybackAdaptor
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor
import ao
schedulerThread(slowmo=0.001).start()

filename = "./snail.ogg"

playStream = LikeFile(Pipeline(VorbisDecode(), AOAudioPlaybackAdaptor()))

# Play the ogg data in the background
oggdata = open(filename, "r+b").read()
playStream.put(oggdata)
while True:
    playStream.get()
    # there's no data produced but this will prevent us from exiting immediately.
Example #5
0
catlist = []
while True:
    input = raw_input(">>> ").lower()
    try:
        command, args = input.split(" ", 1)
    except ValueError:
        command, args = input, ""

    if command == "status":
        print "there are %s threads active and %s components" % (
            threading.activeCount(),
            len(Axon.Scheduler.scheduler.run.threads),
        )
    elif command == "add":
        count = 1
        if args and int(args) > 1:
            count = int(args)
        for i in xrange(0, count):
            newcat = LikeFile(make_cat(*cat_args))
            newcat.activate()
            catlist.append(newcat)
        print "added %s cats." % count
    elif command == "pause":
        for cat in catlist:
            cat.put("pause", "inbox")
        print "paused %s cats" % len(catlist)
    elif command == "toggle":
        for cat in catlist:
            cat.put("toggle", "inbox")
        print "toggled %s cats" % len(catlist)
Example #6
0
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# a slightly more complicated example of a TCP client, where we define an echo.

from Kamaelia.Chassis.ConnectedServer import SimpleServer
from Kamaelia.Protocol.EchoProtocol import EchoProtocol
from Kamaelia.Internet.TCPClient import TCPClient
from Axon.likefile import LikeFile, schedulerThread
import time

schedulerThread(slowmo=0.01).start()

PORT = 1900
# This starts an echo server in the background.
SimpleServer(protocol = EchoProtocol, port = PORT).activate()

# give the component time to commence listening on a port.
time.sleep(0.5)

echoClient = LikeFile(TCPClient(host = "localhost", port = PORT))
while True:
    echoClient.put(raw_input(">>> "))
    print echoClient.get()
Example #7
0
# Copyright 2010 British Broadcasting Corporation and Kamaelia Contributors(1)
#
# (1) Kamaelia Contributors are listed in the AUTHORS file and at
#     http://www.kamaelia.org/AUTHORS - please extend this file,
#     not this notice.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from Axon.likefile import LikeFile, schedulerThread
from Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
background = schedulerThread().start()
p = LikeFile(SimpleHTTPClient())
p.put("http://google.com")
p.put("http://slashdot.org")
p.put("http://whatismyip.org")
google = p.get()
slashdot = p.get()
whatismyip = p.get()
p.shutdown()
print "google is", len(google), "bytes long, and slashdot is", len(
    slashdot), "bytes long. Also, our IP address is:", whatismyip
Example #8
0
       }
    )
    return X

cat_args = (cat_location, screensize, border)
spritescheduler = SpriteScheduler(cat_args, [], background, screen_surface, MyGamesEvents).activate()

catlist = []
while True:
    input = raw_input(">>> ").lower()
    try: command, args = input.split(' ', 1)
    except ValueError: command, args = input, ''

    if command == "status":
        print "there are %s threads active and %s components" % (threading.activeCount(), len(Axon.Scheduler.scheduler.run.threads))
    elif command == "add":
        count = 1
        if args and int(args) > 1: count = int(args)
        for i in xrange(0, count):
            newcat = LikeFile(make_cat(*cat_args))
            newcat.activate()
            catlist.append(newcat)
        print "added %s cats." % count
    elif command == "pause":
        for cat in catlist:
            cat.put("pause", "inbox")
        print "paused %s cats" % len(catlist)
    elif command == "toggle":
       for cat in catlist:
           cat.put("toggle", "inbox")
       print "toggled %s cats" % len(catlist)
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import time, sys, Axon
from Axon.likefile import LikeFile, schedulerThread

schedulerThread().start()


class Reverser(Axon.Component.component):
    def main(self):
        while True:
            if self.dataReady("inbox"):
                item = self.recv("inbox")
                self.send(item[::-1], "outbox")  # strings have no "reverse" method, hence this indexing 'hack'.
            else:
                self.pause()
            yield 1


# Unix's "rev" tool, implemented using likefile.

reverser = LikeFile(Reverser())

while True:
    line = sys.stdin.readline().rstrip()  # get rid of the newline
    reverser.put(line)
    enil = reverser.get()
    print enil
Example #10
0
from Sprites.SpriteScheduler import SpriteScheduler
from Simplegame import *


class catMaker(Axon.Component.component):
    """discards input, makes one cat per item on inbox."""
    def main(self):
        self.spritescheduler = SpriteScheduler(cat_args, cat_sprites,
                                               background, screen_surface,
                                               MyGamesEvents).activate()
        yield 1  # to make sure spritescheduler's main gets called once - there's code outside the loop there that needs to run.
        while True:
            while self.dataReady("inbox"):
                discardedfornow = self.recv("inbox")
                cat_appear_wav.play()
                self.spritescheduler.allsprites.add(
                    make_cat(*self.spritescheduler.cat_args))
            self.pause()
            yield 1


bg = schedulerThread(slowmo=0.01).start()
catmaker = LikeFile(catMaker())
catmaker.activate()

max_cats = 10
for i in xrange(0, max_cats):
    time.sleep(0.5)
    catmaker.put(i)
print "cats over!"
time.sleep(5)
Example #11
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from Axon.likefile import LikeFile, schedulerThread
from Kamaelia.Codec.Vorbis import VorbisDecode, AOAudioPlaybackAdaptor
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor
from Kamaelia.Internet.TCPClient import TCPClient
import ao
schedulerThread(slowmo=0.001).start()

filename = "./snail.ogg"

playStream = LikeFile(Pipeline(VorbisDecode(), AOAudioPlaybackAdaptor()))
playStream.activate()
# set of components for playing the stream back.

host = "bbc.kamaelia.org"
port = 1500

client = LikeFile(TCPClient(host = host, port = port))
# component to grab a stream from the internet

filedump = open("streamdump.ogg", "w+b")

# Play the ogg data in the background
while True:
    data = client.get()
    filedump.write(data)
Example #12
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import time, sys, Axon
from Axon.likefile import LikeFile, schedulerThread

schedulerThread().start()


class Reverser(Axon.Component.component):
    def main(self):
        while True:
            if self.dataReady('inbox'):
                item = self.recv('inbox')
                self.send(item[::-1], 'outbox') # strings have no "reverse" method, hence this indexing 'hack'.
            else: self.pause()
            yield 1


# Unix's "rev" tool, implemented using likefile.

reverser = LikeFile(Reverser())

while True:
    line = sys.stdin.readline().rstrip() # get rid of the newline
    reverser.put(line)
    enil = reverser.get()
    print enil
Example #13
0
# See the License for the specific language governing permissions and
# limitations under the License.

from Axon.likefile import LikeFile, schedulerThread
from Kamaelia.UI.Pygame.Ticker import Ticker
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor
import time

bg = schedulerThread(slowmo=0.01).start()

ticker1 = LikeFile(
    Pipeline(
        Ticker(
            background_colour=(128, 48, 128),
            render_left=1,
            render_top=1,
            render_right=600,
            render_bottom=200,
            position=(100, 250),
        )))
ticker2 = LikeFile(
    Pipeline(
        Ticker(
            background_colour=(128, 48, 128),
            render_left=1,
            render_top=1,
            render_right=600,
            render_bottom=200,
            position=(100, 0),
        )))