Changeset 391 for python/trunk/Mac/PythonLauncher
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Mac/PythonLauncher/FileSettings.h
r2 r391 46 46 + (id)newSettingsForFileType: (NSString *)filetype; 47 47 48 //- (id)init;49 48 - (id)initForFileType: (NSString *)filetype; 50 49 - (id)initForFSDefaultFileType: (NSString *)filetype; 51 50 - (id)initForDefaultFileType: (NSString *)filetype; 52 //- (id)initWithFileSettings: (FileSettings *)source;53 51 54 52 - (void)updateFromSource: (id <FileSettingsSource>)source; 55 53 - (NSString *)commandLineForScript: (NSString *)script; 56 54 57 //- (void)applyFactorySettingsForFileType: (NSString *)filetype;58 //- (void)saveDefaults;59 //- (void)applyUserDefaults: (NSString *)filetype;60 55 - (void)applyValuesFromDict: (NSDictionary *)dict; 61 56 - (void)reset; -
python/trunk/Mac/PythonLauncher/FileSettings.m
r2 r391 15 15 static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc; 16 16 FileSettings **curdefault; 17 17 18 18 if ([filetype isEqualToString: @"Python Script"]) { 19 19 curdefault = &fsdefault_py; … … 37 37 static FileSettings *default_py, *default_pyw, *default_pyc; 38 38 FileSettings **curdefault; 39 39 40 40 if ([filetype isEqualToString: @"Python Script"]) { 41 41 curdefault = &default_py; … … 58 58 { 59 59 FileSettings *cur; 60 60 61 61 cur = [FileSettings new]; 62 62 [cur initForFileType: filetype]; … … 68 68 self = [super init]; 69 69 if (!self) return self; 70 70 71 71 interpreter = [source->interpreter retain]; 72 72 honourhashbang = source->honourhashbang; … … 82 82 prefskey = source->prefskey; 83 83 if (prefskey) [prefskey retain]; 84 84 85 85 return self; 86 86 } … … 89 89 { 90 90 FileSettings *defaults; 91 91 92 92 defaults = [FileSettings getDefaultsForFileType: filetype]; 93 93 self = [self initWithFileSettings: defaults]; … … 96 96 } 97 97 98 //- (id)init99 //{100 // self = [self initForFileType: @"Python Script"];101 // return self;102 //}103 104 98 - (id)initForFSDefaultFileType: (NSString *)filetype 105 99 { … … 108 102 NSDictionary *dict; 109 103 static NSDictionary *factorySettings; 110 104 111 105 self = [super init]; 112 106 if (!self) return self; 113 107 114 108 if (factorySettings == NULL) { 115 109 NSBundle *bdl = [NSBundle mainBundle]; … … 150 144 NSUserDefaults *defaults; 151 145 NSDictionary *dict; 152 146 153 147 defaults = [NSUserDefaults standardUserDefaults]; 154 148 dict = [defaults dictionaryForKey: filetype]; … … 157 151 [self applyValuesFromDict: dict]; 158 152 } 159 153 160 154 - (id)initForDefaultFileType: (NSString *)filetype 161 155 { 162 156 FileSettings *fsdefaults; 163 157 164 158 fsdefaults = [FileSettings getFactorySettingsForFileType: filetype]; 165 159 self = [self initWithFileSettings: fsdefaults]; … … 221 215 { 222 216 id value; 223 217 224 218 value = [dict objectForKey: @"interpreter"]; 225 219 if (value) interpreter = [value retain]; … … 248 242 - (NSString*)_replaceSingleQuotes: (NSString*)string 249 243 { 250 251 252 253 254 255 244 /* Replace all single-quotes by '"'"', that way shellquoting will 245 * be correct when the result value is delimited using single quotes. 246 */ 247 NSArray* components = [string componentsSeparatedByString:@"'"]; 248 249 return [components componentsJoinedByString:@"'\"'\"'"]; 256 250 } 257 251 … … 266 260 script_dir = [script substringToIndex: 267 261 [script length]-[[script lastPathComponent] length]]; 268 262 269 263 if (honourhashbang && 270 (fp=fopen([script cString], "r")) &&264 (fp=fopen([script fileSystemRepresentation], "r")) && 271 265 fgets(hashbangbuf, sizeof(hashbangbuf), fp) && 272 266 strncmp(hashbangbuf, "#!", 2) == 0 && … … 275 269 p = hashbangbuf + 2; 276 270 while (*p == ' ') p++; 277 cur_interp = [NSString stringWith CString: p];271 cur_interp = [NSString stringWithUTF8String: p]; 278 272 } 279 273 if (!cur_interp) 280 274 cur_interp = interpreter; 281 275 282 276 return [NSString stringWithFormat: 283 277 @"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s", … … 298 292 - (NSArray *) interpreters { return interpreters;}; 299 293 300 // FileSettingsSource protocol 294 // FileSettingsSource protocol 301 295 - (NSString *) interpreter { return interpreter;}; 302 296 - (BOOL) honourhashbang { return honourhashbang; }; -
python/trunk/Mac/PythonLauncher/Info.plist.in
r2 r391 41 41 <string>PythonLauncher</string> 42 42 <key>CFBundleGetInfoString</key> 43 <string>%VERSION%, © 001-2006Python Software Foundation</string>43 <string>%VERSION%, © 2001-2013 Python Software Foundation</string> 44 44 <key>CFBundleIconFile</key> 45 45 <string>PythonLauncher.icns</string> -
python/trunk/Mac/PythonLauncher/Makefile.in
r2 r391 3 3 BASECFLAGS=@BASECFLAGS@ 4 4 OPT=@OPT@ 5 CFLAGS= $(BASECFLAGS) $(OPT)5 CFLAGS=@CFLAGS@ $(BASECFLAGS) $(OPT) 6 6 LDFLAGS=@LDFLAGS@ 7 7 srcdir= @srcdir@ … … 22 22 BUNDLEBULDER=$(srcdir)/../../Lib/plat-mac/bundlebuilder.py 23 23 24 PYTHONAPPSDIR= /Applications/$(PYTHONFRAMEWORK) $(VERSION)24 PYTHONAPPSDIR=@FRAMEWORKINSTALLAPPSPREFIX@/$(PYTHONFRAMEWORK) $(VERSION) 25 25 OBJECTS=FileSettings.o MyAppDelegate.o MyDocument.o PreferencesWindowController.o doscript.o main.o 26 26 -
python/trunk/Mac/PythonLauncher/MyAppDelegate.m
r2 r391 34 34 - (BOOL)shouldShowUI 35 35 { 36 // if this call comes before applicationDidFinishLaunching: we 36 // if this call comes before applicationDidFinishLaunching: we 37 37 // should terminate immedeately after starting the script. 38 38 if (!initial_action_done) … … 63 63 NSString **ext_p; 64 64 int i; 65 65 66 66 if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"]) 67 67 return; … … 93 93 } 94 94 } 95 95 96 96 @end -
python/trunk/Mac/PythonLauncher/MyDocument.m
r2 r391 17 17 self = [super init]; 18 18 if (self) { 19 19 20 20 // Add your subclass-specific initialization here. 21 21 // If an error occurs here, send a [self dealloc] message and return nil. … … 38 38 NSApplication *app = [NSApplication sharedApplication]; 39 39 [super close]; 40 if ([ [app delegate] shouldTerminate])40 if ([(MyAppDelegate*)[app delegate] shouldTerminate]) 41 41 [app terminate: self]; 42 42 } … … 44 44 - (void)load_defaults 45 45 { 46 // if (settings) [settings release];47 46 settings = [FileSettings newSettingsForFileType: filetype]; 48 47 } … … 50 49 - (void)update_display 51 50 { 52 // [[self window] setTitle: script];53 54 51 [interpreter setStringValue: [settings interpreter]]; 55 52 [honourhashbang setState: [settings honourhashbang]]; … … 63 60 [scriptargs setStringValue: [settings scriptargs]]; 64 61 [with_terminal setState: [settings with_terminal]]; 65 62 66 63 [commandline setStringValue: [settings commandLineForScript: script]]; 67 64 } … … 76 73 const char *cmdline; 77 74 int sts; 78 79 cmdline = [[settings commandLineForScript: script] cString];75 76 cmdline = [[settings commandLineForScript: script] UTF8String]; 80 77 if ([settings with_terminal]) { 81 78 sts = doscript(cmdline); … … 108 105 // Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead. 109 106 BOOL show_ui; 110 111 // ask the app delegate whether we should show the UI or not. 112 show_ui = [ [[NSApplication sharedApplication] delegate] shouldShowUI];107 108 // ask the app delegate whether we should show the UI or not. 109 show_ui = [(MyAppDelegate*)[[NSApplication sharedApplication] delegate] shouldShowUI]; 113 110 [script release]; 114 111 script = [fileName retain]; 115 112 [filetype release]; 116 113 filetype = [type retain]; 117 // if (settings) [settings release];118 114 settings = [FileSettings newSettingsForFileType: filetype]; 119 115 if (show_ui) { … … 153 149 } 154 150 155 // FileSettingsSource protocol 151 // FileSettingsSource protocol 156 152 - (NSString *) interpreter { return [interpreter stringValue];}; 157 153 - (BOOL) honourhashbang { return [honourhashbang state];}; -
python/trunk/Mac/PythonLauncher/PreferencesWindowController.m
r2 r391 6 6 { 7 7 static PreferencesWindowController *_singleton; 8 8 9 9 if (!_singleton) 10 10 _singleton = [[PreferencesWindowController alloc] init]; … … 22 22 { 23 23 NSString *title = [filetype titleOfSelectedItem]; 24 24 25 25 settings = [FileSettings getDefaultsForFileType: title]; 26 26 } … … 28 28 - (void)update_display 29 29 { 30 // [[self window] setTitle: script]; 31 32 [interpreter reloadData]; 30 [interpreter reloadData]; 33 31 [interpreter setStringValue: [settings interpreter]]; 34 32 [honourhashbang setState: [settings honourhashbang]]; … … 42 40 [with_terminal setState: [settings with_terminal]]; 43 41 // Not scriptargs, it isn't for preferences 44 45 42 [commandline setStringValue: [settings commandLineForScript: @"<your script here>"]]; 46 43 } … … 76 73 } 77 74 78 // FileSettingsSource protocol 75 // FileSettingsSource protocol 79 76 - (NSString *) interpreter { return [interpreter stringValue];}; 80 77 - (BOOL) honourhashbang { return [honourhashbang state]; }; … … 99 96 - (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString 100 97 { 101 98 NSArray *interp_list = [settings interpreters]; 102 99 unsigned int rv = [interp_list indexOfObjectIdenticalTo: aString]; 103 100 return rv; 104 101 } 105 102 106 103 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index 107 104 { 108 105 NSArray *interp_list = [settings interpreters]; 109 106 id rv = [interp_list objectAtIndex: index]; 110 107 return rv; 111 108 } 112 109 113 110 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox 114 111 { 115 112 NSArray *interp_list = [settings interpreters]; 116 113 int rv = [interp_list count]; 117 114 return rv; 118 115 } 119 116 -
python/trunk/Mac/PythonLauncher/doscript.m
r2 r391 12 12 #import "doscript.h" 13 13 14 extern int 14 extern int 15 15 doscript(const char *command) 16 16 { 17 18 19 20 17 char *bundleID = "com.apple.Terminal"; 18 AppleEvent evt, res; 19 AEDesc desc; 20 OSStatus err; 21 21 22 22 [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"]; 23 23 24 25 26 27 28 29 30 31 32 33 34 NSLog(@"AEBuildAppleEvent failed: %d\n",err);35 36 24 // Build event 25 err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript, 26 typeApplicationBundleID, 27 bundleID, strlen(bundleID), 28 kAutoGenerateReturnID, 29 kAnyTransactionID, 30 &evt, NULL, 31 "'----':utf8(@)", strlen(command), 32 command); 33 if (err) { 34 NSLog(@"AEBuildAppleEvent failed: %ld\n", (long)err); 35 return err; 36 } 37 37 38 39 40 41 42 NSLog(@"AESendMessage failed: %d\n",err);43 44 45 46 47 48 49 50 NSLog(@"Terminal returned an error: %d",err);51 52 53 54 55 NSLog(@"AEGetPArmDesc returned an error: %d",err);56 38 // Send event and check for any Apple Event Manager errors 39 err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout); 40 AEDisposeDesc(&evt); 41 if (err) { 42 NSLog(@"AESendMessage failed: %ld\n", (long)err); 43 return err; 44 } 45 // Check for any application errors 46 err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc); 47 AEDisposeDesc(&res); 48 if (!err) { 49 AEGetDescData(&desc, &err, sizeof(err)); 50 NSLog(@"Terminal returned an error: %ld", (long)err); 51 AEDisposeDesc(&desc); 52 } else if (err == errAEDescNotFound) { 53 err = noErr; 54 } else { 55 NSLog(@"AEGetPArmDesc returned an error: %ld", (long)err); 56 } 57 57 58 58 return err; 59 59 } -
python/trunk/Mac/PythonLauncher/main.m
r2 r391 12 12 int main(int argc, const char *argv[]) 13 13 { 14 15 14 char *home = getenv("HOME"); 15 if (home) chdir(home); 16 16 return NSApplicationMain(argc, argv); 17 17 }
Note:
See TracChangeset
for help on using the changeset viewer.