def main():
pg.init()
pg.mouse.set_visible(False) # hide the pointer
#screen = pg.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), pg.FULLSCREEN) # windows
screen = pg.display.set_mode((1920, 1080), pg.NOFRAME) # linux
game = Game(screen)
game.create_sprites()
game.update_calendar()
game.update_weather()
game.change_state()
game.run()
exit(0)
python类FULLSCREEN的实例源码
scheduler.py 文件源码
项目:pygame-event-calendar-and-pianobar
作者: scottpcrawford
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def __init__(self, dimensions, fullscreen = False, soundrenderer="pyaudio",
loop=False):
""" Constructor.
Parameters
----------
dimensions : tuple (width, height)
The dimension of the window in which the video should be shown. Aspect
ratio is maintained.
fullscreen : bool, optional
Indicates whether the video should be displayed in fullscreen.
soundrenderer : {'pyaudio','pygame'}
Designates which sound backend should render the sound.
"""
pygame.init()
(windowWidth, windowHeight) = dimensions
flags = pygame.DOUBLEBUF|pygame.OPENGL|pygame.HWSURFACE
self.fullscreen = fullscreen
if fullscreen:
flags = flags | pygame.FULLSCREEN
pygame.display.set_mode((windowWidth,windowHeight), flags)
self.windowSize = (windowWidth, windowHeight)
self.soundrenderer=soundrenderer
self.loop = loop
self.texUpdated = False
self.__initGL()
self.decoder = Decoder(
videorenderfunc=self.__texUpdate,
)
self.texture_locked = False
def screen(w, h, fullscreen=False):
screen_info.resolution = [w, h]
if fullscreen:
screen_info.screen = pygame.display.set_mode([w, h], pygame.FULLSCREEN)
else:
screen_info.screen = pygame.display.set_mode([w, h])
# Create surface for turtle drawings
create_pen_surface()
# Get screen center
CENTER.x = screen_info.resolution[0] / 2
CENTER.y = screen_info.resolution[1] / 2
def __init__(self, resolution=(640, 480), cmdline=""):
self.color = (0,0,0)
self.resolution = resolution
if "--fullscreen" in cmdline:
self.window = \
pygame.display.set_mode(self.resolution, pygame.FULLSCREEN)
else:
self.window = pygame.display.set_mode(self.resolution)
# pygame.display.set_mode() verändert die Größe des Fensters
# Über das zweite Argument, pygame.FULLSCREEN, kann das Fenster
# in den Vollbildmodus versetzt werden
pygame.display.set_caption('A Simple Yet Insightful Pygame Example')
# Verändert die Beschriftung des Fensters
pygame.mouse.set_visible(0)
# Verhindert, dass die Maus gezeigt wird
self.screen = pygame.display.get_surface()
# Generiert ein Surface des Fensters
# Siehe: Allgemeines über Surfaces
self.screen.fill(self.color)
# Füllt das Surface self.screen mit der übergebenen Farbe
# Siehe: Allgemeines über Farben
self.screen_rect = self.screen.get_rect()
# Rectangle des Fensters
# Siehe: Allgemeines über Rectangles
def __init__(self, drivers=DEFAULT_DRIVERS, size=DEFAULT_SIZE, screen_type=DEFAULT_SCREEN, borders=(5, 5),
border_width=3, line_color=(255, 255, 255), font='freesans', font_color=(255, 255, 255),
icons=ICON_DICTIONARY):
"""DisplayDriver class is the class that build the base display for use in the weather
app. Argument descriptions: drivers is a tuple of strings with available SDL_VIDEODRIVER
environmental varaibles; size is a tuple of two integers describing the x, y size of the
screen; screen_type is a string value that corresponds to the pygame constants for
dispay.set_mode
"""
formats = {'no_frame': pygame.NOFRAME, 'full_screen': pygame.FULLSCREEN, 'double_buff': pygame.DOUBLEBUF,
'hw_surface': pygame.HWSURFACE, 'open_GL': pygame.OPENGL, 'resizable': pygame.RESIZABLE}
self._system_data = SystemData()
self._display_instance = None
self._drivers = drivers
self._size = size
self._borders = borders
self._border_width = border_width
self._line_color = line_color
self._font = font
self._font_color = font_color
self._format = formats[screen_type]
self._icons = icons
self._base_dir = os.getcwd() + ICON_BASE_DIR
self._scale_icons = True
self._xmax = self._size[0] - self._borders[0]
self._ymax = self._size[1] - self._borders[1]
self._av = 1
self._av_time = 1
self._screen = None
self._blits = []
def __init__(self):
"Ininitializes a new pygame screen using the framebuffer"
# Based on "Python GUI in Linux frame buffer"
# http://www.karoltomala.com/blog/?p=679
disp_no = os.getenv("DISPLAY")
if disp_no:
print "I'm running under X display = {0}".format(disp_no)
os.putenv('SDL_FBDEV', '/dev/fb1')
# Select frame buffer driver
# Make sure that SDL_VIDEODRIVER is set
driver = 'fbcon'
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
pygame.display.init()
except pygame.error:
print 'Driver: {0} failed.'.format(driver)
exit(0)
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
# Clear the screen to start
self.screen.fill((0, 0, 0))
# Initialise font support
pygame.font.init()
# Render the screen
pygame.display.update()
def todo_test_set_mode(self):
# __doc__ (as of 2008-08-02) for pygame.display.set_mode:
# pygame.display.set_mode(resolution=(0,0), flags=0, depth=0): return Surface
# initialize a window or screen for display
#
# This function will create a display Surface. The arguments passed in
# are requests for a display type. The actual created display will be
# the best possible match supported by the system.
#
# The resolution argument is a pair of numbers representing the width
# and height. The flags argument is a collection of additional
# options. The depth argument represents the number of bits to use
# for color.
#
# The Surface that gets returned can be drawn to like a regular
# Surface but changes will eventually be seen on the monitor.
#
# If no resolution is passed or is set to (0, 0) and pygame uses SDL
# version 1.2.10 or above, the created Surface will have the same size
# as the current screen resolution. If only the width or height are
# set to 0, the Surface will have the same width or height as the
# screen resolution. Using a SDL version prior to 1.2.10 will raise an
# exception.
#
# It is usually best to not pass the depth argument. It will default
# to the best and fastest color depth for the system. If your game
# requires a specific color format you can control the depth with this
# argument. Pygame will emulate an unavailable color depth which can
# be slow.
#
# When requesting fullscreen display modes, sometimes an exact match
# for the requested resolution cannot be made. In these situations
# pygame will select the closest compatable match. The returned
# surface will still always match the requested resolution.
#
# The flags argument controls which type of display you want. There
# are several to choose from, and you can even combine multiple types
# using the bitwise or operator, (the pipe "|" character). If you pass
# 0 or no flags argument it will default to a software driven window.
# Here are the display flags you will want to choose from:
#
# pygame.FULLSCREEN create a fullscreen display
# pygame.DOUBLEBUF recommended for HWSURFACE or OPENGL
# pygame.HWSURFACE hardware accelerated, only in FULLSCREEN
# pygame.OPENGL create an opengl renderable display
# pygame.RESIZABLE display window should be sizeable
# pygame.NOFRAME display window will have no border or controls
self.fail()
def __init__(self):
if platform.system() == "Windows":
pygame.display.init()
pygame.display.set_caption("pySokoban")
self.size = (800,600)
self.screen = pygame.display.set_mode(self.size)
elif self.getUserInterface() == "graphics":
pygame.display.init()
pygame.display.set_caption("pySokoban")
self.size = (800,600)
self.screen = pygame.display.set_mode(self.size)
else:
"Ininitializes a new pygame screen using the framebuffer"
# Based on "Python GUI in Linux frame buffer"
# http://www.karoltomala.com/blog/?p=679
disp_no = os.getenv("DISPLAY")
if disp_no:
print "I'm running under X display = {0}".format(disp_no)
# Check which frame buffer drivers are available
# Start with fbcon since directfb hangs with composite output
drivers = ['fbcon', 'directfb', 'svgalib']
found = False
for driver in drivers:
# Make sure that SDL_VIDEODRIVER is set
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
pygame.display.init()
except pygame.error:
print 'Driver: {0} failed.'.format(driver)
continue
found = True
break
if not found:
raise Exception('No suitable video driver found!')
self.size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
print "Framebuffer size: %d x %d" % (self.size[0], self.size[1])
self.screen = pygame.display.set_mode(self.size, pygame.FULLSCREEN)
# Clear the screen to start
self.screen.fill((0, 0, 0))
# Initialise font support
pygame.font.init()
# Disable mouse
pygame.mouse.set_visible(False)
# Render the screen
pygame.display.update()
def init():
"Ininitializes a new pygame screen using the framebuffer"
# Based on "Python GUI in Linux frame buffer"
# http://www.karoltomala.com/blog/?p=679
disp_no = os.getenv("DISPLAY")
if disp_no:
print "I'm running under X display = {0}".format(disp_no)
# Check which frame buffer drivers are available
# Start with fbcon since directfb hangs with composite output
drivers = ['fbcon', 'directfb', 'svgalib']
#drivers = ['directfb', 'svgalib']
#drivers = ['fbcon']
found = False
for driver in drivers:
# Make sure that SDL_VIDEODRIVER is set
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
print 'Driver: {0} '.format(driver)
pygame.display.init()
except pygame.error:
print 'Driver: {0} failed.'.format(driver)
continue
found = True
break
if not found:
raise Exception('No suitable video driver found!')
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
print "Framebuffer size: %d x %d" % (size[0], size[1])
pygame.mouse.set_visible(False)
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
#screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.DOUBLEBUF | pygame.HWSURFACE)
#screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.DOUBLEBUF)
#screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.HWSURFACE)
# Clear the screen to start
screen.fill((255, 105, 180))
# Initialise font support
pygame.font.init()
# Render the screen
pygame.display.update()
return screen
def init():
"Ininitializes a new pygame screen using the framebuffer"
# Based on "Python GUI in Linux frame buffer"
# http://www.karoltomala.com/blog/?p=679
disp_no = os.getenv("DISPLAY")
if disp_no:
print "I'm running under X display = {0}".format(disp_no)
# Check which frame buffer drivers are available
# Start with fbcon since directfb hangs with composite output
#drivers = ['fbcon', 'directfb', 'svgalib']
#drivers = ['directfb', 'svgalib']
drivers = ['vesafbdf']
found = False
for driver in drivers:
# Make sure that SDL_VIDEODRIVER is set
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
print 'Driver: {0} '.format(driver)
pygame.display.init()
except pygame.error:
print 'Driver: {0} failed.'.format(driver)
exit()
continue
found = True
break
if not found:
raise Exception('No suitable video driver found!')
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
print "Framebuffer size: %d x %d" % (size[0], size[1])
pygame.mouse.set_visible(False)
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
#screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.DOUBLEBUF | pygame.HWSURFACE)
#screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.DOUBLEBUF)
#screen = pygame.display.set_mode(size, pygame.FULLSCREEN | pygame.HWSURFACE)
# Clear the screen to start
screen.fill((255, 105, 180))
# Initialise font support
pygame.font.init()
# Render the screen
pygame.display.update()
return screen
def todo_test_set_mode(self):
# __doc__ (as of 2008-08-02) for pygame.display.set_mode:
# pygame.display.set_mode(resolution=(0,0), flags=0, depth=0): return Surface
# initialize a window or screen for display
#
# This function will create a display Surface. The arguments passed in
# are requests for a display type. The actual created display will be
# the best possible match supported by the system.
#
# The resolution argument is a pair of numbers representing the width
# and height. The flags argument is a collection of additional
# options. The depth argument represents the number of bits to use
# for color.
#
# The Surface that gets returned can be drawn to like a regular
# Surface but changes will eventually be seen on the monitor.
#
# If no resolution is passed or is set to (0, 0) and pygame uses SDL
# version 1.2.10 or above, the created Surface will have the same size
# as the current screen resolution. If only the width or height are
# set to 0, the Surface will have the same width or height as the
# screen resolution. Using a SDL version prior to 1.2.10 will raise an
# exception.
#
# It is usually best to not pass the depth argument. It will default
# to the best and fastest color depth for the system. If your game
# requires a specific color format you can control the depth with this
# argument. Pygame will emulate an unavailable color depth which can
# be slow.
#
# When requesting fullscreen display modes, sometimes an exact match
# for the requested resolution cannot be made. In these situations
# pygame will select the closest compatable match. The returned
# surface will still always match the requested resolution.
#
# The flags argument controls which type of display you want. There
# are several to choose from, and you can even combine multiple types
# using the bitwise or operator, (the pipe "|" character). If you pass
# 0 or no flags argument it will default to a software driven window.
# Here are the display flags you will want to choose from:
#
# pygame.FULLSCREEN create a fullscreen display
# pygame.DOUBLEBUF recommended for HWSURFACE or OPENGL
# pygame.HWSURFACE hardware accelerated, only in FULLSCREEN
# pygame.OPENGL create an opengl renderable display
# pygame.RESIZABLE display window should be sizeable
# pygame.NOFRAME display window will have no border or controls
self.fail()
def __init__(self):
self.parameters = Parameters("Config/default.ini")
if isfile("Config/config.ini") :
self.parameters.Load("Config/config.ini")
# screen mode
screenMode = self.parameters["screenMode"]
if(screenMode == Screen_mode.Fullscreen) :
args = pygame.HWSURFACE | pygame.FULLSCREEN | pygame.DOUBLEBUF
elif(screenMode == Screen_mode.Borderless) :
os.environ['SDL_VIDEO_WINDOW_POS'] = '0,0'
args = pygame.NOFRAME
else:
args = 0
os.environ["SDL_VIDEO_CENTERED"] = "1"
# window icon
self.icon = pygame.image.load("Assets/icon.png")
self.icon = pygame.transform.scale(self.icon, (32, 32))
pygame.display.set_icon(self.icon)
# window parameters
self.width = self.parameters["windowWidth"]
self.height = self.parameters["windowHeight"]
# some managers and important things
self.screen = pygame.display.set_mode((self.width, self.height), args)
pygame.display.set_caption("Lovely Space")
self.clock = pygame.time.Clock()
self.input = input.Input(self)
self.audio = audio.Audio()
self.size = size.Size(self.width, self.height, 1920, 1080)
# a random font
self.fpsFont = pygame.font.SysFont("Arial", 25)
# drunk shit
self.iniPosition = pygame.math.Vector2(0, 200)
self.drunkY = 1
self.drunkX = 1
# pause things
self.pause = None
self.isPaused = False
self.mode = titlescreen.TitleScreen(self)
#self.mode = game.Game(self)
def _get_screen(xwin=False):
"""Initializes a new pygame screen using the framebuffer"""
if display_mocked:
xwin = True
# Based on "Python GUI in Linux frame buffer"
# http://www.karoltomala.com/blog/?p=679
disp_no = os.getenv("DISPLAY")
if disp_no:
logging.info("Running under X display %s", disp_no)
# Make sure that SDL_VIDEODRIVER is set
if xwin:
driver = 'x11'
else:
driver = 'directfb' # alternatives: 'fbcon', 'svgalib'
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
pygame.display.init()
except pygame.error:
logging.exception("Display init failed using driver: %s", driver)
raise
if xwin:
size = (320, 200)
options = 0
else:
# fullscreen
info = pygame.display.Info()
size = (info.current_w, info.current_h)
logging.info("Framebuffer size: %d x %d", size[0], size[1])
options = pygame.FULLSCREEN | pygame.DOUBLEBUF
screen = pygame.display.set_mode(size, options)
# Clear the screen to start
screen.fill((0, 0, 0))
pygame.mouse.set_visible(False)
# Render the screen
pygame.display.update()
return screen
def main():
DISPLAYSURF = pygame.display.set_mode((0,0),pygame.FULLSCREEN)
pygame.display.set_caption('Agario')
FPSCLOCK = pygame.time.Clock()
FOODAMOUNT = 300
FPS = 1000
world_map = ContinuousMap(DISPLAYSURF,MAP_LENGTH,MAP_LENGTH)
world_map.speed = 10
world_map.character.radius = 100
for _ in range(FOODAMOUNT):
world_map.add_object(random.randint(0,MAP_LENGTH),random.randint(0,MAP_LENGTH))
f = pygame.font.Font(None, 64)
while True:
for e in pygame.event.get():
if e.type == KEYDOWN:
if e.key == K_ESCAPE:
pygame.quit()
sys.exit()
k = pygame.key.get_pressed()
if k[K_UP]:
world_map.character_move(Directions.UP)
if k[K_DOWN]:
world_map.character_move(Directions.DOWN)
if k[K_LEFT]:
world_map.character_move(Directions.LEFT)
if k[K_RIGHT]:
world_map.character_move(Directions.RIGHT)
if k[K_p]:
world_map.character.radius += 1
if k[K_l]:
world_map.character.radius -= 1
#world_map.animate()
world_map.draw()
FPSCLOCK.tick(FPS)
UPDATE()
if world_map.has_lost():
DISPLAYSURF.blit(f.render("GAME OVER", True, (255, 255, 255)), (0,0))
"""
while not any(e.type == KEYDOWN and e.key == K_ESCAPE for e in pygame.event.get()):
pass
pygame.quit()
sys.exit()
"""
def screensaver(screenresolution = (640,480), fullscreen = False):
# -*- coding: utf-8 -*-
"""very simple test "game" or screensaver.
all the user have to do is press ESC or SPACE.
the "game" paint random circles.
the "game" accept a screen resolution tuple as argument.
the "game" returns the time passed until the user pressed space"""
pygame.init() #initialize pygame
if fullscreen:
screen=pygame.display.set_mode((screenresolution[0],screenresolution[1]), pygame.FULLSCREEN) # set screensize of pygame window
else:
screen=pygame.display.set_mode((screenresolution[0],screenresolution[1])) # set screensize of pygame window
background = pygame.Surface(screen.get_size()) #create empty pygame surface
background.fill((255,255,255)) #fill the background white color (red,green,blue)
background = background.convert() #convert Surface object to make blitting faster
screen.blit(background, (0,0)) #draw the background on screen
clock = pygame.time.Clock() #create a pygame clock object
mainloop = True
FPS = 30 # desired framerate in frames per second. try out other values !
playtime = 0.0 # how many seconds the "game" is played
while mainloop:
milliseconds = clock.tick(FPS) # do not go faster than this framerate
playtime += milliseconds / 1000.0 # add seconds to playtime
# paint random circles
color = (random.randint(0,255), random.randint(0,255), random.randint(0,255))
pygame.draw.circle(screen, color, (random.randint(0,screenresolution[0]),
random.randint(0,screenresolution[1])),
random.randint(1, min(screenresolution[0], screenresolution[1])),
random.randint(0,1))
for event in pygame.event.get():
if event.type == pygame.QUIT:
mainloop = False # pygame window closed by user
elif event.type == pygame.KEYDOWN:
print "event key:", event.key
if event.key == pygame.K_ESCAPE:
mainloop = False # user pressed ESC
if event.key == pygame.K_SPACE:
mainloop = False # user pressed ESC
pygame.display.set_caption("press ESC to quit. FPS: %.2f (%ix%i), time: %.2f seonds" % (clock.get_fps(), screenresolution[0], screenresolution[1], playtime))
pygame.display.flip() # flip the screen like in a flip book
print "This 'game' was played for %.2f seconds" % playtime
pygame.quit()
return playtime # in seconds
def initscreen(width, height) :
#Initialisation
pygame.init()
if headless:
#will not anymore be enabled as pygame will not init the screen if headless
os.putenv('SDL_VIDEODRIVER', 'dummy')
screen = pygame.display.set_mode((1,1))
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
print "Pygame interface started in dummy mode, framebuffer size: %d x %d" % (size[0], size[1])
else:
#init screen / window or fullscreen
if windowed:
#window mode with w and h submitted to the function
screen = pygame.display.set_mode((width,height),0,32)
pygame.display.set_caption(mytitle)
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
print "Pygame interface started in window mode, framebuffer size: %d x %d" % (size[0], size[1])
else:
#if FS PUT fb1 as the framebuffer device => pitft, res, 320 x 240
# 29.03.2015... not working anymore on the pitft... with PRE "export SDL_FBDEV=/dev/fb1" IT WORKS!
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDRV"] = "TSLIB"
os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"
#os.putenv('SDL_VIDEODRIVER', 'fbcon')
#os.putenv('SDL_FBDEV' , '/dev/fb1')
#os.putenv('SDL_MOUSEDRV' , 'TSLIB')
#os.putenv('SDL_MOUSEDEV' , '/dev/input/touchscreen')
#screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) #not working anymore...
screen = pygame.display.set_mode([320, 240], pygame.FULLSCREEN) #try like so OR without FS Flag?
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
print "Pygame interface started in fullscreen mode, framebuffer size: %d x %d" % (size[0], size[1])
return screen