From 3216c6dfd93329cc260f69cbb617bde23d307c40 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Sun, 2 Jan 2011 15:47:32 +1100 Subject: [PATCH] It displays stuff --- English.lproj/NotiPod.xib | 369 ++++++++++++++--------------- NotiPodController.py => NotiPod.py | 86 ++++++- NotiPodAppDelegate.py | 51 ---- libsyncitunes.py | 2 +- main.m | 4 +- main.py | 14 -- notipod.xcodeproj/project.pbxproj | 42 +--- syncitunes.py | 2 +- 8 files changed, 267 insertions(+), 303 deletions(-) rename NotiPodController.py => NotiPod.py (50%) delete mode 100644 NotiPodAppDelegate.py delete mode 100644 main.py diff --git a/English.lproj/NotiPod.xib b/English.lproj/NotiPod.xib index 817f256..4ef5559 100644 --- a/English.lproj/NotiPod.xib +++ b/English.lproj/NotiPod.xib @@ -2,14 +2,14 @@ 1050 - 9L30 + 10H574 677 - 949.54 - 353.00 + 1038.35 + 461.00 YES - + YES @@ -18,7 +18,7 @@ YES - + YES @@ -188,7 +188,7 @@ 7 2 - {{335, 417}, {288, 333}} + {{335, 205}, {381, 545}} 1946157056 NotiPod NSWindow @@ -202,7 +202,7 @@ 268 - {{17, 296}, {161, 17}} + {{17, 508}, {161, 17}} YES @@ -221,14 +221,14 @@ controlColor 3 - MC42NjY2NjY2OQA + MC42NjY2NjY2ODY1AA 6 System controlTextColor - + 3 MAA @@ -238,7 +238,7 @@ 268 - {{17, 105}, {254, 17}} + {{17, 135}, {254, 17}} YES @@ -254,7 +254,7 @@ 268 - {{118, 12}, {120, 32}} + {{26, 12}, {120, 32}} YES @@ -274,7 +274,7 @@ 268 - {{29, 73}, {206, 26}} + {{29, 103}, {206, 26}} YES @@ -330,7 +330,7 @@ 268 - {{17, 22}, {105, 17}} + {{17, 52}, {105, 17}} YES @@ -343,67 +343,72 @@ - + 268 YES - - + + 2304 YES - - + + 256 - {219, 102} - + {312, 304} + YES - - + + 256 - {219, 17} - - + {312, 17} + + - - + + 256 - {{220, 0}, {16, 17}} - + {{313, 0}, {16, 17}} + YES - - 1.010000e+02 - 1.600000e+01 - 1.000000e+03 + + 6.400000e+01 + 1.000000e+01 + 3.402823e+38 75628032 0 - - + Playlist + LucidaGrande 1.100000e+01 3100 - - 3 - MC4zMzMzMzI5OQA + + 6 + System + headerColor + + 3 + MQA + - + 6 System headerTextColor - + - + 337772096 2048 Text Cell - + 6 System @@ -415,41 +420,12 @@ 3 YES YES - - - - 1.120000e+02 - 4.000000e+01 - 1.000000e+03 - - 75628032 - 0 - - - - - - - 337772096 - 2048 - Text Cell - - - - - - 3 - YES - YES - + 3.000000e+00 2.000000e+00 - - 3 - MQA - + 6 System @@ -460,69 +436,69 @@ 1.700000e+01 - -767557632 + -700448768 4 15 0 YES + 1 - {{1, 17}, {219, 102}} - - - + {{1, 17}, {312, 304}} + + + 4 - - + + 256 - {{220, 17}, {15, 102}} - - + {{313, 17}, {15, 304}} + + _doScroller: - 3.700000e+01 - 1.390978e-01 + 4.742590e-01 - - + + 256 - {{1, 119}, {219, 15}} - + {{1, 321}, {312, 15}} + 1 - + _doScroller: 5.714286e-01 - - + + 2304 YES - + - {{1, 0}, {219, 17}} - - - + {{1, 0}, {312, 17}} + + + 4 - + - {{32, 153}, {236, 135}} + {{32, 163}, {329, 337}} - + 50 - - - - - + + + + + QSAAAEEgAABBmAAAQZgAAA - {288, 333} + {381, 545} {{0, 0}, {1024, 746}} @@ -580,6 +556,9 @@ {{0, 0}, {1024, 746}} {3.40282e+38, 3.40282e+38} + + PlaylistTableModel + @@ -672,21 +651,37 @@ 435 + + + folderPopup + + + + 451 + playlistView - + - 450 + 461 - folderPopup + playlistModel - + - 451 + 463 + + + + tableView + + + + 464 @@ -694,28 +689,26 @@ YES 0 - - YES - + -2 - + RmlsZSdzIE93bmVyA -1 - + First Responder -3 - + Application @@ -726,7 +719,7 @@ - + MainMenu @@ -842,7 +835,7 @@ YES - + NotiPod @@ -851,11 +844,11 @@ YES - - - + + + @@ -904,7 +897,7 @@ 404 - + NotiPodController @@ -943,7 +936,7 @@ 425 - + NotiPodAppDelegate @@ -953,7 +946,7 @@ YES - + NotiPodLoading @@ -1005,75 +998,65 @@ - 440 - + 452 + YES - - - - + + + + - 441 - - + 453 + + - 442 - - + 454 + + - 443 - + 455 + YES - - + - + - 444 - - + 456 + + - 445 - - - YES - - - + 462 + + - 446 - + 465 + YES - + - - - - 447 - - + - 448 - - + 466 + + YES - + YES -1.IBPluginDependency -2.IBPluginDependency @@ -1138,15 +1121,12 @@ 436.IBPluginDependency 437.IBPluginDependency 438.IBPluginDependency - 440.IBPluginDependency - 441.IBPluginDependency - 442.IBPluginDependency - 443.IBPluginDependency - 444.IBPluginDependency - 445.IBPluginDependency - 446.IBPluginDependency - 447.IBPluginDependency - 448.IBPluginDependency + 452.IBPluginDependency + 453.IBPluginDependency + 454.IBPluginDependency + 455.IBPluginDependency + 456.IBPluginDependency + 462.IBPluginDependency 56.IBPluginDependency 56.ImportedFromIB2 57.IBPluginDependency @@ -1191,8 +1171,8 @@ {74, 862} {{529, 476}, {148, 20}} - {{343, 40}, {288, 333}} - {{343, 40}, {288, 333}} + {{253, 91}, {381, 545}} + {{253, 91}, {381, 545}} {{505, 213}, {252, 190}} com.apple.InterfaceBuilder.CocoaPlugin @@ -1227,9 +1207,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1240,9 +1217,7 @@ YES - - YES - + YES @@ -1250,15 +1225,13 @@ YES - - YES - + YES - 451 + 466 @@ -1266,9 +1239,9 @@ NotiPodAppDelegate NSObject - + IBProjectSource - NotiPodAppDelegate.py + NotiPod.py @@ -1284,7 +1257,7 @@ NSObject YES - + YES doSelectFolder: doSync: @@ -1297,11 +1270,11 @@ YES - + YES folderPopup loadingSheet - playlistView + playlistModel window @@ -1312,10 +1285,7 @@ id - - IBProjectSource - NotiPodController.py - + NotiPodController @@ -1325,6 +1295,15 @@ + + PlaylistTableModel + NSObject + + tableView + id + + + 0 diff --git a/NotiPodController.py b/NotiPod.py similarity index 50% rename from NotiPodController.py rename to NotiPod.py index e415cef..bb810ba 100644 --- a/NotiPodController.py +++ b/NotiPod.py @@ -2,35 +2,57 @@ # Copyright 2009 James Bunton # Licensed for distribution under the GPL version 2, check COPYING for details +import objc from Foundation import * from AppKit import * -import objc +from PyObjCTools import AppHelper + +import libsyncitunes + + +class PlaylistTableModel(NSObject): + tableView = objc.IBOutlet() + + def awakeFromNib(self): + self.playlists = [] + self.tableView.setDataSource_(self) + + def setPlaylists(self, playlists): + self.playlists = playlists + self.tableView.reloadData() + + def tableView_objectValueForTableColumn_row_(self, tableView, col, row): + assert 0 <= row < len(self.playlists) + return self.playlists[row] + + def numberOfRowsInTableView_(self, tableView): + print "get number of rows", len(self.playlists) + return len(self.playlists) + -import itunes class NotiPodController(NSObject): - playlistView = objc.IBOutlet() + playlistModel = objc.IBOutlet() folderPopup = objc.IBOutlet() window = objc.IBOutlet() loadingSheet = objc.IBOutlet() def awakeFromNib(self): -### self.loadLibrary() self.performSelectorInBackground_withObject_(self.loadLibrary, None) print "awakeFromNib" def finishLoading(self): - self.playlistView.setDataSource_(self.library) + self.playlistModel.setPlaylists(self.library.list_playlists()) self.folderPopup.addItemsWithTitles_(NSApp.delegate().folders()) def loadLibrary(self): pool = NSAutoreleasePool.alloc().init() NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo_(self.loadingSheet, self.window, None, None, None) - self.library = itunes.Library.alloc().init() + self.library = libsyncitunes.ITunesLibrary.alloc().init() self.loadingSheet.close() - self.performSelectorOnMainThread_withObject_waitUntilDone_(self.finishLoading, None, False) - pool.drain() + self.performSelectorOnMainThread_withObject_waitUntilDone_(self.finishLoading, None, True) + del pool @objc.signature("v@:@ii") def selectFolderEnd_returnCode_contextInfo_(self, panel, ret, _): @@ -63,3 +85,51 @@ class NotiPodController(NSObject): def doSync_(self, sender): print "hello me" + +class NotiPodAppDelegate(NSObject): + + # Delegate methods + + def applicationWillFinishLaunching_(self, _): + print "loading prefs" + prefs = NSUserDefaults.standardUserDefaults() + self._playlists = prefs.stringArrayForKey_("playlists") + self._folders = prefs.stringArrayForKey_("folders") + print "folders", self._folders + print "playlists", self._playlists + + def applicationDidFinishLaunching_(self, _): + pass + + def applicationWillTerminate_(self, _): + prefs = NSUserDefaults.standardUserDefaults() + prefs.synchronize() + + def applicationShouldTerminateAfterLastWindowClosed_(self, _): + return True + + + # Public accessors + + def playlists(self): + return self._playlists + + def folders(self): + return self._folders or [] + + def addFolder_(self, folder): + self._folders.insert(0, folder) + + def hasPlaylist_(self, playlist): + return playlist in self._playlists + + def removePlaylist_(self, playlist): + self._playlists.remove(playlist) + + def addPlaylist_(self, playlist): + self._playlists.append(playlist) + + + +AppHelper.runEventLoop() + diff --git a/NotiPodAppDelegate.py b/NotiPodAppDelegate.py deleted file mode 100644 index 9cf4d28..0000000 --- a/NotiPodAppDelegate.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -# Copyright 2009 James Bunton -# Licensed for distribution under the GPL version 2, check COPYING for details - -from Foundation import * -from AppKit import * -import objc - -import itunes - -class NotiPodAppDelegate(NSObject): - - # Delegate methods - - def applicationWillFinishLaunching_(self, _): - prefs = NSUserDefaults.standardUserDefaults() - self._playlists = prefs.stringArrayForKey_("playlists") - self._folders = prefs.stringArrayForKey_("folders") - - def applicationDidFinishLaunching_(self, _): - pass - - def applicationWillTerminate_(self, _): - prefs = NSUserDefaults.standardUserDefaults() - prefs.synchronize() - - def applicationShouldTerminateAfterLastWindowClosed_(self, _): - return True - - - # Public accessors - - def playlists(self): - return self._playlists - - def folders(self): - return self._folders or [] - - def addFolder_(self, folder): - self._folders.insert(0, folder) - - def hasPlaylist_(self, playlist): - return playlist in self._playlists - - def removePlaylist_(self, playlist): - self._playlists.remove(playlist) - - def addPlaylist_(self, playlist): - self._playlists.append(playlist) - - diff --git a/libsyncitunes.py b/libsyncitunes.py index ea37541..096abc2 100644 --- a/libsyncitunes.py +++ b/libsyncitunes.py @@ -30,7 +30,7 @@ class Playlist(object): if parent is not None: parent.children.append(self) -class Library(NSObject): +class ITunesLibrary(NSObject): def init(self): return self.initWithFilename_("~/Music/iTunes/iTunes Music Library.xml") diff --git a/main.m b/main.m index 505c846..d9f789b 100644 --- a/main.m +++ b/main.m @@ -20,12 +20,12 @@ main(int argc, char** argv) NSString* mainFilePath = nil; for(NSString* possibleMainExtension in possibleMainExtensions) { - mainFilePath = [mainBundle pathForResource: @"main" ofType: possibleMainExtension]; + mainFilePath = [mainBundle pathForResource: @"NotiPod" ofType: possibleMainExtension]; if(mainFilePath != nil) break; } if(!mainFilePath) { - [NSException raise: NSInternalInconsistencyException format: @"%s:%d main() Failed to find the main.{py,pyc,pyo} file in the application wrapper's Resources directory.", __FILE__, __LINE__]; + [NSException raise: NSInternalInconsistencyException format: @"%s:%d main() Failed to find the main file in the application wrapper's Resources directory.", __FILE__, __LINE__]; } Py_SetProgramName("/usr/bin/python"); diff --git a/main.py b/main.py deleted file mode 100644 index 1ddbb89..0000000 --- a/main.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -# Copyright 2009 James Bunton -# Licensed for distribution under the GPL version 2, check COPYING for details - -import objc -import Foundation -import AppKit -from PyObjCTools import AppHelper - -import NotiPodAppDelegate -import NotiPodController - -AppHelper.runEventLoop() - diff --git a/notipod.xcodeproj/project.pbxproj b/notipod.xcodeproj/project.pbxproj index db5ae1a..7d61add 100644 --- a/notipod.xcodeproj/project.pbxproj +++ b/notipod.xcodeproj/project.pbxproj @@ -8,15 +8,12 @@ /* Begin PBXBuildFile section */ 77631A270C06C501005415CB /* Python.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77631A260C06C501005415CB /* Python.framework */; }; - 77631A3F0C0748CF005415CB /* main.py in Resources */ = {isa = PBXBuildFile; fileRef = 77631A3E0C0748CF005415CB /* main.py */; }; - 7790198F0C07548A00326F66 /* NotiPodController.py in Resources */ = {isa = PBXBuildFile; fileRef = 7790198E0C07548A00326F66 /* NotiPodController.py */; }; 77C8C1F90C07829500965286 /* NotiPod.xib in Resources */ = {isa = PBXBuildFile; fileRef = 77C8C1F70C07829500965286 /* NotiPod.xib */; }; 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; - 93F5D8EB0F930158006FB1E6 /* itunes.py in Resources */ = {isa = PBXBuildFile; fileRef = 93F5D8E90F930158006FB1E6 /* itunes.py */; }; - 93F5D8EC0F930158006FB1E6 /* sync.py in Resources */ = {isa = PBXBuildFile; fileRef = 93F5D8EA0F930158006FB1E6 /* sync.py */; }; - 93F5D91D0F933A00006FB1E6 /* NotiPodAppDelegate.py in Resources */ = {isa = PBXBuildFile; fileRef = 93F5D91C0F933A00006FB1E6 /* NotiPodAppDelegate.py */; }; + 93D64A9A12D030190093DEC9 /* libsyncitunes.py in Resources */ = {isa = PBXBuildFile; fileRef = 93D64A9912D030190093DEC9 /* libsyncitunes.py */; }; + 93D64AB212D037890093DEC9 /* NotiPod.py in Resources */ = {isa = PBXBuildFile; fileRef = 93D64AB112D037890093DEC9 /* NotiPod.py */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -27,14 +24,11 @@ 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 32CA4F630368D1EE00C91783 /* notipod_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = notipod_Prefix.pch; sourceTree = ""; }; 77631A260C06C501005415CB /* Python.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Python.framework; path = /System/Library/Frameworks/Python.framework; sourceTree = ""; }; - 77631A3E0C0748CF005415CB /* main.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = main.py; sourceTree = ""; }; - 7790198E0C07548A00326F66 /* NotiPodController.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = NotiPodController.py; sourceTree = ""; }; 77C8C1F80C07829500965286 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/NotiPod.xib; sourceTree = ""; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8D1107320486CEB800E47090 /* notipod.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = notipod.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 93F5D8E90F930158006FB1E6 /* itunes.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = itunes.py; sourceTree = ""; }; - 93F5D8EA0F930158006FB1E6 /* sync.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = sync.py; sourceTree = ""; }; - 93F5D91C0F933A00006FB1E6 /* NotiPodAppDelegate.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = NotiPodAppDelegate.py; sourceTree = ""; }; + 93D64A9912D030190093DEC9 /* libsyncitunes.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = libsyncitunes.py; sourceTree = ""; }; + 93D64AB112D037890093DEC9 /* NotiPod.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = NotiPod.py; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -50,15 +44,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 080E96DDFE201D6D7F000001 /* Classes */ = { - isa = PBXGroup; - children = ( - 93F5D91C0F933A00006FB1E6 /* NotiPodAppDelegate.py */, - 7790198E0C07548A00326F66 /* NotiPodController.py */, - ); - name = Classes; - sourceTree = ""; - }; 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { isa = PBXGroup; children = ( @@ -88,8 +73,7 @@ 29B97314FDCFA39411CA2CEA /* notipod */ = { isa = PBXGroup; children = ( - 080E96DDFE201D6D7F000001 /* Classes */, - 29B97315FDCFA39411CA2CEA /* Other Sources */, + 29B97315FDCFA39411CA2CEA /* Sources */, 29B97317FDCFA39411CA2CEA /* Resources */, 29B97323FDCFA39411CA2CEA /* Frameworks */, 19C28FACFE9D520D11CA2CBB /* Products */, @@ -97,16 +81,15 @@ name = notipod; sourceTree = ""; }; - 29B97315FDCFA39411CA2CEA /* Other Sources */ = { + 29B97315FDCFA39411CA2CEA /* Sources */ = { isa = PBXGroup; children = ( - 93F5D8E90F930158006FB1E6 /* itunes.py */, - 93F5D8EA0F930158006FB1E6 /* sync.py */, 32CA4F630368D1EE00C91783 /* notipod_Prefix.pch */, 29B97316FDCFA39411CA2CEA /* main.m */, - 77631A3E0C0748CF005415CB /* main.py */, + 93D64AB112D037890093DEC9 /* NotiPod.py */, + 93D64A9912D030190093DEC9 /* libsyncitunes.py */, ); - name = "Other Sources"; + name = Sources; sourceTree = ""; }; 29B97317FDCFA39411CA2CEA /* Resources */ = { @@ -172,12 +155,9 @@ buildActionMask = 2147483647; files = ( 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, - 77631A3F0C0748CF005415CB /* main.py in Resources */, - 7790198F0C07548A00326F66 /* NotiPodController.py in Resources */, 77C8C1F90C07829500965286 /* NotiPod.xib in Resources */, - 93F5D8EB0F930158006FB1E6 /* itunes.py in Resources */, - 93F5D8EC0F930158006FB1E6 /* sync.py in Resources */, - 93F5D91D0F933A00006FB1E6 /* NotiPodAppDelegate.py in Resources */, + 93D64A9A12D030190093DEC9 /* libsyncitunes.py in Resources */, + 93D64AB212D037890093DEC9 /* NotiPod.py in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/syncitunes.py b/syncitunes.py index a354470..0f50780 100755 --- a/syncitunes.py +++ b/syncitunes.py @@ -59,7 +59,7 @@ def main(): sys.exit(1) logging.info("Loading library") - library = libsyncitunes.Library.alloc() + library = libsyncitunes.ITunesLibrary.alloc() if opts.itunes_library: library = library.initWithFilename_(opts.itunes_library) else: -- 2.39.2