ashbb / green_shoes

Green Shoes is one of the colorful Shoes written in pure Ruby.
Other
204 stars 37 forks source link

Threading and shoes #34

Closed glurp closed 13 years ago

glurp commented 13 years ago

Hello,

I appreciate very much green-shoe: Shoes beauty in a regular ruby gem.

One observation:

This is main obstacle for using shoes as perfect GUI complement to core ruby.

The solution I used is queuing :

not very funny... by

ashbb commented 13 years ago

Hi raubarede,

But how use Thread (native) with shoes ?....

How about the following?

require 'green_shoes'
Shoes.app do
 para 'hello'
 Thread.new do
   10.times do |i|
     puts i
     sleep 1
   end
 end
end

The solution I used is queuing :

  • Thread enqueue gui request,
  • Shoes anime() unqueue requast and execute them

Sounds good. Could you show me the code you wrote?

Regards, ashbb

glurp commented 13 years ago

Hello

Here a abstract :

require 'thread'

class Application < Shoes url '/', :build url '/request/(.+)', :request

def request(script) $app=self @queue = Queue.new . . . build end def build @log=edit_box "",:width=>1.0,:height=>100 . . . . every(0.1) do if defined?(@queue) while @queue.size>0 txt=@queue.pop.to_s if txt[0..2]=="LOG" log txt[4..-1] else alert(txt[3..-1]) end end end end

def log(txt) if defined?(@log) @log.text=@log.text+txt rescue alert("ECHO " + txt.to_s) end end end

Thread and gtk2

try that :

require 'green_shoes' Shoes.app { para 'hello' ; Thread.new { win.hide } }

On windows, application scratch.... So with shoes, Thread are ok but can't do gui.

it's seem that ruby/gtk has something special for threading : http://ruby-gnome2.sourceforge.jp/hiki.cgi?tips_threads I would like to do something like :

Thread.new { .... invoke_in_mainloop { |app| app.win.show ; } }

NOTA:

What is the right place for discussion on shoes/green-shoes on the web ? I am getting some stuff from gtk2-ruby (systray icon+menu, hide/show application...) and perhaps it can be useful for anybody...

by

2011/7/20 ashbb < reply@reply.github.com>

Hi raubarede,

But how use Thread (native) with shoes ?....

How about the following?

   require 'green_shoes'
   Shoes.app do
    para 'hello'
    Thread.new do
      10.times do |i|
        puts i
        sleep 1
      end
    end
   end

The solution I used is queuing :

  • Thread enqueue gui request,
  • Shoes anime() unqueue requast and execute them

Sounds good. Could you show me the code you wrote?

Regards, ashbb

Reply to this email directly or view it on GitHub: https://github.com/ashbb/green_shoes/issues/34#issuecomment-1614685



|) | / | /__ | \ |__ > | ./


ashbb commented 13 years ago

Hi raubarede,

Thank you for showing your thought (abstract code). I could understand what you want to do. IMHO,

Try out the following snippet. It works as I expect.

require 'green_shoes'

Shoes.app do
 def log txt
   @log.text += txt
 end

 @log=edit_box height: 100
 @queue = []

 every do
   while @queue.size>0
     txt=@queue.pop.to_s
     if txt[0..2]=="LOG"
       log txt[4..-1]
     else
       alert(txt[3..-1])
     end
   end
 end

 every 3 do
   @queue.push ['LOG:001', 'LOG:002', 'LOG:003', 'aaa bbb ccc'][rand 4]
   p @queue.last # for debug
 end
end

What is the right place for discussion on shoes/green-shoes on the web ?

On the web, here is the right place. But it's better to use Shoes ML (shoes@librelist.com) to discuss with other many Shoesers.

perhaps it can be useful for anybody...

Yes, totally agree! So, please post your messages on Shoes ML.

Cheers, ashbb