From cbf749aac869dcb3bec9077a1d1051a6a461f33c Mon Sep 17 00:00:00 2001 From: James Bunton Date: Sun, 2 Jan 2011 22:59:25 +1100 Subject: [PATCH] Added cancel button and put playlists in their own folder --- English.lproj/NotiPod.xib | 78 +++++++++++++++++++++++++++++++++------ NotiPod.py | 19 +++++++--- libsyncitunes.py | 29 ++++++++------- 3 files changed, 96 insertions(+), 30 deletions(-) diff --git a/English.lproj/NotiPod.xib b/English.lproj/NotiPod.xib index 8d7bb0f..2c2bc5a 100644 --- a/English.lproj/NotiPod.xib +++ b/English.lproj/NotiPod.xib @@ -8,9 +8,9 @@ 461.00 YES - + YES @@ -527,7 +527,7 @@ 7 2 - {{196, 436}, {342, 74}} + {{196, 410}, {342, 100}} 603979776 Window NSWindow @@ -542,7 +542,7 @@ 1292 - {{18, 16}, {306, 20}} + {{18, 42}, {306, 20}} 16394 2.000000e+01 @@ -551,12 +551,12 @@ 268 - {{17, 44}, {308, 17}} + {{17, 70}, {308, 17}} YES 67239488 - 272631296 + 272632320 Please wait... @@ -564,8 +564,28 @@ + + + 268 + {{232, 3}, {96, 32}} + + YES + + 67239424 + 134217728 + Cancel + + + -2038284033 + 129 + + + 200 + 25 + + - {342, 74} + {342, 100} {{0, 0}, {1024, 746}} @@ -717,6 +737,14 @@ 511 + + + doCancel: + + + + 516 + @@ -984,6 +1012,7 @@ YES + @@ -1094,6 +1123,20 @@ + + 514 + + + YES + + + + + + 515 + + + @@ -1173,6 +1216,8 @@ 490.IBPluginDependency 509.IBPluginDependency 510.IBPluginDependency + 514.IBPluginDependency + 515.IBPluginDependency 56.IBPluginDependency 56.ImportedFromIB2 57.IBPluginDependency @@ -1235,8 +1280,8 @@ {{89, 581}, {211, 33}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{82, 574}, {342, 74}} - {{82, 574}, {342, 74}} + {{82, 548}, {342, 100}} + {{82, 548}, {342, 100}} {{196, 436}, {204, 74}} com.apple.InterfaceBuilder.CocoaPlugin @@ -1257,6 +1302,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1281,7 +1328,7 @@ - 511 + 516 @@ -1315,8 +1362,17 @@ NotiPodAppDelegate NSObject - doSync: - id + YES + + YES + doCancel: + doSync: + + + YES + id + id + YES diff --git a/NotiPod.py b/NotiPod.py index f302f6f..5292faf 100644 --- a/NotiPod.py +++ b/NotiPod.py @@ -134,17 +134,26 @@ class NotiPodAppDelegate(NSObject): self.runGeneratorNext() def runGeneratorNext(self): + if self.gen is None or self.finish is None: + return try: msg = self.gen.next() self.loadingLabel.setStringValue_(msg) self.performSelector_withObject_afterDelay_( self.runGeneratorNext, None, 0) except StopIteration: - self.gen = None - NSApp.endSheet_(self.loadingSheet) - self.loadingSheet.orderOut_(self) - self.finish() - self.finish = None + self.stopGenerator() + + def stopGenerator(self): + self.gen = None + NSApp.endSheet_(self.loadingSheet) + self.loadingSheet.orderOut_(self) + self.finish() + self.finish = None + + @objc.IBAction + def doCancel_(self, sender): + self.stopGenerator() @objc.IBAction def doSync_(self, sender): diff --git a/libsyncitunes.py b/libsyncitunes.py index c8d330c..4122891 100644 --- a/libsyncitunes.py +++ b/libsyncitunes.py @@ -133,19 +133,6 @@ def encode_filename(filename): encoded_names[orig_filename] = filename return filename -def export_m3u(dry_run, dest, path_prefix, playlist_name, files): - if dry_run: - return - playlist_file = os.path.join(dest, playlist_name) + ".m3u" - logging.info("Writing: " + playlist_file) - f = open(playlist_file, "w") - for filename in files: - if path_prefix.find("\\") > 0: - filename = filename.replace("/", "\\") - filename = encode_filename(filename) - f.write("%s%s\n" % (path_prefix, filename)) - f.close() - def strip_prefix(s, prefix): assert s.startswith(prefix) s = s[len(prefix):] @@ -166,6 +153,20 @@ def mkdirhier(path): except OSError: pass +def export_m3u(dry_run, dest, path_prefix, playlist_name, files): + if dry_run: + return + playlist_file = os.path.join(dest, "-Playlists-", playlist_name) + ".m3u" + mkdirhier(os.path.dirname(playlist_file)) + logging.info("Writing: " + playlist_file) + f = open(playlist_file, "w") + for filename in files: + if path_prefix.find("\\") > 0: + filename = filename.replace("/", "\\") + filename = encode_filename(filename) + f.write("%s%s\n" % (path_prefix, filename)) + f.close() + def sync(dry_run, source, dest, files): join = os.path.join @@ -198,7 +199,7 @@ def sync(dry_run, source, dest, files): else: yield "Update: " + filename - elif not filename.endswith(".m3u"): + elif not filename.startswith("-Playlists-"): yield "Delete: " + filename if not dry_run: os.unlink(join(dest, filename)) -- 2.39.2