def load_changed(self, webview, state): if state == WebKit2.LoadEvent.STARTED: Bus.emit("trigger_website_loading") finished = state == WebKit2.LoadEvent.FINISHED if not finished: return self.www.run_javascript_from_gresource('/hn/js/Readability.js', None, self._loaded_readability, None)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.old_child = None self.setup_styles() self.set_default_size(360, 720) self.show_all() Bus.on("open_thread", self.set_thread) Bus.on("open_website", self.set_website)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # https://stackoverflow.com/questions/60126579/gtk-builder-error-quark-invalid-object-type-webkitwebview # Can't have the WevView in ui file without hacks, doing it programatically is clearer ctx = WebKit2.WebContext.get_default() ctx.set_web_extensions_directory(WEBEXT_DIR) self.www = WebKit2.WebView.new_with_context(ctx) self.www.connect('load-changed', self.load_changed) self.www.set_hexpand(True) self.www.set_vexpand(True) self.add(self.www) Bus.on("trigger_readability", self.convert_to_readable) Bus.on("open_website", self.load_uri) Bus.on("trigger_stop_website", self.www.stop_loading)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) Bus.on("open_website", lambda url, title: self.page_title.set_label(title)) Bus.on("trigger_website_loading", self.readable_toggle.hide) Bus.on("website_can_be_readable", self.readable_toggle.show)
def do_activate(self): self.window = AppWindow(application=self, title="Hacker News") self.window.present() Bus.emit("refresh_news_list")
def activate_link(self, label, link): Bus.emit("open_website", url=link, title="FIX TITLE") return True
def title_click(self, event): Bus.emit("open_website", url=self.article_url, title=self.thread_title)
def comments_click(self, event): Bus.emit("open_thread", story=self.story)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) Bus.on("open_thread", self.async_load_thread)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) Bus.on("open_thread", self.set_story_details)
def on_refresh(self, event): Bus.emit("refresh_news_list")
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) Bus.on('refresh_news_list', self.async_refresh)
def on_readerable_result(self, webview, result, user_data): result = self.www.run_javascript_finish(result) if result.get_js_value().to_boolean(): Bus.emit("website_can_be_readable") print('making visible', flush=True)
def back_click(self, event): Bus.emit("trigger_stop_website") # FIXME window = self.get_toplevel() window.pop_website()
def readability_click(self, event): self.readable_toggle.hide() Bus.emit("trigger_readability")