Discussion:
[pygame] windows screen saver in pygame?
C. Porter Bassett
2003-03-18 20:58:20 UTC
Permalink
Is it possible to make a pygame program run as a screen saver in
windows? If it is, how do you do it?
Pete Shinners
2003-03-18 21:11:14 UTC
Permalink
Post by C. Porter Bassett
Is it possible to make a pygame program run as a screen saver in
windows? If it is, how do you do it?
i've never seen anyone get this working, but there has been interest in
it before. there isn't anything too special about screensavers. they are
just regular EXE programs that draw do fullscreen drawing.

i believe on windows you just have your program exit when there is any
mouse or keyboard input. i'm not sure if there are any other sort of
"special" windows calls you need to deal with or not?
Leonardo Santagada
2003-03-18 22:59:26 UTC
Permalink
Post by Pete Shinners
i believe on windows you just have your program exit when there is any
mouse or keyboard input. i'm not sure if there are any other sort of
"special" windows calls you need to deal with or not?
windows passes parameter when you are in configuration mode ... i think
it is -o, but i don't remember, also it need to have scr as extension
not .exe. You can search google for more info.
Beni Cherniavsky
2003-03-19 11:48:29 UTC
Permalink
Post by Pete Shinners
Post by C. Porter Bassett
Is it possible to make a pygame program run as a screen saver in
windows? If it is, how do you do it?
i've never seen anyone get this working, but there has been interest in
it before. there isn't anything too special about screensavers. they are
just regular EXE programs that draw do fullscreen drawing.
i believe on windows you just have your program exit when there is any
mouse or keyboard input. i'm not sure if there are any other sort of
"special" windows calls you need to deal with or not?
I don't think there is anything special [1]_, IIRC I once renamed a
DOS (djgpp) text-mode program (!) to .scr and it worked (under win9x,
I think).

With a trivial program that saves its arguments to some file, you can
easily discover the command-line API - IIRC it's a single "s" letter
for running the saver and no arguments for the setup dialog.

So you can just make a trivial .exe that calls your python script.

.. [1] There is one special thing: the preview of the saver inside the
dialog. You progagbly need to do it with GDI calls and I have
no idea how windows detects you know to preview yourself and
gives you the context. In any case it seems completely
optional.
--
Beni Cherniavsky <cben-v2yAWYI3+kL7r6psnUbsSmZHpeb/A1Y/@public.gmane.org>
Syver Enstad
2003-03-19 16:00:32 UTC
Permalink
Post by Beni Cherniavsky
With a trivial program that saves its arguments to some file, you can
easily discover the command-line API - IIRC it's a single "s" letter
for running the saver and no arguments for the setup dialog.
So you can just make a trivial .exe that calls your python script.
.. [1] There is one special thing: the preview of the saver inside the
dialog. You progagbly need to do it with GDI calls and I have
no idea how windows detects you know to preview yourself and
gives you the context. In any case it seems completely
optional.
--
Here's from MSDN:

INFO: Screen Saver Command Line Arguments
ID: Q182383


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Win32 Software Development Kit (SDK)

--------------------------------------------------------------------------------


SUMMARY
Windows communicates with Screen Savers through command line arguments. The ScrnSave.lib library handles this for Screen Savers that are written to use it, but other Win32 Screen Savers marked 4.0 or higher must handle the following command line arguments:


ScreenSaver - Show the Settings dialog box.
ScreenSaver /c - Show the Settings dialog box, modal to the
foreground window.
ScreenSaver /p <HWND> - Preview Screen Saver as child of window <HWND>.
ScreenSaver /s - Run the Screen Saver.
In addition, Windows 95 Screen Savers must handle:

ScreenSaver /a <HWND> - change password, modal to window <HWND>
<HWND> is a HWND presented on the command line as an unsigned decimal number.
--
Vennlig hilsen

Syver Enstad
Pete Shinners
2003-03-19 08:55:13 UTC
Permalink
Post by Syver Enstad
ScreenSaver /p <HWND> - Preview Screen Saver as child of window <HWND>.
therefore, you could still get pygame to do the preview window, the init
code would look like this...

if sys.argv[1] == "/p": #preview mode
os.environ['SDL_VIDEO_DRIVER'] = 'windib'
os.environ['SDL_WINDOWID'] = sys.argv[2]
pygame.init()
window = pygame.display.set_mode((100,100))
width, height = window.get_size()
else: #regular init mode
pygame.init()
window = pygame.display.set_mode((640, 480), FULLSCREEN)
width, height = window.get_size()
--
"if they keep silent, the very stones will cry out"
pete*shinners.org
R. Alan Monroe
2003-03-19 23:31:12 UTC
Permalink
Post by Pete Shinners
os.environ['SDL_VIDEO_DRIVER'] = 'windib'
os.environ['SDL_WINDOWID'] = sys.argv[2]
Where can I find a full list of these environment variables? I don't
see them on libsdl.org and even Google only found them in some pygame
archive, not any official SDL site.

Alan
R. Alan Monroe
2003-03-19 23:56:40 UTC
Permalink
When I open a pygame window from an interactive python session, I
can't move, size, minimize or maximize the pygame display. And if I
bring another window to the front, pygame's window can't be reached or
brought frontmost again. Any workarounds for this? I'm on win32.

Alan
Pete Shinners
2003-03-20 00:23:43 UTC
Permalink
Post by R. Alan Monroe
When I open a pygame window from an interactive python session, I
can't move, size, minimize or maximize the pygame display. And if I
bring another window to the front, pygame's window can't be reached or
brought frontmost again. Any workarounds for this? I'm on win32.
you can create a resizeable window by passing the "RESIZABLE" flag to
display.set_mode(). this will take care of the size and maximize issues.

your other problem is with moving, raising, and minimizing. the problem
is these happen in the same thread as the interactive python. so while
the prompt is sitting there, pygame can't do anything with the window.
all the actions you have taken are sitting inside the system event
queue, but pygame/SDL need a chance to go receive those events and
process them.

calling pygame.event.pump() will tell pygame and SDL to handle the
windows events. you could also call any of the other pygame.event
functions which effect the pygame event queue.

the pump() function will return pretty quick, but any window
interactions you have made will all happen very quick. you will have to
call pump() anytime you do something to the window for it to react.
R. Alan Monroe
2003-03-20 01:23:13 UTC
Permalink
Post by Pete Shinners
your other problem is with moving, raising, and minimizing. the problem
is these happen in the same thread as the interactive python. so while
the prompt is sitting there, pygame can't do anything with the window.
all the actions you have taken are sitting inside the system event
queue, but pygame/SDL need a chance to go receive those events and
process them.
calling pygame.event.pump() will tell pygame and SDL to handle the
windows events. you could also call any of the other pygame.event
functions which effect the pygame event queue.
the pump() function will return pretty quick, but any window
interactions you have made will all happen very quick. you will have to
call pump() anytime you do something to the window for it to react.
Cool. Can you do something really perverse like spawn a new thread to
do the pumping in the background every 1 second? :^)

Alan
Syver Enstad
2003-03-20 09:37:33 UTC
Permalink
This post might be inappropriate. Click to display it.
Syver Enstad
2003-03-20 11:04:34 UTC
Permalink
Post by Syver Enstad
Post by Pete Shinners
os.environ['SDL_VIDEO_DRIVER'] = 'windib'
Should be SDL_VIDEODRIVER

I found out at:
http://sdldoc.csn.ul.ie/sdlenvvars.php
Post by Syver Enstad
I can't get the windowid hack to work. pygame just puts up it's own
window instead of the hwnd passed in. The docs state that one has to
make a child window of the passed HWND, maybe that is what is wrong.
One could perhaps make a child window with win32gui? I'll look into
that and see what happens.
--
Vennlig hilsen

Syver Enstad
Syver Enstad
2003-03-20 11:12:34 UTC
Permalink
Post by Syver Enstad
Post by Pete Shinners
os.environ['SDL_VIDEO_DRIVER'] = 'windib'
Should be SDL_VIDEODRIVER
http://sdldoc.csn.ul.ie/sdlenvvars.php
It works, it works. I now have the preview working. I had to be
careful to not only do 'pygame.init()' after the os.environ calls but
also do 'import pygame' after calling os.environ.
--
Vennlig hilsen

Syver Enstad
R. Alan Monroe
2003-03-20 12:30:43 UTC
Permalink
Post by Syver Enstad
It works, it works. I now have the preview working. I had to be
careful to not only do 'pygame.init()' after the os.environ calls but
also do 'import pygame' after calling os.environ.
Cool, what kind of stub exe (.scr) are you using to spawn the python
interpreter? Can you post its source?

Alan
Syver Enstad
2003-03-20 13:32:29 UTC
Permalink
Post by R. Alan Monroe
Post by Syver Enstad
It works, it works. I now have the preview working. I had to be
careful to not only do 'pygame.init()' after the os.environ calls
but
Post by Syver Enstad
also do 'import pygame' after calling os.environ.
Cool, what kind of stub exe (.scr) are you using to spawn the python
interpreter? Can you post its source?
Of course, it's just a very simple c++ program.

By the way, I have a simple python script that makes an .exe file from
a python script too (just adds about 3 KB to the size of it). If you
use that you don't have to use the stub, you just make an exe of your
script and rename it to .scr. I think it is a drawback that python
doesn't provide for "real" executables under win32, in quite many
cases one has to provide tiny stub programs or dynamic link libraries
to bootstrap python into doing something useful on this platform. It
would be nice to have something like a generic .dll stub for python,
does anybody have any ideas on how to accomplish that?

Here is the source for a very simple pygame screensaver, it doesn't do
anything interesting, but allows me to see the different commandlines
and simulates the operation of a "real" screensaver.
Niki Spahiev
2003-03-20 14:40:47 UTC
Permalink
Syver Enstad wrote:

Better for stub to pass filename(argv[0]) + '.py' to python.exe

Niki Spahiev
Syver Enstad
2003-03-20 16:33:41 UTC
Permalink
Post by Niki Spahiev
Better for stub to pass filename(argv[0]) + '.py' to python.exe
Yeah, I know. I was going to do that, but then I just made an exe file
of the python script instead, and renamed it to .scr. The code that I
provided is strictly throw-away, it's just intended to be used to find
out about how screensavers work.
--
Vennlig hilsen

Syver Enstad
Syver Enstad
2003-03-20 11:40:43 UTC
Permalink
Post by Syver Enstad
INFO: Screen Saver Command Line Arguments
ID: Q182383
ScreenSaver - Show the Settings dialog box.
ScreenSaver /c - Show the Settings dialog box, modal to the
foreground window.
ScreenSaver /c:<HWND>

On my machine (win2k pro), the system passes /C:<HWND> to the screensaver when
pressing the settings button in the screensaver dialog (control
panel). The passed hwnd is the hwnd of the screensaver dialog.
--
Vennlig hilsen

Syver Enstad
Loading...