Add user_open() function

This commit is contained in:
Chris Wood 2014-07-17 00:59:27 -04:00
parent 774e38561c
commit 33aba4b084

View File

@ -380,3 +380,20 @@ def make_bar(percentage):
result = result + (10 - len(result)) * ' ' result = result + (10 - len(result)) * ' '
return result return result
def user_open(url_or_command):
"""Open the specified paramater in the web browser if a URL is detected,
othewrise pass the paramater to the shell as a subprocess. This function
is inteded to bu used in on_leftclick()/on_rightclick() events.
:param url_or_command: String containing URL or command
"""
from urllib.parse import urlparse
scheme = urlparse(url_or_command).scheme
if scheme == 'http' or scheme == 'https':
import webbrowser
webbrowser.open(url_or_command)
else:
import subprocess
subprocess.Popen(url_or_command, shell=True)