def __get_new_view(self, webview, parent): """ Get a new view @param parent as webview @param webview as WebView @return View """ view = View(webview, parent) view.webview.connect("map", self.on_view_map) view.webview.connect("notify::estimated-load-progress", self.__on_estimated_load_progress) view.webview.connect("load-changed", self.__on_load_changed) view.webview.connect("button-press-event", self.__on_button_press) view.webview.connect("uri-changed", self.__on_uri_changed) view.webview.connect("title-changed", self.__on_title_changed) view.webview.connect("enter-fullscreen", self.__on_enter_fullscreen) view.webview.connect("leave-fullscreen", self.__on_leave_fullscreen) view.webview.connect("readable", self.__on_readable) view.webview.connect("new-page", self.__on_new_page) view.webview.connect("create", self.__on_create) view.webview.connect("close", self.__on_close) view.webview.connect("save-password", self.__on_save_password) view.webview.connect("script-dialog", self.__on_script_dialog) view.webview.connect("insecure-content-detected", self.__on_insecure_content_detected) view.show() return view
def __get_new_view(self, webview): """ Get a new view @param webview as WebView @return View """ view = View(webview, self.__window) view.show() return view
def popup_webview(self, webview, destroy): """ Show webview in popopver @param webview as WebView @param destroy webview when popover hidden """ view = View(webview, self.__window, True) view.show() self.__popover.add_view(view, destroy) if not self.__popover.is_visible(): self.__popover.set_relative_to(self.__window.toolbar) self.__popover.set_position(Gtk.PositionType.BOTTOM) self.__popover.popup()
def add_webview(self, uri, window_type, ephemeral=False, parent=None, state=None, load=True): """ Add a web view to container @param uri as str @param window_type as Gdk.WindowType @param parent as View @param ephemeral as bool @param state as WebViewSessionState """ webview = View.get_new_webview(ephemeral) view = self.__get_new_view(webview, parent) if state is not None: webview.restore_session_state(state) view.show() self.__add_view(view, window_type) if uri is not None: if load: # Do not load uri until we are on screen GLib.idle_add(webview.load_uri, uri) else: webview.set_delayed_uri(uri) webview.emit("title-changed", uri)
def popup_webview(self, webview, destroy): """ Show webview in popopver @param webview as WebView @param destroy webview when popover hidden """ view = View(webview, None, self.__window) view.show() self.__popover.add_view(view, destroy) if not self.__popover.is_visible(): self.__popover.set_size_request( self.__window.get_allocated_width() / 3, self.__window.get_allocated_height() / 1.5) self.__popover.set_relative_to(self.__window.toolbar) self.__popover.set_position(Gtk.PositionType.BOTTOM) self.__popover.popup()
def add_webview(self, uri, loading_type, ephemeral=False, state=None, atime=None): """ Add a webview to container @param uri as str @param loading_type as Gdk.LoadingType @param ephemeral as bool @param state as WebViewSessionState @param atime as int @return WebView """ webview = View.get_new_webview(ephemeral, self.__window) if atime is not None: webview.set_atime(atime) if state is not None: webview.restore_session_state(state) if uri is not None: webview.set_uri(uri) # Force loading if loading_type == LoadingType.BACKGROUND or self.in_expose: webview.load_uri(uri) self.add_webview_with_new_view(webview, loading_type) return webview
def __on_ready_to_show(self, webview): """ Add view to window @param webview as WebView """ view = View(webview.private, None, webview) view.show() popover = Gtk.Popover.new() popover.add(view) popover.set_relative_to(self.__window.toolbar) popover.set_position(Gtk.PositionType.BOTTOM) popover.set_size_request(self.__window.get_allocated_width() / 3, self.__window.get_allocated_height() / 1.5) view.webview.connect("close", lambda x: popover.destroy()) popover.connect("closed", lambda x: view.webview.destroy()) popover.show()
def __get_webview(self, ephemeral): """ Get a new webview @param ephemeral as bool @return WebView """ if self.__preloaded and not ephemeral: webview = self.__preloaded.pop(0) else: webview = View.get_new_webview(ephemeral, self.__window) return webview
def __preload_webviews(self): """ Preload some webviews """ self.__preload_timeout_id = None # Ignore stupid values if self.__preloaded_max < 1 or self.__preloaded_max > 20: return webview = View.get_new_webview(False, self.__window) self.__preloaded.append(webview) if len(self.__preloaded) < self.__preloaded_max: return True