librelist archives

« back to archive

Update Window

Update Window

From:
Kc Erb
Date:
2013-10-03 @ 23:41
Hi all,

In my program I need a window to pop-up and let the user know about the
progress of a slow process. So I decided to have the app pop up a new
window with a progress bar which closes on completion.

http://pastebin.com/DQbrGc3T

I'm finding that Shoes draws the window and waits for the slow process to
finish before updating the window's contents which means I get a blank
window with no progress bar.

The only way I've found to make this work is to put an alert between the
window pop up and the slow process which I'm actually OK with (if confirm
"Do you want your computer to be busy for a few minutes?").

Is there a better way?

-KC

PS I'm not entirely OK with needing the alert, because I found another
problem with that solution, but I'll hold off on describing that issue . . .


 "If there is an exception to every rule, then every rule must have at
least one exception; the exception to this one being that it has no
exception."

Re: [shoes] Update Window

From:
ashbb
Date:
2013-10-04 @ 11:25
Hi KC,

Try out the following. ;-)

Shoes.app do
  @@n = 0
  button "run update" do
    w = window width: 200, height: 50 do
      p = progress
      a = animate do |i|
        p.fraction = @@n / 5.0
        (a.stop; w.close) if @@n > 5
      end
    end
    Thread.new{slow_process}
  end

  def slow_process
    10.times do |i|
      @@n = i
      sleep 1
    end
  end
end

Hope this helps,
ashbb

Re: [shoes] Update Window

From:
Kc Erb
Date:
2013-10-04 @ 18:26
ashbb,

Playing around with this, I found that if I add an alert at the end of the
slow process (outside the loop) the program hangs.

Why would that be?

-KC

::::::::::::::::::::
Shoes.app do
  @@n = 0
  button "run update" do
    w = window width: 200, height: 50 do
      p = progress
      a = animate do |i|
        p.fraction = @@n / 5.0
        (a.stop; w.close) if @@n > 5
      end
    end
    Thread.new{slow_process}
  end

  def slow_process
    10.times do |i|
      @@n = i
      sleep 1
    end
    alert "Done!"
  end
end
:::::::::::::::::::::::::



On Fri, Oct 4, 2013 at 5:25 AM, ashbb <ashbbb@gmail.com> wrote:

> Hi KC,
>
> Try out the following. ;-)
>
> Shoes.app do
>   @@n = 0
>   button "run update" do
>     w = window width: 200, height: 50 do
>       p = progress
>       a = animate do |i|
>         p.fraction = @@n / 5.0
>         (a.stop; w.close) if @@n > 5
>       end
>     end
>     Thread.new{slow_process}
>   end
>
>   def slow_process
>     10.times do |i|
>       @@n = i
>       sleep 1
>     end
>   end
> end
>
> Hope this helps,
> ashbb
>



-- 
 "If there is an exception to every rule, then every rule must have at
least one exception; the exception to this one being that it has no
exception."

Re: [shoes] Update Window

From:
ashbb
Date:
2013-10-06 @ 01:02
Hi KC,
You can't use any gui elements in the threads. So, try this out.

Shoes.app do
  @@n = 0
  @@alert = nil
  button "run update" do
    w = window width: 200, height: 50 do
      p = progress
      a = animate do |i|
        p.fraction = @@n / 5.0
        (a.stop; w.close) if @@n > 5
      end
    end
    Thread.new{slow_process}
    b = animate do
      (b.stop; alert @@alert) if @@alert
    end
  end

  def slow_process
    10.times do |i|
      @@n = i
      sleep 1
    end
    @@alert = "Done!"
  end
end

ashbb

Re: [shoes] Update Window

From:
Kc Erb
Date:
2013-10-07 @ 15:03
OK, I see what you did there, very clever!

Thank you


On Sat, Oct 5, 2013 at 7:02 PM, ashbb <ashbbb@gmail.com> wrote:

> Hi KC,
> You can't use any gui elements in the threads. So, try this out.
>
>
> Shoes.app do
>   @@n = 0
>   @@alert = nil
>
>   button "run update" do
>     w = window width: 200, height: 50 do
>       p = progress
>       a = animate do |i|
>         p.fraction = @@n / 5.0
>         (a.stop; w.close) if @@n > 5
>       end
>     end
>     Thread.new{slow_process}
>     b = animate do
>       (b.stop; alert @@alert) if @@alert
>     end
>
>   end
>
>   def slow_process
>     10.times do |i|
>       @@n = i
>       sleep 1
>     end
>     @@alert = "Done!"
>   end
> end
>
> ashbb
>



-- 
 "If there is an exception to every rule, then every rule must have at
least one exception; the exception to this one being that it has no
exception."

Re: [shoes] Update Window

From:
Kc Erb
Date:
2013-10-04 @ 13:13
Awesome! That works beautifully. Thank you. I'll have to learn more about
Thread, I've run into several problems that I think would be better solved
by controlling threads like this.

:)


On Fri, Oct 4, 2013 at 5:25 AM, ashbb <ashbbb@gmail.com> wrote:

> Hi KC,
>
> Try out the following. ;-)
>
> Shoes.app do
>   @@n = 0
>   button "run update" do
>     w = window width: 200, height: 50 do
>       p = progress
>       a = animate do |i|
>         p.fraction = @@n / 5.0
>         (a.stop; w.close) if @@n > 5
>       end
>     end
>     Thread.new{slow_process}
>   end
>
>   def slow_process
>     10.times do |i|
>       @@n = i
>       sleep 1
>     end
>   end
> end
>
> Hope this helps,
> ashbb
>



-- 
 "If there is an exception to every rule, then every rule must have at
least one exception; the exception to this one being that it has no
exception."