librelist archives

« back to archive

progressbar to represent array iteration

progressbar to represent array iteration

From:
Артём Большаков
Date:
2010-05-23 @ 19:17
Hello, folks

I want to represent iterating array by using progressbar. 
And no any idea how to do this. I tried to dance around animate, but 
failed with it
-- 
Artyom Bolshakov <tweekane@gmail.com>

Observer pattern in shoes

From:
Artyom Bolshkov
Date:
2010-05-25 @ 21:02
I'm tried to use Observer pattern from stdlib to update para in shoes app,
but faced with strange behavior. Instead of updating my para on each 
update mathod execution, 
it updates only once  at the end

Here the code:
require "observer"

class Wrapper < Shoes::Widget
  include Observable

  attr_reader : fraction

  def initialize( array )
    @array = array
  end

  def run
    @array.each_index do |index|
      @fraction = index.to_f/@array.size
      changed true
      notify_observers self
    end
  end
end

Shoes::Para.class_eval do
  def update( subject )
    self.replace(
      "Fraction is #{subject.fraction}"
    )
  end
end

Shoes.app do
  @array = Array.new(15000) {rand 20}
  @list = stack :margin => 0.1 do
    @p = para "Initial value"
  end
  button "Go!" do
    @w = Wrapper.new @array
    @w.add_observer @p
    @w.run    
  end
end

What wrong with it?

Regards,
Artyom

Re: [shoes] Observer pattern in shoes

From:
ashbb
Date:
2010-05-26 @ 11:40
Hi Artyom,

Interesting snippet, thanks. :)

> it updates only once at the end
Ah,... Shoes seems to execute all values in your @array.
But Shoes opens Shoes window after doing that.

If you want to update Shoes window each steps, you need to open another
thread. ;-)

Try to run the following:

require "observer"

class Wrapper
  include Observable

  attr_reader :fraction

  def initialize( array )
    @array = array
  end

  def run
    Thread.start do
      @array.each_index do |index|
        @fraction = index.to_f/@array.size
        changed true
        notify_observers self
        sleep 0.1
      end
    end
  end
end

Shoes::Para.class_eval do
  def update( subject )
    self.replace(
      "Fraction is #{subject.fraction}"
    )
  end
end

Shoes.app do
  @array = Array.new(15000) {rand 20}
  @list = stack :margin => 0.1 do
    @p = para "Initial value"
  end
  button "Go!" do
    @w = Wrapper.new @array
    @w.add_observer @p
    @w.run
  end
end

And you also don't have to use `Shoes::Widget`,
because you are not using any Shoes methods in the Wrapper class.

Hope this helps,
ashbb

Re: [shoes] Observer pattern in shoes

From:
Artyom Bolshkov
Date:
2010-05-26 @ 12:05
ashbb,

thanks, this helps! I killed last day solving this problem.
Actualy i need to do this in separate thread, but at first i desided to 
make it without threads. 

And what about MVC in shoes? 
I have seen lot of examples at the-shoebox.org and shoes-tutorial-note.heroku.com
nobody uses mvc.

Regards,  
Artyom

Re: [shoes] Observer pattern in shoes

From:
Vojtěch Šalbaba
Date:
2010-05-26 @ 17:07
My guess is that most shoes app are quick and dirty "proof of concept"
applications. I haven't seen anything really big, but I would like to be
proven wrong. In the days of yore I built a relatively medium app which
tried to do things MVC style (http://the-shoebox.org/apps/167, shameless
self promotion!), but although it did what it was meant to do (earn me
school credits) it failed at proper MVC. But it uses some observer pattern
for history. And it won't probably work with latest shoes anyway. So no
point me bringing it up, really.
Regards,
 Vojtěch Šalbaba



2010/5/26 Artyom Bolshkov <tweekane@gmail.com>

> ashbb,
>
> thanks, this helps! I killed last day solving this problem.
> Actualy i need to do this in separate thread, but at first i desided to
> make it without threads.
>
> And what about MVC in shoes?
> I have seen lot of examples at the-shoebox.org and
> shoes-tutorial-note.heroku.com
> nobody uses mvc.
>
> Regards,
> Artyom
>

Re: [shoes] Observer pattern in shoes

From:
ashbb
Date:
2010-05-27 @ 14:32
Hi Vojtěch,

> And it won't probably work with latest shoes anyway.
Do you have any problem? What platform are you using?
If you find a problem, please let us know. ;-)

ashbb

Re: [shoes] Observer pattern in shoes

From:
Vojtěch Šalbaba
Date:
2010-05-27 @ 20:01
Meh, i don't really care to start this old app up to test whether it works.
Just reminds me the old times when I had a project to complete and _why went
missing week before deadline, shoes were broken and everybody was trying to
fix it FAST.
I've been keeping eye on shoes mail list ever since, but haven't done any
shoes app in a long time. I might, given we might be doing some multi
platform vnc remote control software where shoes might shine. Although I'm
worried how it will react to very integrated usage, I remember external
dependencies were a pain, shoes not being a true ruby and all that. Thoughts
on that?
Regards
 Vojtěch Šalbaba



2010/5/27 ashbb <ashbbb@gmail.com>

> Hi Vojtěch,
>
>
> > And it won't probably work with latest shoes anyway.
> Do you have any problem? What platform are you using?
> If you find a problem, please let us know. ;-)
>
> ashbb
>
>

Re: [shoes] Observer pattern in shoes

From:
Devyn Cairns
Date:
2010-05-27 @ 22:33
I never had any problems using gems with Shoes on Linux...

I know that on Windows it was problematic, though.

2010/5/27 Vojtěch Šalbaba <darktatka@gmail.com>

> Meh, i don't really care to start this old app up to test whether it works.
> Just reminds me the old times when I had a project to complete and _why went
> missing week before deadline, shoes were broken and everybody was trying to
> fix it FAST.
> I've been keeping eye on shoes mail list ever since, but haven't done any
> shoes app in a long time. I might, given we might be doing some multi
> platform vnc remote control software where shoes might shine. Although I'm
> worried how it will react to very integrated usage, I remember external
> dependencies were a pain, shoes not being a true ruby and all that. Thoughts
> on that?
> Regards
>  Vojtěch Šalbaba
>
>
>
> 2010/5/27 ashbb <ashbbb@gmail.com>
>
> Hi Vojtěch,
>>
>>
>> > And it won't probably work with latest shoes anyway.
>> Do you have any problem? What platform are you using?
>> If you find a problem, please let us know. ;-)
>>
>> ashbb
>>
>>
>


-- 
   ~devyn

Re: [shoes] Observer pattern in shoes

From:
ashbb
Date:
2010-05-28 @ 13:21
Yeah, Raisins for Windows couldn't execute samples/simple-rubygems.rb.
But the latest Policeman (0.r1421) can work well!

Look at a tiny note:
http://github.com/ashbb/shoes_hack_note/blob/master/md/hack025.md

ashbb

Re: [shoes] Observer pattern in shoes

From:
Vojtěch Šalbaba
Date:
2010-05-28 @ 20:23
I think shoes really lost a lot when _why disappeared (I mean reputation.
Don't get offended guys, you do terrific job and I appreciate it). From my
point of view, shoes were getting noticed, promoted and all that stuff, and
then it lost its most appreciated features for half a year. Millions of
programmers screamed in terror and were suddenly silenced as installers
stopped working, the disturbance in the force can be felt even now.

Regards,
 Vojtěch Šalbaba



2010/5/28 ashbb <ashbbb@gmail.com>

> Yeah, Raisins for Windows couldn't execute samples/simple-rubygems.rb.
> But the latest Policeman (0.r1421) can work well!
>
> Look at a tiny note:
> http://github.com/ashbb/shoes_hack_note/blob/master/md/hack025.md
>
> ashbb
>

Re: [shoes] Observer pattern in shoes

From:
Steve Klabnik
Date:
2010-05-28 @ 20:30
None taken. You're exactly right. Everything _why did suffered from this, I
think.

Railsbridge is still interested in promoting shoes, though. And I'll be
going on a huge Hackety promotion after 1.0 this summer.

I think with an actual 3.0 release we can undo the damage.

Re: [shoes] Observer pattern in shoes

From:
Devyn Cairns
Date:
2010-06-02 @ 16:34
I think we'll do whatever we can, and have fun doing it! After all, that is
the point, isn't it?

On Fri, May 28, 2010 at 1:30 PM, Steve Klabnik <steve@steveklabnik.com>wrote:

> None taken. You're exactly right. Everything _why did suffered from this, I
> think.
>
> Railsbridge is still interested in promoting shoes, though. And I'll be
> going on a huge Hackety promotion after 1.0 this summer.
>
> I think with an actual 3.0 release we can undo the damage.
>



-- 
   ~devyn

Re: [shoes] Observer pattern in shoes

From:
Vojtěch Šalbaba
Date:
2010-06-02 @ 13:11
I have to say, even though I didn't hope for it, my app still works on shoes
1419, and looks fabulous! I am really astonished, I must keep closer eye on
you guys..
regards
 Vojtěch Šalbaba



2010/5/28 Steve Klabnik <steve@steveklabnik.com>

> None taken. You're exactly right. Everything _why did suffered from this, I
> think.
>
> Railsbridge is still interested in promoting shoes, though. And I'll be
> going on a huge Hackety promotion after 1.0 this summer.
>
> I think with an actual 3.0 release we can undo the damage.
>

Re: [shoes] Observer pattern in shoes

From:
Steve Klabnik
Date:
2010-05-27 @ 05:48
Hackety Hack is fairly large.

2010/5/26 Vojtěch Šalbaba <darktatka@gmail.com>

> My guess is that most shoes app are quick and dirty "proof of concept"
> applications. I haven't seen anything really big, but I would like to be
> proven wrong. In the days of yore I built a relatively medium app which
> tried to do things MVC style (http://the-shoebox.org/apps/167, shameless
> self promotion!), but although it did what it was meant to do (earn me
> school credits) it failed at proper MVC. But it uses some observer pattern
> for history. And it won't probably work with latest shoes anyway. So no
> point me bringing it up, really.
> Regards,
>  Vojtěch Šalbaba
>
>
>
> 2010/5/26 Artyom Bolshkov <tweekane@gmail.com>
>
> ashbb,
>>
>> thanks, this helps! I killed last day solving this problem.
>> Actualy i need to do this in separate thread, but at first i desided to
>> make it without threads.
>>
>> And what about MVC in shoes?
>> I have seen lot of examples at the-shoebox.org and
>> shoes-tutorial-note.heroku.com
>> nobody uses mvc.
>>
>> Regards,
>> Artyom
>>
>
>

Re: [shoes] progressbar to represent array iteration

From:
ashbb
Date:
2010-05-24 @ 12:01
Hi Артём,

> I tried to dance around animate, but failed with it
Umm...
Could you show us your code or a bit more detail information?

I'd like to help you, if possible. :)

Regards,
ashbb

Re: [shoes] progressbar to represent array iteration

From:
Artyom Bolshkov
Date:
2010-05-24 @ 12:45
Ok, e.g. I have an array and need to process each it's value.
Also I need to show how much of data is already processed.
Here is non-working code:

Shoes.app do
  @array = Array.new(150) {rand 20} 
  stack :margin => 0.1 do
    title "Progress example"
    @p = progress :width => 1.0
    @array.each_with_index do |thing, index|
      sleep rand/50 # not so fast
      animate do
        @p.fraction = index/@array.size
      end
    end
  end
end

I feel something wrong with my understanding 'animate'.

Thanks,
Artyom


On Mon, 24 May 2010 21:01:20 +0900
ashbb <ashbbb@gmail.com> wrote:

> Hi Артём,
> 
> > I tried to dance around animate, but failed with it
> Umm...
> Could you show us your code or a bit more detail information?
> 
> I'd like to help you, if possible. :)
> 
> Regards,
> ashbb

Re: [shoes] progressbar to represent array iteration

From:
ashbb
Date:
2010-05-24 @ 14:24
Artyom,

Thx. I got it. :)

This works. Need to add `to_f` and delete `sleep`.

Shoes.app do
  @array = Array.new(150) {rand 20}
  stack :margin => 0.1 do
    title "Progress example"
    @p = progress :width => 1.0
    @array.each_with_index do |thing, index|
      #sleep rand/50 # not so fast
      animate 1 do
        @p.fraction = index.to_f/@array.size
      end
    end
  end
end

But, I guess what you want to do is this. No? ;-)

Shoes.app do
  @array = Array.new(150) {rand 20}
  stack :margin => 0.1 do
    title "Progress example"
    @p = progress :width => 1.0
    #@array.each_with_index do |thing, index|
      #sleep rand/50 # not so fast
      a = animate do |index|
        @p.fraction = index.to_f/@array.size
        para @array[index]
        a.stop if index == @array.size
      end
    #end
  end
end

Hope this helps,
ashbb

Re: [shoes] progressbar to represent array iteration

From:
Artyom Bolshkov
Date:
2010-05-24 @ 14:37
Ashbb, 

This is beautifull! The second - exactly what i need.
Looks really cool :) 

Thanks a lot!

-- 
Artyom