This commit is contained in:
croneter 2018-02-01 08:19:51 +01:00
parent 3fe1f184d6
commit 187a6131f0

View file

@ -1,19 +1,17 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################### ###############################################################################
from logging import getLogger
import logging from os.path import join
import os
import xbmcgui import xbmcgui
import xbmcaddon from xbmcaddon import Addon
from utils import window from utils import window
############################################################################### ###############################################################################
log = logging.getLogger("PLEX."+__name__) LOG = getLogger("PLEX." + __name__)
addon = xbmcaddon.Addon('plugin.video.plexkodiconnect') ADDON = Addon('plugin.video.plexkodiconnect')
ACTION_PARENT_DIR = 9 ACTION_PARENT_DIR = 9
ACTION_PREVIOUS_MENU = 10 ACTION_PREVIOUS_MENU = 10
@ -27,16 +25,16 @@ USER_IMAGE = 150
class ContextMenu(xbmcgui.WindowXMLDialog): class ContextMenu(xbmcgui.WindowXMLDialog):
_options = []
selected_option = None
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self._options = []
self.selected_option = None
self.list_ = None
self.background = None
xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs) xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
def set_options(self, options=[]): def set_options(self, options=None):
if not options:
options = []
self._options = options self._options = options
def is_selected(self): def is_selected(self):
@ -46,17 +44,13 @@ class ContextMenu(xbmcgui.WindowXMLDialog):
return self.selected_option return self.selected_option
def onInit(self): def onInit(self):
if window('PlexUserImage'): if window('PlexUserImage'):
self.getControl(USER_IMAGE).setImage(window('PlexUserImage')) self.getControl(USER_IMAGE).setImage(window('PlexUserImage'))
height = 479 + (len(self._options) * 55) height = 479 + (len(self._options) * 55)
log.info("options: %s", self._options) LOG.debug("options: %s", self._options)
self.list_ = self.getControl(LIST) self.list_ = self.getControl(LIST)
for option in self._options: for option in self._options:
self.list_.addItem(self._add_listitem(option)) self.list_.addItem(self._add_listitem(option))
self.background = self._add_editcontrol(730, height, 30, 450) self.background = self._add_editcontrol(730, height, 30, 450)
self.setFocus(self.list_) self.setFocus(self.list_)
@ -64,27 +58,23 @@ class ContextMenu(xbmcgui.WindowXMLDialog):
if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU): if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU):
self.close() self.close()
if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK): if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK):
if self.getFocusId() == LIST: if self.getFocusId() == LIST:
option = self.list_.getSelectedItem() option = self.list_.getSelectedItem()
self.selected_option = option.getLabel() self.selected_option = option.getLabel()
log.info('option selected: %s', self.selected_option) LOG.info('option selected: %s', self.selected_option)
self.close() self.close()
def _add_editcontrol(self, x, y, height, width, password=0): def _add_editcontrol(self, x, y, height, width, password=None):
media = join(ADDON.getAddonInfo('path'),
media = os.path.join(addon.getAddonInfo('path'), 'resources', 'skins', 'default', 'media') 'resources', 'skins', 'default', 'media')
control = xbmcgui.ControlImage(0, 0, 0, 0, control = xbmcgui.ControlImage(0, 0, 0, 0,
filename=os.path.join(media, "white.png"), filename=join(media, "white.png"),
aspectRatio=0, aspectRatio=0,
colorDiffuse="ff111111") colorDiffuse="ff111111")
control.setPosition(x, y) control.setPosition(x, y)
control.setHeight(height) control.setHeight(height)
control.setWidth(width) control.setWidth(width)
self.addControl(control) self.addControl(control)
return control return control