Source code for ccpn.ui.gui.widgets.WebBrowser

"""Module Documentation here

"""
#=========================================================================================
# Licence, Reference and Credits
#=========================================================================================
__copyright__ = "Copyright (C) CCPN project (http://www.ccpn.ac.uk) 2014 - 2019"
__credits__ = ("Ed Brooksbank, Luca Mureddu, Timothy J Ragan & Geerten W Vuister")
__licence__ = ("CCPN licence. See http://www.ccpn.ac.uk/v3-software/downloads/license")
__reference__ = ("Skinner, S.P., Fogh, R.H., Boucher, W., Ragan, T.J., Mureddu, L.G., & Vuister, G.W.",
                 "CcpNmr AnalysisAssign: a flexible platform for integrated NMR analysis",
                 "J.Biomol.Nmr (2016), 66, 111-124, http://doi.org/10.1007/s10858-016-0060-y")
#=========================================================================================
# Last code modification
#=========================================================================================
__modifiedBy__ = "$modifiedBy: CCPN $"
__dateModified__ = "$dateModified: 2017-07-07 16:32:57 +0100 (Fri, July 07, 2017) $"
__version__ = "$Revision: 3.0.0 $"
#=========================================================================================
# Created
#=========================================================================================
__author__ = "$Author: CCPN $"
__date__ = "$Date: 2017-04-07 10:28:41 +0000 (Fri, April 07, 2017) $"
#=========================================================================================
# Start of code
#=========================================================================================

import webbrowser as wb

from ccpn.ui.gui.widgets.PulldownList import PulldownList
from ccpn.ui.gui.widgets.WebView import WebViewPopup


browserNames = ['firefox', 'netscape', 'mozilla', 'konqueror', 'kfm', 'mosaic',
                'grail', 'w3m', 'windows-default', 'internet-config']


[docs]class WebBrowser: def __init__(self, parent, name=None, url=None): names = getBrowserList() if names and (not name): name = names[0] self.name = name if url: self.open(url)
[docs] def open(self, url): try: browser = wb.get(self.name) browser.open(url) except: WebViewPopup(url)
[docs]class WebBrowserPulldown(PulldownList): def __init__(self, parent, browser=None, **kwds): super().__init__(parent, **kwds) self.browserList = getBrowserList() if not browser: browser = getDefaultBrowser() if self.browserList: if (not browser) or (browser not in self.browserList): browser = self.browserList[0] self.browser = browser if self.browserList: self.setup(self.browserList, self.browserList, self.browserList.index(self.browser)) self.callback = self.setWebBrowser
[docs] def setWebBrowser(self, name): if name != self.browser: self.browser = name
[docs] def destroy(self): pass
[docs]def getBrowserList(): browsers = [] default = getDefaultBrowser() if default: browsers = [default, ] for name in browserNames: if name == default: continue try: wb.get(name) browsers.append(name) except: try: if wb._iscommand(name): wb.register(name, None, wb.Netscape(name)) wb.get(name) browsers.append(name) except: continue return browsers
[docs]def getDefaultBrowser(): try: br = wb.get() except: return if not hasattr(br, 'name'): # Max OS X return try: wb.get(br.name) except: wb.register(br.name, None, br) return br.name