-
Notifications
You must be signed in to change notification settings - Fork 0
/
pygpicture.py
executable file
·133 lines (110 loc) · 4.16 KB
/
pygpicture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
# -*- coding: utf8 -*-
import os
import sys
import platform
import subprocess
import logging
LEVEL = logging.ERROR
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig( filename='pygpicture.log', filemode='w',
format=FORMAT,
level=LEVEL )
logger = logging.getLogger('PygPicture')
import OpenGL.GL as gl
from OpenGL.GLU import gluPerspective
import pygame, pygame.image
import pygame.locals as pl
from lib.coverflow import CoverFlow
# Default search path for game lnk's
SEARCHPATH = [ os.path.join(os.getcwd(), 'Games') ]
def resize((width, height)):
if height==0:
height=1
gl.glViewport(0, 0, width, height)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gluPerspective(45, 1.0*width/height, 0.1, 100.0)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
def shutdown():
logger.info( 'Shutting down system' )
print 'Shutting down system'
if platform.system() == 'Windows':
subprocess.call( ['shutdown.exe', '/f', '/s', '/t', '5'] )
def main():
pygame.init()
pygame.joystick.init()
logger.info( 'Running on ' + platform.system() )
if platform.system() == 'Windows':
import win32com.client
SEARCHPATH.insert(0, os.path.join( win32com.client.Dispatch('WScript.Shell').SpecialFolders('Desktop'), 'Games' ) )
# Fullscreen video
video_flags = pl.OPENGL|pl.DOUBLEBUF|pl.FULLSCREEN
max_fullscreen_mode = pygame.display.list_modes( 0, video_flags )[0]
elif platform.system() == 'Linux':
#video_flags = pl.OPENGL|pl.DOUBLEBUF|pl.FULLSCREEN
#max_fullscreen_mode = pygame.display.list_modes( 0, video_flags )[0]
# Window mode
video_flags = pl.OPENGL|pl.DOUBLEBUF
max_fullscreen_mode = (800,600)
logger.info( 'Selected video mode: ' + str(max_fullscreen_mode) )
lnkpath = None
for path in SEARCHPATH:
if os.path.isdir( path ):
lnkpath = path
break
if not lnkpath:
print 'No path for game links found'
sys.exit(1)
logger.info( 'Using "%s" as lnk path' % lnkpath )
surface = pygame.display.set_mode(max_fullscreen_mode, video_flags)
pygame.display.set_caption('PygPicture')
resize( max_fullscreen_mode )
# init all joisticks
joysticks = list()
for i in xrange(pygame.joystick.get_count()):
joystick = pygame.joystick.Joystick(i)
joystick.init()
joysticks.append(joystick)
logger.info( 'Found and initialized %d joysticks' % len(joysticks) )
cf = CoverFlow(lnkpath)
clock = pygame.time.Clock()
while True:
pygame.event.pump()
event = pygame.event.poll()
if event.type == pl.QUIT:
break
if event.type == pl.KEYDOWN:
kret = cf.handle_key(event)
if kret == 1:
break
elif kret == 2:
shutdown()
break
# Check for new / changed joysticks
# FIXME: Adding new joysticks does not work, pygame.joystick.get_count() never changes whithout a .quit() .init() cycle
if len(joysticks) == 0 or len(joysticks) < pygame.joystick.get_count():
logger.debug( 'No joystick connected/initialized yet, trying to find new ones' )
pygame.joystick.quit()
joysticks = list()
pygame.joystick.init()
if pygame.joystick.get_count() > 0:
logger.debug( 'Found %d joysticks, trying to initialize' % pygame.joystick.get_count() )
for i in xrange(pygame.joystick.get_count()):
joystick = pygame.joystick.Joystick(i)
if not joystick.get_init():
logger.info( 'New joystick (ID: %d): "%s"' % (i, joystick.get_name()) )
joystick.init()
joysticks.append( joystick )
jret = cf.handle_joystick( joysticks )
if jret == 1:
break
elif jret == 2:
shutdown()
break
cf.draw()
pygame.display.flip()
clock.tick(35)
if __name__ == '__main__':
main()