summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
Diffstat (limited to 'Mac')
-rwxr-xr-xMac/OSX/PythonLauncher/FileSettings.h17
-rwxr-xr-xMac/OSX/PythonLauncher/FileSettings.m174
-rwxr-xr-xMac/OSX/PythonLauncher/MyDocument.m13
-rw-r--r--Mac/OSX/PythonLauncher/PreferencesWindowController.m2
-rwxr-xr-xMac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj14
-rw-r--r--Mac/OSX/PythonLauncher/factorySettings.plist79
6 files changed, 242 insertions, 57 deletions
diff --git a/Mac/OSX/PythonLauncher/FileSettings.h b/Mac/OSX/PythonLauncher/FileSettings.h
index f487469..ea69b58 100755
--- a/Mac/OSX/PythonLauncher/FileSettings.h
+++ b/Mac/OSX/PythonLauncher/FileSettings.h
@@ -37,17 +37,22 @@
}
+ (id)getDefaultsForFileType: (NSString *)filetype;
++ (id)getFactorySettingsForFileType: (NSString *)filetype;
+ (id)newSettingsForFileType: (NSString *)filetype;
-- (id)init;
-- (id)initWithFileSettings: (FileSettings *)source;
+//- (id)init;
+- (id)initForFileType: (NSString *)filetype;
+- (id)initForFSDefaultFileType: (NSString *)filetype;
+- (id)initForDefaultFileType: (NSString *)filetype;
+//- (id)initWithFileSettings: (FileSettings *)source;
- (void)updateFromSource: (id <FileSettingsSource>)source;
- (NSString *)commandLineForScript: (NSString *)script;
-- (id)factorySettingsForFileType: (NSString *)filetype;
-- (void)saveDefaults;
-- (void)updateFromUserDefaults: (NSString *)filetype;
-
+//- (void)applyFactorySettingsForFileType: (NSString *)filetype;
+//- (void)saveDefaults;
+//- (void)applyUserDefaults: (NSString *)filetype;
+- (void)applyValuesFromDict: (NSDictionary *)dict;
+- (void)reset;
@end
diff --git a/Mac/OSX/PythonLauncher/FileSettings.m b/Mac/OSX/PythonLauncher/FileSettings.m
index 2147004..89772f6 100755
--- a/Mac/OSX/PythonLauncher/FileSettings.m
+++ b/Mac/OSX/PythonLauncher/FileSettings.m
@@ -9,6 +9,29 @@
#import "FileSettings.h"
@implementation FileSettings
+
++ (id)getFactorySettingsForFileType: (NSString *)filetype
+{
+ static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc;
+ FileSettings **curdefault;
+
+ if ([filetype isEqualToString: @"Python Script"]) {
+ curdefault = &fsdefault_py;
+ } else if ([filetype isEqualToString: @"Python GUI Script"]) {
+ curdefault = &fsdefault_pyw;
+ } else if ([filetype isEqualToString: @"Python Bytecode Document"]) {
+ curdefault = &fsdefault_pyc;
+ } else {
+ NSLog(@"Funny File Type: %@\n", filetype);
+ curdefault = &fsdefault_py;
+ filetype = @"Python Script";
+ }
+ if (!*curdefault) {
+ *curdefault = [[FileSettings new] initForFSDefaultFileType: filetype];
+ }
+ return *curdefault;
+}
+
+ (id)getDefaultsForFileType: (NSString *)filetype
{
static FileSettings *default_py, *default_pyw, *default_pyc;
@@ -26,9 +49,7 @@
filetype = @"Python Script";
}
if (!*curdefault) {
- *curdefault = [[FileSettings new] init];
- [*curdefault factorySettingsForFileType: filetype];
- [*curdefault updateFromUserDefaults: filetype];
+ *curdefault = [[FileSettings new] initForDefaultFileType: filetype];
}
return *curdefault;
}
@@ -37,42 +58,16 @@
{
FileSettings *cur;
- cur = [[FileSettings new] init];
- [cur initWithFileSettings: [FileSettings getDefaultsForFileType: filetype]];
- return cur;
-}
-
-- (id)init
-{
- self = [super init];
- return [self factorySettingsForFileType: @"Python Script"];
-}
-
-- (id)factorySettingsForFileType: (NSString *)filetype
-{
- debug = NO;
- verbose = NO;
- inspect = NO;
- optimize = NO;
- nosite = NO;
- tabs = NO;
- others = @"";
- if ([filetype isEqualToString: @"Python Script"] ||
- [filetype isEqualToString: @"Python Bytecode Document"]) {
- interpreter = @"/Library/Frameworks/Python.framework/Versions/Current/bin/python";
- with_terminal = YES;
- } else if ([filetype isEqualToString: @"Python GUI Script"]) {
- interpreter = @"/Library/Frameworks/Python.framework/Versions/Current/Resources/Python.app/Contents/MacOS/python";
- with_terminal = NO;
- } else {
- NSLog(@"Funny File Type: %@\n", filetype);
- }
- origsource = NULL;
- return self;
+ cur = [FileSettings new];
+ [cur initForFileType: filetype];
+ return [cur retain];
}
- (id)initWithFileSettings: (FileSettings *)source
{
+ self = [super init];
+ if (!self) return self;
+
interpreter = [source->interpreter retain];
debug = source->debug;
verbose = source->verbose;
@@ -82,14 +77,106 @@
tabs = source->tabs;
others = [source->others retain];
with_terminal = source->with_terminal;
+ prefskey = source->prefskey;
+ if (prefskey) [prefskey retain];
- origsource = [source retain];
return self;
}
-- (void)saveDefaults
+- (id)initForFileType: (NSString *)filetype
{
- [origsource updateFromSource: self];
+ FileSettings *defaults;
+
+ defaults = [FileSettings getDefaultsForFileType: filetype];
+ self = [self initWithFileSettings: defaults];
+ origsource = [defaults retain];
+ return self;
+}
+
+//- (id)init
+//{
+// self = [self initForFileType: @"Python Script"];
+// return self;
+//}
+
+- (id)initForFSDefaultFileType: (NSString *)filetype
+{
+ int i;
+ NSString *filename;
+ NSDictionary *dict;
+ NSArray *interpreters;
+ static NSDictionary *factorySettings;
+
+ self = [super init];
+ if (!self) return self;
+
+ if (factorySettings == NULL) {
+ NSBundle *bdl = [NSBundle mainBundle];
+ NSString *path = [ bdl pathForResource: @"factorySettings"
+ ofType: @"plist"];
+ factorySettings = [[NSDictionary dictionaryWithContentsOfFile:
+ path] retain];
+ if (factorySettings == NULL) {
+ NSLog(@"Missing %@", path);
+ return NULL;
+ }
+ }
+ dict = [factorySettings objectForKey: filetype];
+ if (dict == NULL) {
+ NSLog(@"factorySettings.plist misses file type \"%@\"", filetype);
+ interpreter = [@"no default found" retain];
+ return NULL;
+ }
+ [self applyValuesFromDict: dict];
+ interpreters = [dict objectForKey: @"interpreter_list"];
+ interpreter = NULL;
+ for (i=0; i < [interpreters count]; i++) {
+ filename = [interpreters objectAtIndex: i];
+ filename = [filename stringByExpandingTildeInPath];
+ if ([[NSFileManager defaultManager] fileExistsAtPath: filename]) {
+ interpreter = [filename retain];
+ break;
+ }
+ }
+ if (interpreter == NULL)
+ interpreter = [@"no default found" retain];
+ origsource = NULL;
+ return self;
+}
+
+- (void)applyUserDefaults: (NSString *)filetype
+{
+ NSUserDefaults *defaults;
+ NSDictionary *dict;
+
+ defaults = [NSUserDefaults standardUserDefaults];
+ dict = [defaults dictionaryForKey: filetype];
+ if (!dict)
+ return;
+ [self applyValuesFromDict: dict];
+}
+
+- (id)initForDefaultFileType: (NSString *)filetype
+{
+ FileSettings *fsdefaults;
+
+ fsdefaults = [FileSettings getFactorySettingsForFileType: filetype];
+ self = [self initWithFileSettings: fsdefaults];
+ if (!self) return self;
+ [self applyUserDefaults: filetype];
+ prefskey = [filetype retain];
+ return self;
+}
+
+- (void)reset
+{
+ if (origsource) {
+ [self updateFromSource: origsource];
+ } else {
+ FileSettings *fsdefaults;
+ fsdefaults = [FileSettings getFactorySettingsForFileType: prefskey];
+ [self updateFromSource: fsdefaults];
+ }
}
- (void)updateFromSource: (id <FileSettingsSource>)source
@@ -103,6 +190,8 @@
tabs = [source tabs];
others = [[source others] retain];
with_terminal = [source with_terminal];
+ // And if this is a user defaults object we also save the
+ // values
if (!origsource) {
NSUserDefaults *defaults;
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -121,17 +210,10 @@
}
}
-- (void)updateFromUserDefaults: (NSString *)filetype
+- (void)applyValuesFromDict: (NSDictionary *)dict
{
- NSUserDefaults *defaults;
- NSDictionary *dict;
id value;
- prefskey = [filetype retain];
- defaults = [NSUserDefaults standardUserDefaults];
- dict = [defaults dictionaryForKey: filetype];
- if (!dict)
- return;
value = [dict objectForKey: @"interpreter"];
if (value) interpreter = [value retain];
value = [dict objectForKey: @"debug"];
diff --git a/Mac/OSX/PythonLauncher/MyDocument.m b/Mac/OSX/PythonLauncher/MyDocument.m
index 2571857..fdcf86a 100755
--- a/Mac/OSX/PythonLauncher/MyDocument.m
+++ b/Mac/OSX/PythonLauncher/MyDocument.m
@@ -14,13 +14,14 @@
- (id)init
{
- [super init];
+ self = [super init];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self dealloc] message and return nil.
- script = @"<no script>.py";
- filetype = @"Python Script";
+ script = [@"<no script>.py" retain];
+ filetype = [@"Python Script" retain];
+ settings = NULL;
}
return self;
}
@@ -42,6 +43,7 @@
- (void)load_defaults
{
+// if (settings) [settings release];
settings = [FileSettings newSettingsForFileType: filetype];
}
@@ -106,8 +108,11 @@
// ask the app delegate whether we should show the UI or not.
show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI];
+ [script release];
script = [fileName retain];
+ [filetype release];
filetype = [type retain];
+// if (settings) [settings release];
settings = [FileSettings newSettingsForFileType: filetype];
if (show_ui) {
[self update_display];
@@ -135,7 +140,7 @@
- (IBAction)do_reset:(id)sender
{
- [self load_defaults];
+ [settings reset];
[self update_display];
}
diff --git a/Mac/OSX/PythonLauncher/PreferencesWindowController.m b/Mac/OSX/PythonLauncher/PreferencesWindowController.m
index 8842162..79344f6 100644
--- a/Mac/OSX/PythonLauncher/PreferencesWindowController.m
+++ b/Mac/OSX/PythonLauncher/PreferencesWindowController.m
@@ -62,7 +62,7 @@
- (IBAction)do_reset:(id)sender
{
- [self load_defaults];
+ [settings reset];
[self update_display];
}
diff --git a/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj b/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj
index 063339c..93bd1ea 100755
--- a/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj
+++ b/Mac/OSX/PythonLauncher/PythonLauncher.pbproj/project.pbxproj
@@ -235,6 +235,7 @@
2A37F4B4FDCFA73011CA2CEA,
F5A4C13E02F203F601000102,
089C165FFE840EACC02AAC07,
+ F5A42167038BDD8E0110C447,
);
isa = PBXGroup;
name = Resources;
@@ -291,6 +292,7 @@
INSTALL_MODE_FLAG = "a+rX";
INSTALL_PATH = /Applications/Python;
LIBRARY_SEARCH_PATHS = "";
+ OPTIMIZATION_CFLAGS = "-O0";
OTHER_LDFLAGS = "";
PRODUCT_NAME = PythonLauncher;
SECTORDER_FLAGS = "";
@@ -430,6 +432,7 @@
F58D4A3F02F1F94B01000102,
F5A4C13F02F203F701000102,
F5449B4C02FB3F7E01000102,
+ F5A42168038BDD8E0110C447,
);
isa = PBXResourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@@ -577,6 +580,17 @@
settings = {
};
};
+ F5A42167038BDD8E0110C447 = {
+ isa = PBXFileReference;
+ path = factorySettings.plist;
+ refType = 4;
+ };
+ F5A42168038BDD8E0110C447 = {
+ fileRef = F5A42167038BDD8E0110C447;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
F5A4C13E02F203F601000102 = {
isa = PBXFileReference;
path = PreferenceWindow.nib;
diff --git a/Mac/OSX/PythonLauncher/factorySettings.plist b/Mac/OSX/PythonLauncher/factorySettings.plist
new file mode 100644
index 0000000..5b81d7d
--- /dev/null
+++ b/Mac/OSX/PythonLauncher/factorySettings.plist
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Python GUI Script</key>
+ <dict>
+ <key>debug</key>
+ <false/>
+ <key>inspect</key>
+ <false/>
+ <key>interpreter_list</key>
+ <array>
+ <string>/usr/local/bin/pythonw</string>
+ <string>/sw/bin/pythonw</string>
+ <string>/Library/Frameworks/Python.framework/Versions/Current/Resources/Python.app/Contents/MacOS/python</string>
+ <string>/usr/bin/pythonw</string>
+ <string>/Applications/MacPython-OSX/python-additions/Python.app/Contents/MacOS/python</string>
+ </array>
+ <key>nosite</key>
+ <false/>
+ <key>optimize</key>
+ <false/>
+ <key>others</key>
+ <string></string>
+ <key>verbose</key>
+ <false/>
+ <key>with_terminal</key>
+ <false/>
+ </dict>
+ <key>Python Script</key>
+ <dict>
+ <key>debug</key>
+ <false/>
+ <key>inspect</key>
+ <false/>
+ <key>interpreter_list</key>
+ <array>
+ <string>/usr/local/bin/python</string>
+ <string>/sw/bin/python</string>
+ <string>/Library/Frameworks/Python.framework/Versions/Current/bin/python</string>
+ <string>/usr/bin/python</string>
+ </array>
+ <key>nosite</key>
+ <false/>
+ <key>optimize</key>
+ <false/>
+ <key>others</key>
+ <string></string>
+ <key>verbose</key>
+ <false/>
+ <key>with_terminal</key>
+ <true/>
+ </dict>
+ <key>Python Bytecode Document</key>
+ <dict>
+ <key>debug</key>
+ <false/>
+ <key>inspect</key>
+ <false/>
+ <key>interpreter_list</key>
+ <array>
+ <string>/usr/local/bin/python</string>
+ <string>/sw/bin/python</string>
+ <string>/Library/Frameworks/Python.framework/Versions/Current/bin/python</string>
+ <string>/usr/bin/python</string>
+ </array>
+ <key>nosite</key>
+ <false/>
+ <key>optimize</key>
+ <false/>
+ <key>others</key>
+ <string></string>
+ <key>verbose</key>
+ <false/>
+ <key>with_terminal</key>
+ <true/>
+ </dict>
+</dict>
+</plist>