annotate Mac/PythonLauncher/MyAppDelegate.m @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 1cb2ece4b9e1
children 5d41ebc79738
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 #import "MyAppDelegate.h"
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 #import "PreferencesWindowController.h"
24461
7fc2cec4dc82 Only show the UI for selecting options if the ALT key was depressed while
Jack Jansen <jack.jansen@cwi.nl>
parents: 24426
diff changeset
3 #import <Carbon/Carbon.h>
29557
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
4 #import <ApplicationServices/ApplicationServices.h>
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 @implementation MyAppDelegate
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 - (id)init
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 self = [super init];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 initial_action_done = NO;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 should_terminate = NO;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 return self;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 - (IBAction)showPreferences:(id)sender
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 [PreferencesWindowController getPreferencesWindow];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 - (void)applicationDidFinishLaunching:(NSNotification *)notification
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22 {
29557
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
23 // Test that the file mappings are correct
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
24 [self testFileTypeBinding];
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 // If we were opened because of a file drag or doubleclick
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 // we've set initial_action_done in shouldShowUI
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 // Otherwise we open a preferences dialog.
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 if (!initial_action_done) {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 initial_action_done = YES;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 [self showPreferences: self];
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 - (BOOL)shouldShowUI
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 {
24461
7fc2cec4dc82 Only show the UI for selecting options if the ALT key was depressed while
Jack Jansen <jack.jansen@cwi.nl>
parents: 24426
diff changeset
36 // if this call comes before applicationDidFinishLaunching: we
7fc2cec4dc82 Only show the UI for selecting options if the ALT key was depressed while
Jack Jansen <jack.jansen@cwi.nl>
parents: 24426
diff changeset
37 // should terminate immedeately after starting the script.
7fc2cec4dc82 Only show the UI for selecting options if the ALT key was depressed while
Jack Jansen <jack.jansen@cwi.nl>
parents: 24426
diff changeset
38 if (!initial_action_done)
7fc2cec4dc82 Only show the UI for selecting options if the ALT key was depressed while
Jack Jansen <jack.jansen@cwi.nl>
parents: 24426
diff changeset
39 should_terminate = YES;
7fc2cec4dc82 Only show the UI for selecting options if the ALT key was depressed while
Jack Jansen <jack.jansen@cwi.nl>
parents: 24426
diff changeset
40 initial_action_done = YES;
7fc2cec4dc82 Only show the UI for selecting options if the ALT key was depressed while
Jack Jansen <jack.jansen@cwi.nl>
parents: 24426
diff changeset
41 if( GetCurrentKeyModifiers() & optionKey )
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 return YES;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 return NO;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 - (BOOL)shouldTerminate
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 return should_terminate;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 {
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 return NO;
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 }
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55
29557
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
56 - (void)testFileTypeBinding
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
57 {
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
58 NSURL *ourUrl;
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
59 OSStatus err;
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
60 FSRef appRef;
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
61 NSURL *appUrl;
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
62 static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL};
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
63 NSString **ext_p;
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
64 int i;
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
65
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
66 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"])
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
67 return;
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
68 ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]];
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
69 for( ext_p = extensions; *ext_p; ext_p++ ) {
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
70 err = LSGetApplicationForInfo(
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
71 kLSUnknownType,
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
72 kLSUnknownCreator,
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
73 (CFStringRef)*ext_p,
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
74 kLSRolesViewer,
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
75 &appRef,
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
76 (CFURLRef *)&appUrl);
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
77 if (err || ![appUrl isEqual: ourUrl] ) {
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
78 i = NSRunAlertPanel(@"File type binding",
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
79 @"PythonLauncher is not the default application for all " \
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
80 @"Python script types. You should fix this with the " \
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
81 @"Finder's \"Get Info\" command.\n\n" \
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
82 @"See \"Changing the application that opens a file\" in " \
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
83 @"Mac Help for details.",
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
84 @"OK",
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
85 @"Don't show this warning again",
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
86 NULL);
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
87 if ( i == 0 ) { // Don't show again
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
88 [[NSUserDefaults standardUserDefaults]
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
89 setObject:@"YES" forKey:@"SkipFileBindingTest"];
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
90 }
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
91 return;
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
92 }
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
93 }
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
94 }
4272322b92e5 At startup, test that PythonLauncher is the default application for files
Jack Jansen <jack.jansen@cwi.nl>
parents: 24461
diff changeset
95
24426
9afac0dd6b6e First stab at the launcher application. This will be run when the user
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96 @end