views:

138

answers:

1

Is there a way to run a heavy operation in shoes in a different thread so that the GUI is not freezing until the operation is finished? (smth. similar to download but more generic, like SwingWorker.class in Swing).

I have tried the following:

Thread.start { <heavy operation block is here> }

but that didn't help. looks like Shoes main thread is still affected.

Thanks a lot in advance!

+1  A: 

Without seeing your code, I can't give you any specific guidance. But this code, for example, works just fine for me. Note that if the tedious calculations complete while the dialog is up, you won't see the results until a few moments after closing the dialog; Shoes won't change the window AI while the dialog is up. Give it a try and see how it behaves, and we'll go from there.

Shoes.app do

  @window_slot = stack do
    button('Tell me about ponies') do
      @window_slot.append { para 'OMG PONIES!' }
    end
    button('I like dialogs') { alert 'I like dialogs, too!' }
    button('Does this button make things slow?') do
      Thread.new do
        @window_slot.append { para 'Why did you click that?  Are you crazy?!' }

        #Let's do a bunch of calculations!
        arr = []
        sum = 0
        0.upto(10000) do |i|
          0.upto(1000) do |j|
            sum += j
          end
          arr << sum
        end

        @window_slot.append { para arr.join(' ') }
      end
    end
  end
end
Pesto