コード例 #1
0
def evaluate_js(script, uid='master'):
    """
    Evaluate given JavaScript code and return the result
    :param script: The JavaScript code to be evaluated
    :param uid: uid of the target instance
    :return: Return value of the evaluated code
    """
    escaped_script = 'JSON.stringify(eval("{0}"))'.format(escape_string(script))
    return gui.evaluate_js(escaped_script, uid)
コード例 #2
0
ファイル: __init__.py プロジェクト: Nablast/pywebview
def evaluate_js(script):
    """
    Evaluate given JavaScript code and return the result
    :param script: The JavaScript code to be evaluated
    :return: Return value of the evaluated code
    """
    try:
        _webview_ready.wait(5)
        return gui.evaluate_js(script)
    except NameError:
        raise Exception(
            "Create a web view window first, before invoking this function")
コード例 #3
0
def evaluate_js(script):
    """
    Evaluate given JavaScript code and return the result
    :param script: The JavaScript code to be evaluated
    :return: Return value of the evaluated code
    """
    try:
        _webview_ready.wait(5)
        assert gui.is_running()
        return gui.evaluate_js(script)
    except NameError:
        raise Exception("Create a web view window first, before invoking this function")
    except AssertionError:
        raise Exception("Cannot call function: the webview has been closed")
コード例 #4
0
def evaluate_js(script, uid='master'):
    """
    Evaluate given JavaScript code and return the result
    :param script: The JavaScript code to be evaluated
    :param uid: uid of the target instance
    :return: Return value of the evaluated code
    """
    try:
        _webview_ready.wait(5)
        return gui.evaluate_js(script, uid)
    except NameError:
        raise Exception('Create a web view window first, before invoking this function')
    except KeyError:
        raise Exception('Cannot call function: No webview exists with uid: {}'.format(uid))
コード例 #5
0
def load_css(stylesheet, uid='master'):
    code = css.src % stylesheet.replace('\n', '').replace('\r', '').replace('"', "'")
    gui.evaluate_js(code)