Skip to content

Commit

Permalink
Merge pull request #10 from wikkiewikkie/bgm
Browse files Browse the repository at this point in the history
gracefully handle music resource unavailability
  • Loading branch information
EricGoldsteinNz authored Jul 25, 2023
2 parents c9d97c0 + 14283f4 commit e4c0c9f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
30 changes: 22 additions & 8 deletions tadpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import frogtool
import tadpole_functions

import requests

import time

basedir = os.path.dirname(__file__)
Expand Down Expand Up @@ -157,7 +159,11 @@ def __init__(self):

widget = QWidget()
self.setCentralWidget(widget)


# Status Bar
self.status_bar = QStatusBar()
self.setStatusBar(self.status_bar)

#Load the Menus
self.create_actions()
self.loadMenus()
Expand Down Expand Up @@ -211,10 +217,6 @@ def __init__(self):
self.tbl_gamelist.horizontalHeader().setSectionResizeMode(1,QHeaderView.ResizeToContents)
self.tbl_gamelist.cellClicked.connect(catchTableCellClicked)
layout.addWidget(self.tbl_gamelist,rowCounter, 0, 1, -1)

# Status Bar
self.status_bar = QStatusBar()
self.setStatusBar(self.status_bar)

def create_actions(self):
#File Menu
Expand Down Expand Up @@ -243,9 +245,21 @@ def loadMenus(self):

# Background Music Menu
self.menu_bgm = self.menuBar().addMenu("&Background Music")
self.music_options = tadpole_functions.get_background_music()
for music in self.music_options:
self.menu_bgm.addAction(QAction(music, self, triggered=self.change_background_music))
try:
self.music_options = tadpole_functions.get_background_music()
except (ConnectionError, requests.exceptions.ConnectionError):
self.status_bar.showMessage("Error loading external music resources.", 20000)
error_action = QAction(QIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_MessageBoxCritical)),
"Error Loading External Resources!",
self)
error_action.setDisabled(True)
self.menu_bgm.addAction(error_action)
else:
for music in self.music_options:
self.menu_bgm.addAction(QAction(QIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_MediaVolume)),
music,
self,
triggered=self.change_background_music))

self.menu_consoleLogos = self.menuBar().addMenu("Console Logos")
self.menu_consoleLogos.addAction(self.action_consolelogos_Default)
Expand Down
11 changes: 8 additions & 3 deletions tadpole_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,14 @@ def checkDriveLooksFroggy(drivePath):
def get_background_music(url="https://api.github.com/repos/EricGoldsteinNz/SF2000_Resources/contents/BackgroundMusic"):
"""gets index of background music from provided GitHub API URL"""
music = {}
for item in json.loads(requests.get(url).content):
music[item['name'].replace(".bgm", "")] = item['download_url']
return music
response = requests.get(url)

if response.status_code == 200:
data = json.loads(response.content)
for item in data:
music[item['name'].replace(".bgm", "")] = item['download_url']
return music
raise ConnectionError("Unable to obtain music resources. (Status Code: {})".format(response.status_code))

"""
This function downloads a file from the internet and renames it to pagefile.sys to replace the background music.
Expand Down

0 comments on commit e4c0c9f

Please sign in to comment.