當前位置: 首頁>>代碼示例>>Python>>正文


Python webbrowser.BackgroundBrowser方法代碼示例

本文整理匯總了Python中webbrowser.BackgroundBrowser方法的典型用法代碼示例。如果您正苦於以下問題:Python webbrowser.BackgroundBrowser方法的具體用法?Python webbrowser.BackgroundBrowser怎麽用?Python webbrowser.BackgroundBrowser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在webbrowser的用法示例。


在下文中一共展示了webbrowser.BackgroundBrowser方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: open_in_browser

# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import BackgroundBrowser [as 別名]
def open_in_browser(sf_basic_config, url, browser_name = '', browser_path = ''):
    settings =  sf_basic_config.get_setting()
    if not browser_path or not os.path.exists(browser_path) or browser_name == "default":
        webbrowser.open_new_tab(url)

    elif browser_name == "chrome-private":
        # os.system("\"%s\" --incognito %s" % (browser_path, url))
        browser = webbrowser.get('"' + browser_path +'" --incognito %s')
        browser.open(url)
        
    else:
        try:
            # show_in_panel("33")
            # browser_path = "\"C:\Program Files\Google\Chrome\Application\chrome.exe\" --incognito"
            webbrowser.register('chromex', None, webbrowser.BackgroundBrowser(browser_path))
            webbrowser.get('chromex').open_new_tab(url)
        except Exception as e:
            webbrowser.open_new_tab(url) 
開發者ID:exiahuang,項目名稱:SalesforceXyTools,代碼行數:20,代碼來源:util.py

示例2: open_in_default_browser

# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import BackgroundBrowser [as 別名]
def open_in_default_browser(sf_basic_config, url):
    browser_map = sf_basic_config.get_default_browser()
    browser_name = browser_map['name']
    browser_path = browser_map['path']

    if not browser_path or not os.path.exists(browser_path) or browser_name == "default":
        webbrowser.open_new_tab(url)

    elif browser_map['name'] == "chrome-private":
        # chromex = "\"%s\" --incognito %s" % (browser_path, url)
        # os.system(chromex)
        browser = webbrowser.get('"' + browser_path +'" --incognito %s')
        browser.open(url)

        # os.system("\"%s\" -ArgumentList @('-incognito', %s)" % (browser_path, url))

    else:
        try:
            webbrowser.register('chromex', None, webbrowser.BackgroundBrowser(browser_path))
            webbrowser.get('chromex').open_new_tab(url)
        except Exception as e:
            webbrowser.open_new_tab(url)


##########################################################################################
#END
########################################################################################## 
開發者ID:exiahuang,項目名稱:SalesforceXyTools,代碼行數:29,代碼來源:util.py

示例3: open_url_in_browser

# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import BackgroundBrowser [as 別名]
def open_url_in_browser(url, browser_path=None, run=run):
    if browser_path:
        filesnpaths.is_file_exists(browser_path)
        run.info_single('You are launching an alternative browser. Keep an eye on things!', mc='red', nl_before=1)
        webbrowser.register('users_preferred_browser', None, webbrowser.BackgroundBrowser(browser_path))
        webbrowser.get('users_preferred_browser').open_new(url)
    else:
        webbrowser.open_new(url) 
開發者ID:merenlab,項目名稱:anvio,代碼行數:10,代碼來源:utils.py

示例4: patch_webbrowser

# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import BackgroundBrowser [as 別名]
def patch_webbrowser():
    """
    Some custom patches on top of the python webbrowser module to fix
    user reported bugs and limitations of the module.
    """

    # https://bugs.python.org/issue31014
    # https://github.com/michael-lazar/ttrv/issues/588
    def register_patch(name, klass, instance=None, update_tryorder=None, preferred=False):
        """
        Wrapper around webbrowser.register() that detects if the function was
        invoked with the legacy function signature. If so, the signature is
        fixed before passing it along to the underlying function.

        Examples:
            register(name, klass, instance, -1)
            register(name, klass, instance, update_tryorder=-1)
            register(name, klass, instance, preferred=True)
        """
        if update_tryorder is not None:
            preferred = (update_tryorder == -1)
        return webbrowser._register(name, klass, instance, preferred=preferred)

    if sys.version_info[:2] >= (3, 7):
        webbrowser._register = webbrowser.register
        webbrowser.register = register_patch

    # Add support for browsers that aren't defined in the python standard library
    webbrowser.register('surf', None, webbrowser.BackgroundBrowser('surf'))
    webbrowser.register('vimb', None, webbrowser.BackgroundBrowser('vimb'))
    webbrowser.register('qutebrowser', None, webbrowser.BackgroundBrowser('qutebrowser'))

    # Fix the opera browser, see https://github.com/michael-lazar/ttrv/issues/476.
    # By default, opera will open a new tab in the current window, which is
    # what we want to do anyway.
    webbrowser.register('opera', None, webbrowser.BackgroundBrowser('opera'))

    # https://bugs.python.org/issue31348
    # Use MacOS actionscript when opening the program defined in by $BROWSER
    if sys.platform == 'darwin' and 'BROWSER' in os.environ:
        _userchoices = os.environ["BROWSER"].split(os.pathsep)
        for cmdline in reversed(_userchoices):
            if cmdline in ('safari', 'firefox', 'chrome', 'default'):
                browser = webbrowser.MacOSXOSAScript(cmdline)
                webbrowser.register(cmdline, None, browser, update_tryorder=-1) 
開發者ID:tildeclub,項目名稱:ttrv,代碼行數:47,代碼來源:objects.py

示例5: display_qr_code

# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import BackgroundBrowser [as 別名]
def display_qr_code(png, seed):
    """
    Display MFA QR code
    :param png:
    :param seed:
    :return:
    """
    # This NamedTemporaryFile is deleted as soon as it is closed, so
    # return it to caller, who must close it (or program termination
    # could cause it to be cleaned up, that's fine too).
    # If we don't keep the file around until after the user has synced
    # his MFA, the file will possibly be already deleted by the time
    # the operating system gets around to execing the browser, if
    # we're using a browser.
    qrcode_file = tempfile.NamedTemporaryFile(suffix='.png', delete=True, mode='wt')
    qrcode_file.write(png)
    qrcode_file.flush()
    if _fabulous_available:
        fabulous.utils.term.bgcolor = 'white'
        with open(qrcode_file.name, 'rb') as png_file:
            print(fabulous.image.Image(png_file, 100))
    else:
        graphical_browsers = [webbrowser.BackgroundBrowser,
                              webbrowser.Mozilla,
                              webbrowser.Galeon,
                              webbrowser.Chrome,
                              webbrowser.Opera,
                              webbrowser.Konqueror]
        if sys.platform[:3] == 'win':
            graphical_browsers.append(webbrowser.WindowsDefault)
        elif sys.platform == 'darwin':
            graphical_browsers.append(webbrowser.MacOSXOSAScript)

        browser_type = None
        try:
            browser_type = type(webbrowser.get())
        except webbrowser.Error:
            pass

        if browser_type in graphical_browsers:
            printError("Unable to print qr code directly to your terminal, trying a web browser.")
            webbrowser.open('file://' + qrcode_file.name)
        else:
            printInfo("Unable to print qr code directly to your terminal, and no graphical web browser seems available.")
            printInfo("But, the qr code file is temporarily available as this file:")
            printInfo("\n    %s\n" % qrcode_file.name)
            printInfo("Alternately, if you feel like typing the seed manually into your MFA app:")
            # this is a base32-encoded binary string (for case
            # insensitivity) which is then dutifully base64-encoded by
            # amazon before putting it on the wire.  so the actual
            # secret is b32decode(b64decode(seed)), and what users
            # will need to type in to their app is just
            # b64decode(seed).  print that out so users can (if
            # desperate) type in their MFA app.
            printInfo("\n    %s\n" % base64.b64decode(seed))
    return qrcode_file 
開發者ID:nccgroup,項目名稱:AWS-recipes,代碼行數:58,代碼來源:awsrecipes_enable_mfa.py

示例6: patch_webbrowser

# 需要導入模塊: import webbrowser [as 別名]
# 或者: from webbrowser import BackgroundBrowser [as 別名]
def patch_webbrowser():
    """
    Some custom patches on top of the python webbrowser module to fix
    user reported bugs and limitations of the module.
    """

    # https://bugs.python.org/issue31014
    # https://github.com/michael-lazar/rtv/issues/588
    def register_patch(name, klass, instance=None, update_tryorder=None, preferred=False):
        """
        Wrapper around webbrowser.register() that detects if the function was
        invoked with the legacy function signature. If so, the signature is
        fixed before passing it along to the underlying function.

        Examples:
            register(name, klass, instance, -1)
            register(name, klass, instance, update_tryorder=-1)
            register(name, klass, instance, preferred=True)
        """
        if update_tryorder is not None:
            preferred = (update_tryorder == -1)
        return webbrowser._register(name, klass, instance, preferred=preferred)

    if sys.version_info[:2] >= (3, 7):
        webbrowser._register = webbrowser.register
        webbrowser.register = register_patch

    # Add support for browsers that aren't defined in the python standard library
    webbrowser.register('surf', None, webbrowser.BackgroundBrowser('surf'))
    webbrowser.register('vimb', None, webbrowser.BackgroundBrowser('vimb'))
    webbrowser.register('qutebrowser', None, webbrowser.BackgroundBrowser('qutebrowser'))

    # Fix the opera browser, see https://github.com/michael-lazar/rtv/issues/476.
    # By default, opera will open a new tab in the current window, which is
    # what we want to do anyway.
    webbrowser.register('opera', None, webbrowser.BackgroundBrowser('opera'))

    # https://bugs.python.org/issue31348
    # Use MacOS actionscript when opening the program defined in by $BROWSER
    if sys.platform == 'darwin' and 'BROWSER' in os.environ:
        _userchoices = os.environ["BROWSER"].split(os.pathsep)
        for cmdline in reversed(_userchoices):
            if cmdline in ('safari', 'firefox', 'chrome', 'default'):
                browser = webbrowser.MacOSXOSAScript(cmdline)
                webbrowser.register(cmdline, None, browser, update_tryorder=-1) 
開發者ID:michael-lazar,項目名稱:rtv,代碼行數:47,代碼來源:objects.py


注:本文中的webbrowser.BackgroundBrowser方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。