Need some help with Python script
#1
I use below python script to launch Internet Explorer. It should switch back to Kodi when IE is closed.
Unfortunately the script only launches IE in the background.

I'm running Kodi Alpha4 Git:20140930 on Win7 x64.
Can someone please help me? What do I do wrong?

Code:
import sys
import subprocess

if (__name__ == "__main__"):
    child = subprocess.Popen("C:\Progra~2\Intern~1\iexplore.exe")
    rc = child.wait()
    child = subprocess.Popen("C:\Progra~2\Kodi\Kodi.exe")

sys.modules.clear()
Reply
#2
Here's what I use. It uses the default browser on the system, and is multiplatform. Opens the window in front of xbmc. Manually closing the window returns focus back to XBMC. I think I found this digging around in someone's repo, but I don't remember where, unfortunately.

PHP Code:
def open_url():
    
url "http://www.rhapsody.com/freetrial"
    
print "opening web browser at "+url
    
if sys.platform=='win32':
        
os.startfile(url)
    
elif sys.platform=='darwin':
        
subprocess.Popen(['open'url])
    else:
        try:
            
subprocess.Popen(['xdg-open'url])
        
except OSError:
            print 
'Please open a browser on: '+url 
Reply
#3
Thanks Jerimiah

Unfortunately nothing happens when I run this script.

I have tried running the script with "Use a fullscreen window rather than true fullscreen" switched on (as Advanced Launcher requires this setting to enable switching to external programs) but this didn't help.
Perhaps it's because Kodi doesn't support it. I don't know.
Reply
#4
This is a just a function definition. You have to call the function somewhere in the script, typically in response to some user action. If you just want to run it to test it out, add the following line in your main script:

PHP Code:
open_url() 
Reply
#5
I'm sorry I'm not a developer. This is way over my head Smile
I just found the script in my first post somewhere on this forum. It used to work with XBMC 13 and IE9.
Reply
#6
You can open IE in kiosk mode using:
Code:
import subprocess
child = subprocess.call(["C:\Program Files\Internet Explorer\iexplore.exe", "-k"])

But you then need to use Alt-F4 to exit and only works properly if in fullscreen windowed mode. I tested on the latest Gotham, but I see no reason it shouldn't work on the Kodi alpha.
Reply
#7
Thanks! Unfortunately I receive message "No PVR add-ons available" when I run the script.
Reply
#8
(2014-10-11, 15:19)AussieFries Wrote: Thanks! Unfortunately I receive message "No PVR add-ons available" when I run the script.

Hmmmm. That doesn't make any sense. Can u post a log to xbmclogs.com and post the link here?
Also, is the entirety of your script what I posted above?
Reply
#9
Well I did remove the PVR add-ons.
I replaced
child = subprocess.Popen("C:\Progra~2\Intern~1\iexplore.exe")
With
child = subprocess.call(["C:\Program Files\Internet Explorer\iexplore.exe", "-k"])
Reply
#10
(2014-10-11, 17:02)AussieFries Wrote: Well I did remove the PVR add-ons.
I replaced
child = subprocess.Popen("C:\Progra~2\Intern~1\iexplore.exe")
With
child = subprocess.call(["C:\Program Files\Internet Explorer\iexplore.exe", "-k"])

Ok, so that message appears independently of running the script?
Are you invoking the script by editing keyboard.xml? Or are you running it as an addon thru 'Programs'?
Do you get IE in fullscreen?

A log would still be useful if you need further assistance...
Reply
#11
Yes I start the script via a key mapped in keyboard.xml. Unfortunately it doesn't work in maximized screen either.

The thing is, my system becomes notably slower when I enable "Use maximized screen instead of true full screen".
Reply
#12
Well, I can think of two options:
  1. Install AutoHotKey and write a simple script that sends XBMC/Kodi the "\\" key before and after launching IE. Then call that script instead of IE.

  2. Somewhat more complicated:
  1. If you don't have it already, install Python 2.7 for win32: https://www.python.org/ftp/python/2.7/python-2.7.msi
  2. Install pywin32: http://sourceforge.net/projects/pywin32/...e/download
  3. Under "C:\Users\YOUR USERNAME\AppData\Roaming\XBMC\system" create the following subdirectory structure: "python\Lib\site-packages"
  4. Copy everything from "C:\Python27\Lib\site-packages" to the newly created directory
  5. Edit "C:\Program Files (x86)\XBMC\system\python\Lib\site.py" add the path of the newly created directory to line where PREFIXES is defined (ie. PREFIXES = [sys.prefix, sys.exec_prefix, r"C:\Users\YOUR USERNAME\AppData\Roaming\XBMC\system\python\Lib\site-packages"]


You can then invoke the whole thing with:
Code:
import xbmc
import win32com
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("XBMC")
xbmc.sleep(500)
shell.SendKeys("\\")
import subprocess
child = subprocess.call(["C:\Program Files\Internet Explorer\iexplore.exe", "-k"])
shell.AppActivate("XBMC")
xbmc.sleep(500)
shell.SendKeys("\\")
Reply
#13
Do you want XBMC running in the background when the browser is open? I have a basic add-on for killing XBMC, launching internet explorer then after internet explorer is closed it re-laumches xbmc that I can post if you like.
Reply
#14
@KenV99: Thank you very much for your efforts and time. Much appreciated. I will look into AutoHotKey. I noticed Python scripting requires some basic coding experience which I unfortunately don't have. I mean if a script stops working I'm unable to troubleshoot it myself.

@teeedubb: Yes that's what I'm after. Does your add-on require the option "Use maximized screen instead of true full screen" to be enabled?
Reply
#15
I found a simpler way...

Code:
import subprocess
import xbmc
xbmc.executebuiltin('XBMC.Action(togglefullscreen)')
child = subprocess.call(["C:\Program Files\Internet Explorer\iexplore.exe", "-k"])
xbmc.executebuiltin('XBMC.Action(togglefullscreen)')

This is working for me to drop out of true fullscreen, launches IE in kiosk mode and then brings back a fullscreen after you close IE with Alt-F4.
Reply

Logout Mark Read Team Forum Stats Members Help
Need some help with Python script0