def __init__(self, *args, **kwargs): self.c = kwargs['c'] del kwargs['c'] super().__init__(*args, **kwargs) # were we opened by an @ rich node? Calling code will set self.at_rich = False # are we being closed by leaving an @ rich node? Calling code will set self.at_rich_close = False # read settings. self.reloadSettings() # load HTML template template_path = g.os_path_join(g.computeLeoDir(), 'plugins', 'cke_template.html') self.template = open(template_path).read() path = g.os_path_join(g.computeLeoDir(), 'external', 'ckeditor') self.template = self.template.replace( '[CKEDITOR]', QtCore.QUrl.fromLocalFile(path).toString()) # make widget containing QWebView self.setLayout(QtWidgets.QVBoxLayout()) self.layout().setSpacing(0) self.layout().setContentsMargins(0, 0, 0, 0) # enable inspector, if this really is QtWebKit if real_webkit: QtWebKit.QWebSettings.globalSettings().setAttribute( QtWebKit.QWebSettings.DeveloperExtrasEnabled, True) self.webview = QtWebKitWidgets.QWebView() self.layout().addWidget(self.webview) g.registerHandler('select3', self.select_node) g.registerHandler('unselect1', self.unselect_node) # load current node self.select_node('', {'c': self.c, 'new_p': self.c.p})
def create_ui(self): self.w = w = QtWidgets.QWidget() w.setWindowTitle("Leo search") lay = QtWidgets.QVBoxLayout() self.web = web = QtWebKitWidgets.QWebView(w) self.web.linkClicked.connect(self._lnk_handler) self.led = led = QtWidgets.QLineEdit(w) led.returnPressed.connect(self.docmd) lay.addWidget(led) lay.addWidget(web) self.lc = lc = LeoConnector() web.page().mainFrame().addToJavaScriptWindowObject("leo",lc) web.page().setLinkDelegationPolicy(QtWebKitWidgets.QWebPage.DelegateAllLinks) w.setLayout(lay) #web.load(QUrl("http://google.fi")) self.show_help() # w.show() def help_handler(tgt,qs): if qs == "help": self.show_help() return True return False self.add_cmd_handler(help_handler) self.led.setFocus()
def update_jupyter(self, s, keywords): '''Update @jupyter node in the vr pane.''' pc = self c = pc.c if pc.must_change_widget(QtWebKitWidgets.QWebView): # g.trace('===== instantiating QWebView') w = QtWebKitWidgets.QWebView() n = c.config.getInt('qweb_view_font_size') if n: settings = w.settings() settings.setFontSize(settings.DefaultFontSize, n) pc.embed_widget(w) assert(w == pc.w) else: w = pc.w url = g.getUrlFromNode(c.p) if url and nbformat: s = urlopen(url).read().decode() try: nb = nbformat.reads(s, as_version=4) e = HTMLExporter() (s, junk_resources) = e.from_notebook_node(nb) except nbformat.reader.NotJSONError: # Assume the result is html. pass elif url: s = 'can not import nbformt: %r' % url else: s = g.u('') if isQt5: w.hide() # This forces a proper update. w.setHtml(s) w.show() c.bodyWantsFocusNow()
def update_latex(self, s, keywords): '''Update latex in the vr pane.''' import sys pc = self c = pc.c if g.isPython3 and sys.platform.startswith('win'): g.es_print('latex rendering not ready for Python 3') w = pc.ensure_text_widget() pc.show() w.setPlainText(s) c.bodyWantsFocusNow() else: if pc.must_change_widget(QtWebKitWidgets.QWebView): w = QtWebKitWidgets.QWebView() n = c.config.getInt('qweb_view_font_size') if n: settings = w.settings() settings.setFontSize(settings.DefaultFontSize, n) pc.embed_widget(w) assert (w == pc.w) else: w = pc.w w.hide() # This forces a proper update. s = self.create_latex_html(s) w.setHtml(s) w.show() c.bodyWantsFocusNow()
def __init__(self, *args, **kwargs): self.c = kwargs['c'] del kwargs['c'] QtWidgets.QWidget.__init__(self, *args, **kwargs) # were we opened by an @ rich node? Calling code will set self.at_rich = False # are we being closed by leaving an @ rich node? Calling code will set self.at_rich_close = False # read autosave preference if not hasattr(self.c, '_ckeeditor_autosave'): auto = self.c.config.getBool("richtext_cke_autosave") or False self.c._ckeeditor_autosave = auto if auto: g.es("NOTE: automatic saving of rich text edits") # load HTML template template_path = g.os_path_join( g.computeLeoDir(), 'plugins', 'cke_template.html', ) self.template = open(template_path).read() path = g.os_path_join(g.computeLeoDir(), 'external', 'ckeditor') self.template = self.template.replace( '[CKEDITOR]', QtCore.QUrl.fromLocalFile(path).toString()) # load config self.config = self.c.config.getData("richtext_cke_config") if self.config: self.config = '\n'.join(self.config).strip() # make widget containing QWebView self.setLayout(QtWidgets.QVBoxLayout()) self.layout().setSpacing(0) self.layout().setContentsMargins(0, 0, 0, 0) # enable inspector QtWebKit.QWebSettings.globalSettings().setAttribute( QtWebKit.QWebSettings.DeveloperExtrasEnabled, True) self.webview = QtWebKitWidgets.QWebView() self.layout().addWidget(self.webview) g.registerHandler('select3', self.select_node) g.registerHandler('unselect1', self.unselect_node) # load current node self.select_node('', {'c': self.c, 'new_p': self.c.p})
def init (): '''Return True if the plugin has loaded successfully.''' ok = g.app.gui.guiName() == "qt" if ok: try: QtWebKitWidgets.QWebView(None) except AttributeError: print('bigdash.py: QWebView must be installed') ok = False if ok: g.app._global_search = GlobalSearch() g.plugin_signon(__name__) return ok
def create_ui(self): self.w = w = QtWidgets.QWidget() w.setWindowTitle("Leo search") lay = QtWidgets.QVBoxLayout() if (not QtWebKitWidgets # Workaround #1114: https://github.com/leo-editor/leo-editor/issues/1114 or isQt5 and sys.platform.startswith('win') # Workaround #304: https://github.com/leo-editor/leo-editor/issues/304 ): self.web = web = QtWidgets.QTextBrowser(w) else: self.web = web = QtWebKitWidgets.QWebView(w) try: # PyQt4 self.web.linkClicked.connect(self._lnk_handler) # AttributeError: 'QWebEngineView' object has no attribute 'linkClicked' except AttributeError: # PyQt5 pass # Not clear what to do. self.led = led = QtWidgets.QLineEdit(w) led.returnPressed.connect(self.docmd) lay.addWidget(led) lay.addWidget(web) self.lc = lc = LeoConnector() try: web.page().mainFrame().addToJavaScriptWindowObject("leo", lc) web.page().setLinkDelegationPolicy( QtWebKitWidgets.QWebPage.DelegateAllLinks) except AttributeError: # PyQt5 pass # Not clear what to do. w.setLayout(lay) #web.load(QUrl("http://google.fi")) self.show_help() # w.show() def help_handler(tgt, qs): if qs == "help": self.show_help() return True return False self.add_cmd_handler(help_handler) self.led.setFocus()
def update_html(self, s, keywords): '''Update html in the vr pane.''' pc = self c = pc.c if pc.must_change_widget(QtWebKitWidgets.QWebView): # g.trace('===== instantiating QWebView') w = QtWebKitWidgets.QWebView() n = c.config.getInt('qweb_view_font_size') if n: settings = w.settings() settings.setFontSize(settings.DefaultFontSize, n) pc.embed_widget(w) assert(w == pc.w) else: w = pc.w if isQt5: w.hide() # This forces a proper update. w.setHtml(s) w.show() c.bodyWantsFocusNow()