Revision: 10012 http://pure-data.svn.sourceforge.net/pure-data/?rev=10012&view=rev Author: eighthave Date: 2008-06-17 06:46:37 -0700 (Tue, 17 Jun 2008)
Log Message: ----------- first stab at an app creator for Mac OS X. Basically, it just copies itself and sets up the patch to be started automatically
Modified Paths: -------------- branches/pd-extended/v0-40/pd/src/u_main.tk
Modified: branches/pd-extended/v0-40/pd/src/u_main.tk =================================================================== --- branches/pd-extended/v0-40/pd/src/u_main.tk 2008-06-17 13:26:13 UTC (rev 10011) +++ branches/pd-extended/v0-40/pd/src/u_main.tk 2008-06-17 13:46:37 UTC (rev 10012) @@ -810,6 +810,9 @@ } else { # Mac OS X # Cmd-m is minimize window on Mac OS X, so remove binding .mbar.file add command -label Message -command {menu_send} + .mbar.file add separator + .mbar.file add command -label "Make app from patch..." -state disabled + .mbar.file add command -label "Make app from folder..." -state disabled } .mbar.file add separator .mbar.file add command -label Close -accelerator [accel_munge "Ctrl+w"] \ @@ -881,6 +884,114 @@
########### functions for menu functions on document windows ########
+# make embedded application on Mac OS X +proc makeapp_promptreplace {appdir} { + if {[file exists $appdir]} { + set answer [tk_messageBox -message [concat overwrite $appdir "?"] \ + -type yesno -icon question] + return [string equal $answer "yes"] + } else { + return 1 + } +} + +proc makeapp_createapp {appdir} { + global pd_guidir + set pdapp_contents [file normalize "$pd_guidir/.."] + pdtk_post "Copying:$pdapp_contents\n -->\t$appdir/\n" + file delete -force -- $appdir + file mkdir -- $appdir + file copy -- $pdapp_contents "$appdir/" + file rename -force -- $appdir/Contents/org.puredata.pd.default.plist \ + $appdir/Contents/org.puredata.pd.plist +} + +proc makeapp_makeinfoplist {appdir} { + regexp {.*/(.+).app} $appdir -> appname + pdtk_post "Setting up $appdir/Contents/Info.plist\n" + set info_plist [open "$appdir/Contents/Info.plist" r] + set new_info_plist [read $info_plist] + regsub -- {CFBundleName</key>.*?<string>Pd-extended<} $new_info_plist \ + "CFBundleName</key>\n\t<string>$appname<" new_info_plist + set cfbundleversion [clock format [clock seconds] -format %Y.%m.%d] + regsub -- {CFBundleVersion</key>.*?<string>.*?<} $new_info_plist \ + "CFBundleVersion</key>\n\t<string>$cfbundleversion<" new_info_plist + regsub -- {org.puredata.pd.wish} $new_info_plist \ + "org.puredata.pd.app.$appname" new_info_plist + regsub -- {<key>CFBundleDocumentTypes.+</array>} $new_info_plist \ + {} new_info_plist + close $info_plist + set info_plist [open "$appdir/Contents/Info.plist" w] + puts $info_plist $new_info_plist + close $info_plist +} + +proc makeapp_copycurrentpatch {appdir patch patchname isdir} { + if {$isdir} { + pdtk_post [format "Copying:%s\n -->\t$appdir/Contents/Resources/extra/\n" \ + [file dirname $patch]] + file copy -- [file dirname $patch] "$appdir/Contents/Resources/extra/" + } else { + set embedded_patch "$appdir/Contents/Resources/extra/$patchname/$patchname.pd" + pdtk_post "Copying:$patch\n -->\t$embedded_patch\n" + file mkdir -- "$appdir/Contents/Resources/extra/$patchname" + file copy -- $patch $embedded_patch + } +} + +proc makeapp_getpatchname {top_window} { + set top_window_path [wm attributes $top_window -titlepath] + if {$top_window_path != ""} { + pdtk_post "top window path $top_window_path\n" + return $top_window_path + } else { + return "" + } +} + +proc makeapp_embedprefs {appdir patch_to_open} { + pdtk_post "Setting up $appdir/Contents/org.puredata.pd.plist\n" + set plist [open "$appdir/Contents/org.puredata.pd.plist" r] + set new_plist [read $plist] + close $plist + regsub -- {flags</key>.*?<string>.*?<} $new_plist \ + "flags</key>\n\t<string>-open hcs/embed.pd -open $patch_to_open<" new_plist + set plist [open "$appdir/Contents/org.puredata.pd.plist" w] + puts $plist $new_plist + close $plist + +} + +proc menu_makeapp {isdir} { + set top_window [lindex [wm stackorder .] end] + menu_windowparent $top_window + set patch [makeapp_getpatchname $top_window] + if {$patch == ""} { + pdtk_post \ + "No patch found! Select an open parent patch with the mouse, then try again.\n" + return + } + # TODO set -parent to patch being turned into app + pdtk_post "Select name for app to build...\n" + set appdir [tk_getSaveFile -filetypes { {{Mac OS X Application} {.app}} } \ + -parent $top_window -defaultextension .app \ + -title "Save application to..."] + if {$appdir != ""} { + if {![string match "*.app" $appdir]} { + set appdir "$appdir.app" +# pdtk_post "Adding .app extension: $appdir\n" + } + if {[makeapp_promptreplace $appdir]} { + makeapp_createapp $appdir + makeapp_makeinfoplist $appdir + regexp {.*/(.*?).pd} $patch -> patchname + makeapp_copycurrentpatch $appdir $patch $patchname $isdir + makeapp_embedprefs $appdir "$patchname/$patchname.pd" + pdtk_post "$appdir is complete!\n" + } + } +} + proc menu_save {name} { pdtk_canvas_checkgeometry $name pd [concat $name menusave ;] @@ -1233,6 +1344,11 @@ } else { # Cmd-m is minimize window on Mac OS X $name.m.file add command -label Message -command {menu_send} + $name.m.file add separator + $name.m.file add command -label "Make app from patch..." \ + -command {menu_makeapp 0} + $name.m.file add command -label "Make app from folder..." \ + -command {menu_makeapp 1} }
$name.m.file add separator
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.