FROM : Hamish Allan
DATE : Tue Apr 12 13:52:08 2005
On Mon, 11 Apr 2005 21:51:09 -0400, Ken Tozier <<email_removed>>
wrote:
> Sorry to keep beating this issue, but there is something fundamentally
> wrong somewhere in the following six steps and I'm just not experienced
> enough with Cocoa GUI stuff to see it. To me, the algorithm looks fine,
> but there is some subtle thing that Cocoa doesn't like.
>
> The problem is that the window generated in step 6.A and displayed in
> 6.B is never frontmost and can't even be forced to front by clicking on
> it. The only way to bring it to front is to put the window load code
> inside a thread (which I'm told is bad for GUI stuff) Even when it's
> placed in a thread, it doesn't become frontmost without manually
> clicking on it.
>
> Anyone see the error?
You're receiving the camera connect notification on the main thread, so
you're also performing the download on the main thread. This lengthy
task is blocking the thread from dealing with make-key-and-order-front
events which, as things stand, can only be processed after the download
is done and the window is closed.
You need to spawn a new thread for step 6C, like this:
- (void)startDownloading:
{
// ...load and show DownloadWindow...
[NSThread detachNewThreadSelector: @selector(doDownloading:)
toTarget:self withObject:downloadDirectory];
}
- (void)doDownloading:(id)userData
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *dataType = (NSString *)userData;
// ...do downloading...
[self performSelectorOnMainThread: @selector(finishDownloading:)
withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)finishDownloading:(id)userData
{
// ...hide DownloadWindow...
}
Best wishes,
Hamish
>
> Thanks
>
> Ken
>
> Sequence of events:
> --------------------------------
> 1. Application opens "main" nib
>
> 2. "AppController" instance inside "main" nib initializes it's
> "downloader" instance
>
> - (id) init
> {
> self = [super init];
> if (self)
> {
> downloader = [[ICADownloader alloc] init];
> }
>
> return self;
> }
>
> 3. Downloader instance registers for camera connect events in it's
> "init" method
>
>
> - (id) init
> {
> self = [super init];
> if (self)
> {
> [self registerForCameraConnectNotifications];
> }
>
> return self;
> }
>
>
> 4. Time passes
>
> 5. User plugs in a camera
>
> 6. Downloader receives camera connect notification and performs
> following actions:
>
> A. Creates a new window by loading the "DownloadWindow" nib file using
> NSWindowController with an owner of "self".
> B. Displays the window.
> C. Downloads photos to a specified directory.
> D. Closes window.
>
> 7. Done/Waits for another camera connect event.
>
>
> Hierarchically, the location of the window create code is
>
> App
> {
> Main Nib
> {
> AppController
> {
> downloader
> {
> handleCameraConnect <- (callback method)
> {
> NSWindowController *wind
> }
> }
> }
> }
> }
>
DATE : Tue Apr 12 13:52:08 2005
On Mon, 11 Apr 2005 21:51:09 -0400, Ken Tozier <<email_removed>>
wrote:
> Sorry to keep beating this issue, but there is something fundamentally
> wrong somewhere in the following six steps and I'm just not experienced
> enough with Cocoa GUI stuff to see it. To me, the algorithm looks fine,
> but there is some subtle thing that Cocoa doesn't like.
>
> The problem is that the window generated in step 6.A and displayed in
> 6.B is never frontmost and can't even be forced to front by clicking on
> it. The only way to bring it to front is to put the window load code
> inside a thread (which I'm told is bad for GUI stuff) Even when it's
> placed in a thread, it doesn't become frontmost without manually
> clicking on it.
>
> Anyone see the error?
You're receiving the camera connect notification on the main thread, so
you're also performing the download on the main thread. This lengthy
task is blocking the thread from dealing with make-key-and-order-front
events which, as things stand, can only be processed after the download
is done and the window is closed.
You need to spawn a new thread for step 6C, like this:
- (void)startDownloading:
{
// ...load and show DownloadWindow...
[NSThread detachNewThreadSelector: @selector(doDownloading:)
toTarget:self withObject:downloadDirectory];
}
- (void)doDownloading:(id)userData
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *dataType = (NSString *)userData;
// ...do downloading...
[self performSelectorOnMainThread: @selector(finishDownloading:)
withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)finishDownloading:(id)userData
{
// ...hide DownloadWindow...
}
Best wishes,
Hamish
>
> Thanks
>
> Ken
>
> Sequence of events:
> --------------------------------
> 1. Application opens "main" nib
>
> 2. "AppController" instance inside "main" nib initializes it's
> "downloader" instance
>
> - (id) init
> {
> self = [super init];
> if (self)
> {
> downloader = [[ICADownloader alloc] init];
> }
>
> return self;
> }
>
> 3. Downloader instance registers for camera connect events in it's
> "init" method
>
>
> - (id) init
> {
> self = [super init];
> if (self)
> {
> [self registerForCameraConnectNotifications];
> }
>
> return self;
> }
>
>
> 4. Time passes
>
> 5. User plugs in a camera
>
> 6. Downloader receives camera connect notification and performs
> following actions:
>
> A. Creates a new window by loading the "DownloadWindow" nib file using
> NSWindowController with an owner of "self".
> B. Displays the window.
> C. Downloads photos to a specified directory.
> D. Closes window.
>
> 7. Done/Waits for another camera connect event.
>
>
> Hierarchically, the location of the window create code is
>
> App
> {
> Main Nib
> {
> AppController
> {
> downloader
> {
> handleCameraConnect <- (callback method)
> {
> NSWindowController *wind
> }
> }
> }
> }
> }
>
| Related mails | Author | Date |
|---|---|---|
| Ken Tozier | Apr 11, 17:54 | |
| Lorenzo | Apr 11, 19:03 | |
| Ken Tozier | Apr 11, 20:31 | |
| j o a r | Apr 11, 20:59 | |
| Ken Tozier | Apr 11, 21:59 | |
| Ken Tozier | Apr 12, 03:51 | |
| Charilaos Skiadas | Apr 12, 04:13 | |
| Ken Tozier | Apr 12, 06:32 | |
| Charilaos Skiadas | Apr 12, 07:06 | |
| Ken Tozier | Apr 12, 07:35 | |
| Hamish Allan | Apr 12, 13:52 |






Cocoa mail archive

