programming a bird -- yes!

Discussion in 'Ruby' started by Gerard A.W. Vreeswijk, Jul 14, 2003.

  1. Hello all,

    Hi all,

    Serious (but possibly less attracting) subject title: Win32ole event loop
    with MSAgent.

    Thanks to Suketa Masaki for doing such a good job on giving us 'win32ole'.
    It relieves us from Microsoft's RSI-stimulating clickfests.

    Inspired by Rubytalk 36676, Shusaku <>:

    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/36676

    I decided I wanted to beef up my Agent-app with MSAgent (sorry, Unix):

    http://www.microsoft.com/msagent/downloads/user.asp
    (download merlin + speech engine + maybe more, depending on your
    hardware)

    Tried out the script below. All works fine --- as a matter of fact, I
    showed one of the characters who happens to be a bird called Peedy to my
    4-year old son pronouncing my son's name. He ran down to his mom and said
    that a bird talked to him and knew his name :)

    Anyway:
    ======================================================================
    #!/usr/bin/ruby
    require 'win32ole'

    agent = WIN32OLE.new('Agent.Control.1')
    agent.Connected = true
    agent.Characters.Load("some random string, 'peedy' or so", "peedy.acs")

    peedy = agent.Characters("some random string, 'peedy' or so")

    # The way we should officialy check when we're done:
    ev = WIN32OLE_EVENT.new(agent, nil)
    ev.on_event("RequestComplete") { |rRequest|

    # rRequest.ole_obj_help.name -> "IAgentCtlRequest"
    # rRequest.ole_obj_help.typekind -> 4 ( TKIND_DISPATCH )
    # rRequest.ole_obj_help.ole_type -> "Dispatch"
    # rRequest.ID -> 197 ( ?? )

    if rRequest.ID == $peedySpeak.ID
    peedy.Hide # or exit, or move on, or ..
    end

    }

    peedy.Show

    # You can program gestures here. Nothing fancy at the moment, just
    speak.

    $peedySpeak = peedy.Speak <<EOF
    Thanks Suketa Masaki, for giving us win32ole!
    And thanks Shusaku, for giving us a link between Ruby-win32ole and
    MsAgent!
    EOF

    # speak = peedy.ole_method("Speak") #=> WIN32OLE_METHOD
    # speak.return_vtype #=> 26
    # speak.return_type #=> "IAgentCtlRequest"
    # speak.return_type_detail #=> ["PTR", "USERDEFINED", "IAgentCtlRequest"]


    # More mundane check to see when we're done:
    loop do
    $stderr.puts $peedySpeak.Status
    $stderr.flush
    # status should become 0 or so, see
    #
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msagent/pacontrol_3tws.asp
    break if $peedySpeak.Status != 2
    sleep 1
    end

    # never get here :-(

    ======================================================================


    As you see, the WIN32OLE_EVENT-loop doesn't seem to recognize events,
    which is needed to recognize that an action is over.
    Also, the "Status" attribute does not work. Status could also be used to
    see that an action is over. Currently, Status keeps returning 2's. This
    is different from Perl's,

    foreach my $animation ($c->AnimationNames)
    {
    my $request = $c->Play($animation);
    $c->Speak($animation);
    my $i = 0;
    while (($request->Status == 2) || ($request->Status == 4))
    { $c->Stop($request) if $i >10; sleep(1); $i++}
    }


    where it *does** work (not the events, though). (Thanks, Jouke). See

    http://www.cpan.org/modules/by-authors/id/J/JO/JOUKE/

    Examined Suketa Masaki "ienavi.rb" example for inspiration. There must be
    some "DWebBrowserEvents" event sink identifier for MSAgent as well, but
    which??

    Thanks.
    Gerard
     
    Gerard A.W. Vreeswijk, Jul 14, 2003
    #1
    1. Advertising

  2. Gerard A.W. Vreeswijk

    Shusaku Guest

    Hi, Gerard

    On Mon, 14 Jul 2003 09:55:35 GMT
    (Gerard A.W. Vreeswijk) wrote:

    > loop do
    > $stderr.puts $peedySpeak.Status
    > $stderr.flush
    > break if $peedySpeak.Status != 2

    WIN32OLE_EVENT.message_loop # <== You should insert this!
    > sleep 1
    > end


    Now, the loop would be terminated by 'Status == 4', although it
    means "Request in progress". I think the break condition might
    be 'Status == 0', which means "Request successfully completed".

    --
    Shusaku <>
     
    Shusaku, Jul 14, 2003
    #2
    1. Advertising

  3. Gerard A.W. Vreeswijk

    Shusaku Guest

    I forgot to answer your other question.

    On Mon, 14 Jul 2003 09:55:35 GMT
    (Gerard A.W. Vreeswijk) wrote:

    > Examined Suketa Masaki "ienavi.rb" example for inspiration. There must be
    > some "DWebBrowserEvents" event sink identifier for MSAgent as well, but
    > which??


    "_AgentEvents" is the one you are looking for.

    agent = WIN32OLE.new('Agent.Control.1')
    ev = WIN32OLE_EVENT.new(agent, '_AgentEvents')

    --
    Shusaku <>
     
    Shusaku, Jul 14, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MarionEll
    Replies:
    0
    Views:
    395
    MarionEll
    Feb 17, 2004
  2. Guido van Rossum

    PyCon Reminder: Early bird reg deadline 2/1

    Guido van Rossum, Jan 19, 2004, in forum: Python
    Replies:
    0
    Views:
    291
    Guido van Rossum
    Jan 19, 2004
  3. John Benson
    Replies:
    2
    Views:
    349
  4. teo
    Replies:
    3
    Views:
    540
  5. Jamie Herre
    Replies:
    1
    Views:
    202
    why the lucky stiff
    Jan 7, 2005
Loading...

Share This Page