PlexKodiConnect/resources/lib/context.py

84 lines
2.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2016-10-23 02:15:10 +11:00
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, unicode_literals
2018-02-01 18:19:51 +11:00
from logging import getLogger
2016-10-23 02:15:10 +11:00
import xbmcgui
2018-06-22 03:24:37 +10:00
from . import utils
from . import path_ops
from . import variables as v
2016-10-23 02:15:10 +11:00
###############################################################################
2018-06-22 03:24:37 +10:00
LOG = getLogger('PLEX.context')
2016-10-23 02:15:10 +11:00
ACTION_PARENT_DIR = 9
ACTION_PREVIOUS_MENU = 10
ACTION_BACK = 92
ACTION_SELECT_ITEM = 7
ACTION_MOUSE_LEFT_CLICK = 100
LIST = 155
USER_IMAGE = 150
###############################################################################
class ContextMenu(xbmcgui.WindowXMLDialog):
def __init__(self, *args, **kwargs):
2018-02-01 18:19:51 +11:00
self._options = []
self.selected_option = None
self.list_ = None
self.background = None
2016-10-23 02:15:10 +11:00
xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
2018-02-01 18:19:51 +11:00
def set_options(self, options=None):
if not options:
options = []
2016-10-23 02:15:10 +11:00
self._options = options
def is_selected(self):
return True if self.selected_option else False
def get_selected(self):
return self.selected_option
def onInit(self):
2018-06-22 03:24:37 +10:00
if utils.window('PlexUserImage'):
self.getControl(USER_IMAGE).setImage(utils.window('PlexUserImage'))
2016-10-23 02:15:10 +11:00
height = 479 + (len(self._options) * 55)
2018-02-01 18:19:51 +11:00
LOG.debug("options: %s", self._options)
2016-10-23 02:15:10 +11:00
self.list_ = self.getControl(LIST)
for option in self._options:
self.list_.addItem(self._add_listitem(option))
self.background = self._add_editcontrol(730, height, 30, 450)
self.setFocus(self.list_)
def onAction(self, action):
if action in (ACTION_BACK, ACTION_PARENT_DIR, ACTION_PREVIOUS_MENU):
self.close()
if action in (ACTION_SELECT_ITEM, ACTION_MOUSE_LEFT_CLICK):
if self.getFocusId() == LIST:
option = self.list_.getSelectedItem()
self.selected_option = option.getLabel()
2018-02-01 18:19:51 +11:00
LOG.info('option selected: %s', self.selected_option)
2016-10-23 02:15:10 +11:00
self.close()
2018-02-01 18:19:51 +11:00
def _add_editcontrol(self, x, y, height, width, password=None):
media = path_ops.path.join(
v.ADDON_PATH, 'resources', 'skins', 'default', 'media')
filename = utils.try_encode(path_ops.path.join(media, 'white.png'))
2016-10-23 02:15:10 +11:00
control = xbmcgui.ControlImage(0, 0, 0, 0,
filename=filename,
2016-10-23 02:15:10 +11:00
aspectRatio=0,
colorDiffuse="ff111111")
control.setPosition(x, y)
control.setHeight(height)
control.setWidth(width)
self.addControl(control)
return control
@classmethod
def _add_listitem(cls, label):
return xbmcgui.ListItem(label)