Skip to content

Commit

Permalink
Set runtime icon for PyGame apps
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Nov 21, 2023
1 parent ccda123 commit 1dfb847
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 36 deletions.
1 change: 1 addition & 0 deletions changes/1532.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The BeeWare icon of Brutus is now used as the runtime icon for new projects created with PyGame.
12 changes: 6 additions & 6 deletions src/briefcase/bootstraps/pursuedpybear.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def __init__(self, **props):
def main():
# Linux desktop environments use app's .desktop file to integrate the app
# to their application menus. The .desktop file of this app will include
# StartupWMClass key, set to app's formal name, which helps associate
# Linux desktop environments use an app's .desktop file to integrate the app
# in to their application menus. The .desktop file of this app will include
# the StartupWMClass key, set to app's formal name. This helps associate the
# app's windows to its menu item.
#
# For association to work any windows of the app must have WMCLASS
# property set to match the value set in app's desktop file. For PPB this
# is set using environment variable.
# For association to work, any windows of the app must have WMCLASS property
# set to match the value set in app's desktop file. For PPB, this is set
# using the SDL_VIDEO_X11_WMCLASS environment variable.
# Find the name of the module that was used to start the app
app_module = sys.modules["__main__"].__package__
Expand Down
20 changes: 14 additions & 6 deletions src/briefcase/bootstraps/pygame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def app_source(self):
import importlib.metadata
import os
import sys
from pathlib import Path
import pygame
Expand All @@ -18,14 +19,14 @@ def app_source(self):
def main():
# Linux desktop environments use app's .desktop file to integrate the app
# to their application menus. The .desktop file of this app will include
# StartupWMClass key, set to app's formal name, which helps associate
# Linux desktop environments use an app's .desktop file to integrate the app
# in to their application menus. The .desktop file of this app will include
# the StartupWMClass key, set to app's formal name. This helps associate the
# app's windows to its menu item.
#
# For association to work any windows of the app must have WMCLASS
# property set to match the value set in app's desktop file. For PPB this
# is set using environment variable.
# For association to work, any windows of the app must have WMCLASS property
# set to match the value set in app's desktop file. For PyGame, this is set
# using the SDL_VIDEO_X11_WMCLASS environment variable.
# Find the name of the module that was used to start the app
app_module = sys.modules["__main__"].__package__
Expand All @@ -34,6 +35,13 @@ def main():
os.environ["SDL_VIDEO_X11_WMCLASS"] = metadata["Formal-Name"]
# Set the app's runtime icon
pygame.display.set_icon(
pygame.image.load(
Path(__file__).parent / "resources" / "{{ cookiecutter.app_name }}.png"
)
)
pygame.init()
pygame.display.set_caption(metadata["Formal-Name"])
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
Expand Down
12 changes: 6 additions & 6 deletions src/briefcase/bootstraps/pyside6.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def init_ui(self):
def main():
# Linux desktop environments use app's .desktop file to integrate the app
# to their application menus. The .desktop file of this app will include
# StartupWMClass key, set to app's formal name, which helps associate
# Linux desktop environments use an app's .desktop file to integrate the app
# in to their application menus. The .desktop file of this app will include
# the StartupWMClass key, set to app's formal name. This helps associate the
# app's windows to its menu item.
#
# For association to work any windows of the app must have WMCLASS
# property set to match the value set in app's desktop file. For PySide6
# this is set with setApplicationName().
# For association to work, any windows of the app must have WMCLASS property
# set to match the value set in app's desktop file. For PySide6, this is set
# with setApplicationName().
# Find the name of the module that was used to start the app
app_module = sys.modules["__main__"].__package__
Expand Down
44 changes: 26 additions & 18 deletions tests/commands/new/test_build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,14 @@ def init_ui(self):
def main():
# Linux desktop environments use app's .desktop file to integrate the app
# to their application menus. The .desktop file of this app will include
# StartupWMClass key, set to app's formal name, which helps associate
# Linux desktop environments use an app's .desktop file to integrate the app
# in to their application menus. The .desktop file of this app will include
# the StartupWMClass key, set to app's formal name. This helps associate the
# app's windows to its menu item.
#
# For association to work any windows of the app must have WMCLASS
# property set to match the value set in app's desktop file. For PySide6
# this is set with setApplicationName().
# For association to work, any windows of the app must have WMCLASS property
# set to match the value set in app's desktop file. For PySide6, this is set
# with setApplicationName().
# Find the name of the module that was used to start the app
app_module = sys.modules["__main__"].__package__
Expand Down Expand Up @@ -496,14 +496,14 @@ def __init__(self, **props):
def main():
# Linux desktop environments use app's .desktop file to integrate the app
# to their application menus. The .desktop file of this app will include
# StartupWMClass key, set to app's formal name, which helps associate
# Linux desktop environments use an app's .desktop file to integrate the app
# in to their application menus. The .desktop file of this app will include
# the StartupWMClass key, set to app's formal name. This helps associate the
# app's windows to its menu item.
#
# For association to work any windows of the app must have WMCLASS
# property set to match the value set in app's desktop file. For PPB this
# is set using environment variable.
# For association to work, any windows of the app must have WMCLASS property
# set to match the value set in app's desktop file. For PPB, this is set
# using the SDL_VIDEO_X11_WMCLASS environment variable.
# Find the name of the module that was used to start the app
app_module = sys.modules["__main__"].__package__
Expand Down Expand Up @@ -647,6 +647,7 @@ def test_question_sequence_pygame(new_command):
import importlib.metadata
import os
import sys
from pathlib import Path
import pygame
Expand All @@ -656,14 +657,14 @@ def test_question_sequence_pygame(new_command):
def main():
# Linux desktop environments use app's .desktop file to integrate the app
# to their application menus. The .desktop file of this app will include
# StartupWMClass key, set to app's formal name, which helps associate
# Linux desktop environments use an app's .desktop file to integrate the app
# in to their application menus. The .desktop file of this app will include
# the StartupWMClass key, set to app's formal name. This helps associate the
# app's windows to its menu item.
#
# For association to work any windows of the app must have WMCLASS
# property set to match the value set in app's desktop file. For PPB this
# is set using environment variable.
# For association to work, any windows of the app must have WMCLASS property
# set to match the value set in app's desktop file. For PyGame, this is set
# using the SDL_VIDEO_X11_WMCLASS environment variable.
# Find the name of the module that was used to start the app
app_module = sys.modules["__main__"].__package__
Expand All @@ -672,6 +673,13 @@ def main():
os.environ["SDL_VIDEO_X11_WMCLASS"] = metadata["Formal-Name"]
# Set the app's runtime icon
pygame.display.set_icon(
pygame.image.load(
Path(__file__).parent / "resources" / "{{ cookiecutter.app_name }}.png"
)
)
pygame.init()
pygame.display.set_caption(metadata["Formal-Name"])
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
Expand Down

0 comments on commit 1dfb847

Please sign in to comment.