Feedback messages to user using Tk

Thanks again Morton!

The code was written off the top of my head into the email (which would explain the syntax errors, honest!) but the conceptual error is probably where I was having the problem. I'm still a ruby nuby and my coding ability is somewhat immature... As such any help and criticism is welcomed and vastly appreciated!!! How else am I to learn?!

I also followed the Tk "Stopwatch" recipe in the O'Reilly Ruby cookbook and came across the timer before, however they used TkAfter instead of TkTimer.

Thanks again for all your help - I will keep you all posted on the progress (if you're interested of course)

Thanks

Gem

···

-----Original Message-----
From: Morton Goldberg [mailto:m_goldberg@ameritech.net]
Sent: 27 September 2006 18:18
To: ruby-talk ML
Subject: Re: Feedback messages to user using Tk...

There are quite a few errors in that code. Even if you fixed its
syntax, you'd have a conceptual error. You'd only see the last
message: "I'm done". The initial message would be replaced by the
first update call and the second message would then be replaced by
the second update call before the window got on the screen. But
you're moving in the right direction.

You need something to delay the updates until the window gets
displayed. A timer is one way to do it.

<code>
#! /usr/bin/ruby -w

require 'tk'

class GraphicalProgress
    def initialize
       root = TkRoot.new { title 'Progress' }
       @my_label = TkLabel.new(root) {
          text 'Waiting for something to report...'
       }
       @my_label.pack(:pady=>20)
       # Set initial window geometry; i.e., size and placement.
       win_w, win_h = 300, 80
       # root.minsize(win_w, win_h)
       win_x = (root.winfo_screenwidth - win_w) / 2
       root.geometry("#{win_w}x#{win_h}+#{win_x}+50")
       root.resizable(false, false)
    end

    def update(message)
       @my_label.text = message
    end
end

msgs = ["I'm doing something", "I'm done"]
indx = 0
progress = GraphicalProgress.new
timer = TkTimer.start(1000, 2) do
    progress.update(msgs[indx])
    indx += 1
end

Tk.mainloop
</code>

Regards, Morton

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

I also followed the Tk "Stopwatch" recipe in the O'Reilly Ruby cookbook and came across the timer before, however they used TkAfter instead of TkTimer.

TkTimer and TkAfter are one and the same. TkAfter is an alias of TkTimer. Use whichever name you think makes your code more readable.

Thanks again for all your help - I will keep you all posted on the progress (if you're interested of course)

Sure, keep us posted. I'm always interested in people's adventures with Ruby/Tk.

Regards, Morton

···

On Sep 28, 2006, at 5:15 AM, Cameron, Gemma (UK) wrote: