Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app starts minimized #140

Closed
ronaldoussoren opened this issue Mar 15, 2014 · 8 comments
Closed

app starts minimized #140

ronaldoussoren opened this issue Mar 15, 2014 · 8 comments
Labels
bug Something isn't working

Comments

@ronaldoussoren
Copy link
Owner

Original report by stefan karos (Bitbucket: bwanaaa, GitHub: bwanaaa).


I have successfully created a mac app of my python script which is the game, pong. The game runs fine but for some reason its pygame window starts minimized. I have to go down to the app launch at and click on the little smiling python to bring it up. The script itself executes properly in IDLE. Why is this and how to fix?

@ronaldoussoren
Copy link
Owner Author

Original comment by stefan karos (Bitbucket: bwanaaa, GitHub: bwanaaa).


well i found some VERY BIZARRE.
naming ANY python script either
pongforone.py
or
pongfortwo.py
and then running app2py results in an app that starts minimized.
The actual setup script can be named anything. For example,
Here is a script that puts up a window with a label and it is named test.py

#!python

import pygame, random, math

#game settings
width =1024
height = 800
color_black = 0,0,0
color_green = 166,206,57
score = 10

#Initialization   
pygame.init()
screen = pygame.display.set_mode ((width, height))
# initialize font; must be called after 'pygame.init()' to avoid 'Font not Initialized' error
#Label 1
myfont = pygame.font.SysFont("monospace", 35)
label = myfont.render("Label1", 1, color_green)

#draw
def draw():
    screen.fill(color_black)
    screen.blit(label, (200, 100))
    pygame.display.flip()

done=False
while not done:
    events = pygame.event.get()
    for event in events:
        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            done = True
    draw()
    
pygame.quit()

the setup script named 'setuptest.py' is this:

#!python

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup
import os, pygame
APP = ['test.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}

setup(
    app=APP,
    data_files = DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

then i run this in terminal:

#!python


arch -i386 python2.7 setuptest.py py2app

and i get an app named 'test' in my folder named 'dist'. double clicking on this app gives a black window with a green word in it that says 'Label1'.

If I change the name of my script from test.py to pongforone.py
and obviously change the line in the setup script to read
APP = ['pongforone.py']

then i get an app named pongforone that starts minimized. I have to go down to the launch bar and click on the little smiling python to bring it to the front. renaming the app in finder to 'test' or anything else does not change this behavior. it still starts in the background.

Is there something freaky about my Mavericks OS or can anyone reproduce this behavior?

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


This is pretty weird, I'll try to reproduce the problem.

As an aside, arch -i386 python2.7 setuptest.py py2app does not result in a 32-bit only binary, you wan to use python2.7 setuptest.py py2app --arch i386 for that.

@ronaldoussoren
Copy link
Owner Author

Original comment by Statue11 (Bitbucket: Statue11, ).


I have the same problem - py2app. My app has no console output, but uses Tkinter to throw up a GUI screen. When I run the app, the icon appears in the dock, but the TK window is not visible unless I click on the icon to un-minimize it. I'm running the latest version of py2app as of today.

@ronaldoussoren
Copy link
Owner Author

Original comment by Ryan Holmes (Bitbucket: blitzmann, GitHub: blitzmann).


We ran into a similar issue: pyfa-org/Pyfa#423

Basically, we had to set argv_emulation to False, which seemed to get the app to pop to the foreground after launching. I have no idea why this is.

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Hmmm.... argv_emulation is more or less useless with any script that uses a GUI library, those should have their own mechanisms. Py2applet is only useful for command-line scripts that expect one or more filenames as their argument.

I've changed py2applet to no longer enable argv_emulation by default, argv_emulation causes more problems than it solves when it is enabled by default.

@ronaldoussoren
Copy link
Owner Author

Original comment by Paul McCarthy (Bitbucket: pauldmccarthy, GitHub: pauldmccarthy).


After some experimenting, I've been able to use argv emulation, and have the app start up normally (i.e. without getting minimised) by editing argv_emulation.py. Changing this line to:

        sts = carbon.ReceiveNextEvent(1, ctypes.byref(eventType),
            start + timeout[0] - now, FALSE, ctypes.byref(event))

fixes the issue without any undesirable side-effects (although have only tested on El Capitan).

@ronaldoussoren
Copy link
Owner Author

Original comment by Matthew Clapp (Bitbucket: itsayellow, GitHub: itsayellow).


It would be nice if this issue could be fixed, because argv_emulation is how to open an app by double-clicking on it a document in Finder that belongs to the app. (if a proper plist is attached to the app).
Right now in Sierra I am seeing this problem.

I am faced with the choice of my app either starting up minimized (with argv_emulation) or not loading the file I double-clicked on in Finder (without argv_emulation.)

Is there another way for my app to receive which file was double-clicked on in Finder and started it up, besides receiving it in argv?

@ronaldoussoren
Copy link
Owner Author

Original comment by Matthew Clapp (Bitbucket: itsayellow, GitHub: itsayellow).


I can confirm Paul McCarthy's fix also works for me in Mac OS Sierra.

@ronaldoussoren ronaldoussoren added major bug Something isn't working labels Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant