Re: [MacRuby-devel] Dynamic refresh in a view - xcode 4 / MacRuby
Just as an extra FYI, you are indeed blocking the main thread by using `sleep 1`, which is a synchronous call and thus in that one second no other code on the same thread will have a chance to update your views. On Wed, May 25, 2011 at 7:50 AM, Thomas R. Koll wrote: > Laurent is right and and I think best would be for you to use a NSTimer. > > def drawWord > if !next_word > self.timer.invalidate > return > end > self.label.stringValue = next_word > self.setNeedsDisplay true > end > > def next_word > ... > end > > self.timer = NSTimer.scheduledTimerWithTimeInterval( 1/20.0, > target:self, selector:"drawWord:", userInfo:nil, repeats:true) > > > > Am 25.05.2011 um 02:06 schrieb [email protected]: > >> I have a label that I have set to blank, and after a user clicks 'go' I >> generate a random word or number and use: >> >> self.label.stringValue = "some_word" >> >> to update the view. >> >> However, I would like to show 200 or so random words in quick succession >> before the final one is shown - just because it's too plain at the moment. >> Alternatively, I'd be happy with showing an animated graphic in its place - >> which is replaced by the final random word after a few seconds. >> >> I've tried things like: >> >> 100.times do >> num = rand(40) >> self.label.stringValue = num >> sleep 1 >> end >> >> But it doesn't work. I've also (after googling) tried .reloadData but to no >> avail as well. >> >> Any ideas on how to achieve this? Or pointers on how to add animations to my >> window/views? > > > -- > Thomas R. "TomK32" Koll, Ruby/Rails freelancer > http://ananasblau.com | http://github.com/TomK32 > > > > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] Break in Block Fails only in Macruby
Greetings,
If I run the following under the system ruby 1.8.7:
require 'find'
starting_directory="/Users/developer/Desktop/Top"
file_name_I_want_to_find="target_file.txt"
path=Find.find(starting_directory) {|p| break p if
p.include?(file_name_I_want_to_find) }
puts "path = #{path}"
... I get the expected output:
path = /Users/developer/Desktop/Top/Lev_1-2/Lev_2.1/target_file.txt
However, if I run it under Macruby I get nothing, just:
path =
I'm running MacRuby 0.10 (ruby 1.9.2) [universal-darwin10.0, x86_64] on 10.6.7
Not sure what is going on.
Thanks,
Shannon
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Break in Block Fails only in Macruby
Indeed.
$ ./miniruby -e "require 'find'; p Find.find('.') { break 42 }"
nil
$ ruby1.9 -e "require 'find'; p Find.find('.') { break 42 }"
42
Can you file a ticket?
Thanks,
Laurent
On May 25, 2011, at 1:23 PM, Shannon Love wrote:
> Greetings,
>
> If I run the following under the system ruby 1.8.7:
>
> require 'find'
> starting_directory="/Users/developer/Desktop/Top"
> file_name_I_want_to_find="target_file.txt"
> path=Find.find(starting_directory) {|p| break p if
> p.include?(file_name_I_want_to_find) }
> puts "path = #{path}"
>
> ... I get the expected output:
>
> path = /Users/developer/Desktop/Top/Lev_1-2/Lev_2.1/target_file.txt
>
> However, if I run it under Macruby I get nothing, just:
>
> path =
>
> I'm running MacRuby 0.10 (ruby 1.9.2) [universal-darwin10.0, x86_64] on 10.6.7
>
> Not sure what is going on.
>
> Thanks,
> Shannon
>
>
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Dynamic refresh in a view - xcode 4 / MacRuby
Just one minor detail, the NSTimer callback method accepts an argument (which is a reference to the NSTimer object). So it should be: def drawWord(sender) … end If it works otherwise, then it's pure luck :) Laurent On May 24, 2011, at 10:50 PM, Thomas R. Koll wrote: > Laurent is right and and I think best would be for you to use a NSTimer. > > def drawWord > if !next_word >self.timer.invalidate >return > end > self.label.stringValue = next_word > self.setNeedsDisplay true > end > > def next_word > ... > end > > self.timer = NSTimer.scheduledTimerWithTimeInterval( 1/20.0, > target:self, selector:"drawWord:", userInfo:nil, repeats:true) > > > > Am 25.05.2011 um 02:06 schrieb [email protected]: > >> I have a label that I have set to blank, and after a user clicks 'go' I >> generate a random word or number and use: >> >> self.label.stringValue = "some_word" >> >> to update the view. >> >> However, I would like to show 200 or so random words in quick succession >> before the final one is shown - just because it's too plain at the moment. >> Alternatively, I'd be happy with showing an animated graphic in its place - >> which is replaced by the final random word after a few seconds. >> >> I've tried things like: >> >> 100.times do >> num = rand(40) >> self.label.stringValue = num >> sleep 1 >> end >> >> But it doesn't work. I've also (after googling) tried .reloadData but to no >> avail as well. >> >> Any ideas on how to achieve this? Or pointers on how to add animations to my >> window/views? > > > -- > Thomas R. "TomK32" Koll, Ruby/Rails freelancer > http://ananasblau.com | http://github.com/TomK32 > > > > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Dynamic refresh in a view - xcode 4 / MacRuby
Hey guys - thanks for the tips. I must be really thick as I couldn't get it to work but... I managed to work something out by just creating a new thread for the loop - and it seems to be working ok *grin* Thanks again for your help! Aston On 25 May 2011, at 21:28, Laurent Sansonetti wrote: > Just one minor detail, the NSTimer callback method accepts an argument (which > is a reference to the NSTimer object). So it should be: > > def drawWord(sender) >… > end > > If it works otherwise, then it's pure luck :) > > Laurent > > On May 24, 2011, at 10:50 PM, Thomas R. Koll wrote: > >> Laurent is right and and I think best would be for you to use a NSTimer. >> >> def drawWord >> if !next_word >> self.timer.invalidate >> return >> end >> self.label.stringValue = next_word >> self.setNeedsDisplay true >> end >> >> def next_word >> ... >> end >> >> self.timer = NSTimer.scheduledTimerWithTimeInterval( 1/20.0, >> target:self, selector:"drawWord:", userInfo:nil, repeats:true) >> >> >> >> Am 25.05.2011 um 02:06 schrieb [email protected]: >> >>> I have a label that I have set to blank, and after a user clicks 'go' I >>> generate a random word or number and use: >>> >>> self.label.stringValue = "some_word" >>> >>> to update the view. >>> >>> However, I would like to show 200 or so random words in quick succession >>> before the final one is shown - just because it's too plain at the moment. >>> Alternatively, I'd be happy with showing an animated graphic in its place - >>> which is replaced by the final random word after a few seconds. >>> >>> I've tried things like: >>> >>> 100.times do >>> num = rand(40) >>> self.label.stringValue = num >>> sleep 1 >>> end >>> >>> But it doesn't work. I've also (after googling) tried .reloadData but to no >>> avail as well. >>> >>> Any ideas on how to achieve this? Or pointers on how to add animations to >>> my window/views? >> >> >> -- >> Thomas R. "TomK32" Koll, Ruby/Rails freelancer >> http://ananasblau.com | http://github.com/TomK32 >> >> >> >> >> ___ >> MacRuby-devel mailing list >> [email protected] >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
