Add compatibility for Kodi 19 Python API (#20)

This commit is contained in:
mediaminister 2020-04-03 14:46:27 +00:00 committed by GitHub
parent 6cec23ba1a
commit 2df7282d7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 37 deletions

View File

@ -218,15 +218,19 @@ def ok_dialog(heading='', message=''):
from xbmcgui import Dialog from xbmcgui import Dialog
if not heading: if not heading:
heading = addon_name() heading = addon_name()
if kodi_version_major() < 19:
return Dialog().ok(heading=heading, line1=message) return Dialog().ok(heading=heading, line1=message)
return Dialog().ok(heading=heading, message=message)
def yesno_dialog(heading='', message='', nolabel=None, yeslabel=None): def yesno_dialog(heading='', message='', nolabel=None, yeslabel=None, autoclose=0):
"""Show Kodi's OK dialog""" """Show Kodi's Yes/No dialog"""
from xbmcgui import Dialog from xbmcgui import Dialog
if not heading: if not heading:
heading = addon_name() 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): 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) return Dialog().multiselect(heading=heading, options=options, autoclose=autoclose, preselect=preselect, useDetails=use_details)
def progress(heading='', message=''): class progress(xbmcgui.DialogProgress, object): # pylint: disable=invalid-name,useless-object-inheritance
""" Show a Kodi progress dialog """ """Show Kodi's Progress dialog"""
from xbmcgui import DialogProgress
def __init__(self, heading='', message=''):
"""Initialize and create a progress dialog"""
super(progress, self).__init__()
if not heading: if not heading:
heading = ADDON.getAddonInfo('name') heading = ADDON.getAddonInfo('name')
dialog_progress = DialogProgress() self.create(heading, message=message)
dialog_progress.create(heading=heading, line1=message)
return dialog_progress 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(): def set_locale():
@ -396,8 +413,13 @@ def has_addon(name):
def kodi_version(): def kodi_version():
"""Returns major Kodi version""" """Returns full Kodi version as string"""
return int(xbmc.getInfoLabel('System.BuildVersion').split('.')[0]) 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(): def get_tokens_path():

View File

@ -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)) print('\033[37;44;1mNOTIFICATION:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, message))
@staticmethod @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""" """A stub implementation for the xbmcgui Dialog class ok() method"""
heading = kodi_to_ansi(heading) heading = kodi_to_ansi(heading)
line1 = kodi_to_ansi(line1) message = kodi_to_ansi(message)
print('\033[37;44;1mOK:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, line1)) print('\033[37;44;1mOK:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, message or line1))
@staticmethod @staticmethod
def info(listitem): def info(listitem):
@ -87,11 +87,11 @@ class Dialog:
return -1 return -1
@staticmethod @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""" """A stub implementation for the xbmcgui Dialog class yesno() method"""
heading = kodi_to_ansi(heading) heading = kodi_to_ansi(heading)
line1 = kodi_to_ansi(line1) message = kodi_to_ansi(message)
print('\033[37;44;1mYESNO:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, line1)) print('\033[37;44;1mYESNO:\033[35;49;1m [%s] \033[37;1m%s\033[39;0m' % (heading, message or line1))
return True return True
@staticmethod @staticmethod
@ -113,38 +113,38 @@ class DialogProgress:
def __init__(self): def __init__(self):
"""A stub constructor for the xbmcgui DialogProgress class""" """A stub constructor for the xbmcgui DialogProgress class"""
self.percentage = 0 self.percent = 0
def close(self): def close(self):
"""A stub implementation for the xbmcgui DialogProgress class close() method""" """A stub implementation for the xbmcgui DialogProgress class close() method"""
self.percentage = 0 self.percent = 0
print() print()
sys.stdout.flush() 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""" """A stub implementation for the xbmcgui DialogProgress class create() method"""
self.percentage = 0 self.percent = 0
heading = kodi_to_ansi(heading) heading = kodi_to_ansi(heading)
line1 = kodi_to_ansi(line1) 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() sys.stdout.flush()
def iscanceled(self): def iscanceled(self):
"""A stub implementation for the xbmcgui DialogProgress class iscanceled() method""" """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""" """A stub implementation for the xbmcgui DialogProgress class update() method"""
if (percentage - 5) < self.percentage: if (percent - 5) < self.percent:
return return
self.percentage = percentage self.percent = percent
line1 = kodi_to_ansi(line1) line1 = kodi_to_ansi(line1)
line2 = kodi_to_ansi(line2) line2 = kodi_to_ansi(line2)
line3 = kodi_to_ansi(line3) line3 = kodi_to_ansi(line3)
if line1 or line2 or 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: 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() sys.stdout.flush()
@ -153,7 +153,7 @@ class DialogProgressBG:
def __init__(self): def __init__(self):
"""A stub constructor for the xbmcgui DialogProgressBG class""" """A stub constructor for the xbmcgui DialogProgressBG class"""
self.percentage = 0 self.percent = 0
@staticmethod @staticmethod
def close(): def close():
@ -171,16 +171,16 @@ class DialogProgressBG:
def isfinished(): def isfinished():
"""A stub implementation for the xbmcgui DialogProgressBG class isfinished() method""" """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""" """A stub implementation for the xbmcgui DialogProgressBG class update() method"""
if (percentage - 5) < self.percentage: if (percent - 5) < self.percent:
return return
self.percentage = percentage self.percent = percent
message = kodi_to_ansi(message) message = kodi_to_ansi(message)
if 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: 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: class DialogBusy: