plugin.video.viervijfzes/test/xbmcgui.py

328 lines
12 KiB
Python
Raw Normal View History

2020-03-19 16:45:31 +01:00
# -*- coding: utf-8 -*-
# Copyright: (c) 2019, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
2020-03-20 13:32:55 +01:00
"""This file implements the Kodi xbmcgui module, either using stubs or alternative functionality"""
2020-03-19 16:45:31 +01:00
2020-03-20 13:32:55 +01:00
# pylint: disable=invalid-name,super-on-old-class,too-many-arguments,unused-argument,useless-super-delegation
2020-03-19 16:45:31 +01:00
from __future__ import absolute_import, division, print_function, unicode_literals
2020-03-20 13:32:55 +01:00
import sys
2020-03-19 16:45:31 +01:00
from xbmcextra import kodi_to_ansi
2020-03-20 13:32:55 +01:00
class Control:
"""A reimplementation of the xbmcgui Control class"""
def __init__(self):
"""A stub constructor for the xbmcgui Control class"""
@staticmethod
def selectItem(index):
"""A stub implementation for the xbmcgui Control class selectItem() method"""
return
class ControlLabel(Control):
"""A reimplementation of the xbmcgui ControlLabel class"""
def __init__(self): # pylint: disable=super-init-not-called
"""A stub constructor for the xbmcgui ControlLabel class"""
@staticmethod
def getLabel():
"""A stub implementation for the xbmcgui ControlLabel class getLabel() method"""
return 'Label'
@staticmethod
def setLabel(label='', font=None, textColor=None, disabledColor=None, shadowColor=None, focusedColor=None, label2=''):
"""A stub implementation for the xbmcgui ControlLabel class getLabel() method"""
2020-03-19 16:45:31 +01:00
class Dialog:
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcgui Dialog class"""
2020-03-19 16:45:31 +01:00
def __init__(self):
2020-03-20 13:32:55 +01:00
"""A stub constructor for the xbmcgui Dialog class"""
2020-03-19 16:45:31 +01:00
@staticmethod
def notification(heading, message, icon=None, time=None, sound=None):
2020-03-20 13:32:55 +01:00
"""A working implementation for the xbmcgui Dialog class notification() method"""
2020-03-19 16:45:31 +01:00
heading = kodi_to_ansi(heading)
message = kodi_to_ansi(message)
print('\033[37;44;1mNOTIFICATION:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, message))
@staticmethod
def ok(heading, line1, line2=None, line3=None):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui Dialog class ok() method"""
2020-03-19 16:45:31 +01:00
heading = kodi_to_ansi(heading)
line1 = kodi_to_ansi(line1)
print('\033[37;44;1mOK:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, line1))
@staticmethod
def info(listitem):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui Dialog class info() method"""
@staticmethod
def select(heading, opt_list, autoclose=0, preselect=None, useDetails=False):
"""A stub implementation for the xbmcgui Dialog class select() method"""
if preselect is None:
preselect = []
heading = kodi_to_ansi(heading)
print('\033[37;44;1mSELECT:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, ', '.join(opt_list)))
return -1
2020-03-19 16:45:31 +01:00
@staticmethod
def multiselect(heading, options, autoclose=0, preselect=None, useDetails=False): # pylint: disable=useless-return
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui Dialog class multiselect() method"""
2020-03-19 16:45:31 +01:00
if preselect is None:
preselect = []
heading = kodi_to_ansi(heading)
print('\033[37;44;1mMULTISELECT:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, ', '.join(options)))
return None
@staticmethod
def contextmenu(items):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui Dialog class contextmenu() method"""
2020-03-19 16:45:31 +01:00
print('\033[37;44;1mCONTEXTMENU:\033[35;49;1m \033[37;1m%s\033[39;0m' % (', '.join(items)))
return -1
@staticmethod
def yesno(heading, line1, line2=None, line3=None, nolabel=None, yeslabel=None, autoclose=0):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui Dialog class yesno() method"""
2020-03-19 16:45:31 +01:00
heading = kodi_to_ansi(heading)
line1 = kodi_to_ansi(line1)
print('\033[37;44;1mYESNO:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, line1))
return True
@staticmethod
def textviewer(heading, text=None, usemono=None):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui Dialog class textviewer() method"""
2020-03-19 16:45:31 +01:00
heading = kodi_to_ansi(heading)
text = kodi_to_ansi(text)
print('\033[37;44;1mTEXTVIEWER:\033[35;49;1m [%s]\n\033[37;1m%s\033[39;0m' % (heading, text))
@staticmethod
2020-03-20 13:32:55 +01:00
def browseSingle(type, heading, shares, mask=None, useThumbs=None, treatAsFolder=None, defaultt=None): # pylint: disable=redefined-builtin
"""A stub implementation for the xbmcgui Dialog class browseSingle() method"""
2020-03-19 16:45:31 +01:00
print('\033[37;44;1mBROWSESINGLE:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (type, heading))
return 'special://masterprofile/addon_data/script.module.inputstreamhelper/'
class DialogProgress:
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcgui DialogProgress"""
2020-03-19 16:45:31 +01:00
def __init__(self):
2020-03-20 13:32:55 +01:00
"""A stub constructor for the xbmcgui DialogProgress class"""
2020-03-19 16:45:31 +01:00
self.percentage = 0
2020-03-20 13:32:55 +01:00
def close(self):
"""A stub implementation for the xbmcgui DialogProgress class close() method"""
self.percentage = 0
2020-03-19 16:45:31 +01:00
print()
2020-03-20 13:32:55 +01:00
sys.stdout.flush()
2020-03-19 16:45:31 +01:00
2020-03-20 13:32:55 +01:00
def create(self, heading, line1, line2=None, line3=None):
"""A stub implementation for the xbmcgui DialogProgress class create() method"""
self.percentage = 0
2020-03-19 16:45:31 +01:00
heading = kodi_to_ansi(heading)
line1 = kodi_to_ansi(line1)
print('\033[37;44;1mPROGRESS:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, line1))
2020-03-20 13:32:55 +01:00
sys.stdout.flush()
2020-03-19 16:45:31 +01:00
def iscanceled(self):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui DialogProgress class iscanceled() method"""
return self.percentage > 5 # Cancel at 5%
2020-03-19 16:45:31 +01:00
def update(self, percentage, line1=None, line2=None, line3=None):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui DialogProgress class update() method"""
2020-03-19 16:45:31 +01:00
if (percentage - 5) < self.percentage:
return
self.percentage = percentage
line1 = kodi_to_ansi(line1)
line2 = kodi_to_ansi(line2)
line3 = kodi_to_ansi(line3)
if line1 or line2 or line3:
2020-03-20 13:32:55 +01:00
print('\033[1G\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%] \033[37;1m%s\033[39;0m' % (percentage, line1 or line2 or line3), end='')
2020-03-19 16:45:31 +01:00
else:
print('\033[1G\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%]\033[39;0m' % (percentage), end='')
2020-03-20 13:32:55 +01:00
sys.stdout.flush()
2020-03-19 16:45:31 +01:00
class DialogProgressBG:
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcgui DialogProgressBG"""
2020-03-19 16:45:31 +01:00
def __init__(self):
2020-03-20 13:32:55 +01:00
"""A stub constructor for the xbmcgui DialogProgressBG class"""
2020-03-19 16:45:31 +01:00
self.percentage = 0
@staticmethod
def close():
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui DialogProgressBG class close() method"""
2020-03-19 16:45:31 +01:00
print()
@staticmethod
def create(heading, message):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui DialogProgressBG class create() method"""
2020-03-19 16:45:31 +01:00
heading = kodi_to_ansi(heading)
message = kodi_to_ansi(message)
print('\033[37;44;1mPROGRESS:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, message))
@staticmethod
def isfinished():
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui DialogProgressBG class isfinished() method"""
2020-03-19 16:45:31 +01:00
def update(self, percentage, heading=None, message=None):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui DialogProgressBG class update() method"""
2020-03-19 16:45:31 +01:00
if (percentage - 5) < self.percentage:
return
self.percentage = percentage
message = kodi_to_ansi(message)
if message:
print('\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%] \033[37;1m%s\033[39;0m' % (percentage, message))
else:
print('\033[1G\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%]\033[39;0m' % (percentage), end='')
class DialogBusy:
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcgui DialogBusy"""
2020-03-19 16:45:31 +01:00
def __init__(self):
2020-03-20 13:32:55 +01:00
"""A stub constructor for the xbmcgui DialogBusy class"""
2020-03-19 16:45:31 +01:00
@staticmethod
def close():
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui DialogBusy class close() method"""
2020-03-19 16:45:31 +01:00
@staticmethod
def create():
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui DialogBusy class create() method"""
2020-03-19 16:45:31 +01:00
class ListItem:
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcgui ListItem class"""
2020-03-19 16:45:31 +01:00
def __init__(self, label='', label2='', iconImage='', thumbnailImage='', path='', offscreen=False):
2020-03-20 13:32:55 +01:00
"""A stub constructor for the xbmcgui ListItem class"""
2020-03-19 16:45:31 +01:00
self.label = kodi_to_ansi(label)
self.label2 = kodi_to_ansi(label2)
self.path = path
@staticmethod
def addContextMenuItems(items, replaceItems=False):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class addContextMenuItems() method"""
2020-03-19 16:45:31 +01:00
return
@staticmethod
def addStreamInfo(stream_type, stream_values):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui LitItem class addStreamInfo() method"""
2020-03-19 16:45:31 +01:00
return
@staticmethod
def setArt(key):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class setArt() method"""
2020-03-19 16:45:31 +01:00
return
@staticmethod
def setContentLookup(enable):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class setContentLookup() method"""
2020-03-19 16:45:31 +01:00
return
@staticmethod
def setInfo(type, infoLabels): # pylint: disable=redefined-builtin
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class setInfo() method"""
2020-03-19 16:45:31 +01:00
return
@staticmethod
def setIsFolder(isFolder):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class setIsFolder() method"""
2020-03-19 16:45:31 +01:00
return
@staticmethod
def setMimeType(mimetype):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class setMimeType() method"""
2020-03-19 16:45:31 +01:00
return
def setPath(self, path):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class setPath() method"""
2020-03-19 16:45:31 +01:00
self.path = path
@staticmethod
def setProperty(key, value):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class setProperty() method"""
2020-03-19 16:45:31 +01:00
return
@staticmethod
def setProperties(dictionary):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class setProperties() method"""
2020-03-19 16:45:31 +01:00
return
@staticmethod
def setSubtitles(subtitleFiles):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcgui ListItem class setSubtitles() method"""
return
@staticmethod
def setUniqueIDs(values, defaultrating=None):
"""A stub implementation for the xbmcgui ListItem class setUniqueIDs() method"""
2020-03-19 16:45:31 +01:00
return
2020-03-20 13:32:55 +01:00
class Window:
"""A reimplementation of the xbmcgui Window"""
def __init__(self, windowId):
"""A stub constructor for the xbmcgui Window class"""
return None
def close(self):
"""A stub implementation for the xbmcgui Window class close() method"""
@staticmethod
def getControl():
"""A stub implementation for the xbmcgui Window class getControl() method"""
return ControlLabel()
@staticmethod
def getFocusId():
"""A stub implementation for the xbmcgui Window class getFocusId() method"""
return 0
@staticmethod
def getProperty(key):
"""A stub implementation for the xbmcgui Window class getProperty() method"""
return ''
@staticmethod
def setProperty(key, value):
"""A stub implementation for the xbmcgui Window class setProperty() method"""
return
@staticmethod
def clearProperty(key):
"""A stub implementation for the xbmcgui Window class clearProperty() method"""
return
def show(self):
"""A stub implementation for the xbmcgui Window class show() method"""
class WindowXML(Window):
"""A reimplementation of the xbmcgui WindowXML"""
def __init__(self):
"""A stub constructor for the xbmcgui WindowXML class"""
super(WindowXML, self).__init__()
class WindowXMLDialog(WindowXML):
"""A reimplementation of the xbmcgui WindowXMLDialog"""
def __init__(self):
"""A stub constructor for the xbmcgui WindowXMLDialog class"""
super(WindowXMLDialog, self).__init__()
def getCurrentWindowId():
"""A stub implementation of the xbmcgui getCurrentWindowId() method"""
return 0