Add utils dialog

Centralize for later, control icon, etc. Pylint.
This commit is contained in:
angelblue05 2016-09-06 22:07:14 -05:00
parent 9e9054865a
commit 21f8a62ebd
3 changed files with 63 additions and 50 deletions

View file

@ -80,7 +80,6 @@ class InitialSetup(object):
current_server = self.user_client.get_server() current_server = self.user_client.get_server()
if current_server is not None: if current_server is not None:
server = self.connectmanager.get_server(current_server) server = self.connectmanager.get_server(current_server)
log.info(server)
settings('ServerId', value=server['Id']) settings('ServerId', value=server['Id'])
self.user_client.get_userid() self.user_client.get_userid()
self.user_client.get_token() self.user_client.get_token()

View file

@ -50,6 +50,23 @@ def language(string_id):
# Central string retrieval - unicode # Central string retrieval - unicode
return xbmcaddon.Addon(id='plugin.video.emby').getLocalizedString(string_id) return xbmcaddon.Addon(id='plugin.video.emby').getLocalizedString(string_id)
def dialog(type_, **kwargs):
d = xbmcgui.Dialog()
if "icon" in kwargs:
kwargs['icon'] = kwargs['icon'].replace("{default}",
"special://home/addons/plugin.video.emby/icon.png")
types = {
'yesno': d.yesno,
'ok': d.ok,
'notification': d.notification,
'input': d.input
}
return types[type_](**kwargs)
class JSONRPC(object): class JSONRPC(object):
id_ = 1 id_ = 1

View file

@ -5,21 +5,19 @@
import logging import logging
import os import os
import sys import sys
import time
import _strptime # Workaround for threads using datetime: _striptime is locked import _strptime # Workaround for threads using datetime: _striptime is locked
from datetime import datetime from datetime import datetime
import xbmc import xbmc
import xbmcaddon import xbmcaddon
import xbmcgui import xbmcgui
import xbmcvfs
################################################################################################# #################################################################################################
_addon = xbmcaddon.Addon(id='plugin.video.emby') _ADDON = xbmcaddon.Addon(id='plugin.video.emby')
_addon_path = _addon.getAddonInfo('path').decode('utf-8') _CWD = _ADDON.getAddonInfo('path').decode('utf-8')
_base_resource = xbmc.translatePath(os.path.join(_addon_path, 'resources', 'lib')).decode('utf-8') _BASE_LIB = xbmc.translatePath(os.path.join(_CWD, 'resources', 'lib')).decode('utf-8')
sys.path.append(_base_resource) sys.path.append(_BASE_LIB)
################################################################################################# #################################################################################################
@ -31,7 +29,7 @@ import librarysync
import player import player
import videonodes import videonodes
import websocket_client as wsc import websocket_client as wsc
from utils import window, settings, language as lang from utils import window, settings, dialog, language as lang
################################################################################################# #################################################################################################
@ -66,13 +64,13 @@ class Service(object):
window('emby_kodiProfile', value=xbmc.translatePath('special://profile')) window('emby_kodiProfile', value=xbmc.translatePath('special://profile'))
# Initial logging # Initial logging
log.warn("======== START %s ========" % self.addonName) log.warn("======== START %s ========", self.addonName)
log.warn("Python Version: %s", sys.version) log.warn("Python Version: %s", sys.version)
log.warn("Platform: %s" % (self.clientInfo.get_platform())) log.warn("Platform: %s", self.clientInfo.get_platform())
log.warn("KODI Version: %s" % xbmc.getInfoLabel('System.BuildVersion')) log.warn("KODI Version: %s", xbmc.getInfoLabel('System.BuildVersion'))
log.warn("%s Version: %s" % (self.addonName, self.clientInfo.get_version())) log.warn("%s Version: %s", self.addonName, self.clientInfo.get_version())
log.warn("Using plugin paths: %s" % (settings('useDirectPaths') == "0")) log.warn("Using plugin paths: %s", settings('useDirectPaths') == "0")
log.warn("Log Level: %s" % logLevel) log.warn("Log Level: %s", logLevel)
# Reset window props for profile switch # Reset window props for profile switch
properties = [ properties = [
@ -92,7 +90,7 @@ class Service(object):
window('emby_minDBVersion', value="1.1.63") window('emby_minDBVersion', value="1.1.63")
def ServiceEntryPoint(self): def service_entry_point(self):
# Important: Threads depending on abortRequest will not trigger # Important: Threads depending on abortRequest will not trigger
# if profile switch happens more than once. # if profile switch happens more than once.
@ -114,9 +112,8 @@ class Service(object):
if window('emby_kodiProfile') != kodiProfile: if window('emby_kodiProfile') != kodiProfile:
# Profile change happened, terminate this thread and others # Profile change happened, terminate this thread and others
log.info("Kodi profile was: %s and changed to: %s. Terminating old Emby thread." log.info("Kodi profile was: %s and changed to: %s. Terminating old Emby thread.",
% (kodiProfile, window('emby_kodiProfile'))) kodiProfile, window('emby_kodiProfile'))
break break
# Before proceeding, need to make sure: # Before proceeding, need to make sure:
@ -171,14 +168,14 @@ class Service(object):
add = ", %s" % ", ".join(additionalUsers) add = ", %s" % ", ".join(additionalUsers)
else: else:
add = "" add = ""
xbmcgui.Dialog().notification( dialog(type_="notification",
heading=lang(29999), heading=lang(29999),
message=("%s %s%s!" message=("%s %s%s!"
% (lang(33000), user.get_username().decode('utf-8'), % (lang(33000), user.get_username().decode('utf-8'),
add.decode('utf-8'))), add.decode('utf-8'))),
icon="special://home/addons/plugin.video.emby/icon.png", icon="{default}",
time=2000, time=2000,
sound=False) sound=False)
# Start monitoring kodi events # Start monitoring kodi events
if not self.kodimonitor_running: if not self.kodimonitor_running:
@ -228,11 +225,11 @@ class Service(object):
window('emby_online', value="false") window('emby_online', value="false")
if settings('offlineMsg') == "true": if settings('offlineMsg') == "true":
xbmcgui.Dialog().notification( dialog(type_="notification",
heading=lang(33001), heading=lang(33001),
message="%s %s" % (self.addonName, lang(33002)), message="%s %s" % (self.addonName, lang(33002)),
icon="special://home/addons/plugin.video.emby/icon.png", icon="{default}",
sound=False) sound=False)
self.server_online = False self.server_online = False
@ -257,12 +254,12 @@ class Service(object):
# Abort was requested while waiting. # Abort was requested while waiting.
break break
# Alert the user that server is online. # Alert the user that server is online.
xbmcgui.Dialog().notification( dialog(type_="notification",
heading=lang(29999), heading=lang(29999),
message=lang(33003), message=lang(33003),
icon="special://home/addons/plugin.video.emby/icon.png", icon="{default}",
time=2000, time=2000,
sound=False) sound=False)
self.server_online = True self.server_online = True
log.info("Server is online and ready.") log.info("Server is online and ready.")
@ -294,14 +291,14 @@ class Service(object):
if self.websocket_running: if self.websocket_running:
ws.stopClient() ws.stopClient()
log.warn("======== STOP %s ========" % self.addonName) log.warn("======== STOP %s ========", self.addonName)
# Delay option # Delay option
delay = int(settings('startupDelay')) DELAY = int(settings('startupDelay'))
log.warn("Delaying emby startup by: %s sec..." % delay) log.warn("Delaying emby startup by: %s sec...", DELAY)
if delay and xbmc.Monitor().waitForAbort(delay): if DELAY and xbmc.Monitor().waitForAbort(DELAY):
# Start the service # Start the service
log.warn("Abort requested while waiting. Emby for kodi not started.") log.warn("Abort requested while waiting. Emby for kodi not started.")
else: else:
Service().ServiceEntryPoint() Service().service_entry_point()