Skip to content

Commit

Permalink
Merge pull request #21 from elParaguayo/issue_20_runscript
Browse files Browse the repository at this point in the history
Issue 20 runscript
  • Loading branch information
elParaguayo committed Jan 20, 2015
2 parents aa9d9e4 + ef63745 commit 097f439
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 109 deletions.
2 changes: 2 additions & 0 deletions addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<import addon="script.module.simplejson" version="2.0.10" />
<import addon="script.module.pyxbmct" version="1.1.4"/>
</requires>
<extension point="xbmc.python.library" library="helper.py" />
<extension point="xbmc.python.script" library="helper.py" />
<extension point="xbmc.service" library="default.py" start="login"/>
<extension point="xbmc.addon.metadata">

Expand Down
10 changes: 5 additions & 5 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
85 changes: 85 additions & 0 deletions helper.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
'''

''' 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()
22 changes: 0 additions & 22 deletions league_tables.py → resources/lib/league_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
22 changes: 0 additions & 22 deletions live_scores_detail.py → resources/lib/live_scores_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
87 changes: 87 additions & 0 deletions resources/lib/menu.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
'''

''' 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))
Loading

0 comments on commit 097f439

Please sign in to comment.