(2013-08-13, 17:08)sphere Wrote: (2013-08-13, 17:03)v0idnull Wrote: So my code should look more like this:
def monitor = xmbc.Monitor()
RUN = True
while RUN:
if monitor.onAbortRequested():
RUN = False
No. If you want to poll for the abort requested just do it the way Martijn and Spiff said.
If you know what "async callback" means, you should already know what that means and how to use it
(2013-08-13, 17:03)v0idnull Wrote: Is there a plugin any of you guys are aware of that utilizes such an approach?
See my Nyan Cat Screensaver for an example. But it does not wait for the onAbortRequested-callback but for the onScreensaverDeactivated() callback.
AHH I think I am beginning to better understand now.
so if I write a class that extends xbmc.Monitor, instantiate it, then its callbacks will automatically be called by XBMC?
Based on your screensaver code, something like this may work:
Code:
class MyMonitor(xbmc.Monitor):
def __init__(self, service):
self.service = service
def onAbortRequested(self):
self.service.stop()
class MyService(object):
def __init__(self):
self.monitor = MyMonitor(service=self)
self.run = True
def loop(self):
while self.run:
# do my loop
xbmc.sleep(2000)
def stop(self):
self.run = False
service = MyService()
service.loop()
If this is case, then this is nice and clean. Keeps logic for controlling the loop out of it loop itself.
so if I'm correct, does that mean I can restart the loop? eg:
Code:
class MyMonitor(xbmc.Monitor):
def __init__(self, service):
self.service = service
def onAbortRequested():
self.service.stop()
def onScreensaverActivated():
self.service.stop()
def onScreensaverDeactivated():
self.service.loop()
class MyService(object):
def __init__(self):
self.monitor = MyMonitor(service=self)
self.run = True
def loop(self):
while self.run:
# do my loop
xbmc.sleep(2000)
def stop(self):
self.run = False
service = MyService()
service.loop()
Will this do what I think it will do? I can't seem to find clear documentation on this so thanks everyone for your patience and help.