def __init__(self, parent = None): QWebEngineSettings.globalSettings().setAttribute(QWebEngineSettings.PluginsEnabled,True) super().__init__(parent) self.mSrcUrl = "" self.mMaxWidth = 720 self.mMaxHeight = 480 self.baseUrl = "local" self.mLayout = QVBoxLayout(self) self.mLayout.setContentsMargins(0, 0, 0, 0) self.mLayout.setSpacing(0) self.mWebView = QWebEngineView(self) self.mWebView.setContentsMargins(0, 0, 0, 0) self.mWebView.settings().setAttribute(QWebEngineSettings.FullScreenSupportEnabled, True) self.mWebView.page().fullScreenRequested.connect(lambda request: request.accept()) self.mLayout.addWidget(self.mWebView) self.setWindowFlags(Qt.FramelessWindowHint) self.setFixedSize(self.mMaxWidth + 20, self.mMaxHeight + 20) self.setObjectName("YTB") self.setStyleSheet("#YTB{background-color: white; border: 1px solid lightgrey;}") self.setAutoFillBackground(True) self.setContentsMargins(0, 0, 0, 0) self.show()
def setup_markdown_editor(self): self.renderers = {} self.fallback_renderer = PlainRenderer() self.add_renderer(self.fallback_renderer) self.add_renderer(MarkdownRenderer()) self.add_renderer(ReSTRenderer()) # Set up Markdown editor self.setup_lexer() self.setup_scintilla(self.ui.markdownEditor) # Set up our custom page to open external links in a browser page = CustomWebPage(self) self.ui.markdownPreview.setPage(page) QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.FocusOnNavigationEnabled, False) # self.ui.markdownPreview. # Set up the web channel to intercept clicks on links channel = QWebChannel(self) self.channel_proxy = WebChannelProxy(self) channel.registerObject("proxy", self.channel_proxy) page.setWebChannel(channel) self.channel_proxy.link_clicked.connect(self.link_clicked) # Set up HTML preview self.ui.htmlPreview.setLexer(QsciLexerHTML()) # Connect signals self.ui.actionUndo.triggered.connect(self.undo) self.ui.actionRedo.triggered.connect(self.redo) self.ui.actionSave.triggered.connect(self.save_article) self.ui.actionCommit.triggered.connect(self.commit_article) self.ui.actionEdit.toggled.connect(self.edit_toggled) self.ui.actionFullscreen.triggered.connect(self.show_fullscreen_editor) self.ui.actionAutoLink.triggered.connect(self.auto_link_word) self.ui.actionAutoLinkAll.triggered.connect(self.auto_link_all) self.ui.markdownEditor.installEventFilter(self) # Load Github style style_file = QFile(':/styles/github.css') style_file.open(QIODevice.ReadOnly) self.style = QTextStream(style_file).readAll() style_file.close() self.current_article = None self.ui.markdownEditor.hide() self.ui.actionUndo.setEnabled(False) self.ui.actionRedo.setEnabled(False) self.update_toolbar()
def youtube_search(self,data): query = "" for i in data: query += i query += '+' #print(query[:-1]) QWebEngineSettings.globalSettings().setAttribute(QWebEngineSettings.PluginsEnabled, True) search = "https://www.youtube.com/results?search_query="+ query[:-1] #search = "https://www.google.com/maps/dir/Lane+No+12,+Dhaka+1216/Govt.+Teachers'+Training+College,+New+Market+-+Pilkhana+Rd,+Dhaka+1205" self.widget(search)
def __init__(self, parent=QtWidgets.QWidget): QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.PluginsEnabled, True) super(window, self).__init__(parent) self.webview = QtWebEngineWidgets.QWebEngineView(self) self.webview.setUrl( QUrl("https://www.youtube.com/embed/TMG461qFrAE?autoplay=1")) self.webview.setGeometry(0, 0, 500, 300) self.show()
def __init__(self): QWebEngineView.__init__(self) # Flash 등을 사용하기 위해서 Plugin 사용을 허락 QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.PluginsEnabled, True); # 로컬파일 사용시 절대경로만 사용해야 함 url = QDir().current().filePath( "html/QWebEngineView_10_plugin_enabled.html") url = QUrl.fromLocalFile(url) self.setUrl(url)
def __init__(self): QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.PluginsEnabled, True) super(window, self).__init__() self.centralwid = QtWidgets.QWidget(self) self.vlayout = QtWidgets.QVBoxLayout() self.webview = QtWebEngineWidgets.QWebEngineView() self.webview.setUrl( QUrl("https://www.youtube.com/watch?v=Mq4AbdNsFVw")) self.vlayout.addWidget(self.webview) self.centralwid.setLayout(self.vlayout) self.setCentralWidget(self.centralwid) self.show()
def setJS2(self): self.settings = QWebSettings.globalSettings() self.settings.setAttribute(QWebSettings.LocalContentCanAccessFileUrls, True) self.settings.setAttribute( QWebSettings.LocalContentCanAccessRemoteUrls, True) self.settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
def setJS(self): self.settings = QWebSettings.globalSettings() # self.settings.setAttribute(QWebSettings.JavascriptEnabled, True) self.settings.setAttribute(QWebSettings.LocalContentCanAccessFileUrls, True) self.settings.setAttribute( QWebSettings.LocalContentCanAccessRemoteUrls, True)
def set_default_font(font, size): fontDataBase = QFontDatabase() defaultSettings = QWebEngineSettings.globalSettings() standardFont = fontDataBase.font(font, "", 12) defaultSettings.setFontFamily(QWebEngineSettings.StandardFont, standardFont.family()) defaultSettings.setFontSize(QWebEngineSettings.DefaultFontSize, size)
def default_font(which): s = QWebEngineSettings.defaultSettings() which = getattr(s, { 'serif': 'SerifFont', 'sans': 'SansSerifFont', 'mono': 'FixedFont' }[which]) return s.fontFamily(which)
def default_font(which): from PyQt5.QtWebEngineWidgets import QWebEngineSettings s = QWebEngineSettings.defaultSettings() which = getattr(s, { 'serif': 'SerifFont', 'sans': 'SansSerifFont', 'mono': 'FixedFont' }[which]) return s.fontFamily(which)
def createWindow(self, QWebPage_WebWindowType): webview = BrowserEngineView(self.mainWindow) tab = BrowserTab(self.mainWindow) webview.settings().setAttribute( QWebEngineSettings.FullScreenSupportEnabled, True) webview.settings().setAttribute(QWebEngineSettings.JavascriptEnabled, True) webview.settings().setAttribute(QWebEngineSettings.PluginsEnabled, True) QWebEngineSettings.defaultSettings().setAttribute( QWebEngineSettings.PluginsEnabled, True) QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.PluginsEnabled, True) tab.browser = webview tab.setCentralWidget(tab.browser) self.tabs.append(tab) self.mainWindow.add_new_tab(tab) return webview
def __init__(self, conf_path, args, instance_name="default"): QApplication.__init__(self, args) self.__class__.INSTANCE = self self.instance_name = instance_name if (version.opengl_vendor() == 'nouveau' and not (os.environ.get('LIBGL_ALWAYS_SOFTWARE') == '1' or 'QT_XCB_FORCE_SOFTWARE_OPENGL' in os.environ)): sys.exit("You are using the nouveau graphics driver but it" " has issues with multithreaded opengl. You must" " use another driver or set the variable environment" " QT_XCB_FORCE_SOFTWARE_OPENGL to force software" " opengl. Note that it might be slow, depending" " on your hardware.") if version.is_mac: self.setAttribute(Qt.AA_MacDontSwapCtrlAndMeta) self._conf_path = conf_path if not os.path.isdir(self.profiles_path()): os.makedirs(self.profiles_path()) self._interceptor = UrlInterceptor(self) self._download_manager = DownloadManager(self) self.profile = default_profile() self.profile.enable(self) settings = QWebEngineSettings.globalSettings() settings.setAttribute( QWebEngineSettings.LinksIncludedInFocusChain, False, ) settings.setAttribute( QWebEngineSettings.PluginsEnabled, True, ) settings.setAttribute( QWebEngineSettings.FullScreenSupportEnabled, True, ) settings.setAttribute( QWebEngineSettings.JavascriptCanOpenWindows, True, ) if version.min_qt_version >= (5, 8): settings.setAttribute( QWebEngineSettings.FocusOnNavigationEnabled, False, ) self.installEventFilter(LOCAL_KEYMAP_SETTER) self.setQuitOnLastWindowClosed(False) self.network_manager = QNetworkAccessManager(self)
def __init__(self, parent=None): super().__init__(parent) # 클래스 기본 설정 path = os.getcwd() + '/support/webplayer.html' file = open(path, 'r', encoding="UTF8") self.html = file.read() file.close() NotificationCenter.subscribe(NotificationName.play, self.play) QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.PluginsEnabled, True) QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.JavascriptEnabled, True) # UI 설정 self.setHtml(self.html) self.web_channel = QWebChannel(self) self.web_channel.registerObject('handler', self) self.page().setWebChannel(self.web_channel)
def _create_web_engine_view(self, parent, object_name: str) -> QWebEngineView : web_engine_view = MyQWebEngineView(parent, lambda e: self._on_drop(e), self._dev_mode) settings = QWebEngineSettings.defaultSettings() settings.setAttribute(QWebEngineSettings.LocalContentCanAccessRemoteUrls, True) web_engine_view.setAutoFillBackground(False) web_engine_view.setStyleSheet("") web_engine_view.setUrl(QtCore.QUrl("about:blank")) web_engine_view.setObjectName(object_name) web_engine_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) # 禁用右键菜单 return web_engine_view
def scaleMe(self): fontSize = self.mdiParent.fontSize settings = QWebEngineSettings.globalSettings() settings.setFontSize(QWebEngineSettings.DefaultFontSize, floor(fontSize * 1.6)) scaleFactor = self.mdiParent.scaleFactor windowWidth = 800 * scaleFactor windowHeight = 580 * scaleFactor self.resize(windowWidth, windowHeight)
def update_settings(self): settings = QWebEngineSettings.globalSettings() try: settings.setAttribute( QWebEngineSettings.PluginsEnabled, self.emacs_var_dict["eaf-browser-enable-plugin"] == "true") settings.setAttribute( QWebEngineSettings.JavascriptEnabled, self.emacs_var_dict["eaf-browser-enable-javascript"] == "true") except Exception: pass
def initUI(self): self.setWindowFlags(QtCore.Qt.FramelessWindowHint) self.setGeometry(0, 0, 800, 480) self.setWindowTitle("PyAlarm") self.setWindowIcon(QIcon("pyalarm.png")) self.mousePressEvent = self.__windowClicked self.background = QLabel(self) self.background.setGeometry(0, 0, 800, 480) self.background.setPixmap( QPixmap( "C:\\Users\\V-Modder\\projects\\pyalarm\\pyalarm\\pyalarm.png") ) self.time = QLabel(self) self.time.setGeometry(122, 50, 250, 50) self.time.setText("00:00") font = QFont("SansSerif", pointSize=45) font.setBold(True) self.time.setFont(font) self.time.setObjectName("time") self.time.setStyleSheet("QLabel#time {color: white}") self.calender = QCalendarWidget(self) self.calender.setGeometry(50, 130, 320, 250) self.calender.setEnabled(False) self.timer = QTimer() self.timer.timeout.connect(self.__timerTick) self.timer.start(1000) settings = QWebEngineSettings.globalSettings() settings.setAttribute(QWebEngineSettings.ShowScrollBars, False) settings.setAttribute(QWebEngineSettings.ErrorPageEnabled, False) self.browser = QWebEngineView(self) self.browser.load(QUrl(self.LIBREELEC_URL)) self.browser.setGeometry(410, 10, 380, 460) self.browser.loadFinished.connect(self.__browserLoadFinished) self.contextButton = StripedButton(self) self.contextButton.setGeometry(3, 3, 50, 50) self.contextButton.clicked.connect(self.__contextClicked) self.__contextMenu = ContextMenu(self) self.__contextMenu.show() self.__contextMenu.setVisible(False) self.__alarmWidget = AlarmWidget(self) self.__alarmWidget.show() self.__alarmWidget.setVisible(False) self.show()
def initSettings(self): """ eg: 初始化设置 """ # 获取浏览器默认设置 settings = QWebEngineSettings.globalSettings() # 设置默认编码utf8 settings.setDefaultTextEncoding("utf-8") # 自动加载图片,默认开启 # settings.setAttribute(QWebEngineSettings.AutoLoadImages,True) # 自动加载图标,默认开启 # settings.setAttribute(QWebEngineSettings.AutoLoadIconsForPage,True) # 开启js,默认开启 # settings.setAttribute(QWebEngineSettings.JavascriptEnabled,True) # js可以访问剪贴板 settings.setAttribute(QWebEngineSettings.JavascriptCanAccessClipboard, True) # js可以打开窗口,默认开启 # settings.setAttribute(QWebEngineSettings.JavascriptCanOpenWindows,True) # 链接获取焦点时的状态,默认开启 # settings.setAttribute(QWebEngineSettings.LinksIncludedInFocusChain,True) # 本地储存,默认开启 # settings.setAttribute(QWebEngineSettings.LocalStorageEnabled,True) # 本地访问远程 settings.setAttribute( QWebEngineSettings.LocalContentCanAccessRemoteUrls, True) # 本地加载,默认开启 # settings.setAttribute(QWebEngineSettings.LocalContentCanAccessFileUrls,True) # 监控负载要求跨站点脚本,默认关闭 # settings.setAttribute(QWebEngineSettings.XSSAuditingEnabled,False) # 空间导航特性,默认关闭 # settings.setAttribute(QWebEngineSettings.SpatialNavigationEnabled,False) # 支持平超链接属性,默认关闭 # settings.setAttribute(QWebEngineSettings.HyperlinkAuditingEnabled,False) # 使用滚动动画,默认关闭 settings.setAttribute(QWebEngineSettings.ScrollAnimatorEnabled, True) # 支持错误页面,默认启用 # settings.setAttribute(QWebEngineSettings.ErrorPageEnabled, True) # 支持插件,默认关闭 settings.setAttribute(QWebEngineSettings.PluginsEnabled, True) # 支持全屏应用程序,默认关闭 settings.setAttribute(QWebEngineSettings.FullScreenSupportEnabled, True) # 支持屏幕截屏,默认关闭 settings.setAttribute(QWebEngineSettings.ScreenCaptureEnabled, True) # 支持html5 WebGl,默认开启 settings.setAttribute(QWebEngineSettings.WebGLEnabled, True) # 支持2d绘制,默认开启 settings.setAttribute(QWebEngineSettings.Accelerated2dCanvasEnabled, True) # 支持图标触摸,默认关闭 settings.setAttribute(QWebEngineSettings.TouchIconsEnabled, True)
def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.resize(600, 400) layout = QHBoxLayout(self) # 左侧 widgetLeft = QWidget(self) layoutLeft = QVBoxLayout(widgetLeft) # 右侧 self.widgetRight = QListWidget(self, minimumWidth=200, iconSize=QSize(150, 150)) self.widgetRight.setViewMode(QListWidget.IconMode) layout.addWidget(widgetLeft) layout.addWidget(self.widgetRight) self.webView = QWebEngineView() layoutLeft.addWidget(self.webView) # 截图方式一 groupBox1 = QGroupBox('截图方式一', self) layout1 = QVBoxLayout(groupBox1) layout1.addWidget(QPushButton('截图1', self, clicked=self.onScreenShot1)) layoutLeft.addWidget(groupBox1) # 截图方式二(采用js) groupBox2 = QGroupBox('截图方式二', self) layout2 = QVBoxLayout(groupBox2) self.codeEdit = QLineEdit( 'body', groupBox2, placeholderText='请输入需要截图的元素、ID或者class:如body、#id .class') layout2.addWidget(self.codeEdit) self.btnMethod2 = QPushButton('', self, clicked=self.onScreenShot2, enabled=False) layout2.addWidget(self.btnMethod2) layoutLeft.addWidget(groupBox2) # 提供访问接口 self.channel = QWebChannel(self) # 把自身对象传递进去 self.channel.registerObject('_self', self) # 设置交互接口 self.webView.page().setWebChannel(self.channel) # 支持截图 settings = QWebEngineSettings.globalSettings() settings.setAttribute(QWebEngineSettings.ScreenCaptureEnabled, True) self.webView.loadStarted.connect(self.onLoadStarted) self.webView.loadFinished.connect(self.onLoadFinished) self.webView.load(QUrl("https://pyqt.site"))
def valider(self): parameters = self.parent.parent.dbConnection.executewithreturn( """SELECT * FROM parameters""") self.parent.parent.dbConnection.executewithoutreturn( """UPDATE parameters SET home = ? WHERE id = ?""", (self.urlAccueil.text(), parameters[0][0])) self.parent.parent.dbConnection.executewithoutreturn( """UPDATE parameters SET moteur = ? WHERE id = ?""", (self.listeMoteur[self.moteurBox.currentIndex()], parameters[0][0])) self.parent.parent.dbConnection.executewithoutreturn( """UPDATE parameters SET js = ? WHERE id = ?""", (self.listejs[self.jsbox.currentIndex()], parameters[0][0])) if self.listejs[self.jsbox.currentIndex()] == "Activé": QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.JavascriptEnabled, True) else: QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.JavascriptEnabled, False) QMessageBox().about( self, "Enregistrement fait", "L'enregistrement des paramètres a été fait sans problème")
def initUi(self): self.progressBar.hide() self.showMaximized() self.tabWidget.tabCloseRequested.connect(self.closeTab) self.tabWidget.currentChanged.connect(self.tabChange) self.view = NewWebView(self) self.view.load(QUrl("{}".format(self.web))) self.newTab(self.view) self.lineEdit.installEventFilter(self) self.lineEdit.setMouseTracking(True) settings = QWebEngineSettings.defaultSettings() settings.setAttribute(QWebEngineSettings.PluginsEnabled, True) self.getModel()
def map_search(self,origin,destination): orgn = "" dest = "" for i in origin: orgn += i orgn += '+' #print(orgn[:-1]) for i in destination: dest += i dest += '+' #print(dest[:-1]) map_url ="https://www.google.com/maps/dir/" QWebEngineSettings.globalSettings().setAttribute(QWebEngineSettings.PluginsEnabled, True) search = map_url + origin + '/'+destination response = requests.get( 'https://maps.googleapis.com/maps/api/directions/json?origin=mirpur+10&destination=dhanmondi+27&key=AIzaSyBl0LiJQvtWY97ZCcT5myjiRyP6W7iV6vE') json_data = json.loads(response.text) s = json_data['routes'][0]["legs"][0]["steps"] clean_text = [] #print(len(json_data['routes'][0]["legs"][0]["steps"])) for i in range(len(json_data['routes'][0]["legs"][0]["steps"])): clean_text.append(((((s[i]['html_instructions']).replace('<b>', '')).replace('</b>', '')).replace( '<div style="font-size:0.9em">', ' ')).replace('</div>', '')+'.') #print('clean text',clean_text) c = '' raw_text = [] for i in range(len(clean_text)): k = clean_text[i] for j in range(len(k)): if k[j] != ' ' : c += k[j] else: raw_text.append(c) c = '' raw_text.append(c) self.widget(search) return raw_text
def __init__(self, args): QApplication.__init__(self, args) self.__class__.INSTANCE = self if (opengl_vendor() == 'nouveau' and not (os.environ.get('LIBGL_ALWAYS_SOFTWARE') == '1' or 'QT_XCB_FORCE_SOFTWARE_OPENGL' in os.environ)): sys.exit("You are using the nouveau graphics driver but it" " has issues with multithreaded opengl. You must" " use another driver or set the variable environment" " QT_XCB_FORCE_SOFTWARE_OPENGL to force software" " opengl. Note that it might be slow, depending" " on your hardware.") with open(os.path.join(THIS_DIR, "app_style.css")) as f: self.setStyleSheet(f.read()) self._setup_conf_paths() self._adblock_thread = None self._interceptor = UrlInterceptor(self) self.adblock_update() self._download_manager = DownloadManager(self) self.profile = default_profile() self.profile.enable(self) self.aboutToQuit.connect(self.profile.save_session) self.installEventFilter(GLOBAL_EVENT_FILTER) settings = QWebEngineSettings.globalSettings() settings.setAttribute( QWebEngineSettings.LinksIncludedInFocusChain, False, ) settings.setAttribute( QWebEngineSettings.PluginsEnabled, True, ) settings.setAttribute( QWebEngineSettings.FullScreenSupportEnabled, True, ) settings.setAttribute( QWebEngineSettings.JavascriptCanOpenWindows, True, ) _app_requires()
def __init__(self, browserwin, *args, **kwargs): # Strip out arguments we handle that are different from QMainWindow: if 'width' in kwargs: self.width = kwargs['width'] del kwargs['width'] else: self.width = 1024 if 'height' in kwargs: self.height = kwargs['height'] del kwargs['height'] else: self.height = 768 if 'parent' in kwargs: super().__init__(kwargs['parent']) else: super().__init__() self.settings().defaultSettings().setDefaultTextEncoding("utf-8") QWebEngineSettings.globalSettings().setAttribute( QWebEngineSettings.FullScreenSupportEnabled, True) self.browser_win = browserwin self.installEventFilter(self) # ICK! I can't find any way to intercept a middle click and get # the URL under the mouse during the click. But we do get hover # events -- so if we always record the last hovered URL, # then when we see a middleclick we can load that URL. self.last_hovered = None # Another ICK -- there's no reliable way to get URL loading # errors, so we'll store URLs we try to load, and compare # after load_finished to see if we're in the right place. self.try_url = None
def __init__(self): # QWebView self.view = QWebEngineView.__init__(self) self.setWindowTitle('Loading...') self.titleChanged.connect(self.adjustTitle) settings = QWebEngineSettings.globalSettings() settings.setAttribute(QWebEngineSettings.AllowRunningInsecureContent, True) settings.setAttribute(QWebEngineSettings.PluginsEnabled, True) settings.setAttribute(QWebEngineSettings.HyperlinkAuditingEnabled, True) settings.setAttribute( QWebEngineSettings.LocalContentCanAccessRemoteUrls, True)
def __init__(self, browserwin, *args, **kwargs): # Strip out arguments we handle that are different from QMainWindow: if 'width' in kwargs: self.width = kwargs['width'] del kwargs['width'] else: self.width = 1024 if 'height' in kwargs: self.height = kwargs['height'] del kwargs['height'] else: self.height = 768 if 'parent' in kwargs: super(BrowserView, self).__init__(kwargs['parent']) else: super(BrowserView, self).__init__() self.settings().defaultSettings().setDefaultTextEncoding("utf-8") QWebEngineSettings.globalSettings().setAttribute(QWebEngineSettings.FullScreenSupportEnabled, True) self.browser_win = browserwin self.installEventFilter(self) # ICK! I can't find any way to intercept a middle click and get # the URL under the mouse during the click. But we do get hover # events -- so if we always record the last hovered URL, # then when we see a middleclick we can load that URL. self.last_hovered = None # Another ICK -- there's no reliable way to get URL loading # errors, so we'll store URLs we try to load, and compare # after load_finished to see if we're in the right place. self.try_url = None
def __init__(self, parent=None): super().__init__(parent) self.settings = QWebEngineSettings.globalSettings() self.settings.setAttribute( QWebEngineSettings.LocalContentCanAccessFileUrls, True) self.settings.setAttribute( QWebEngineSettings.LocalContentCanAccessRemoteUrls, True) # self.settings.setAttribute(QWebEngineSettings.DeveloperExtrasEnabled, True ) # nam = QNetworkAccessManager() page = QWebEnginePage(self) # page.setNetworkAccessManager(nam) self.setPage(page) self.loadFinished.connect(self.onLoadFinish) self.setUrl(QUrl(self.pdf_viewer_page))
def __init__(self, args): QApplication.__init__(self, args) self.__class__.INSTANCE = self if (opengl_vendor() == 'nouveau' and not (os.environ.get('LIBGL_ALWAYS_SOFTWARE') == '1' or 'QT_XCB_FORCE_SOFTWARE_OPENGL' in os.environ)): sys.exit("You are using the nouveau graphics driver but it" " has issues with multithreaded opengl. You must" " use another driver or set the variable environment" " QT_XCB_FORCE_SOFTWARE_OPENGL to force software" " opengl. Note that it might be slow, depending" " on your hardware.") self._setup_conf_paths() self._interceptor = UrlInterceptor(self) self._download_manager = DownloadManager(self) self.profile = default_profile() self.profile.enable(self) settings = QWebEngineSettings.globalSettings() settings.setAttribute( QWebEngineSettings.LinksIncludedInFocusChain, False, ) settings.setAttribute( QWebEngineSettings.PluginsEnabled, True, ) settings.setAttribute( QWebEngineSettings.FullScreenSupportEnabled, True, ) settings.setAttribute( QWebEngineSettings.JavascriptCanOpenWindows, True, ) self.installEventFilter(LOCAL_KEYMAP_SETTER) self.setQuitOnLastWindowClosed(False) self.network_manager = QNetworkAccessManager(self) _app_requires()
def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict): BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, False, QColor(255, 255, 255, 255)) self.config_dir = config_dir # When arguments is "temp_html_file", browser will load content of html file, then delete temp file. # Usually use for render html mail. if arguments == "temp_html_file": with open(url, "r") as html_file: self.buffer_widget.setHtml(html_file.read()) if os.path.exists(url): os.remove(url) else: self.buffer_widget.setUrl(QUrl(url)) self.history_log_file_path = os.path.join(self.config_dir, "browser", "history", "log.txt") self.history_url_pattern = re.compile("(.*?)\s([^\s]+)$") self.buffer_widget.titleChanged.connect(self.record_history) self.buffer_widget.titleChanged.connect(self.change_title) self.buffer_widget.translate_selected_text.connect(self.translate_text) self.buffer_widget.open_url_in_new_tab.connect( self.open_url_in_new_tab) self.buffer_widget.open_url_in_background_tab.connect( self.open_url_in_background_tab) # Reset to default zoom when page init or url changed. self.reset_default_zoom() self.buffer_widget.urlChanged.connect( lambda url: self.reset_default_zoom()) settings = QWebEngineSettings.globalSettings() try: settings.setAttribute( QWebEngineSettings.PluginsEnabled, self.emacs_var_dict["eaf-browser-enable-plugin"] == "true") settings.setAttribute( QWebEngineSettings.JavascriptEnabled, self.emacs_var_dict["eaf-browser-enable-javascript"] == "true") except Exception: pass
def _click_js(self, _click_target): settings = QWebEngineSettings.globalSettings() attribute = QWebEngineSettings.JavascriptCanOpenWindows could_open_windows = settings.testAttribute(attribute) settings.setAttribute(attribute, True) # Get QtWebEngine do apply the settings # (it does so with a 0ms QTimer...) # This is also used in Qt's tests: # https://github.com/qt/qtwebengine/commit/5e572e88efa7ba7c2b9138ec19e606d3e345ac90 qapp = QApplication.instance() qapp.processEvents(QEventLoop.ExcludeSocketNotifiers | QEventLoop.ExcludeUserInputEvents) def reset_setting(_arg): settings.setAttribute(attribute, could_open_windows) self._js_call('click', callback=reset_setting)
def __init__(self, parent=None): QWebEngineView.__init__(self, parent) self.settings = QWebEngineSettings.globalSettings() self.settings.setAttribute(QWebEngineSettings.LocalContentCanAccessFileUrls, True)
def disableJS(self): settings = QWebEngineSettings.globalSettings() settings.setAttribute(QWebEngineSettings.JavascriptEnabled, False)