xbmcbackup/resources/lib/progressbar.py

55 lines
1.6 KiB
Python
Raw Normal View History

2019-11-22 14:53:20 -06:00
import xbmcgui
2019-08-27 14:55:22 -05:00
from . import utils as utils
2019-11-25 15:56:59 -06:00
class BackupProgressBar:
NONE = 2
DIALOG = 0
BACKGROUND = 1
mode = 2
progressBar = None
override = False
2019-11-25 15:33:34 -06:00
2019-11-25 15:45:41 -06:00
def __init__(self, progressOverride):
self.override = progressOverride
2019-11-25 15:33:34 -06:00
2019-11-25 15:19:57 -06:00
# check if we should use the progress bar
if(utils.getSettingInt('progress_mode') != 2):
2019-11-25 15:19:57 -06: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 15:45:41 -06:00
def create(self, heading, message):
if(self.mode != self.NONE):
2019-11-25 15:45:41 -06:00
self.progressBar.create(heading, message)
2019-11-25 15:45:41 -06:00
def updateProgress(self, percent, message=None):
2019-11-25 15:33:34 -06:00
2019-11-25 15:19:57 -06:00
# update the progress bar
if(self.mode != self.NONE):
2019-11-25 15:56:59 -06:00
if(message is not None):
2019-11-25 15:19:57 -06:00
# need different calls for dialog and background bars
if(self.mode == self.DIALOG):
2019-11-25 15:45:41 -06:00
self.progressBar.update(percent, message)
else:
2019-11-25 15:45:41 -06: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()