Skip to content

Commit 8d4e1ac

Browse files
committed
Working on #4
1 parent 7caf3e3 commit 8d4e1ac

File tree

6 files changed

+254
-212
lines changed

6 files changed

+254
-212
lines changed

changelog.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
v 0.2.4 [17/01/15]:
2+
- Fixed #7
3+
- Fixed #8
4+
- Fixed #9
5+
- Fixed #5
6+
7+
v 0.2.3 [17/01/04]:
8+
- Fixed #4
9+
110
v 0.2.2 [17/01/03]:
211
- Fixed #3
312

resources/lib/interface.py

Lines changed: 76 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,96 @@
33
import time
44
import threading
55
import xbmc, xbmcgui, xbmcaddon
6+
__addon__ = xbmcaddon.Addon("script.simkl")
7+
from simklapi import api as API
68
tmp = time.time()
79

8-
__addon__ = xbmcaddon.Addon("script.simkl")
910
__icon__ = __addon__.getAddonInfo("icon")
1011
def getstr(strid): return __addon__.getLocalizedString(strid)
1112

1213
xbmc.log("Simkl: Icon: "+str(__icon__))
1314

1415
not_dialog = xbmcgui.Dialog()
1516
def notify(txt="Test", title="Simkl", icon=__icon__):
16-
not_dialog.notification(title, txt, icon)
17+
not_dialog.notification(title, txt, icon)
1718

1819
PIN_LABEL = 201
1920
INSTRUCTION_ID = 202
2021
CANCEL_BUTTON = 203
22+
ACTION_PREVIOUS_MENU = 10
23+
ACTION_BACK = 92
2124

2225
#xmlfile = ""
2326
#script = __addon__.getAddonInfo("path").decode("utf-8")
27+
def login(logged):
28+
"Change the things that need to be changed. E.g: The settings dialog"
29+
__addon__.setSetting("loginbool", str(bool(1)).lower())
30+
2431
class loginDialog(xbmcgui.WindowXMLDialog):
25-
def __init__(self, xmlFilename, scriptPath, pin, url, check_login, log,
26-
exp=900, inter=5, api=None):
27-
self.pin = pin
28-
self.url = url
29-
self.check_login = check_login
30-
self.log = log
31-
self.exp = exp
32-
self.inter = inter
33-
self.api = api
34-
self.waiting = True
35-
self.canceled = False
36-
37-
def threaded(self):
38-
cnt = 0
39-
while self.waiting:
40-
if cnt % (self.inter+1) == 0 and cnt>1:
41-
xbmc.log("Simkl: Still waiting... {}".format(cnt))
42-
if self.check_login(self.pin, self.log):
43-
44-
xbmc.log(str(self.api.USERSETTINGS))
45-
notify("Hello {}".format(self.api.USERSETTINGS["user"]["name"]))
46-
self.waiting = False
47-
#Now check the user has done what it has to be done
48-
cnt += 1
49-
time.sleep(1)
50-
if self.canceled or cnt >= self.exp:
51-
self.waiting = False
52-
notify("Couldn't log in")
53-
54-
xbmc.log("Simkl: Stop waiting")
55-
self.close()
56-
57-
def onInit(self):
58-
instruction = self.getControl(INSTRUCTION_ID)
59-
instruction.setLabel(
60-
getstr(32022).format("[COLOR ffffbf00]" + self.url + "[/COLOR]"))
61-
self.getControl(PIN_LABEL).setLabel(self.pin)
62-
63-
t = threading.Thread(target=self.threaded)
64-
t.start()
65-
66-
def onControl(self, controlID):
67-
pass
68-
def onFocus(self, controlID):
69-
pass
70-
71-
def onClick(self, controlID):
72-
xbmc.log("Simkl: onclick {}".format(controlID))
73-
if controlID == CANCEL_BUTTON:
74-
self.canceled = True
32+
def __init__(self, xmlFilename, scriptPath, pin, url, check_login, log,
33+
exp=900, inter=5, api=None):
34+
self.pin = pin
35+
self.url = url
36+
self.check_login = check_login
37+
self.log = log
38+
self.exp = exp
39+
self.inter = inter
40+
self.api = api
41+
self.waiting = True
42+
self.canceled = False
43+
44+
def threaded(self):
45+
""" A loop threaded function, so you can do another things meanwhile """
46+
xbmc.log("Simkl: threaded: {}".format(self))
47+
cnt = 0
48+
while self.waiting:
49+
if cnt % (self.inter+1) == 0 and cnt>1:
50+
xbmc.log("Simkl: Still waiting... {}".format(cnt))
51+
if self.check_login(self.pin, self.log):
52+
53+
xbmc.log(str(self.api.USERSETTINGS))
54+
notify("Hello {}".format(self.api.USERSETTINGS["user"]["name"]))
55+
self.waiting = False
56+
#Now check that the user has done what it has to be done
57+
58+
cnt += 1
59+
time.sleep(1)
60+
if self.canceled or cnt >= self.exp:
61+
self.waiting = False
62+
notify("Couldn't log in")
63+
64+
xbmc.log("Simkl: Stop waiting")
65+
self.close()
66+
67+
def onInit(self):
68+
"""The function that is loaded on Window init"""
69+
instruction = self.getControl(INSTRUCTION_ID)
70+
instruction.setLabel(
71+
getstr(32022).format("[COLOR ffffbf00]" + self.url + "[/COLOR]"))
72+
self.getControl(PIN_LABEL).setLabel(self.pin)
73+
74+
#t = threading.Thread(target=self.threaded)
75+
76+
if API.is_user_logged(): #If user is alredy logged in
77+
dialog = xbmcgui.Dialog()
78+
username = API.USERSETTINGS["user"]["name"]
79+
ret = dialog.yesno("Simkl LogIn Warning", "You are alredy logged in as {}".format(username),
80+
nolabel="Cancel", yeslabel="Continue", autoclose=30000)
81+
#xbmc.log("Ret: {}".format(ret))
82+
xbmc.log("Simkl:ret: {}".format(ret))
83+
if ret == 1: pass #t.start()
84+
elif ret == 0: self.onClick(CANCEL_BUTTON)
85+
86+
def onControl(self, controlID):
87+
pass
88+
def onFocus(self, controlID):
89+
pass
90+
91+
def onAction(self, action):
92+
if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK:
93+
self.close()
94+
95+
def onClick(self, controlID):
96+
xbmc.log("Simkl: onclick {}, {}".format(controlID, self))
97+
if controlID == CANCEL_BUTTON:
98+
self.canceled = True

0 commit comments

Comments
 (0)