Re: updating NSTextField before spinner animates

2014-11-12 Thread Graham Cox
The right solution is, as Fritz mentioned, to design your code to work 
asynchronously. But for a quick-and-dirty solution to force a text field (or 
any other UI) to show a change straight away is to include the redraw directly 
yourself. This should not be done from a thread other than main however.

[_infoField setStringValue:@"hello world!"];
[[_infoField window] displayIfNeeded];  // processes view 
updates pending

// . some lengthy code that blocks the main thread, delaying normal updates 
.


--Graham



> On 12 Nov 2014, at 7:58 pm, sqwarqDev  wrote:
> 
>> On 11 Nov 2014, at 23:01, Fritz Anderson  wrote:
> 
>> -needsDisplay schedules a view’s -drawRect: for the next pass through the 
>> runloop. You’re putting your process to sleep at the OS level, so the 
>> runloop is suspended along with everything else.
>> 
>> What you posted is evidently a minimal case, and maybe, instead of sleep(), 
>> your lengthy method is called instead. Same principle: Unless that method 
>> runs asynchronously (or simulates asynchrony by doing its work piecewise on 
>> an NSTimer, or by periodically sending -runMode:beforeDate: to the runloop), 
>> the runloop never has the chance to dispatch view updates.
> 
> 
> Thanks for this Fritz. I think I get it. I need to get a clearer idea of how 
> the run loop works. This isn't the first time I've been confused about why a 
> line doesn't appear to return the result I expect before the next line 
> executes. I suppose this is part of the difference between using traditonal 
> procedural languages and these /new-fangled/ object-oriented ones... :~)
> 
> I guess I've got some reading up to do! Thanks again.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: updating NSTextField before spinner animates

2014-11-12 Thread Fritz Anderson
On 12 Nov 2014, at 2:58 AM, sqwarqDev  wrote:

> Thanks for this Fritz. I think I get it. I need to get a clearer idea of how 
> the run loop works. This isn't the first time I've been confused about why a 
> line doesn't appear to return the result I expect before the next line 
> executes. I suppose this is part of the difference between using traditonal 
> procedural languages and these /new-fangled/ object-oriented ones... :~)

For the record, this isn’t a procedural-vs-object-oriented matter. Procedural 
applications may run in an asynchronous environment and OO languages can be run 
in a synchronous environment.

— F


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: updating NSTextField before spinner animates

2014-11-12 Thread sqwarqDev
> On 11 Nov 2014, at 23:01, Fritz Anderson  wrote:

> -needsDisplay schedules a view’s -drawRect: for the next pass through the 
> runloop. You’re putting your process to sleep at the OS level, so the runloop 
> is suspended along with everything else.
> 
> What you posted is evidently a minimal case, and maybe, instead of sleep(), 
> your lengthy method is called instead. Same principle: Unless that method 
> runs asynchronously (or simulates asynchrony by doing its work piecewise on 
> an NSTimer, or by periodically sending -runMode:beforeDate: to the runloop), 
> the runloop never has the chance to dispatch view updates.


Thanks for this Fritz. I think I get it. I need to get a clearer idea of how 
the run loop works. This isn't the first time I've been confused about why a 
line doesn't appear to return the result I expect before the next line 
executes. I suppose this is part of the difference between using traditonal 
procedural languages and these /new-fangled/ object-oriented ones... :~)

I guess I've got some reading up to do! Thanks again.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: updating NSTextField before spinner animates

2014-11-11 Thread Fritz Anderson
On 11 Nov 2014, at 4:15 AM, sqwarqDev  wrote:

> I have  an NSTextView, whose string I want to update while I wait for another 
> method to complete. Since this method is going to take around 10-30 seconds, 
> I'm displaying a spinner progress indicator.
> 
> However, I want the text field to update before (and, ideall, during, but 
> I'll settle for before) the spinner starts, but no matter where I put the 
> text field message, it waits until the spinner has finished before updating. 
> I've even tested to make sure the update happens first (see the conditional 
> clause below), but the update is not shown in the view until the spinner 
> finishes. 
> 
...
> [_mySpinner startAnimation:nil];
> 
> [_infoField setString:@"display something..."];
> 
> NSString *didChange = [_infoField string];
>NSRange r = [didChange rangeOfString:@"something"];
>[_infoField needsDisplay];
>if (r.location !=NSNotFound) {
>NSLog(@"hit sleep");
>sleep(5);
>}
>[_mySpinner stopAnimation:nil];
> 
> 
> Putting the _infoField setString call before the spinner's startAnimation 
> call makes no difference. What am I doing wrong?
> 

-needsDisplay schedules a view’s -drawRect: for the next pass through the 
runloop. You’re putting your process to sleep at the OS level, so the runloop 
is suspended along with everything else.

What you posted is evidently a minimal case, and maybe, instead of sleep(), 
your lengthy method is called instead. Same principle: Unless that method runs 
asynchronously (or simulates asynchrony by doing its work piecewise on an 
NSTimer, or by periodically sending -runMode:beforeDate: to the runloop), the 
runloop never has the chance to dispatch view updates.

— F


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

updating NSTextField before spinner animates

2014-11-11 Thread sqwarqDev
Using Xcode Version 6.1 (6A1052d) on the latest developer build of Yosemite.

I'm confused as to whether this is a bug, or if I'm just doing something wrong. 

I have  an NSTextView, whose string I want to update while I wait for another 
method to complete. Since this method is going to take around 10-30 seconds, 
I'm displaying a spinner progress indicator.

However, I want the text field to update before (and, ideall, during, but I'll 
settle for before) the spinner starts, but no matter where I put the text field 
message, it waits until the spinner has finished before updating. I've even 
tested to make sure the update happens first (see the conditional clause 
below), but the update is not shown in the view until the spinner finishes. 

In the following method, the 'hit sleep' message and sleep functions are both 
called, but the text "display something..." isn't shown until after the spinner 
stopAnimation call. 

 [_mySpinner startAnimation:nil];

 [_infoField setString:@"display something..."];
  
NSString *didChange = [_infoField string];
NSRange r = [didChange rangeOfString:@"something"];
[_infoField needsDisplay];
if (r.location !=NSNotFound) {
NSLog(@"hit sleep");
sleep(5);
}
[_mySpinner stopAnimation:nil];


Putting the _infoField setString call before the spinner's startAnimation call 
makes no difference. What am I doing wrong?


Related? I do get an error in Xcode's console when this method fires, but its 
one I've had (and filed) before in a completely different scenario and I'm not 
sure it's related:


IMK Stall detected, *please Report* your user scenario in 
 - (imkxpc_selectedRangeWithReply:) block performed 
very slowly (4.29 secs)
2014-11-11 16:52:24.447 App Fixer[507:4410] IMK Stall detected, *please Report* 
your user scenario in  - 
(imkxpc_attributesForCharacterIndex:reply:) block performed very slowly (2.29 
secs)


Any thoughts as to how I can get my text field to update, before or duing the 
spinner's run would be very much appreciated.


Best


Phil



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com