[Tutor] More than one thing at a time?

Michael Sparks zathras at thwackety.com
Sat Oct 1 16:24:07 CEST 2005


On Saturday 01 October 2005 12:36, Kent Johnson wrote:
> Another way to do what you want is to use Twisted; this is touched on in
> the second thread above.

Another way is to use Kamaelia - its' specifically aimed at making it
easy for newbies (and everyone else, me especially :-) do more than one
thing at a time. If you understand unix pipelines you already understand
the core ideas. (or indeed, how to wire a battery to a bulb :)

Though until we've had a number newbies do the mini-axon tutorial and say
what they wold like to see improved (in terms of clarity, ease of use), I'd
hesitate suggestng it. (People who write things have already by definition
gone up the learning curve and hence can't truly evaluate ease no matter
how hard they try).

However logically using Kamaelia (or any other system) you have 3
concurrent activities/3 things happening at a time here:

    * Handling sending & receiving of data
    * Accepting user input to send
    * Displaying output from the connection

In Kamaelia we would /directly/ wrap this as 3 hypothetical components
with a top level that might look like this:

pipeline(
    TkTextInputWidget(mode="lineatatime"),
    IRCClient(host="server",
                     port = 6667,
                     nick = "userid",
                     nickinfo = "myclient 1.0",
                     defaultChannel = "#test" ),
    TkDisplayWidget(),
).run()

Or using a more explicit/low level description of the same system:

Graphline(
     IRC = IRCClient(host="server",
                     port = 6667,
                     nick = "userid",
                     nickinfo = "myclient 1.0",
                     defaultChannel = "#test" ),
     TOIRC = TkTextInputWidget(mode="lineatatime"),
     FROMIRC = TkDisplayWidget(),

     linkages = {
          ("IRC", "outbox") : ("FROMIRC", "inbox"),
          ("TOIRC", "outbox") : ("IRC", "inbox"),
     }
).run()

(personally I prefer the latter implementation here since it's more clear
the 3 things are relatively independent rather than dependent on the
start of the chain. They are both equivalent though.)

We've got a nascent IRCClient component in /Sketches of our codebase,
and there's display & type in code in the PipeBuilder code in /Sketches
that could serve as a starting point. 

Writing TkDIsplayWidget should be trivial - since it's equivalent if a
"hello world" program (more or less) in Tk, and the TkTextInputWidget
should also be trivial since it's a matter of writing a Tk based program
that allows you to say "What is your name" and have a type in box to
answer. 

In the mainloop, the display widget would check its inbox for data, grab
it and display it. The input widget would send data to it's outbox when
some types something in. We'd normally recommend writing standalone
small scripts for each of these interacting with stdin (instead of an inbox)
and stdout (instead of an outbox)  - say via "print" when writing them and
then turn them into components and then wire everything together.

Also aside from a tutorial on how to build the system itself (it's not
really that complex) at:
    * http://kamaelia.sourceforge.net/MiniAxon.

We've also got a tutorilal on writing components here:
    * http://kamaelia.sourceforge.net/cgi-bin/blog/blog.cgi?rm=viewpost&postid=1113495151

If the OP does choose to take this approach, they'd need to use a CVS
checkout rather than the main release though since we haven't done a
release yet including the TK stuff (Though one is imminent).

One key aim of Kamaelia is to make it simple & easy to make it possible
to have more than one thing at a time to be dealt with - especially with
regard to networking things, so I'd //hope// that using Kamaelia here might
be the easiest place to start.

Hoping this was useful, 


Michael.


More information about the Tutor mailing list