Skip to content

Commit

Permalink
Enabling manual icon setting
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-james authored and lordmauve committed May 6, 2019
1 parent 1df05a8 commit 225bfe5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/asteroids/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from space import create_star_scape
from actors import Player, Asteroid

ICON = 'player'
WIDTH = 800
HEIGHT = 600

Expand Down
15 changes: 10 additions & 5 deletions pgzero/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pgzero.clock
import pgzero.keyboard
import pgzero.screen
import pgzero.loaders

from . import constants

Expand Down Expand Up @@ -62,11 +63,7 @@ def reinit_screen(self):

icon = getattr(self.mod, 'ICON', DEFAULTICON)
if icon and icon != self.icon:
if icon is DEFAULTICON:
self.show_default_icon()
else:
pygame.display.set_icon(pygame.image.load(icon))
self.icon = icon
self.show_icon()

w = getattr(mod, 'WIDTH', 800)
h = getattr(mod, 'HEIGHT', 600)
Expand Down Expand Up @@ -95,6 +92,14 @@ def show_default_icon():
buf = BytesIO(get_data(__name__, 'data/icon.png'))
pygame.display.set_icon(pygame.image.load(buf))

def show_icon(self):
icon = getattr(self.mod, 'ICON', DEFAULTICON)
if icon is DEFAULTICON:
self.show_default_icon()
else:
pygame.display.set_icon(pgzero.loaders.images.load(icon))
self.icon = icon

EVENT_HANDLERS = {
pygame.MOUSEBUTTONDOWN: 'on_mouse_down',
pygame.MOUSEBUTTONUP: 'on_mouse_up',
Expand Down

0 comments on commit 225bfe5

Please sign in to comment.