本文整理汇总了Python中webbrowser.register函数的典型用法代码示例。如果您正苦于以下问题:Python register函数的具体用法?Python register怎么用?Python register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_browser
def start_browser(entry):
if browser and \
browser not in ('xdg-open', 'start') and \
not grass.find_program(browser):
grass.fatal(_("Browser '%s' not found") % browser)
if flags['o']:
major,minor,patch = grass.version()['version'].split('.')
url_path = 'http://grass.osgeo.org/grass%s%s/manuals/%s.html' % (major,minor,entry)
if urllib.urlopen(url_path).getcode() != 200:
url_path = 'http://grass.osgeo.org/grass%s%s/manuals/addons/%s.html' % (major,minor,entry)
else:
path = os.path.join(gisbase, 'docs', 'html', entry + '.html')
if not os.path.exists(path) and os.getenv('GRASS_ADDON_BASE'):
path = os.path.join(os.getenv('GRASS_ADDON_BASE'), 'docs', 'html', entry + '.html')
if not os.path.exists(path):
grass.fatal(_("No HTML manual page entry for '%s'") % entry)
url_path = 'file://' + path
if browser and browser not in ('xdg-open', 'start'):
webbrowser.register(browser_name, None)
grass.verbose(_("Starting browser '%(browser)s' for manual"
" entry '%(entry)s'...") % \
dict(browser=browser_name, entry=entry))
try:
webbrowser.open(url_path)
except:
grass.fatal(_("Error starting browser '%(browser)s' for HTML file"
" '%(path)s'") % dict(browser=browser, path=path))
示例2: set_config
def set_config():
"""Set optional API keys, browser, and bookmarks in CONFIG."""
for key, val in iteritems(read_config()):
CONFIG[key] = val
if 'browser' in CONFIG and CONFIG['browser'] != 'Automatically detected':
try:
CONFIG['browser_obj'] = webbrowser.get(CONFIG['browser'])
return
except webbrowser.Error as err:
sys.stderr.write('{} at {}\n'.format(str(err), CONFIG['browser']))
CONFIG['browser_obj'] = None
pass
except IndexError:
CONFIG['browser_obj'] = None
pass
# If no valid browser found then use webbrowser to automatically detect one
try:
supported_platforms = {'win32': 'windows-default', 'cygwin': 'cygstart', 'darwin': 'macosx'}
if sys.platform not in supported_platforms:
browser_name = 'Automatically detected'
browser_obj = webbrowser.get()
else:
browser_name = supported_platforms[sys.platform]
if browser_name == 'cygstart':
# Cygwin requires us to register browser type (or export BROWSER='cygstart')
webbrowser.register(browser_name, None, webbrowser.GenericBrowser(browser_name))
browser_obj = webbrowser.get(browser_name)
CONFIG['browser'] = browser_name
CONFIG['browser_obj'] = browser_obj
except webbrowser.Error:
pass
示例3: __init__
def __init__(self, browser, session):
self.jd = JSONDecoder()
self.browser = browser
self.windows = {}
webbrowser.register(self.browser, None,
webbrowser.Chrome(self.browser))
self.tabs = self._set_session(session)
示例4: main
def main():
try:
buildServer = run_local_build_server()
while not is_build_server_running():
print "[build server] BOOTING"
print "[build server] ONLINE"
appInventor = start_appinventor()
while not is_app_inventor_running():
print "[app inventor] BOOTING"
print "[app inventor] ONLINE"
print "[app inventor] OPENING"
try:
browser = webbrowser.get("chrome")
except webbrowser.Error:
try:
webbrowser.register("firefox", None, webbrowser.GenericBrowser(os.environ["ProgramFiles"] + r"\Mozilla Firefox\firefox.exe"), 1)
browser = webbrowser.get("firefox")
except webbrowser.Error:
browser = webbrowser.get()
browser.open("http://localhost:8888/_ah/login?continue=http://localhost:8888/")
except Exception as e:
print type(e)
print e
finally:
taskkill(buildServer.pid)
taskkill(appInventor.pid)
示例5: setbrowser
def setbrowser(browser=None):
""" Registers the given browser and saves it as the module default.
This is used to control which browser is used to display the plot.
The argument should be a value that can be passed to webbrowser.get()
to obtain a browser. If no argument is given, the default is reset
to the system default.
webbrowser provides some predefined browser names, including:
'firefox'
'opera'
If the browser string contains '%s', it is interpreted as a literal
browser command line. The URL will be substituted for '%s' in the command.
For example:
'google-chrome %s'
'cmd "start iexplore.exe %s"'
See the webbrowser documentation for more detailed information.
Note: Safari does not reliably work with the webbrowser module,
so we recommend using a different browser.
"""
global _browser
if browser is None:
_browser = None # Use system default
else:
webbrowser.register(browser, None, webbrowser.get(browser))
_browser = browser
示例6: _register_gvfs_open
def _register_gvfs_open():
'''
GVFS is the virtual file system for the GNOME desktop
gvfs-open opens a file in the using the appropriate applicatioin when
the user is using the GNOME desktop
'''
if 'GNOME_DESKTOP_SESSION_ID' in os.environ and _iscommand('gvfs-open'):
register('gvfs-open', None, BackgroundBrowser('gvfs-open'))
示例7: open_htmlcode_in_browser
def open_htmlcode_in_browser( html ) :
import os , time , webbrowser
tmp_file_name = "__temp__.html"
webbrowser.register('firefox', None, webbrowser.GenericBrowser('firefox'), 1)
with open( tmp_file_name , "w+" ) as f :
f.write( html )
webbrowser.get("firefox").open( "file://" + os.popen( "cygpath -w " + os.path.realpath( tmp_file_name ) ).read() )
time.sleep( 2 )
示例8: get_browser
def get_browser():
browser_list = ['galeon', 'mozilla', 'lynx']
for b in browser_list:
if test_access( b):
browser = webbrowser.GenericBrowser( b + ' %s')
webbrowser.register( b, None, browser)
return b
print 'No Web browser found.'
return ''
示例9: openChrome
def openChrome(self):
url = "http://localhost:9901/debug?port=5858"
config = sublime.load_settings(SETTINGS_FILE)
chrome_path = config.get('chrome_path',"")
chrome = webbrowser.BackgroundBrowser(chrome_path)
webbrowser.register('chrome', None, chrome)
webbrowser.get('chrome').open_new_tab(url)
示例10: register_webbrowser_url_hook
def register_webbrowser_url_hook():
"""registers pythons webbrowser module as url_hook"""
import webbrowser
def open_url(d, link, data):
webbrowser.open(link)
if sys.platform.startswith("linux"):
webbrowser.register("xdg-open", None,
webbrowser.GenericBrowser('xdg-open'), update_tryorder=-1)
gtk.about_dialog_set_url_hook(open_url, None)
示例11: run
def run(self, edit):
chromePath = 'D:\\Program\\Chrome\\chrome.exe'
chromePath2 = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
if not os.path.isfile(chromePath):
chromePath = chromePath2
print(os.path.isfile(chromePath))
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chromePath))
webbrowser.get('chrome').open_new_tab(self.view.file_name())
示例12: run
def run(self):
settings = context.get_toolingapi_settings()
browser_path = settings["default_chrome_path"]
plugin_url = "https://github.com/xjsender/SublimeApex#sublime-ide-for-salesforce"
if os.path.exists(browser_path):
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(browser_path))
webbrowser.get('chrome').open_new_tab(plugin_url)
else:
webbrowser.open_new_tab(plugin_url)
示例13: open_documentation
def open_documentation(self, index):
if index == -1: return
link = self.title_link[self.titles[index]]
show_url= 'http://www.salesforce.com/us/developer/docs/%s%s' % (link["attr"], link["url"])
settings = context.get_toolingapi_settings()
browser_path = settings["default_chrome_path"]
if os.path.exists(browser_path):
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(browser_path))
webbrowser.get('chrome').open_new_tab(show_url)
else:
webbrowser.open_new_tab(show_url)
示例14: test_register
def test_register(self):
webbrowser = support.import_fresh_module('webbrowser')
self.assertIsNone(webbrowser._tryorder)
self.assertFalse(webbrowser._browsers)
class ExampleBrowser:
pass
webbrowser.register('Example1', ExampleBrowser)
self.assertTrue(webbrowser._tryorder)
self.assertEqual(webbrowser._tryorder[-1], 'Example1')
self.assertTrue(webbrowser._browsers)
self.assertIn('example1', webbrowser._browsers)
self.assertEqual(webbrowser._browsers['example1'], [ExampleBrowser, None])
示例15: _credentials_flow_interactive
def _credentials_flow_interactive(client_secrets_path):
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_path,
scopes=[_ASSISTANT_OAUTH_SCOPE])
if 'DISPLAY' in os.environ:
# Use chromium-browser by default. Raspbian Stretch uses Epiphany by
# default but that seems to cause issues:
# https://github.com/google/aiyprojects-raspbian/issues/269
webbrowser.register('chromium-browser', None, webbrowser.Chrome('chromium-browser'), -1)
credentials = flow.run_local_server()
else:
credentials = flow.run_console()
return credentials