[Tutor] More than one thing at a time?

Michael Sparks zathras at thwackety.com
Mon Oct 3 02:41:36 CEST 2005


[ cc'ing the Kamaelia list in case it makes sense to move this conversation
 there. ]
On Sunday 02 October 2005 15:20, Joseph Quigley wrote:
> Hi Michael,
> You're explanation helped a lot, however, I'm really not good at gui
> programming and the irc client was supposed to be a console application,
> but: Would it be hard to just have a send texbox and receive read-only
> text box?

It shouldn't be difficult at all really. If you find an example of a hello
world program, and a "hello who are you" program, then it's just a
simple matter of using that. 

If you're happy using pygame as a display, then you could use our Ticker
component already.

Example 11 shows how to use the Ticker. (Essentially though it takes text
strings on it's inbox and displays them. Which gives you a read-only text box) 

I should've thought of it sooner though, but you //could// do this:

pipeline(
    ConsoleReader(),
    IRCClient(host="server",
                     port = 6667,
                     nick = "userid",
                     nickinfo = "myclient 1.0",
                     defaultChannel = "#test" ),
    Ticker(background_colour=(128,48,128),
                 render_left = 1,
                 render_top = 1,
                 render_right = 600,
                 render_bottom = 200,
                 position = (100, 300),
    )
).run()

We don't actually have a console reader component, but it's simple to knock 
one up. The only complicating factor here is that reading from the console 
can be blocking which would lock up the whole system. As a result you'd want 
that to be a threaded component. (The API for those needs cleaning up 
admittedly)

However the code and simple system test for that looks like this:

################################
# Tested on my machine just now and works :-):-)
from Axon.ThreadedComponent import threadedcomponent
from Kamaelia.Util.ConsoleEcho import consoleEchoer
from Kamaelia.Util.PipelineComponent import pipeline

class ConsoleReader(threadedcomponent):
   def run(self):  # Threaded components use this method instead of "main"
      while 1:
         line = raw_input()
         line = line + "\n"
         self.outqueues["outbox"].put(line)

pipeline(ConsoleReader(),
         consoleEchoer()
).run()
#######################

Considering we do have a nascent IRClient component in /Sketches, the Ticker 
exists and the above ConsoleReader exists, this might speed things up for 
you. 

> I'll try this, but I think I should mention that I'm using python-irclib
> from sourceforge.

I'd suggest that our IRCClient code is nowhere near complete though, and 
whilst I've not tried python-irclib, I'd suggest looking at our IRCClient 
component to see how you might want to rewrite it to use python-irclib.

> I'll try Kamaelia, thanks a lot.

Please do. If you're willing to wait 24 hours we're doing the 0.3 release, 
which is a much expanded base to work with. If you can't wait, do a cvs 
checkout of the whole tree - ie:

mkdir kamaelia
cd kamaelia  # So easy to forget to do this, leaving clutter everywhere :-):-)
cvs -d:pserver:anonymous at cvs.sourceforge.net:/cvsroot/kamaelia login 
cvs -z3 -d:pserver:anonymous at cvs.sourceforge.net:/cvsroot/kamaelia co -d . 

That'll leave you with a full check out. You'll need to then install Axon:
cd Code/Python/Axon
python setup.py install

Similarly to install Kamaelia:
cd Code/Python/Kamaelia
python setup.py install

You'll then find an example program using the ticker in:
Code/Python/Kamaelia/Examples/example11

You might also find Code/Python/Kamaelia/Examples/example9 of interest
given your query on the pygame list regarding moving pictures about. :):)

It's a **simple** game designed to amuse very young children bouncing sprites
around the screen. It demonstrates very simple keyboard handling as well - 
specifically pausing, unpausing and toggling movement.

As I say to everyone who looks at Kamaelia - if you find it useful, that's
great - if you have any ideas for improvement, please let us know. If you
have any criticisms (postive or negative - especially if negative) please
let us know.

Finally if you want to share any components back to the project we'd be happy 
to merge them first into sketches and then into the main tree if there's a 
logical fit. Even a trivial component (such as the one above) has a useful 
place in the tree - as you can see from this reply :-):-)

Best Regards,


Michael.
--
"Though we are not now that which in days of old moved heaven and earth, 
   that which we are, we are: one equal temper of heroic hearts made 
     weak by time and fate but strong in will to strive, to seek, 
          to find and not to yield" -- "Ulysses", Tennyson


More information about the Tutor mailing list