def __init__(self):
self.gui = KodiVkGUI(self)
self.conn = self.__connect_()
if not self.conn: raise Exception()
u_info = self.conn.users.get()[0]
self.u = User(u_info['id'], self.conn)
self.u.set_info()
p = {'do': _DO_HOME}
if sys.argv[2]:
p.update(dict(urlparse.parse_qsl(sys.argv[2][1:])))
p['oid'] = int(p.get('oid', self.u.info['id']))
self.params = p
if 'content_type' not in self.params.keys():
cw_id = xbmcgui.getCurrentWindowId()
if cw_id in (10006, 10024, 10025, 10028):
self.params['content_type'] = _CTYPE_VIDEO
#elif id in (10005, 10500, 10501, 10502):
# self.params['content_type'] = _CTYPE_AUDIO
elif id in (10002,):
self.params['content_type'] = _CTYPE_IMAGE
self.c_type = self.params.get('content_type', None)
python类getCurrentWindowId()的实例源码
def get_cached_item(self, cache_id):
"""Returns an item from the in memory cache
Parameters
----------
cache_id : :obj:`str`
ID of the cache entry
Returns
-------
mixed
Contents of the requested cache item or none
"""
ret = None
current_window = xbmcgui.getCurrentWindowId()
window = xbmcgui.Window(current_window)
try:
cached_items = pickle.loads(window.getProperty('memcache'))
ret = cached_items.get(cache_id)
except EOFError:
ret = None
return ret
def GetUI(self, param, api, handle):
content_type = param.get('content_type')
if content_type == 'video':
return XVKVideo(param, handle, api)
elif content_type == 'audio':
return XVKAudio(param, handle, api)
elif content_type == 'image':
return XVKImage(param, handle, api)
#fallback if no content_type provided
#bloody hacks http://wiki.xbmc.org/index.php?title=Window_IDs
id = xbmcgui.getCurrentWindowId()
if id in (10006, 10024, 10025, 10028):
return XVKVideo(param, handle, api)
elif id in (10005, 10500, 10501, 10502):
return XVKAudio(param, handle, api)
elif id in (10002,):
return XVKImage(param, handle, api)
else:
print "Invalid context: " + str(id)
def onInit(self):
self.CurrentWindow = xbmcgui.getCurrentWindowId()
self.nextButton = self.getControl(33000)
self.prevButton = self.getControl(33001)
self.nextButton.setVisible(False)
self.prevButton.setVisible(False)
self.setDetails(self.url)
def set_main_menu_selection(self, type):
"""Persist the chosen main menu entry in memory
Parameters
----------
type : :obj:`str`
Selected menu item
"""
current_window = xbmcgui.getCurrentWindowId()
xbmcgui.Window(current_window).setProperty('main_menu_selection', type)
def get_main_menu_selection(self):
"""Gets the persisted chosen main menu entry from memory
Returns
-------
:obj:`str`
The last chosen main menu entry
"""
current_window = xbmcgui.getCurrentWindowId()
window = xbmcgui.Window(current_window)
return window.getProperty('main_menu_selection')
def setup_memcache(self):
"""Sets up the memory cache if not existant"""
current_window = xbmcgui.getCurrentWindowId()
window = xbmcgui.Window(current_window)
try:
cached_items = window.getProperty('memcache')
# no cache setup yet, create one
if len(cached_items) < 1:
window.setProperty('memcache', pickle.dumps({}))
except EOFError:
pass
def invalidate_memcache(self):
"""Invalidates the memory cache"""
current_window = xbmcgui.getCurrentWindowId()
window = xbmcgui.Window(current_window)
try:
window.setProperty('memcache', pickle.dumps({}))
except EOFError:
pass
def activate(self):
if not self._winID:
self._winID = xbmcgui.getCurrentWindowId()
xbmc.executebuiltin('ReplaceWindow({0})'.format(self._winID))
def onInit(self):
self._winID = xbmcgui.getCurrentWindowId()
if self.started:
self.onReInit()
else:
self.started = True
self.onFirstInit()
self.finishedInit = True
def setProperty(self, key, value):
if self._closing:
return
if not self._winID:
self._winID = xbmcgui.getCurrentWindowId()
try:
xbmcgui.Window(self._winID).setProperty(key, value)
xbmcgui.WindowXML.setProperty(self, key, value)
except RuntimeError:
xbmc.log('kodigui.BaseWindow.setProperty: Missing window', xbmc.LOGDEBUG)
def setProperty(self, key, value):
if self._closing:
return
if not self._winID:
self._winID = xbmcgui.getCurrentWindowId()
try:
xbmcgui.Window(self._winID).setProperty(key, value)
xbmcgui.WindowXMLDialog.setProperty(self, key, value)
except RuntimeError:
xbmc.log('kodigui.BaseDialog.setProperty: Missing window', xbmc.LOGDEBUG)
def add_dir(self, name, params, logo='', infoLabels={}, menuItems={}):
name = util.decode_html(name)
if 'title' not in infoLabels:
infoLabels['title'] = ''
if logo is None:
logo = ''
liz = xbmcgui.ListItem(name, iconImage='DefaultFolder.png', thumbnailImage=logo)
if 'art' in infoLabels.keys():
liz.setArt(infoLabels['art'])
if 'selected' in infoLabels.keys():
#wnd = xbmcgui.Window(xbmcgui.getCurrentWindowId())
#util.debug("[SC] wnd: %s [%d]" % (str(wnd), xbmcgui.getCurrentWindowId()))
pass
try:
liz.setInfo(type='Video', infoLabels=self._extract_infolabels(infoLabels))
except:
sys.exc_info()
util.debug("CHYBA")
util.debug(infoLabels)
items = []
for mi in menuItems.keys():
action = menuItems[mi]
if not type(action) == type({}):
items.append((mi, action))
else:
if 'action-type' in action:
action_type = action['action-type']
del action['action-type']
if action_type == 'list':
items.append((mi, 'Container.Update(%s)' % sctop._create_plugin_url(action)))
elif action_type == 'play':
items.append((mi, 'PlayMedia(%s)' % sctop._create_plugin_url(action)))
else:
items.append((mi, 'RunPlugin(%s)' % sctop._create_plugin_url(action)))
else:
items.append((mi, 'RunPlugin(%s)' % sctop._create_plugin_url(action)))
if len(items) > 0:
liz.addContextMenuItems(items)
return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=sctop._create_plugin_url(params),
listitem=liz, isFolder=True)
def add_video(self, name, params={}, logo='', infoLabels={}, menuItems={}):
#util.debug("_add_video")
#util.debug("[SC] add video info: %s" % str(infoLabels))
_infoLabels=self._extract_infolabels(infoLabels)
name = util.decode_html(name)
if 'Title' not in _infoLabels:
_infoLabels['Title'] = name
#util.debug("[SC] params: %s" % str(params))
url = sctop._create_plugin_url(params)
if logo == '' or logo is None:
logo = self.noImage
li = xbmcgui.ListItem(name, path=url, iconImage='DefaultVideo.png', thumbnailImage=logo)
li.setInfo(type='Video', infoLabels=_infoLabels)
mt = sctop.getMediaType()
#util.debug("[SC] item media type: %s" % mt)
if 'selected' in infoLabels.keys():
wnd = xbmcgui.Window(xbmcgui.getCurrentWindowId())
#util.debug("[SC] wnd: %s [%d]" % (str(wnd), xbmcgui.getCurrentWindowId()))
if 'mvideo' in infoLabels.keys():
li.addStreamInfo('video', infoLabels['mvideo'])
if 'maudio' in infoLabels.keys():
li.addStreamInfo('audio', infoLabels['maudio'])
if 'msubtitle' in infoLabels.keys():
li.addStreamInfo('subtitle', infoLabels['msubtitle'])
if 'art' in infoLabels.keys():
li.setArt(infoLabels['art'])
li.setProperty('IsPlayable', 'true')
if 'runtime' in infoLabels.keys() and infoLabels['runtime'] > 0:
duration = int(infoLabels['runtime']) * 60
li.addStreamInfo('video', {'duration': duration})
items = [(xbmc.getLocalizedString(13347), 'Action(Queue)')]
self.setUniq(li, infoLabels)
for mi in menuItems.keys():
action = menuItems[mi]
if not type(action) == type({}):
items.append((mi, action))
else:
if 'action-type' in action:
action_type = action['action-type']
del action['action-type']
if action_type == 'list':
items.append((mi, 'Container.Update(%s)' % sctop._create_plugin_url(action)))
elif action_type == 'play':
items.append((mi, 'PlayMedia(%s)' % sctop._create_plugin_url(action)))
elif action_type == 'trailer':
items.append((mi, 'PlayMedia(%s)' % action['url']))
else:
items.append((mi, 'RunPlugin(%s)' % sctop._create_plugin_url(action)))
else:
items.append((mi, 'RunPlugin(%s)' % sctop._create_plugin_url(action)))
if len(items) > 0:
li.addContextMenuItems(items)
#xbmc.executebuiltin("Container.SetViewMode(515)")
return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li,
isFolder=False)