Add compatibility for Kodi 19 Python API (#20)
This commit is contained in:
parent
6cec23ba1a
commit
2df7282d7e
@ -218,15 +218,19 @@ def ok_dialog(heading='', message=''):
|
||||
from xbmcgui import Dialog
|
||||
if not heading:
|
||||
heading = addon_name()
|
||||
return Dialog().ok(heading=heading, line1=message)
|
||||
if kodi_version_major() < 19:
|
||||
return Dialog().ok(heading=heading, line1=message)
|
||||
return Dialog().ok(heading=heading, message=message)
|
||||
|
||||
|
||||
def yesno_dialog(heading='', message='', nolabel=None, yeslabel=None):
|
||||
"""Show Kodi's OK dialog"""
|
||||
def yesno_dialog(heading='', message='', nolabel=None, yeslabel=None, autoclose=0):
|
||||
"""Show Kodi's Yes/No dialog"""
|
||||
from xbmcgui import Dialog
|
||||
if not heading:
|
||||
heading = addon_name()
|
||||
return Dialog().yesno(heading=heading, line1=message, nolabel=nolabel, yeslabel=yeslabel)
|
||||
if kodi_version_major() < 19:
|
||||
return Dialog().yesno(heading=heading, line1=message, nolabel=nolabel, yeslabel=yeslabel, autoclose=autoclose)
|
||||
return Dialog().yesno(heading=heading, message=message, nolabel=nolabel, yeslabel=yeslabel, autoclose=autoclose)
|
||||
|
||||
|
||||
def notification(heading='', message='', icon='info', time=4000):
|
||||
@ -247,14 +251,27 @@ def multiselect(heading='', options=None, autoclose=0, preselect=None, use_detai
|
||||
return Dialog().multiselect(heading=heading, options=options, autoclose=autoclose, preselect=preselect, useDetails=use_details)
|
||||
|
||||
|
||||
def progress(heading='', message=''):
|
||||
""" Show a Kodi progress dialog """
|
||||
from xbmcgui import DialogProgress
|
||||
if not heading:
|
||||
heading = ADDON.getAddonInfo('name')
|
||||
dialog_progress = DialogProgress()
|
||||
dialog_progress.create(heading=heading, line1=message)
|
||||
return dialog_progress
|
||||
class progress(xbmcgui.DialogProgress, object): # pylint: disable=invalid-name,useless-object-inheritance
|
||||
"""Show Kodi's Progress dialog"""
|
||||
|
||||
def __init__(self, heading='', message=''):
|
||||
"""Initialize and create a progress dialog"""
|
||||
super(progress, self).__init__()
|
||||
if not heading:
|
||||
heading = ADDON.getAddonInfo('name')
|
||||
self.create(heading, message=message)
|
||||
|
||||
def create(self, heading, message=''): # pylint: disable=arguments-differ
|
||||
"""Create and show a progress dialog"""
|
||||
if kodi_version_major() < 19:
|
||||
return super(progress, self).create(heading, line1=message)
|
||||
return super(progress, self).create(heading, message=message)
|
||||
|
||||
def update(self, percent, message=''): # pylint: disable=arguments-differ
|
||||
"""Update the progress dialog"""
|
||||
if kodi_version_major() < 19:
|
||||
return super(progress, self).update(percent, line1=message)
|
||||
return super(progress, self).update(percent, message=message)
|
||||
|
||||
|
||||
def set_locale():
|
||||
@ -396,8 +413,13 @@ def has_addon(name):
|
||||
|
||||
|
||||
def kodi_version():
|
||||
"""Returns major Kodi version"""
|
||||
return int(xbmc.getInfoLabel('System.BuildVersion').split('.')[0])
|
||||
"""Returns full Kodi version as string"""
|
||||
return xbmc.getInfoLabel('System.BuildVersion').split(' ')[0]
|
||||
|
||||
|
||||
def kodi_version_major():
|
||||
"""Returns major Kodi version as integer"""
|
||||
return int(kodi_version().split('.')[0])
|
||||
|
||||
|
||||
def get_tokens_path():
|
||||
|
@ -52,11 +52,11 @@ class Dialog:
|
||||
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):
|
||||
def ok(heading, message='', line1='', line2='', line3=''):
|
||||
"""A stub implementation for the xbmcgui Dialog class ok() method"""
|
||||
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))
|
||||
message = kodi_to_ansi(message)
|
||||
print('\033[37;44;1mOK:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, message or line1))
|
||||
|
||||
@staticmethod
|
||||
def info(listitem):
|
||||
@ -87,11 +87,11 @@ class Dialog:
|
||||
return -1
|
||||
|
||||
@staticmethod
|
||||
def yesno(heading, line1, line2=None, line3=None, nolabel=None, yeslabel=None, autoclose=0):
|
||||
def yesno(heading, message='', line1='', line2='', line3='', nolabel=None, yeslabel=None, autoclose=0):
|
||||
"""A stub implementation for the xbmcgui Dialog class yesno() method"""
|
||||
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))
|
||||
message = kodi_to_ansi(message)
|
||||
print('\033[37;44;1mYESNO:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, message or line1))
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
@ -113,38 +113,38 @@ class DialogProgress:
|
||||
|
||||
def __init__(self):
|
||||
"""A stub constructor for the xbmcgui DialogProgress class"""
|
||||
self.percentage = 0
|
||||
self.percent = 0
|
||||
|
||||
def close(self):
|
||||
"""A stub implementation for the xbmcgui DialogProgress class close() method"""
|
||||
self.percentage = 0
|
||||
self.percent = 0
|
||||
print()
|
||||
sys.stdout.flush()
|
||||
|
||||
def create(self, heading, line1, line2=None, line3=None):
|
||||
def create(self, heading, message='', line1='', line2='', line3=''):
|
||||
"""A stub implementation for the xbmcgui DialogProgress class create() method"""
|
||||
self.percentage = 0
|
||||
self.percent = 0
|
||||
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))
|
||||
print('\033[37;44;1mPROGRESS:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, message or line1))
|
||||
sys.stdout.flush()
|
||||
|
||||
def iscanceled(self):
|
||||
"""A stub implementation for the xbmcgui DialogProgress class iscanceled() method"""
|
||||
return self.percentage > 5 # Cancel at 5%
|
||||
return self.percent > 5 # Cancel at 5%
|
||||
|
||||
def update(self, percentage, line1=None, line2=None, line3=None):
|
||||
def update(self, percent, message='', line1='', line2='', line3=''):
|
||||
"""A stub implementation for the xbmcgui DialogProgress class update() method"""
|
||||
if (percentage - 5) < self.percentage:
|
||||
if (percent - 5) < self.percent:
|
||||
return
|
||||
self.percentage = percentage
|
||||
self.percent = percent
|
||||
line1 = kodi_to_ansi(line1)
|
||||
line2 = kodi_to_ansi(line2)
|
||||
line3 = kodi_to_ansi(line3)
|
||||
if line1 or line2 or line3:
|
||||
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='')
|
||||
print('\033[1G\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%] \033[37;1m%s\033[39;0m' % (percent, message or line1 or line2 or line3), end='')
|
||||
else:
|
||||
print('\033[1G\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%]\033[39;0m' % (percentage), end='')
|
||||
print('\033[1G\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%]\033[39;0m' % (percent), end='')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
@ -153,7 +153,7 @@ class DialogProgressBG:
|
||||
|
||||
def __init__(self):
|
||||
"""A stub constructor for the xbmcgui DialogProgressBG class"""
|
||||
self.percentage = 0
|
||||
self.percent = 0
|
||||
|
||||
@staticmethod
|
||||
def close():
|
||||
@ -171,16 +171,16 @@ class DialogProgressBG:
|
||||
def isfinished():
|
||||
"""A stub implementation for the xbmcgui DialogProgressBG class isfinished() method"""
|
||||
|
||||
def update(self, percentage, heading=None, message=None):
|
||||
def update(self, percent, heading=None, message=None):
|
||||
"""A stub implementation for the xbmcgui DialogProgressBG class update() method"""
|
||||
if (percentage - 5) < self.percentage:
|
||||
if (percent - 5) < self.percent:
|
||||
return
|
||||
self.percentage = percentage
|
||||
self.percent = percent
|
||||
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))
|
||||
print('\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%] \033[37;1m%s\033[39;0m' % (percent, message))
|
||||
else:
|
||||
print('\033[1G\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%]\033[39;0m' % (percentage), end='')
|
||||
print('\033[1G\033[37;44;1mPROGRESS:\033[35;49;1m [%d%%]\033[39;0m' % (percent), end='')
|
||||
|
||||
|
||||
class DialogBusy:
|
||||
|
Loading…
Reference in New Issue
Block a user