Skip to content

Commit

Permalink
added manual library management option ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Ehlke committed May 31, 2010
1 parent bda718a commit d44d9fb
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 38 deletions.
238 changes: 227 additions & 11 deletions English.lproj/MainMenu.xib

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions config.py
@@ -0,0 +1,77 @@


#from configobj import ConfigObj
#import ConfigParser
#import json
import pickle

import sys
from os import path, environ, makedirs

APP_NAME = "Download To iTunes"
CONFIG_FILENAME = 'config.cfg'

DEFAULTS = {'iTunesManagesMyLibrary': 1}

def data_path():
#if sys.platform == 'darwin':
from AppKit import NSSearchPathForDirectoriesInDomains
# http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSearchPathForDirectoriesInDomains
# NSApplicationSupportDirectory = 14
# NSUserDomainMask = 1
# True for expanding the tilde into a fully qualified path
ret = path.join(NSSearchPathForDirectoriesInDomains(14, 1, True)[0], APP_NAME)
if not path.exists(ret):
makedirs(ret)
return ret

def config_file_path():
data_dir = data_path()
return path.join(data_dir, CONFIG_FILENAME)


def get_config():
#return ConfigObj(config_file_path())
#config2 = ConfigParser.RawConfigParser()
#config2.read(config_file_path())
#return config2
try:
f = open(config_file_path())
s = f.read()
f.close()
except IOError:
return {}
if s:
#return json.loads(s)
return pickle.loads(s)
else:
return {}


def save_config(config_obj):
#config_obj.write(config_file_path())
f = file(config_file_path(), 'w')
#s = json.dumps(config_obj)
s = pickle.dumps(config_obj)
f.write(s)
f.close()

def set_config_option(key, value):
'''Sets and saves option.'''
config_obj = get_config()
#config_obj[key] = value
config_obj[key] = value
save_config(config_obj)

def get_config_option(key):
config_obj = get_config()
return config_obj.get(key, DEFAULTS.get(key, None))




#elif sys.platform == 'win32':
# appdata = path.join(environ['APPDATA'], APPNAME)
#else:
# appdata = path.expanduser(path.join("~", "." + APPNAME))

88 changes: 88 additions & 0 deletions controller.py
@@ -0,0 +1,88 @@
#
# controller.py
# itunesloader
#
# Created by Alex Ehlke on 5/30/10.
# Copyright (c) 2010 __MyCompanyName__. All rights reserved.
#

from objc import YES, NO, IBAction, IBOutlet, ivar, accessor
from Foundation import *
from AppKit import *

import config



class controller(NSWindowController):
iTunesManagesMyLibrary = ivar('iTunesManagesMyLibrary')
#iTunesManagesMyLibrary = ivar()
iTunesManagesMyLibraryMenuItem = IBOutlet()
iTunesLibraryLocationMenuItem = IBOutlet()
iTunesLibraryLocationMenuItemEnabled = ivar('iTunesLibraryLocationMenuItemEnabled')

def awakeFromNib(self):
#NSLog('awakeFromNib')
self.iTunesManagesMyLibrary = config.get_config_option('iTunesManagesMyLibrary')
self.iTunesManagesMyLibraryMenuItem.setState_(self.iTunesManagesMyLibrary)
self.refreshMenuEnable()

#@accessor
#def iTunesManagesMyLibraryValue(self):
# return self.iTunesManagesMyLibrary

@accessor
def setITunesManagesMyLibrary_(self, value):
#NSLog('setITunesManagesMyLibrary_')
self.iTunesManagesMyLibrary = value
#NSLog(str(self.iTunesManagesMyLibrary))
config.set_config_option('iTunesManagesMyLibrary', value)
self.refreshMenuEnable()

@IBAction
def setLibraryLocation_(self, sender):
#NSLog('setLibraryLocation_')
panel = NSOpenPanel.openPanel()
panel.setCanChooseDirectories_(YES)
panel.setAllowsMultipleSelection_(NO)
panel.setCanChooseFiles_(NO)
old_path = config.get_config_option('iTunesLibraryLocation')
ret = panel.runModalForDirectory_file_types_(old_path, None, None)
#NSLog(str(ret))
if ret:
path = panel.filenames()[0]
config.set_config_option('iTunesLibraryLocation', path)
else:
# Canceled
pass

def refreshMenuEnable(self):
#NSLog('refreshMenuEnable')
if self.iTunesManagesMyLibrary:
#NSLog('NO')
#self.iTunesLibraryLocationMenuItem.setEnabled_(NO)
self.iTunesLibraryLocationMenuItemEnabled = NO
else:
#NSLog('YES')
#self.iTunesLibraryLocationMenuItem.setEnabled_(YES)
self.iTunesLibraryLocationMenuItemEnabled = YES

@IBAction
def toggleITunesManagesMyLibrary_(self, sender):
#NSLog('toggleITunesManagesMyLibrary_')
#self.refreshMenuEnable()
pass
#NSLog('tog action')
#self.iTunesLibraryLocationMenuItem.setEnabled_(self.iTunesManagesMyLibrary == 0)
#pass

#NSLog(sender.state())
#NSLog(dir(self).__repr__())#self.iTunesManagesMyLibrary).__repr__())
#self.toggleITunesManagesMyLibrary_.setState_(0)
#NSLog(dir(self.toggleITunesManagesMyLibrary).__repr__())
#toggleITunesManagesMyLibrary_.setEnabled(false)

#self.iTunesManagesMyLibrary.setState_(0)
#self.iTunesManagesMyLibrary.setEnabled(false)


35 changes: 20 additions & 15 deletions itunesloader.xcodeproj/jehlke.mode1v3
Expand Up @@ -229,6 +229,8 @@
<key>Layout</key> <key>Layout</key>
<array> <array>
<dict> <dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key> <key>ContentConfiguration</key>
<dict> <dict>
<key>PBXBottomSmartGroupGIDs</key> <key>PBXBottomSmartGroupGIDs</key>
Expand Down Expand Up @@ -277,12 +279,13 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key> <key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array> <array>
<array> <array>
<integer>21</integer> <integer>10</integer>
<integer>20</integer> <integer>7</integer>
<integer>0</integer>
</array> </array>
</array> </array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key> <key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 81}, {186, 445}}</string> <string>{{0, 0}, {186, 445}}</string>
</dict> </dict>
<key>PBXTopSmartGroupGIDs</key> <key>PBXTopSmartGroupGIDs</key>
<array/> <array/>
Expand Down Expand Up @@ -317,30 +320,31 @@
<key>PBXProjectModuleGUID</key> <key>PBXProjectModuleGUID</key>
<string>1CE0B20306471E060097A5F4</string> <string>1CE0B20306471E060097A5F4</string>
<key>PBXProjectModuleLabel</key> <key>PBXProjectModuleLabel</key>
<string>Info.plist</string> <string>main.py</string>
<key>PBXSplitModuleInNavigatorKey</key> <key>PBXSplitModuleInNavigatorKey</key>
<dict> <dict>
<key>Split0</key> <key>Split0</key>
<dict> <dict>
<key>PBXProjectModuleGUID</key> <key>PBXProjectModuleGUID</key>
<string>1CE0B20406471E060097A5F4</string> <string>1CE0B20406471E060097A5F4</string>
<key>PBXProjectModuleLabel</key> <key>PBXProjectModuleLabel</key>
<string>Info.plist</string> <string>main.py</string>
<key>_historyCapacity</key> <key>_historyCapacity</key>
<integer>0</integer> <integer>0</integer>
<key>bookmark</key> <key>bookmark</key>
<string>B82BC13D11B2E27A00C8B0FE</string> <string>B82BC14C11B2F71200C8B0FE</string>
<key>history</key> <key>history</key>
<array> <array>
<string>B87CEEB4110843DC00C4D1EA</string>
<string>B87CEEB5110843DC00C4D1EA</string>
<string>B87CEEB6110843DC00C4D1EA</string> <string>B87CEEB6110843DC00C4D1EA</string>
<string>B82BC12411B2E17A00C8B0FE</string>
<string>B82BC12511B2E17A00C8B0FE</string>
<string>B82BC12611B2E17A00C8B0FE</string> <string>B82BC12611B2E17A00C8B0FE</string>
<string>B82BC12711B2E17A00C8B0FE</string>
<string>B82BC13B11B2E27A00C8B0FE</string> <string>B82BC13B11B2E27A00C8B0FE</string>
<string>B82BC13C11B2E27A00C8B0FE</string> <string>B82BC14511B2F71200C8B0FE</string>
<string>B82BC14611B2F71200C8B0FE</string>
<string>B82BC14711B2F71200C8B0FE</string>
<string>B82BC14811B2F71200C8B0FE</string>
<string>B82BC14911B2F71200C8B0FE</string>
<string>B82BC14A11B2F71200C8B0FE</string>
<string>B82BC14B11B2F71200C8B0FE</string>
</array> </array>
</dict> </dict>
<key>SplitCount</key> <key>SplitCount</key>
Expand All @@ -362,8 +366,6 @@
<string>260pt</string> <string>260pt</string>
</dict> </dict>
<dict> <dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key> <key>ContentConfiguration</key>
<dict> <dict>
<key>PBXProjectModuleGUID</key> <key>PBXProjectModuleGUID</key>
Expand Down Expand Up @@ -540,6 +542,9 @@
<integer>5</integer> <integer>5</integer>
<key>WindowOrderList</key> <key>WindowOrderList</key>
<array> <array>
<string>B82BC14E11B2F71200C8B0FE</string>
<string>B82BC14F11B2F71200C8B0FE</string>
<string>1C78EAAD065D492600B07095</string>
<string>1CD10A99069EF8BA00B06720</string> <string>1CD10A99069EF8BA00B06720</string>
<string>B87CEE831108407D00C4D1EA</string> <string>B87CEE831108407D00C4D1EA</string>
<string>/Users/jehlke/workspace/pyobjc/itunesloader/itunesloader.xcodeproj</string> <string>/Users/jehlke/workspace/pyobjc/itunesloader/itunesloader.xcodeproj</string>
Expand Down Expand Up @@ -912,7 +917,7 @@
<key>TableOfContents</key> <key>TableOfContents</key>
<array> <array>
<string>1C78EAAD065D492600B07095</string> <string>1C78EAAD065D492600B07095</string>
<string>B8EA6D6D110912A400203C30</string> <string>B82BC14D11B2F71200C8B0FE</string>
<string>1C78EAAC065D492600B07095</string> <string>1C78EAAC065D492600B07095</string>
</array> </array>
<key>ToolbarConfiguration</key> <key>ToolbarConfiguration</key>
Expand Down
103 changes: 97 additions & 6 deletions itunesloader.xcodeproj/jehlke.pbxuser
Expand Up @@ -161,6 +161,14 @@
B82BC13B11B2E27A00C8B0FE /* PBXTextBookmark */ = B82BC13B11B2E27A00C8B0FE /* PBXTextBookmark */; B82BC13B11B2E27A00C8B0FE /* PBXTextBookmark */ = B82BC13B11B2E27A00C8B0FE /* PBXTextBookmark */;
B82BC13C11B2E27A00C8B0FE /* PlistBookmark */ = B82BC13C11B2E27A00C8B0FE /* PlistBookmark */; B82BC13C11B2E27A00C8B0FE /* PlistBookmark */ = B82BC13C11B2E27A00C8B0FE /* PlistBookmark */;
B82BC13D11B2E27A00C8B0FE /* PlistBookmark */ = B82BC13D11B2E27A00C8B0FE /* PlistBookmark */; B82BC13D11B2E27A00C8B0FE /* PlistBookmark */ = B82BC13D11B2E27A00C8B0FE /* PlistBookmark */;
B82BC14511B2F71200C8B0FE /* PlistBookmark */ = B82BC14511B2F71200C8B0FE /* PlistBookmark */;
B82BC14611B2F71200C8B0FE /* PBXTextBookmark */ = B82BC14611B2F71200C8B0FE /* PBXTextBookmark */;
B82BC14711B2F71200C8B0FE /* PBXTextBookmark */ = B82BC14711B2F71200C8B0FE /* PBXTextBookmark */;
B82BC14811B2F71200C8B0FE /* PBXBookmark */ = B82BC14811B2F71200C8B0FE /* PBXBookmark */;
B82BC14911B2F71200C8B0FE /* PBXTextBookmark */ = B82BC14911B2F71200C8B0FE /* PBXTextBookmark */;
B82BC14A11B2F71200C8B0FE /* PBXTextBookmark */ = B82BC14A11B2F71200C8B0FE /* PBXTextBookmark */;
B82BC14B11B2F71200C8B0FE /* PBXTextBookmark */ = B82BC14B11B2F71200C8B0FE /* PBXTextBookmark */;
B82BC14C11B2F71200C8B0FE /* PBXTextBookmark */ = B82BC14C11B2F71200C8B0FE /* PBXTextBookmark */;
B87CEEA41108433F00C4D1EA = B87CEEA41108433F00C4D1EA /* PBXTextBookmark */; B87CEEA41108433F00C4D1EA = B87CEEA41108433F00C4D1EA /* PBXTextBookmark */;
B87CEEB4110843DC00C4D1EA = B87CEEB4110843DC00C4D1EA /* PBXTextBookmark */; B87CEEB4110843DC00C4D1EA = B87CEEB4110843DC00C4D1EA /* PBXTextBookmark */;
B87CEEB5110843DC00C4D1EA = B87CEEB5110843DC00C4D1EA /* PBXTextBookmark */; B87CEEB5110843DC00C4D1EA = B87CEEB5110843DC00C4D1EA /* PBXTextBookmark */;
Expand All @@ -175,9 +183,9 @@
}; };
29B97316FDCFA39411CA2CEA /* main.m */ = { 29B97316FDCFA39411CA2CEA /* main.m */ = {
uiCtxt = { uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {950, 702}}"; sepNavIntBoundsRect = "{{0, 0}, {1398, 650}}";
sepNavSelRange = "{0, 0}"; sepNavSelRange = "{0, 0}";
sepNavVisRange = "{0, 536}"; sepNavVisRange = "{1209, 607}";
}; };
}; };
32CA4F630368D1EE00C91783 /* itunesloader_Prefix.pch */ = { 32CA4F630368D1EE00C91783 /* itunesloader_Prefix.pch */ = {
Expand All @@ -189,16 +197,16 @@
}; };
77631A3E0C0748CF005415CB /* main.py */ = { 77631A3E0C0748CF005415CB /* main.py */ = {
uiCtxt = { uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {621, 273}}"; sepNavIntBoundsRect = "{{0, 0}, {621, 364}}";
sepNavSelRange = "{0, 0}"; sepNavSelRange = "{0, 0}";
sepNavVisRange = "{2, 417}"; sepNavVisRange = "{0, 386}";
}; };
}; };
7790198E0C07548A00326F66 /* itunesloaderAppDelegate.py */ = { 7790198E0C07548A00326F66 /* itunesloaderAppDelegate.py */ = {
uiCtxt = { uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {519, 637}}"; sepNavIntBoundsRect = "{{0, 0}, {635, 1053}}";
sepNavSelRange = "{593, 0}"; sepNavSelRange = "{593, 0}";
sepNavVisRange = "{142, 459}"; sepNavVisRange = "{141, 543}";
}; };
}; };
8D1107260486CEB800E47090 /* iTunes Loader */ = { 8D1107260486CEB800E47090 /* iTunes Loader */ = {
Expand Down Expand Up @@ -371,6 +379,89 @@
rLen = 0; rLen = 0;
rLoc = 9223372036854775807; rLoc = 9223372036854775807;
}; };
B82BC14511B2F71200C8B0FE /* PlistBookmark */ = {
isa = PlistBookmark;
fRef = 8D1107310486CEB800E47090 /* Info.plist */;
fallbackIsa = PBXBookmark;
isK = 0;
kPath = (
CFBundleIdentifier,
);
name = /Users/jehlke/workspace/pyobjc/itunesloader/Info.plist;
rLen = 0;
rLoc = 9223372036854775807;
};
B82BC14611B2F71200C8B0FE /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = B87CEEC311084C0A00C4D1EA /* downloadtoitunes.py */;
name = "downloadtoitunes.py: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 328;
vrLoc = 0;
};
B82BC14711B2F71200C8B0FE /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = B87CEEC211084C0A00C4D1EA /* addToITunesLibrary */;
name = "addToITunesLibrary: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 178;
vrLoc = 0;
};
B82BC14811B2F71200C8B0FE /* PBXBookmark */ = {
isa = PBXBookmark;
fRef = B82BC13111B2E1A700C8B0FE /* icon.icns */;
};
B82BC14911B2F71200C8B0FE /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 29B97316FDCFA39411CA2CEA /* main.m */;
name = "main.m: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 607;
vrLoc = 1209;
};
B82BC14A11B2F71200C8B0FE /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 7790198E0C07548A00326F66 /* itunesloaderAppDelegate.py */;
name = "itunesloaderAppDelegate.py: 25";
rLen = 0;
rLoc = 593;
rType = 0;
vrLen = 543;
vrLoc = 141;
};
B82BC14B11B2F71200C8B0FE /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 77631A3E0C0748CF005415CB /* main.py */;
name = "main.py: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 387;
vrLoc = 0;
};
B82BC14C11B2F71200C8B0FE /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 77631A3E0C0748CF005415CB /* main.py */;
name = "main.py: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 386;
vrLoc = 0;
};
B82BC15411B2F81B00C8B0FE /* controller.py */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {643, 780}}";
sepNavSelRange = "{1181, 0}";
sepNavVisRange = "{0, 348}";
};
};
B87CEE7C1108407800C4D1EA /* iTunes Loader */ = { B87CEE7C1108407800C4D1EA /* iTunes Loader */ = {
isa = PBXExecutable; isa = PBXExecutable;
activeArgIndices = ( activeArgIndices = (
Expand Down

0 comments on commit d44d9fb

Please sign in to comment.