Solved Why doesn't this work?
#1
Why doesn't the script ignore dialog = and location = if the condition "Window.IsVisible(12006)" is false and continue on with the rest of the script?

I have a concert widget on my Home screen and it runs the script on startup to populate and get the data for the default concert widget on the Home screen. However I also am building a Lyric/Concert widget accessible when playing audio while the Visualization screen is visible and I want to be able to search a location and use the input from the dialog for the location. I only want the dialog to pop up when running the script from the widget i am building. I want it to ignore the dialog = and location = part of the script on startup on the Home screen concert widget.
If I take out the condition check the dialog pops up on the home screen as well as the concert widget I am building and I don't want it to. With the condition check it works on the built widget just fine. If I try to indent the dialog = and the local = it doesn't work at all it throws an error right away, I have tried several different ways but I am just trying to learn and I could use a little guidance of what I am doing wrong and maybe a little example of how I can accomplish what I need to make it work. I hope in my own dumb newbie way I explained correctly what I am trying to do. Thanks.

PHP Code:
def GetNearEvents(tag False,festivalsonly Falselat ""lon ""):
    if 
xbmc.getCondVisibility("Window.IsVisible(12006)"):
    
dialog xbmcgui.Dialog()
    
location dialog.input('Enter location to search'type=xbmcgui.INPUT_ALPHANUMautoclose=20000)
    if 
festivalsonly:
        
festivalsonly "1"
    
else:
        
festivalsonly "0"
    
url 'method=geo.getevents&location=%s&festivalsonly=%s&limit=80' % (location,festivalsonly)
    if 
tag:
        
url url '&tag=%s' % (urllib.quote_plus(tag))  
    if 
lat:
        
url url '&lat=%s&long=%s' % (lat,lon)  # &distance=60
    
results GetLastFMData(url)
    if 
True:
        return 
HandleLastFMEventResult(results)
    else:
        return [] 
Reply
#2
Can you post the error message you get when the lines are indented please.

If it's indented the "location" is only set if the condition is true. If the condition is false then "location" is not set and the line where you define "url" will fail with a NameError.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#3
(2014-05-23, 18:15)el_Paraguayo Wrote: Can you post the error message you get when the lines are indented please.

If it's indented the "location" is only set if the condition is true. If the condition is false then "location" is not set and the line where you define "url" will fail with a NameError.

I tried it like this ...

PHP Code:
def GetNearEvents(tag False,festivalsonly Falselat ""lon ""):
    if 
xbmc.getCondVisibility("Window.IsVisible(12006)"):
        
dialog xbmcgui.Dialog()
        
location dialog.input('Enter location to search'type=xbmcgui.INPUT_ALPHANUMautoclose=20000)
    if 
festivalsonly:
        
festivalsonly "1"
    
else:
        
festivalsonly "0"
    
url 'method=geo.getevents&location=%s&festivalsonly=%s&limit=80' % (location,festivalsonly)
    if 
tag:
        
url url '&tag=%s' % (urllib.quote_plus(tag))  
    if 
lat:
        
url url '&lat=%s&long=%s' % (lat,lon)  # &distance=60
    
results GetLastFMData(url)
    if 
True:
        return 
HandleLastFMEventResult(results)
    else:
        return [] 

An this is the error...

PHP Code:
ERROREXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - 
NOTEIGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            
Error Type: <type 'exceptions.IndentationError'>
                                            
Error Contents: ('unindent does not match any outer indentation level', ('C:\\Users\\Woodside\\AppData\\Roaming\\XBMC\\addons\\script.extendedinfo-master\\OnlineMusicInfo.py'204105"       location = dialog.input('Enter location to search', type=xbmcgui.INPUT_ALPHANUM, autoclose=20000)\n"))
                                            
Traceback (most recent call last):
                                              
File "C:\Users\Woodside\AppData\Roaming\XBMC\addons\script.extendedinfo-master\default.py"line 919in <module>
                                                
Main()
                                              
File "C:\Users\Woodside\AppData\Roaming\XBMC\addons\script.extendedinfo-master\default.py"line 75in __init__
                                                self
._StartInfoActions()
                                              
File "C:\Users\Woodside\AppData\Roaming\XBMC\addons\script.extendedinfo-master\default.py"line 365in _StartInfoActions
                                                from OnlineMusicInfo import GetNearEvents
                                            IndentationError
: ('unindent does not match any outer indentation level', ('C:\\Users\\Woodside\\AppData\\Roaming\\XBMC\\addons\\script.extendedinfo-master\\OnlineMusicInfo.py'204105"       location = dialog.input('Enter location to search', type=xbmcgui.INPUT_ALPHANUM, autoclose=20000)\n"))
                                            -->
End of Python script error report<-- 
Reply
#4
Have you checked you're not mixing spaces and tabs?
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#5
(2014-05-23, 19:35)el_Paraguayo Wrote: Have you checked you're not mixing spaces and tabs?

I tried moving every line from def on down to the last return [] all the way to the left and then used the tab key to move every line to
the same positions above but I still get the exact same error. Is that how I can check for mixing tabs and spaces?
Reply
#6
Or put your code in an editor that gives you the option to convert tabs to spaces, or shows special characters.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#7
(2014-05-23, 20:07)el_Paraguayo Wrote: Or put your code in an editor that gives you the option to convert tabs to spaces, or shows special characters.

Hey hey.. I converted tabs to spaces and it worked on the widget I'm building with the indent. Thanks very much for that tip.
however when first starting up now the concert widget on the home screen is throwing this error...

PHP Code:
11:22:19 T:1424   ERROREXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                             - 
NOTEIGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            
Error Type: <type 'exceptions.UnboundLocalError'>
                                            
Error Contentslocal variable 'location' referenced before assignment
                                            Traceback 
(most recent call last):
                                              
File "C:\Users\Woodside\AppData\Roaming\XBMC\addons\script.extendedinfo-master\default.py"line 919in <module>
                                                
Main()
                                              
File "C:\Users\Woodside\AppData\Roaming\XBMC\addons\script.extendedinfo-master\default.py"line 75in __init__
                                                self
._StartInfoActions()
                                              
File "C:\Users\Woodside\AppData\Roaming\XBMC\addons\script.extendedinfo-master\default.py"line 366in _StartInfoActions
                                                passDataToSkin
('NearEvents'GetNearEvents(self.tag,self.festivalsonly), self.prop_prefix)
                                              
File "C:\Users\Woodside\AppData\Roaming\XBMC\addons\script.extendedinfo-master\OnlineMusicInfo.py"line 209in GetNearEvents
                                                url 
'method=geo.getevents&location=%s&festivalsonly=%s&limit=80' % (location,festivalsonly)
                                            
UnboundLocalErrorlocal variable 'location' referenced before assignment
                                            
-->End of Python script error report<-- 
Reply
#8
Yes - that's the point I was referring to earlier. You only define "location" inside an if block. so if that condition is false, "location" is not defined so you can't reference it.

A simple fix would just be to add
Code:
location = ""
as the first line of the code e.g.:
Code:
def GetNearEvents(tag = False,festivalsonly = False, lat = "", lon = ""):
    location = ""
    if xbmc.getCondVisibility("Window.IsVisible(12006)"):
        dialog = xbmcgui.Dialog()
        location = dialog.input('Enter location to search', type=xbmcgui.INPUT_ALPHANUM, autoclose=20000)
    if festivalsonly:
        festivalsonly = "1"
    else:
        festivalsonly = "0"
    url = 'method=geo.getevents&location=%s&festivalsonly=%s&limit=80' % (location,festivalsonly)
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#9
(2014-05-23, 20:41)el_Paraguayo Wrote: Yes - that's the point I was referring to earlier. You only define "location" inside an if block. so if that condition is false, "location" is not defined so you can't reference it.

A simple fix would just be to add
Code:
location = ""
as the first line of the code e.g.:
Code:
def GetNearEvents(tag = False,festivalsonly = False, lat = "", lon = ""):
    location = ""
    if xbmc.getCondVisibility("Window.IsVisible(12006)"):
        dialog = xbmcgui.Dialog()
        location = dialog.input('Enter location to search', type=xbmcgui.INPUT_ALPHANUM, autoclose=20000)
    if festivalsonly:
        festivalsonly = "1"
    else:
        festivalsonly = "0"
    url = 'method=geo.getevents&location=%s&festivalsonly=%s&limit=80' % (location,festivalsonly)

Success!!! Thank you very much for your time and expertise. I had no idea about mixing tabs with spaces. I will check that on any error I get from now on... Thanks again!
Reply
#10
My pleasure. Enjoy your script - and consider submitting it to the official repo if you think others may like it.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#11
(2014-05-23, 21:00)el_Paraguayo Wrote: My pleasure. Enjoy your script - and consider submitting it to the official repo if you think others may like it.

I am going to make an addon with it when I get python educated enough to do so
But if your interested... this post is kinda what I got going. It is as of this time just a mod.

http://forum.xbmc.org/showthread.php?tid=195901
Reply

Logout Mark Read Team Forum Stats Members Help
Why doesn't this work?0