mirror of
https://github.com/allankoechke/pywebview.git
synced 2026-11-30 10:58:50 +00:00
* Update change_url.md * Update api.md * Update installation.md * Add Google Analytics * Fix installation * 2.4 info * [Docs] add information about window.pywebview availability * Update debuggig info about QTWebEngine * [Docs] Add information about app architecture * Update cef.md * [CEF] Fix JS logic not persisting after navigating to another page * #169 Frameless window (#313) * Merge PR #177: [Cocoa] Implement frameless windows * [All] Add skeleton for `frameless` parameter * [Cocoa] Add `frameless` kwarg to remove the window frame. - Implement a DragBar class to enable dragging the webview - Make the drag bar stick to the top and autoresize to the width of the view. * [WinForms] Implement frameless window + easy drag * Merge PR #177: [Cocoa] Implement frameless windows * [All] Add skeleton for `frameless` parameter * [Cocoa] Add `frameless` kwarg to remove the window frame. - Implement a DragBar class to enable dragging the webview - Make the drag bar stick to the top and autoresize to the width of the view. * [WinForms] Implement frameless window + easy drag * [GTK] partial implementation of frameless window * [QT] Partial implementation of frameless window * [QT] implement easy drag * [Cocoa] Hide standard buttons and make the entire window draggable * [GTK] implement easy move * Add frameless tests * Remove unused parameter * [Cocoa] Implement free drag * Revert WebBrowserInterops * Code cleanup * Update interop DLLs * Fix interop dll * Update docs; Fix tests * Add example * Update examples * [CEF]: Implement support for pyinstaller one-file mode * [CEF] Fix typo * [All] Change api_call timeout to 15 seconds * Update setup.py * [QT] Simplify QT installation * New API Cocoa implementation Revamped tests and examples * Fix web engine force setting * Rename destroy_window to destroy * Update documentation * Add documentation for 2.4 * Refactor project structure * [GTK] New API support * Rename confirm_quit to confirm_close Split lifecycle events to shown and loaded * [GTK] Implement new API Fix tests * [QT] New API implementation * Remove multiprocessing * [Windows/CEF] New API implementation * Implement CSRF token [All] Implement get_element * Update Flask app example * Rename get_element to get_elements. Bug fixes. * [GTK] Implement propert JS-Python bridge for WebKit2 >2.2 * Update documentation * [Windows/CEF] New API implementation * Add token test * [Winforms] Fix js api initialization * [Cocoa] Fix events * Debug: print webkit version * [GTK] Check for old webkit * [GTK] Fix event issues * Catch notimlementederror in tests * Update travis conf with qt from pip * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * Update .travis.yml * [Windows] Preliminary implementation of EdgeHTML based on PR from @HeavenVolkoff * [docs] Add information about EdgeHTML * EdgeHTML WIP * Remove windows.web import * EdgeHTML improvements. Fix MSHTML evaluate_js * [Docs] Add information about renderer limitations * [EdgeHTML] Fix bugs and tests * Remove window from windows list after it is destroyed * Fix window object deletion after window is closed via GUI * [Docs] Add information about renderer codes * Refactor and fix JS API Remove multiprocessing example [MSHTML] Add console.log debug support * [Travis] Change conf * [WinForms] Fix fullscreen * Fix dll installation * [Windows] Fix DLL bundling * Update changelog * [CEF]: Fix JS API * Update changelog * Built-in HTTP server implementation * Add http server test * Add http server testcd * Add http server testcd * [EdgeHTML] allow localhost urls * Add video example * Bug fixing * [Cocoa] Remove media prefs * Update .travis.yml * Update .travis.yml * Update .travis.yml * [Travis] Disable QT 5.12 builds * Update html_load.md
139 lines
4.6 KiB
Python
Executable File
139 lines
4.6 KiB
Python
Executable File
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
pywebview is a lightweight cross-platform wrapper around a webview component that allows to display HTML content in its
|
|
own dedicated window. Works on Windows, OS X and Linux and compatible with Python 2 and 3.
|
|
|
|
(C) 2014-2019 Roman Sirokov and contributors
|
|
Licensed under BSD license
|
|
|
|
http://github.com/r0x0r/pywebview/
|
|
"""
|
|
|
|
|
|
import json
|
|
import logging
|
|
import os
|
|
import re
|
|
import sys
|
|
import threading
|
|
from uuid import uuid4
|
|
from copy import deepcopy
|
|
|
|
from webview.event import Event
|
|
from webview.guilib import initialize
|
|
from webview.util import _token, base_uri, parse_file_type, escape_string, transform_url, make_unicode, escape_line_breaks, WebViewException
|
|
from webview.window import Window
|
|
from .localization import localization as original_localization
|
|
|
|
logger = logging.getLogger('pywebview')
|
|
handler = logging.StreamHandler()
|
|
formatter = logging.Formatter('[pywebview] %(message)s')
|
|
handler.setFormatter(formatter)
|
|
logger.addHandler(handler)
|
|
|
|
log_level = logging.DEBUG if os.environ.get('PYWEBVIEW_LOG') == 'debug' else logging.INFO
|
|
logger.setLevel(log_level)
|
|
|
|
OPEN_DIALOG = 10
|
|
FOLDER_DIALOG = 20
|
|
SAVE_DIALOG = 30
|
|
|
|
guilib = None
|
|
_debug = False
|
|
_multiprocessing = False
|
|
_http_server = False
|
|
|
|
token = _token
|
|
windows = []
|
|
|
|
def start(func=None, args=None, localization={}, gui=None, debug=False, http_server=False):
|
|
global guilib, _debug, _multiprocessing, _http_server
|
|
|
|
def _create_children(other_windows):
|
|
if not windows[0].shown.wait(10):
|
|
raise WebViewException('Main window failed to load')
|
|
|
|
for window in other_windows:
|
|
guilib.create_window(window)
|
|
|
|
_debug = debug
|
|
#_multiprocessing = multiprocessing
|
|
multiprocessing = False # TODO
|
|
_http_server = http_server
|
|
|
|
if multiprocessing:
|
|
from multiprocessing import Process as Thread
|
|
else:
|
|
from threading import Thread
|
|
|
|
original_localization.update(localization)
|
|
|
|
if threading.current_thread().name != 'MainThread':
|
|
raise WebViewException('This function must be run from a main thread.')
|
|
|
|
if len(windows) == 0:
|
|
raise WebViewException('You must create a window first before calling this function.')
|
|
|
|
guilib = initialize(gui)
|
|
|
|
for window in windows:
|
|
window._initialize(guilib, multiprocessing, http_server)
|
|
|
|
if len(windows) > 1:
|
|
t = Thread(target=_create_children, args=(windows[1:],))
|
|
t.start()
|
|
|
|
if func:
|
|
if args is not None:
|
|
if not hasattr(args, '__iter__'):
|
|
args = (args,)
|
|
t = Thread(target=func, args=args)
|
|
else:
|
|
t = Thread(target=func)
|
|
t.start()
|
|
|
|
guilib.create_window(windows[0])
|
|
|
|
|
|
def create_window(title, url=None, html=None, js_api=None, width=800, height=600,
|
|
resizable=True, fullscreen=False, min_size=(200, 100), confirm_close=False,
|
|
background_color='#FFFFFF', text_select=False, frameless=False):
|
|
"""
|
|
Create a web view window using a native GUI. The execution blocks after this function is invoked, so other
|
|
program logic must be executed in a separate thread.
|
|
:param title: Window title
|
|
:param url: URL to load
|
|
:param width: window width. Default is 800px
|
|
:param height:window height. Default is 600px
|
|
:param resizable True if window can be resized, False otherwise. Default is True
|
|
:param fullscreen: True if start in fullscreen mode. Default is False
|
|
:param min_size: a (width, height) tuple that specifies a minimum window size. Default is 200x100
|
|
:param confirm_close: Display a window close confirmation dialog. Default is False
|
|
:param background_color: Background color as a hex string that is displayed before the content of webview is loaded. Default is white.
|
|
:param text_select: Allow text selection on page. Default is False.
|
|
:param frameless: Whether the window should have a frame.
|
|
:return: The uid of the created window.
|
|
"""
|
|
|
|
valid_color = r'^#(?:[0-9a-fA-F]{3}){1,2}$'
|
|
if not re.match(valid_color, background_color):
|
|
raise ValueError('{0} is not a valid hex triplet color'.format(background_color))
|
|
|
|
uid = 'master' if len(windows) == 0 else 'child_' + uuid4().hex[:8]
|
|
|
|
window = Window(uid, make_unicode(title), transform_url(url), html,
|
|
width, height, resizable, fullscreen, min_size, confirm_close,
|
|
background_color, js_api, text_select, frameless)
|
|
windows.append(window)
|
|
|
|
if threading.current_thread().name != 'MainThread' and guilib:
|
|
window._initialize(guilib, _multiprocessing, _http_server)
|
|
guilib.create_window(window)
|
|
|
|
return window
|
|
|
|
|
|
|