Hi Folks,
I have just developed a screensaver for Windows Desktops, which might be interesting to have also as screensaver in XBMC. The screensaver is a Dashboard displaying News with Pictures from an RSS feed, Quotes from stocks, Time, Date, weather forecasts, etc.
I am looking to port this to a XBMC screensaver and am searching for a simple sample of a Screensaver "Ideally displaying only Helloworld". Anyone who can provide such a sample so I can give it a go ?
Would be also interested in any other resources available. So far did not find a lot on this Topic where to start,....
Wow... How can it be that nobody has a simple sample....
Thanks, sphere. This helped a lot. I modified your example and built a kind of Dashboard (showing weather conditions, RSS News and some stock quotes... Good stuff I think... will post soon a release of it...
I am struggling now with threads started from within the init method of my class. There is an issue when I want to exit the xbmc screensaver (pressing any button), screen just freezes and dims and you cannot do anything..
Similar to this issue described here:
http://forum.xbmc.org/showthread.php?tid=146241
How can I Close everything down if use the sleep timer... ?
Here is the method causing the problem:
Code:
def PostRssNews(self,NewsXML):
try:
for x in range(0,11):
itemid = 9 + x
# Extract Image URL
regex = re.compile("img src=\"(.*?)\"")
r = regex.search(NewsXML[0][itemid][6].text)
img = r.group(1)
self.getControl(100).setImage(img)
self.getControl(101).setLabel(NewsXML[0][itemid][0].text)
self.getControl(102).setText(NewsXML[0][itemid][1].text)
if self.abort_requested:
self.exit()
return
time.sleep(60)
t = threading.Timer(0, self.getRssNews)
t.start() # after 300 seconds = 5 min, update Newsreturn NewsId
except Exception:
self.exit
return
You should use "xbmc.sleep()" instead "time.sleep()" (Keep in mind that xbmc.sleep() takes msecs, not secs).
It is even better to loop 60 times over a sleep time of 1 sec and checking abort_requested each time.
Also you should cancel your timer thread with "t.cancel()" before exiting!
Hi Sphere,
thanks for your swift reply. Works a bit better now. I can cancel it via the cancel button and Screen disappears. However, my onScreensaverDeactivated not firing up when I press the button. It fires only with the second time... I removed the timer method and called now drictly my method... Here is my full code:
Code:
import sys
import xbmcaddon
import xbmcgui
import xbmc
import time
import httplib
import re
import time, threading
Addon = xbmcaddon.Addon('script.screensaver.test')
__scriptname__ = Addon.getAddonInfo('name')
__path__ = Addon.getAddonInfo('path')
class Screensaver(xbmcgui.WindowXMLDialog):
NewsXML = ''
class ExitMonitor(xbmc.Monitor):
def __init__(self, exit_callback):
self.exit_callback = exit_callback
def onScreensaverDeactivated(self):
print '3 ExitMonitor: sending exit_callback'
self.exit_callback()
def onInit(self):
self.abort_requested = False
print '2 Screensaver: onInit'
# try:
self.getStocks()
Status = self.getRssNews()
print Status
# except Exception:
# pass
self.monitor = self.ExitMonitor(self.exit)
def exit(self):
print '4 Screensaver: Exit requested'
self.abort_requested = True
self.close()
def getStocks(self):
print 'Get Yahoo! Quotes'
conn = httplib.HTTPConnection("query.yahooapis.com")
conn.request("GET", "/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AB100A.DE%22)&env=store://datatables.org/alltableswithkeys")
r1 = conn.getresponse()
data1 = r1.read()
conn.close()
import xml.etree.ElementTree as ET
root = ET.fromstring(str(data1))
LastTradePriceOnly = root[0][0][40].text # LastTradePriceOnly
ChangeinPercent = root[0][0][56].text # ChangeinPercent
ChangeinPercentColor = '0xFF00FF00'
if '-' in ChangeinPercent:
ChangeinPercentColor = '0xFFFF0000'
self.CtrlLastTradePriceOnly=xbmcgui.ControlLabel(80, 380, 100, 100, LastTradePriceOnly,'font28_title')
self.addControl(self.CtrlLastTradePriceOnly)
self.CtrlChangeinPercent=xbmcgui.ControlLabel(85, 420, 100, 100, ChangeinPercent,'font14',ChangeinPercentColor)
self.addControl(self.CtrlChangeinPercent)
def getRssNews(self):
print 'Get RSS News'
conn = httplib.HTTPConnection("www.n-tv.de")
conn.request("GET", "/rss")
r1 = conn.getresponse()
data1 = r1.read()
import xml.etree.ElementTree as ET
NewsXML = ET.fromstring(str(data1))
self.PostRssNews(NewsXML)
return 'Screensaver news successfully loaded'
def PostRssNews(self,NewsXML):
for x in range(0,11):
itemid = 9 + x
# Extract Image URL
regex = re.compile("img src=\"(.*?)\"")
r = regex.search(NewsXML[0][itemid][6].text)
img = r.group(1)
self.getControl(100).setImage(img)
self.getControl(101).setLabel(NewsXML[0][itemid][0].text)
self.getControl(102).setText(NewsXML[0][itemid][1].text)
if self.abort_requested:
self.exit()
return
xbmc.sleep(2000)
self.getRssNews()
# global t.start() # after 300 seconds = 5 min, update Newsreturn NewsId
# for x in range(0, 6):
if __name__ == '__main__':
print '1 Python Screensaver Started'
screensaver_gui = Screensaver(
'script-%s-main.xml' % __scriptname__,
__path__,
'default',
)
screensaver_gui.doModal()
# screensaver_gui.getRssNews(screensaver_gui)
print '******5 Python Screensaver Exited*****'
del screensaver_gui
sys.modules.clear()
Hi Sphere,
any other suggestion you might think of .... ?
Still struggling with this one. Googled now for hours and do not get to a proper solution. Even with the xbmc.timer function. My issue currently is that if I press a key to deactivate the screensaver my Event "onScreensaverDeactivated" is not firing up... Everything works fine if i do not use in this combination the xbmc.timer method.
Any way to get around this ?