Skip to content

Commit

Permalink
add background progress dialog and remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnKaijser committed Apr 12, 2014
1 parent 405a928 commit 96f5fac
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 65 deletions.
3 changes: 2 additions & 1 deletion lib/fileops.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

### import libraries
from lib.script_exceptions import *
from lib.utils import dialog_msg, log
from lib.gui import dialog_msg
from lib.utils import log
from traceback import print_exc
from urllib2 import HTTPError, URLError

Expand Down
53 changes: 40 additions & 13 deletions lib/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
### set button actions for GUI
ACTION_PREVIOUS_MENU = (9, 10, 92, 216, 247, 257, 275, 61467, 61448)

pDialog = xbmcgui.DialogProgress()
pDialogBG = xbmcgui.DialogProgressBG()

# Define dialogs
def dialog_msg(action,
percentage = 0,
Expand All @@ -49,26 +52,50 @@ def dialog_msg(action,

# Dialog logic
if not line0 == '':
line0 = __addonname__ + line0
line0 = __addonname__ + ' : ' + line0
else:
line0 = __addonname__
if not background:
if action == 'create':
dialog.create(__addonname__, line1, line2, line3)
if action == 'update':
dialog.update(percentage, line1, line2, line3)
if action == 'close':
dialog.close()
if action == 'iscanceled':
if dialog.iscanceled():
pDialog.create(__addonname__,
line1,
line2,
line3)
elif action == 'update':
pDialog.update(percentage,
line1,
line2,
line3)
elif action == 'close':
pDialog.close()
elif action == 'iscanceled':
if pDialog.iscanceled():
return True
else:
return False
if action == 'okdialog':
xbmcgui.Dialog().ok(line0, line1, line2, line3)
if action == 'yesno':
return xbmcgui.Dialog().yesno(line0, line1, line2, line3, nolabel, yeslabel)
if background:
elif action == 'createBG':
pDialogBG.create(__addonname__,
line1)
elif action == 'updateBG':
pDialogBG.update(percent = percentage,
message = line1)
elif action == 'closeBG':
pDialogBG.close()
elif action == 'iscanceledBG':
return False
elif action == 'okdialog':
xbmcgui.Dialog().ok(line0,
line1,
line2,
line3)
elif action == 'yesno':
return xbmcgui.Dialog().yesno(line0,
line1,
line2,
line3,
nolabel,
yeslabel)
else:
if (action == 'create' or action == 'okdialog'):
if line2 == '':
msg = line1
Expand Down
3 changes: 2 additions & 1 deletion lib/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import xbmc
import xbmcaddon
import lib.common
from lib.utils import dialog_msg, log
from lib.gui import dialog_msg
from lib.utils import log

### get addon info
__addon__ = lib.common.__addon__
Expand Down
50 changes: 0 additions & 50 deletions lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
### Cache bool
CACHE_ON = True

### Declare dialog
dialog = xbmcgui.DialogProgress()


# Fixes unicode problems
def string_unicode(text, encoding='utf-8'):
try:
Expand Down Expand Up @@ -89,52 +85,6 @@ def log(txt, severity=xbmc.LOGDEBUG):
message = ('%s: UnicodeEncodeError' %__addonname__)
xbmc.log(msg=message, level=xbmc.LOGWARNING)

# Define dialogs
def dialog_msg(action,
percentage = 0,
line0 = '',
line1 = '',
line2 = '',
line3 = '',
background = False,
nolabel = __localize__(32026),
yeslabel = __localize__(32025),
cancelled = False):
# Fix possible unicode errors
line0 = line0.encode( 'utf-8', 'ignore' )
line1 = line1.encode( 'utf-8', 'ignore' )
line2 = line2.encode( 'utf-8', 'ignore' )
line3 = line3.encode( 'utf-8', 'ignore' )

# Dialog logic
if not line0 == '':
line0 = __addonname__ + line0
else:
line0 = __addonname__
if not background:
if action == 'create':
dialog.create(__addonname__, line1, line2, line3)
if action == 'update':
dialog.update(percentage, line1, line2, line3)
if action == 'close':
dialog.close()
if action == 'iscanceled':
if dialog.iscanceled():
return True
else:
return False
if action == 'okdialog':
xbmcgui.Dialog().ok(line0, line1, line2, line3)
if action == 'yesno':
return xbmcgui.Dialog().yesno(line0, line1, line2, line3, nolabel, yeslabel)
if background:
if (action == 'create' or action == 'okdialog'):
if line2 == '':
msg = line1
else:
msg = line1 + ': ' + line2
if cancelled == False:
xbmc.executebuiltin("XBMC.Notification(%s, %s, 7500, %s)" % (line0, msg, __icon__))

# Retrieve JSON data from cache function
def get_data(url, data_type ='json'):
Expand Down

0 comments on commit 96f5fac

Please sign in to comment.