Re: Draw a nsview with nsbutton cell

2012-10-18 Thread Graham Cox

On 18/10/2012, at 4:05 PM, Sanjay Arora saar...@quark.com wrote:

 Is there a way I could draw my NSView with the how a NSButtonCell draws
 on NSButton.
 
 I mean I only want the drawing part of the NSButton to draw on my nsview
 all other NSButton actions/events should not work. I don't want to add
 NSButton as subview of my NSView however.


Instantiate a NSButtonCell and call its drawing methods from your view's 
drawRect:

--Graham



___

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: Draw a nsview with nsbutton cell

2012-10-18 Thread Sanjay Arora
Thanks. That works like a charm!

Regards
Sanjay

-Original Message-
From: Graham Cox [mailto:graham@bigpond.com] 
Sent: 18 October 2012 12:15 PM
To: Sanjay Arora
Cc: Cocoa Dev
Subject: Re: Draw a nsview with nsbutton cell


On 18/10/2012, at 4:05 PM, Sanjay Arora saar...@quark.com wrote:

 Is there a way I could draw my NSView with the how a NSButtonCell
draws
 on NSButton.
 
 I mean I only want the drawing part of the NSButton to draw on my
nsview
 all other NSButton actions/events should not work. I don't want to add
 NSButton as subview of my NSView however.


Instantiate a NSButtonCell and call its drawing methods from your view's
drawRect:

--Graham



___

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: How to send fetchrequest to main context from a local context on a separate thread?

2012-10-18 Thread Koen van der Drift
After some more searching I came to the following plan.

1. get the main context from another thread as follows:

  AppDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
  NSManagedObjectContext *mainContext = [appDelegate managedObjectContext];

2. use performSelectorOnMainThread to execute the fetch request:

[mainContext performSelectorOnMainThread:@selector(executeFetchRequest:)
withObject:fetchRequest
 waitUntilDone:YES];

However, performSelectorOnMainThread does not give a return value
back, and the selector should really be executeFetchRequest:error:

One way to solve this would be to use an NSInvocation, I think? Or
maybe wrap the executeFetchRequest in another method, call
performSelectorOnMainThread on it, and then use a notification to send
the result back.

Will try this later, does any of these approaches sound reasonable?

- Koen.



On Wed, Oct 17, 2012 at 12:25 PM, Koen van der Drift
koenvanderdr...@gmail.com wrote:
 I'm reading up on importing data into the CD store using multiple
 contexts and threads.This article has already been very helpful:
 http://www.duckrowing.com/2010/03/11/using-core-data-on-multiple-threads/
  Now if I have a local context on a separate thread to import my data,
 how can I send a fetchrequest to the main context to see if a certain
 entity already exists, and thus skip the import?  I already have the
 fetchrequest code, just trying to understand how to access the main
 context form a separate thread.

 Thanks,

 - Koen.
___

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: How to send fetchrequest to main context from a local context on a separate thread?

2012-10-18 Thread Mike Abdullah

On 18 Oct 2012, at 16:01, Koen van der Drift koenvanderdr...@gmail.com wrote:

 After some more searching I came to the following plan.
 
 1. get the main context from another thread as follows:
 
  AppDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
  NSManagedObjectContext *mainContext = [appDelegate managedObjectContext];
 
 2. use performSelectorOnMainThread to execute the fetch request:
 
 [mainContext performSelectorOnMainThread:@selector(executeFetchRequest:)
withObject:fetchRequest
 waitUntilDone:YES];
 
 However, performSelectorOnMainThread does not give a return value
 back, and the selector should really be executeFetchRequest:error:
 
 One way to solve this would be to use an NSInvocation, I think? Or
 maybe wrap the executeFetchRequest in another method, call
 performSelectorOnMainThread on it, and then use a notification to send
 the result back.
 
 Will try this later, does any of these approaches sound reasonable?

Here's what you want:

__block BOOL exists;
dispatch_sync(dispatch_get_main_queue, ^{
NSManagedObjectContext *context = … // grab the context
exists = … // query the context to see if the data already exists
});


Works on OS X 10.6+ and iOS4+
___

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

Cross-fading between layers

2012-10-18 Thread Gabriel Zachmann
About a week ago I have posted about my problem with (not) cross-fading Core 
Animation layers in Mountain Lion.

Perhaps, my post was too long ;-)
Perhaps I forgot to mention that I did google quite bit, but didn't understand 
what the best solution would be in my case.

So far, I am fading out an existing layer, and fading in a new layer by the 
following 5 lines of code:

   [CATransaction begin];
   [CATransaction setAnimationDuration: fading_duration]; 
   [mainLayer_ replaceSublayer: currentLayer_ with: newlayer];
   currentLayer_ = newlayer;
   [CATransaction commit];

This works fine under Lion, and it worked fine under Snow Leopard.

It does not work any more under ML, i.e., the layers get replaced, but there is 
no cross-dissolve effect.

Apparently, a number of other people have a similar problem, but the solutions 
some of them propose were not clear to me.

Could some kind soul explain to me how to achieve the cross-dissolve effect 
under ML?

Thanks a lot in advance.


Best regards,
Gabriel.


___

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: Cross-fading between layers

2012-10-18 Thread Kyle Sluder
On Oct 18, 2012, at 8:50 AM, Gabriel Zachmann z...@tu-clausthal.de wrote:

 So far, I am fading out an existing layer, and fading in a new layer by the 
 following 5 lines of code:
 
   [CATransaction begin];
   [CATransaction setAnimationDuration: fading_duration]; 
   [mainLayer_ replaceSublayer: currentLayer_ with: newlayer];
   currentLayer_ = newlayer;
   [CATransaction commit];
 
 This works fine under Lion, and it worked fine under Snow Leopard.
 
 It does not work any more under ML, i.e., the layers get replaced, but there 
 is no cross-dissolve effect.

My psychic powers tell me that mainLayer_'s delegate is an NSView instance.

Read the Mountain Lion release notes and watch the WWDC videos on implicit 
animations in AppKit using NSAnimationContext.

--Kyle Sluder
___

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: Cross-fading between layers

2012-10-18 Thread Corbin Dunn

On Oct 18, 2012, at 9:53 AM, Kyle Sluder k...@ksluder.com wrote:

 On Oct 18, 2012, at 8:50 AM, Gabriel Zachmann z...@tu-clausthal.de wrote:
 
 So far, I am fading out an existing layer, and fading in a new layer by the 
 following 5 lines of code:
 
  [CATransaction begin];
  [CATransaction setAnimationDuration: fading_duration]; 
  [mainLayer_ replaceSublayer: currentLayer_ with: newlayer];
  currentLayer_ = newlayer;
  [CATransaction commit];
 
 This works fine under Lion, and it worked fine under Snow Leopard.
 
 It does not work any more under ML, i.e., the layers get replaced, but there 
 is no cross-dissolve effect.
 
 My psychic powers tell me that mainLayer_'s delegate is an NSView instance.

I had that same inclination!

 Read the Mountain Lion release notes and watch the WWDC videos on implicit 
 animations in AppKit using NSAnimationContext.

Yeah, those videos are great. 

corbin

PS: NSAnimationContext.currentContext.allowsImplicitAnimations = YES;

 
 
 --Kyle Sluder
 ___
 
 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/corbind%40apple.com
 
 This email sent to corb...@apple.com


___

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: Associate icon with file ext. / quick look

2012-10-18 Thread Seth Willits
On Oct 18, 2012, at 4:04 AM, Jean Suisse wrote:

 Thank you for your reply. I am not familiar with the topic, but if I 
 understand you correctly, what you say implies that :
 
 1. The icon for the file type must be the same than the icon for the app.
 2. If my app generates three files of different types for each record (e.g.: 
 a setup file containing parameters, a raw acquired data file, a signature 
 file), I can't have three different icons, one for each file

No, not at all.


A dozen different applications may be able to open and edit a certain file 
type, but only *one* application on the system is designated as the default 
handler for that file type. (It owns the file type in my prior lingo.) This 
is the application that will launch and open the file if you double-click it in 
Finder.

*That* application is the one responsible for supplying the icon for the file 
type, not the application which created the file. In other words Acrobat and 
Preview can both open and save pdf files, but Preview is the default handler 
for pdf files on my system, so the system will show pdf files using Previews's 
pdf file icon, even if I create a pdf file inside of Acrobat. If I set Acrobat 
as the default handler, all pdf files would display using Acrobat's pdf icon.

However, there are exceptions to this.

1) You (or an application) can set a file to open with an application 
other than the default handler for its file type, so it would not use the 
default handling application's icon for that file type.

2) You (or an application) can set a custom file icon on a file, even 
if it isn't the default handling application. So while Preview may be the 
default handler for pdfs on my system, Acrobat could set a custom icon on the 
file. When I double-click on it, it may still open in Preview, though unless 
Acrobat did #1 and overrides the default to claim ownership for that *specific* 
file.



So what I am saying is if your Creator application is creating .jean files, 
but the Viewer application is the one set to be the default handler for .jean 
files when they're double-clicked in Finder, then Finder will display .jean 
files using the icon for the .jean file type that Viewer has in its bundle. 
Creator's icon for .jean files will not be used. 


___

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


iOS; how to connect to 3G

2012-10-18 Thread M Pulis
My iOS app uses the Reachability sample code to detect network  
availability to work offline or online.


When using 3G, we get to the connectionrequired state. What to do  
then? We try a login to our web site and that fails.


WIFI works great, but we need 3G also.

What am I missing or should read up on?

Gary
___

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: iOS; how to connect to 3G

2012-10-18 Thread David Duncan
On Oct 18, 2012, at 12:55 PM, M Pulis tooth...@fastq.com wrote:

 My iOS app uses the Reachability sample code to detect network availability 
 to work offline or online.
 
 When using 3G, we get to the connectionrequired state. What to do then? We 
 try a login to our web site and that fails.
 
 WIFI works great, but we need 3G also.
 
 What am I missing or should read up on?


If you use CF or NS (or anything build on top of that) to connect, then it 
should just work. If you are using raw BSD sockets, then there is no way to 
connect other than using CF or NS.

Also Reachability isn't meant to be used to determine online vs offline. Its 
meant to determine if it is a good time to try to connect or not. Due to 
realities of networking it is entirely possible for Reachability to tell you 
try to connect and to fail completely.

Basically when using Reachability, you should always use the callback to know 
when to retry any previously failed connections, and once you get a callback 
that says that connection is possible, then you should try to make the 
connection, while continuing plan for possible failure.
--
David Duncan


___

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: iOS; how to connect to 3G

2012-10-18 Thread M Pulis

Thanks!

Not using anything low level... hence the surprise we actually use  
it to determine if our login url is reachable; if not we work  
offline. I'll take a deeper look at what we are doing there.


Gary


On Oct 18, 2012, at 1:12 PM, David Duncan wrote:


On Oct 18, 2012, at 12:55 PM, M Pulis tooth...@fastq.com wrote:

My iOS app uses the Reachability sample code to detect network  
availability to work offline or online.


When using 3G, we get to the connectionrequired state. What to do  
then? We try a login to our web site and that fails.


WIFI works great, but we need 3G also.

What am I missing or should read up on?



If you use CF or NS (or anything build on top of that) to connect,  
then it should just work. If you are using raw BSD sockets, then  
there is no way to connect other than using CF or NS.


Also Reachability isn't meant to be used to determine online vs  
offline. Its meant to determine if it is a good time to try to  
connect or not. Due to realities of networking it is entirely  
possible for Reachability to tell you try to connect and to fail  
completely.


Basically when using Reachability, you should always use the  
callback to know when to retry any previously failed connections,  
and once you get a callback that says that connection is possible,  
then you should try to make the connection, while continuing plan  
for possible failure.

--
David Duncan


___

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: iOS; how to connect to 3G

2012-10-18 Thread Kyle Sluder
On Thu, Oct 18, 2012, at 01:25 PM, M Pulis wrote:
 Thanks!
 
 Not using anything low level... hence the surprise we actually use  
 it to determine if our login url is reachable; if not we work  
 offline. I'll take a deeper look at what we are doing there.

You can't use Reachability to determine if a URL is reachable. The
concept of a URL exists at a much higher level than Reachability
operates at.

Reachability determines if you have a route to a host at a hostname.
That means it asks the system to resolve the hostname if necessary, then
consults the routing table to determine if it has a rule to route
packets to that host out of the device.

It tells you nothing about whether the packets would actually make it
there once they've left your device, or if they did whether they could
be used to form form a working higher-level connection like HTTP.

If you want to determine whether you can connect to a server on a TCP
socket, the only thing you can do is attempt the connection.

If you want to determine whether you can access a resource over HTTP,
the only thing you can do is attempt to access the resource.

The only thing Reachability is good for is an early test to see if the
device knows it can't possibly communicate with a host because it can't
route packets to it. If this is the case, it also gives you a way to be
notified when circumstances change and you should try again.

--Kyle Sluder
___

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