|
1
|
|
|
#!/usr/bin/python |
|
2
|
|
|
# -*- coding: UTF-8 -*- |
|
3
|
|
|
""" |
|
4
|
|
|
Utils module. Some basic functions that maybe I'll need more than once |
|
5
|
|
|
""" |
|
6
|
|
|
import sys |
|
7
|
|
|
import xbmc, xbmcaddon, xbmcgui |
|
8
|
|
|
from threading import Timer |
|
9
|
|
|
|
|
10
|
|
|
__addon__ = xbmcaddon.Addon("script.simkl") |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
def log(s): |
|
14
|
|
|
xbmc.log("-- Simkl: {0}".format(s), level=xbmc.LOGDEBUG) |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
def get_str(strid): |
|
18
|
|
|
""" Given an id, returns the localized string """ |
|
19
|
|
|
return __addon__.getLocalizedString(strid) |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
def get_setting(settingid): |
|
23
|
|
|
""" Given an id, return the setting """ |
|
24
|
|
|
ret = __addon__.getSetting(settingid) |
|
25
|
|
|
log("get setting {0} = {1}".format(settingid, ret)) |
|
26
|
|
|
return ret |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
def set_setting(settingid, val): |
|
30
|
|
|
""" Given an id, return the setting """ |
|
31
|
|
|
log("set setting, {0} = {1}".format(settingid, val)) |
|
32
|
|
|
__addon__.setSetting(settingid, val) |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
def system_lock(name, sec=0): |
|
36
|
|
|
w = xbmcgui.Window(10000) |
|
37
|
|
|
if w.getProperty(name) == "True": |
|
38
|
|
|
log('already started, ' + name) |
|
39
|
|
|
sys.exit(0) |
|
40
|
|
|
w.setProperty(name, "True") |
|
41
|
|
|
if sec != 0: |
|
42
|
|
|
def stop_singleton(): |
|
43
|
|
|
w.clearProperty(name) |
|
44
|
|
|
|
|
45
|
|
|
t = Timer(sec, stop_singleton) |
|
46
|
|
|
t.start() |
|
47
|
|
|
|