diff --git a/addon.xml b/addon.xml index 315fa47..ab8cbd0 100644 --- a/addon.xml +++ b/addon.xml @@ -10,6 +10,8 @@ + + diff --git a/default.py b/default.py index f197c38..1cc57b2 100644 --- a/default.py +++ b/default.py @@ -173,8 +173,8 @@ def checkMatch(match): if match.Goal: # Gooooooooooooooooooooooooooooollllllllllllllll! - Notify("GOAL!", str(match), IMG_GOAL, timeout=NOTIFY_TIME) - debug("GOAL: %s" % (match)) + Notify("GOAL!", unicode(match), IMG_GOAL, timeout=NOTIFY_TIME) + debug(u"GOAL: {0}".format(unicode(match))) # Has the status changed? e.g. kick-off, half-time, full-time? if match.StatusChanged: @@ -183,8 +183,8 @@ def checkMatch(match): info = STATUS_DICT.get(match.status, STATUS_DICT["Fixture"]) # Send the notification - Notify(info[0], str(match), info[1], timeout=NOTIFY_TIME) - debug("STATUS: %s" % (match)) + Notify(info[0], unicode(match), info[1], timeout=NOTIFY_TIME) + debug(u"STATUS: {0}".format(unicode(match))) def doUpdates(matchdict): '''Main function to updated leagues and check matches for updates. @@ -227,7 +227,7 @@ def doUpdates(matchdict): # Build dictionary of leagues we want to follow matchdict = updateWatchedLeagues({}, getSelectedLeagues()) -debug("LeagueList - {0}".format(matchdict)) +debug(u"LeagueList - {0}".format(matchdict)) # Check if we need to show alerts or not. alerts = checkAlerts() diff --git a/helper.py b/helper.py new file mode 100644 index 0000000..470b349 --- /dev/null +++ b/helper.py @@ -0,0 +1,85 @@ +''' + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +''' + +''' This script is part of the BBC Football Scores service by elParaguayo + + Its purpose is to handle all non-core elements of the service. + + If called directly it will (eventually) present a menu of different options. + Alternatively it can be called passing any of the following parameters: + + mode: + selectleague: run the Select Leagues dialogue + leaguetable: display league tables + matchdetail: display additional match detail + fixtures: display upcoming fixturs (WIP) + results: display historic results (WIP) +''' + +import sys + +# Import standard xbmc/kodi modules +import xbmc +import xbmcgui +import xbmcaddon + +# Import service specific objects +from resources.lib.settings import selectLeagues, toggleNotification +from resources.lib.league_tables import XBMCLeagueTable +from resources.lib.live_scores_detail import XBMCLiveScoresDetail +from resources.lib.utils import closeAddonSettings +from resources.lib.menu import FootballHelperMenu + +# Import PyXBMCt module. +from pyxbmct.addonwindow import * + +try: + params = dict((x.split("=") for x in sys.argv[1].lower().split(";"))) +except (ValueError, AttributeError, IndexError): + params = {} + +# If no parameters are passed then we show default menu +if not params: + + menu = FootballHelperMenu() + menu.show() + + +# If there are parameters, let's see what we want to do... +if params.get("mode") == "selectleague": + + selectLeagues() + +elif params.get("mode") == "leaguetable": + + # Close addon setting window (if open) + closeAddonSettings() + + # Create an instance of the XBMC League Table + xlt = XBMCLeagueTable() + + # and display it! + xlt.start() + +elif params.get("mode") == "matchdetail": + + # Close addon setting window (if open) + closeAddonSettings() + + # Create an instance of the XBMC League Table + xlsd = XBMCLiveScoresDetail() + + # and display it! + xlsd.start() diff --git a/league_tables.py b/resources/lib/league_tables.py similarity index 93% rename from league_tables.py rename to resources/lib/league_tables.py index d66afca..0eefe62 100644 --- a/league_tables.py +++ b/resources/lib/league_tables.py @@ -15,17 +15,6 @@ ''' This script is part of the BBC Football Scores service by elParaguayo - It allows users to select which leagues they wish to receive updates - for. - - It is called via the script configuration screen or by passing - parameters to trigger specific functions. - - The script accepts the following parameters: - toggle: Turns score notifications on and off - reset: Resets watched league data - - NB only one parameter should be passed at a time. ''' import sys @@ -302,14 +291,3 @@ def start(self): # Show a league table self.showLeagueTable() - -if __name__ == "__main__": - - # Close addon setting window (if open) - closeAddonSettings() - - # Create an instance of the XBMC League Table - xlt = XBMCLeagueTable() - - # and display it! - xlt.start() diff --git a/live_scores_detail.py b/resources/lib/live_scores_detail.py similarity index 95% rename from live_scores_detail.py rename to resources/lib/live_scores_detail.py index 167a265..fdc44e9 100644 --- a/live_scores_detail.py +++ b/resources/lib/live_scores_detail.py @@ -15,17 +15,6 @@ ''' This script is part of the BBC Football Scores service by elParaguayo - It allows users to select which leagues they wish to receive updates - for. - - It is called via the script configuration screen or by passing - parameters to trigger specific functions. - - The script accepts the following parameters: - toggle: Turns score notifications on and off - reset: Resets watched league data - - NB only one parameter should be passed at a time. ''' import sys import os @@ -392,14 +381,3 @@ def start(self): # Show a league table self.showLiveMatches() - -if __name__ == "__main__": - - # Close addon setting window (if open) - closeAddonSettings() - - # Create an instance of the XBMC League Table - xlsd = XBMCLiveScoresDetail() - - # and display it! - xlsd.start() diff --git a/resources/lib/menu.py b/resources/lib/menu.py new file mode 100644 index 0000000..c7ef8ad --- /dev/null +++ b/resources/lib/menu.py @@ -0,0 +1,87 @@ +''' + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +''' + +''' This script is part of the BBC Football Scores service by elParaguayo + +''' +import xbmc + +# Import PyXBMCt module. +from pyxbmct.addonwindow import * + +_A_ = xbmcaddon.Addon("service.bbclivefootballscores") +_S_ = _A_.getSetting + +def localise(id): + '''Gets localised string. + + Shamelessly copied from service.xbmc.versioncheck + ''' + string = _A_.getLocalizedString(id).encode( 'utf-8', 'ignore' ) + return string + +class FootballHelperMenu(object): + + def __init__(self): + + pass + + def show(self): + + # Set the title and menu size + self.window = AddonDialogWindow("Menu") + self.window.setGeometry(450,300,5,2) + + # ITEM 1 - LEAGUE TABLES + self.ltbutton = Button("Show League Tables") + self.window.placeControl(self.ltbutton, 0, 0, columnspan = 2) + + # ITEM 2 - MATCH DETAIL + self.mdbutton = Button("Show Match Detail") + self.window.placeControl(self.mdbutton, 1, 0, columnspan = 2) + + # CLOSE BUTTON + + self.clbutton = Button("Close") + self.window.placeControl(self.clbutton, 4, 0, columnspan = 2) + + # Bind actions + self.window.connect(ACTION_PREVIOUS_MENU, lambda: self.window.close()) + self.window.connect(ACTION_NAV_BACK, lambda: self.window.close()) + self.window.connect(self.clbutton, lambda: self.window.close()) + self.window.connect(self.ltbutton, lambda: self.open("leaguetable")) + self.window.connect(self.mdbutton, lambda: self.open("matchdetail")) + + self.window.setFocus(self.ltbutton) + + # Handle navigation to make user experience better + self.ltbutton.controlDown(self.mdbutton) + self.mdbutton.controlUp(self.ltbutton) + self.mdbutton.controlDown(self.clbutton) + self.clbutton.controlUp(self.mdbutton) + # self.leaguelist.controlLeft(self.leaguebutton) + # self.leaguelist.controlRight(self.closebutton) + # self.closebutton.controlUp(self.leaguelist) + # self.closebutton.controlLeft(self.leaguebutton) + # self.leaguebutton.controlRight(self.closebutton) + # self.leaguebutton.controlUp(self.leaguelist) + + # Ready to go... + self.window.doModal() + + def open(self, mode): + + self.window.close() + xbmc.executebuiltin("RunScript(service.bbclivefootballscores, mode={0})".format(mode)) diff --git a/settings.py b/resources/lib/settings.py similarity index 82% rename from settings.py rename to resources/lib/settings.py index ccd4484..221342f 100644 --- a/settings.py +++ b/resources/lib/settings.py @@ -15,17 +15,6 @@ ''' This script is part of the BBC Football Scores service by elParaguayo - It allows users to select which leagues they wish to receive updates - for. - - It is called via the script configuration screen or by passing - parameters to trigger specific functions. - - The script accepts the following parameters: - toggle: Turns score notifications on and off - reset: Resets watched league data - - NB only one parameter should be passed at a time. ''' import sys @@ -74,7 +63,7 @@ def selectLeagues(): '''Get list of available leagues and allow user to select those leagues from which they want to receive updates. ''' - + # Get list of leagues # Format is [{"name": "Name of League", # "id": "competition-xxxxxxx"}] @@ -99,68 +88,68 @@ def selectLeagues(): try: # Add league details to our list # leagues.append([league["name"],int(league["id"][12:])]) - + # Check whether leagues is one we're following if int(league["id"]) in watchedleagues: # Mark the league if it's one the user has previously # selected and add it to the select dialog userchoice.append("*" + league["name"]) - + else: - + # If not previously selected, we still need to add to # select dialog userchoice.append(league["name"]) - + # Hopefully we don't end up here... except: # Tell the user there's a problem userchoice.append(localise(32020)) - + # We only need to tell the user once! break - + # Add an option to say we've finished selecting leagues userchoice.append(localise(32022)) - - + + # Display the list - inputchoice = xbmcgui.Dialog().select(localise(32021), + inputchoice = xbmcgui.Dialog().select(localise(32021), userchoice) - + # Check whether the user has clicked on a league... if (inputchoice >=0 and not userchoice[inputchoice] == localise(32022) and not userchoice[inputchoice] == localise(32021)): - + # If it's one that's already in our watched league list... if int(leagues[inputchoice]["id"]) in watchedleagues: # ...then we need to remove it watchedleagues.remove(int(leagues[inputchoice]["id"])) - + # if not... - else: + else: # ... then we need to add it watchedleagues.append(int(leagues[inputchoice]["id"])) - + # If we're done elif userchoice[inputchoice] == localise(32022): - + # Save our new list saveLeagues(watchedleagues) # Set the flag to leave the select dialog loop finishedSelection = True - - # If there's an error or we hit cancel - elif (inputchoice == -1 or + + # If there's an error or we hit cancel + elif (inputchoice == -1 or userchoice[inputchoice] == localise(32020)): - - + + # end the selection (but don't save new settings) finishedSelection = True @@ -184,7 +173,7 @@ def getMasterLeagueList(): except: masterLeagueList = [] - masterLeagueList += [x for x in currentleagues + masterLeagueList += [x for x in currentleagues if x not in masterLeagueList] _A_.setSetting(id="masterlist",value=json.dumps(masterLeagueList)) @@ -197,15 +186,15 @@ def loadLeagues(): Returns list of league IDs. ''' - try: + try: watchedleagues = json.loads(str(_S_("watchedleagues"))) - except: + except: watchedleagues = [] return watchedleagues def saveLeagues(leagues): - '''Converts list to JSON compatible string and saves it to our + '''Converts list to JSON compatible string and saves it to our user's settings. ''' @@ -226,24 +215,3 @@ def toggleNotification(): state = not (_S_("Alerts") == "true") Notify("BBC Football Scores", localise(32024) % (localise(32025) if state else localise(32026))) _A_.setSetting(id="Alerts", value=str(state).lower()) - -# Let's check how the user has called the script - -# If an argument has bee passed to the script, is it one that the script -# is expecting? -try: - mode = modes[sys.argv[1].lower()] -except (IndexError, KeyError): - mode = STANDARD - -# User wants to reset league data -if mode == RESET: - resetLeagues() - -# User wants to toggle notifications -elif mode == TOGGLE_NOTIFICATIONS: - toggleNotification() - -# Let's run the script to select leagues to watch -else: - selectLeagues() \ No newline at end of file diff --git a/resources/settings.xml b/resources/settings.xml index 85d58dd..af4eb08 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -1,7 +1,7 @@ - + @@ -10,7 +10,7 @@ - - + +