2017-01-03 00:07:24 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
###############################################################################
|
2017-09-10 23:06:46 +10:00
|
|
|
from cPickle import dumps, loads
|
2017-01-03 00:07:24 +11:00
|
|
|
|
2017-09-10 23:06:46 +10:00
|
|
|
from xbmcgui import Window
|
2017-09-10 23:22:06 +10:00
|
|
|
from xbmc import log, LOGDEBUG
|
2017-01-03 00:07:24 +11:00
|
|
|
###############################################################################
|
2017-09-10 23:06:46 +10:00
|
|
|
WINDOW = Window(10000)
|
2017-09-10 23:22:06 +10:00
|
|
|
PREFIX = 'PLEX.%s: ' % __name__
|
2017-01-03 00:07:24 +11:00
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
2017-09-10 23:06:46 +10:00
|
|
|
def pickl_window(property, value=None, clear=False):
|
|
|
|
"""
|
|
|
|
Get or set window property - thread safe! For use with Pickle
|
|
|
|
Property and value must be string
|
|
|
|
"""
|
|
|
|
if clear:
|
|
|
|
WINDOW.clearProperty(property)
|
|
|
|
elif value is not None:
|
|
|
|
WINDOW.setProperty(property, value)
|
|
|
|
else:
|
|
|
|
return WINDOW.getProperty(property)
|
|
|
|
|
|
|
|
|
2017-01-03 00:07:24 +11:00
|
|
|
def pickle_me(obj, window_var='plex_result'):
|
|
|
|
"""
|
|
|
|
Pickles the obj to the window variable. Use to transfer Python
|
|
|
|
objects between different PKC python instances (e.g. if default.py is
|
|
|
|
called and you'd want to use the service.py instance)
|
|
|
|
|
|
|
|
obj can be pretty much any Python object. However, classes and
|
|
|
|
functions won't work. See the Pickle documentation
|
|
|
|
"""
|
2018-01-22 21:20:37 +11:00
|
|
|
log('%sStart pickling' % PREFIX, level=LOGDEBUG)
|
2017-09-10 23:06:46 +10:00
|
|
|
pickl_window(window_var, value=dumps(obj))
|
2017-09-10 23:22:06 +10:00
|
|
|
log('%sSuccessfully pickled' % PREFIX, level=LOGDEBUG)
|
2017-01-03 00:07:24 +11:00
|
|
|
|
|
|
|
|
|
|
|
def unpickle_me(window_var='plex_result'):
|
|
|
|
"""
|
|
|
|
Unpickles a Python object from the window variable window_var.
|
|
|
|
Will then clear the window variable!
|
|
|
|
"""
|
|
|
|
result = pickl_window(window_var)
|
|
|
|
pickl_window(window_var, clear=True)
|
2017-09-10 23:22:06 +10:00
|
|
|
log('%sStart unpickling' % PREFIX, level=LOGDEBUG)
|
2017-09-10 23:06:46 +10:00
|
|
|
obj = loads(result)
|
2017-09-10 23:22:06 +10:00
|
|
|
log('%sSuccessfully unpickled: %s' % (PREFIX, obj), level=LOGDEBUG)
|
2017-01-03 00:07:24 +11:00
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
|
class Playback_Successful(object):
|
|
|
|
"""
|
|
|
|
Used to communicate with another PKC Python instance
|
|
|
|
"""
|
|
|
|
listitem = None
|