33import time
44import threading
55import xbmc , xbmcgui , xbmcaddon
6+ __addon__ = xbmcaddon .Addon ("script.simkl" )
7+ from simklapi import api as API
68tmp = time .time ()
79
8- __addon__ = xbmcaddon .Addon ("script.simkl" )
910__icon__ = __addon__ .getAddonInfo ("icon" )
1011def getstr (strid ): return __addon__ .getLocalizedString (strid )
1112
1213xbmc .log ("Simkl: Icon: " + str (__icon__ ))
1314
1415not_dialog = xbmcgui .Dialog ()
1516def notify (txt = "Test" , title = "Simkl" , icon = __icon__ ):
16- not_dialog .notification (title , txt , icon )
17+ not_dialog .notification (title , txt , icon )
1718
1819PIN_LABEL = 201
1920INSTRUCTION_ID = 202
2021CANCEL_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+
2431class 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