2015-07-16, 19:42
2015-07-16, 22:25
I've probably been doing it all wrong (so I'll be interested in any other answers to this thread!) but my approach was that I didn't want to restart the service, instead, I wanted the new settings to have effect from that point.
All I ended up doing was just reloading the settings in the service loop and updating variables as necessary.
It's not big, it's not clever, but it works for me.
All I ended up doing was just reloading the settings in the service loop and updating variables as necessary.
It's not big, it's not clever, but it works for me.
2015-07-16, 23:16
here's what i use to load new settings:
PHP Code:
class Main:
def __init__( self ):
self._service_setup()
while (not self.Monitor.abortRequested()):
# rest of your code here
xbmc.sleep(1000)
def _service_setup( self ):
self.Monitor = MyMonitor(action = self._get_settings)
self._get_settings
def _get_settings( self ):
self.user = __addon__.getSetting('username')
self.pass = __addon__.getSetting('password')
class MyMonitor(xbmc.Monitor):
def __init__( self, *args, **kwargs ):
xbmc.Monitor.__init__( self )
self.action = kwargs['action']
def onSettingsChanged( self ):
self.action()
2015-07-17, 00:15
Maybe it's time to change my code... That's far more professional than my "solution"!
Thanks for sharing, ronie.
Thanks for sharing, ronie.
2015-07-19, 17:53
thank ronie, I would try that !
I would think there was a kodi method to do that like
Ex.(made up) or something instead of reloading variables and settings individually.
I would think there was a kodi method to do that like
Ex.(made up)
Code:
xbmc.Addon().reloadAddon()
2015-09-10, 17:49
Need some help. I can't seem to get Kodi to recognize settings being changed. There doesn't seem to be an event created when they change. I've called the onSettingsChanged() routine directly and it works so there shouldn't be an error its getting caught on. The main program just chugs along and there aren't any logs written from the restart routine.
Any ideas what I might be doing wrong? Here's the code below.
Any ideas what I might be doing wrong? Here's the code below.
Code:
class Main:
def __init__(self):
self._reset = False #Reset used to kill threaded loops in main program
self.Monitor = MyMonitor(action = self.restart)
self.start()
def restart(self):
common.log_verbose("A setting change has been detected!")
self._reset = False
common.log_normal("Applying changed settings in 10 seconds")
self.Monitor.waitForAbort(10)
self._reset = True
self.start()
def start(self):
#Main Code here
class MyMonitor(xbmc.Monitor):
def __init__(self, *args, **kwargs):
xbmc.Monitor.__init__(self)
self.action = kwargs['action']
def onSettingsChanged(self):
self.action()
if __name__ == '__main__':
Main()
2015-09-12, 05:03
I'll post this here for other people. I solve my problem. In the main code I was threading. In each of those threads they looped. But the main thread ends so I had to add a loop that doesn't do anything at the end of the code to keep the monitor alive to act on settings changes. I figured it out on a fluke when I accidentally killed the thread initializing.
Code:
class Main:
def __init__(self):
self._reset = False #Reset used to kill threaded loops in main program
self.Monitor = MyMonitor(action = self.restart)
self.start()
def restart(self):
common.log_verbose("A setting change has been detected!")
self._reset = False
common.log_normal("Applying changed settings in 10 seconds")
self.Monitor.waitForAbort(10)
self._reset = True
self.start()
def start(self):
#Main Code here - Started threads that looped. This didn't work until the loop was added below - even though I had other loops processing.
while not self.Monitor.abortRequested():
xbmc.sleep(1000)
class MyMonitor(xbmc.Monitor):
def __init__(self, *args, **kwargs):
xbmc.Monitor.__init__(self)
self.action = kwargs['action']
def onSettingsChanged(self):
self.action()
if __name__ == '__main__':
Main()