xbmcbackup/resources/lib/progressbar.py

55 lines
1.6 KiB
Python
Raw Permalink Normal View History

2019-11-22 21:53:20 +01:00
import xbmcgui
2019-08-27 21:55:22 +02:00
from . import utils as utils
2019-11-25 22:56:59 +01:00
class BackupProgressBar:
NONE = 2
DIALOG = 0
BACKGROUND = 1
mode = 2
progressBar = None
override = False
2019-11-25 22:33:34 +01:00
2019-11-25 22:45:41 +01:00
def __init__(self, progressOverride):
self.override = progressOverride
2019-11-25 22:33:34 +01:00
2019-11-25 22:19:57 +01:00
# check if we should use the progress bar
if(utils.getSettingInt('progress_mode') != 2):
2019-11-25 22:19:57 +01:00
# check if background or normal
if(utils.getSettingInt('progress_mode') == 0 and not self.override):
self.mode = self.DIALOG
self.progressBar = xbmcgui.DialogProgress()
else:
self.mode = self.BACKGROUND
self.progressBar = xbmcgui.DialogProgressBG()
2019-11-25 22:45:41 +01:00
def create(self, heading, message):
if(self.mode != self.NONE):
2019-11-25 22:45:41 +01:00
self.progressBar.create(heading, message)
2019-11-25 22:45:41 +01:00
def updateProgress(self, percent, message=None):
2019-11-25 22:33:34 +01:00
2019-11-25 22:19:57 +01:00
# update the progress bar
if(self.mode != self.NONE):
2019-11-25 22:56:59 +01:00
if(message is not None):
2019-11-25 22:19:57 +01:00
# need different calls for dialog and background bars
if(self.mode == self.DIALOG):
2019-11-25 22:45:41 +01:00
self.progressBar.update(percent, message)
else:
2019-11-25 22:45:41 +01:00
self.progressBar.update(percent, message=message)
else:
self.progressBar.update(percent)
def checkCancel(self):
result = False
if(self.mode == self.DIALOG):
result = self.progressBar.iscanceled()
return result
def close(self):
if(self.mode != self.NONE):
self.progressBar.close()