From 1a187b2df6568b7ae2ea01d03b14f1ab2ebc4b41 Mon Sep 17 00:00:00 2001 From: lmancini Date: Tue, 8 Jun 2010 10:44:27 +0000 Subject: [PATCH] Transforms the process type under Mac OS X (darwin platform) in foreground mode if we're running with the windowed loader: this allows to both have focus and a dock icon for the running application, while the unpacker helper application still doesn't get a dock icon - to do so and still have a non-Carbon loader for console apps, this patch adds a windowed loader (with specific cflags and ldflags) and its debug counterpart. git-svn-id: http://svn.pyinstaller.org/trunk@848 8dd32b29-ccff-0310-8a9a-9233e24343b1 --- Build.py | 7 ++++--- source/linux/Make.py | 26 +++++++++++++++++++++++--- source/linux/main.c | 10 +++++++++- source/linux/makemakefile.py | 6 +++--- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Build.py b/Build.py index ba0a45c..847beb6 100755 --- a/Build.py +++ b/Build.py @@ -1114,9 +1114,10 @@ class BUNDLE(Target): # Setting this to 1 will cause Mac OS X *not* to show # a dock icon for the PyInstaller process which - # decompresses the real executable's contents - - # actually, it's not clear why the real executable - # gets instead an icon doing so. + # decompresses the real executable's contents. As a + # side effect, the main application doesn't get one + # as well, but at startup time the loader will take + # care of transforming the process type. "LSBackgroundOnly": "1", } diff --git a/source/linux/Make.py b/source/linux/Make.py index fd8ee67..c7362e8 100755 --- a/source/linux/Make.py +++ b/source/linux/Make.py @@ -120,9 +120,11 @@ def main(): pprint.pprint(config, configf) configf.close() - targets = [None, None] + targets = [None, None, None, None] targets[0] = os.path.join('../../support/loader/', 'run') targets[1] = os.path.join('../../support/loader/', 'run_d') + targets[2] = os.path.join('../../support/loader/', 'runw') + targets[3] = os.path.join('../../support/loader/', 'runw_d') # include local 'common' dir includes.append('-I../common') @@ -184,11 +186,29 @@ def main(): files + \ ['$(MODLIBS)', '$(LIBS)', '$(SYSLIBS)', '-lz'] # XXX zlib not always -lz + + ## Windowed and debug need per-target cflags and ldflags, we'll pass them to + # makemakefile.writerules. + flagsw = '-DWINDOWED' + flags_d = '-D_DEBUG -DLAUNCH_DEBUG' + ldflagsw = '' + ldflags_d = '' + + if sys.platform.startswith("darwin"): + flagsw += " -I/Developer/Headers/FlatCarbon" + ldflagsw += " -framework Carbon" + + flagsw_d = ' '.join([flagsw, flags_d]) + ldflagsw_d = ' '.join([ldflagsw, ldflags_d]) + ## + outfp = bkfile.open('Makefile', 'w') try: makemakefile.writevars(outfp, somevars, string.join(targets)) - makemakefile.writerules(outfp, files[:], '', '', targets[0]) - makemakefile.writerules(outfp, files[:], '_d', '-D_DEBUG -DLAUNCH_DEBUG', targets[1]) + makemakefile.writerules(outfp, files[:], '', '', '', targets[0]) + makemakefile.writerules(outfp, files[:], '_d', flags_d, ldflags_d, targets[1]) + makemakefile.writerules(outfp, files[:], 'w', flagsw, ldflagsw, targets[2]) + makemakefile.writerules(outfp, files[:], 'w_d', flagsw_d, ldflagsw_d, targets[3]) finally: outfp.close() diff --git a/source/linux/main.c b/source/linux/main.c index 4ec2d1a..b62c9ec 100644 --- a/source/linux/main.c +++ b/source/linux/main.c @@ -29,6 +29,11 @@ #include "getpath.h" #include +// To call TransformProcessType in the child process +#if defined(__APPLE__) && defined(WINDOWED) +#include "Processes.h" +#endif + #ifdef FREEZE_EXCEPTIONS extern unsigned char M_exceptions[]; static struct _frozen _PyImport_FrozenModules[] = { @@ -113,6 +118,10 @@ int main(int argc, char* argv[]) if (workpath) { /* we're the "child" process */ +#if defined(__APPLE__) && defined(WINDOWED) + ProcessSerialNumber psn = { 0, kCurrentProcess }; + OSStatus returnCode = TransformProcessType(&psn, kProcessTransformToForegroundApplication); +#endif VS("Already have a workpath - running!\n"); rc = doIt(argc, argv); } @@ -147,4 +156,3 @@ int main(int argc, char* argv[]) } return rc; } - diff --git a/source/linux/makemakefile.py b/source/linux/makemakefile.py index 38dc9aa..9727990 100644 --- a/source/linux/makemakefile.py +++ b/source/linux/makemakefile.py @@ -29,7 +29,7 @@ def writevars(outfp, makevars, target): outfp.write("\nall: %s\n\n" % target) outfp.write("\nclean:\n\t-rm -f *.o %s\n" % target) -def writerules(outfp, files, suffix, dflag, target): +def writerules(outfp, files, suffix, dflag, lflag, target): deps = [] for i in range(len(files)): file = files[i] @@ -42,5 +42,5 @@ def writerules(outfp, files, suffix, dflag, target): deps.append(dest) outfp.write("\n%s: %s\n" % (target, string.join(deps))) - outfp.write("\t$(CC) %s -o %s $(LDLAST)\n" % - (string.join(files), target)) + outfp.write("\t$(CC) %s -o %s %s $(LDLAST)\n\n\n" % + (string.join(files), target, lflag))