def __init__(self, uid, title, url, html, width, height, x, y, resizable, fullscreen, min_size, hidden, frameless, minimized, confirm_close, background_color, js_api, text_select): self.uid = uid self.title = make_unicode(title) self.url = None if html else transform_url(url) self.html = html self.width = width self.height = height self.x = x self.y = y self.resizable = resizable self.fullscreen = fullscreen self.min_size = min_size self.confirm_close = confirm_close self.background_color = background_color self.text_select = text_select self.frameless = frameless self.hidden = hidden self.minimized = minimized self._js_api = js_api self._functions = {} self.closed = Event() self.closing = Event() self.loaded = Event() self.shown = Event() self.gui = None self._httpd = None self._is_http_server = False
def create_window(title, url=None, js_api=None, width=800, height=600, resizable=True, fullscreen=False, min_size=(200, 100), strings={}, confirm_quit=False, background_color='#FFFFFF', text_select=False, frameless=False, debug=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 strings: a dictionary with localized strings :param confirm_quit: Display a quit 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)) # Check if starting up from main thread; if not, wait; finally raise exception if current_thread().name == 'MainThread': uid = 'master' if not _initialized: _initialize_imports() localization.update(strings) else: uid = 'child_' + uuid4().hex[:8] if not _webview_ready.wait(5): raise Exception('Call create_window from the main thread first') _webview_ready.clear( ) # Make API calls wait while the new window is created gui.create_window(uid, make_unicode(title), transform_url(url), width, height, resizable, fullscreen, min_size, confirm_quit, background_color, debug, js_api, text_select, frameless, _webview_ready) if uid == 'master': _webview_ready.clear() else: return uid
def create_window(title, url=None, html=None, js_api=None, width=800, height=600, x=None, y=None, resizable=True, fullscreen=False, min_size=(200, 100), hidden=False, frameless=False, minimized=False, on_top=False, confirm_close=False, background_color='#FFFFFF', text_select=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 hidden: Whether the window should be hidden. :param frameless: Whether the window should have a frame. :param minimized: Display window minimized :param on_top: Keep window above other windows (required OS: Windows) :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. :return: window object. """ 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, x, y, resizable, fullscreen, min_size, hidden, frameless, minimized, on_top, confirm_close, background_color, js_api, text_select) windows.append(window) if threading.current_thread().name != 'MainThread' and guilib: window._initialize(guilib, _multiprocessing, _http_server) guilib.create_window(window) return window
def load_url(self, url): """ Load a new URL into a previously created WebView window. This function must be invoked after WebView windows is created with create_window(). Otherwise an exception is thrown. :param url: url to load :param uid: uid of the target instance """ if self._httpd: self._httpd.shutdown() self._httpd = None url = transform_url(url) if (self._httpd or self.gui.renderer == 'edgehtml') and url.startswith('file://'): url, self._httpd = start_server(url) self.gui.load_url(url, self.uid)
def __init__(self, uid, title, url, html, width, height, resizable, fullscreen, min_size, confirm_close, background_color, js_api, text_select, frameless): self.uid = uid self.title = make_unicode(title) self.url = None if html else transform_url(url) self.html = html self.width = width self.height = height self.resizable = resizable self.fullscreen = fullscreen self.min_size = min_size self.confirm_close = confirm_close self.background_color = background_color self.js_api = js_api self.text_select = text_select self.frameless = frameless self.loaded = Event() self.shown = Event() self.gui = None