0

Pyqt5 QtWebEngineWidgets | Problem.

There is a website (https://sites.google.com/view/aerlis-page-sites/).

If you open the site, then everything is OK. But if you try to open the site by clicking on the button open site on the site. She won't work anymore. No matter how hard I try. Button does not work. How can I fix this problem?

There is another problem if you open Spotify, for example, there will be an error at the entrance. I don't know why but the site refuses to work. Can you help me solve this problem too?

code :

from turtle import down
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtPrintSupport import *
from PyQt5 import QtGui
import os, sys, pyperclip, re
 
class MainWindow(QMainWindow):
 
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        self.browser = QWebEngineView()
        self.browser.settings().setAttribute(
            QWebEngineSettings.FullScreenSupportEnabled, True
        )
        self.browser.setUrl(QUrl("http://google.com"))
        self.browser.urlChanged.connect(self.update_urlbar)
        self.browser.loadFinished.connect(self.update_title)
        self.setCentralWidget(self.browser)
        self.status = QStatusBar()
        self.setStatusBar(self.status)

        

        self.browser.page().fullScreenRequested.connect(
            lambda request, browser=self.browser: self.handle_fullscreen_requested(
                request, browser = self.browser
            )
        )

        
        

        self.navtb = QToolBar("Navigation")
        self.navtb2 = QToolBar("Url")

        self.addToolBar(self.navtb)
        self.addToolBar(self.navtb2)
 
        back_btn = QAction("", self)
        back_btn.setStatusTip("Back to previous page")
        back_btn.triggered.connect(self.browser.back)
        self.navtb.addAction(back_btn)
 
        next_btn = QAction("", self)
        next_btn.setStatusTip("Forward to next page")
        next_btn.triggered.connect(self.browser.forward)
        self.navtb.addAction(next_btn)
 
        reload_btn = QAction("⥁", self)
        reload_btn.setStatusTip("Reload page")
        reload_btn.triggered.connect(self.browser.reload)
        self.navtb.addAction(reload_btn)
 
        home_btn = QAction("Home", self)
        home_btn.setStatusTip("Go home")
        home_btn.triggered.connect(self.navigate_home)
        self.navtb.addAction(home_btn)

        self.navtb.addSeparator()#_____

        ytb_btn = QAction("Youtube", self)
        ytb_btn.setStatusTip("Go youtube")
        ytb_btn.triggered.connect(self.navigate_youtube)
        self.navtb.addAction(ytb_btn)

        n_a_tv_btn = QAction("Not Alone TV", self)
        n_a_tv_btn.setStatusTip("Watch a movie in a place with a friend online on the site Alone TV")
        n_a_tv_btn.triggered.connect(self.navigate_not_alone_tv)
        self.navtb.addAction(n_a_tv_btn)

        rezka_btn = QAction("Rezka", self)
        rezka_btn.setStatusTip("Go watch free films in Rezka")
        rezka_btn.triggered.connect(self.navigate_rezka)
        self.navtb.addAction(rezka_btn)

        Sweet_btn = QAction("Sweet Tv", self)
        Sweet_btn.setStatusTip("Go Sweet Tv")
        Sweet_btn.triggered.connect(self.navigate_sveet_tv)
        self.navtb.addAction(Sweet_btn)
 
        Copy_btn = QAction("[Copy]", self)
        Copy_btn.setStatusTip("Copy URL")
        Copy_btn.triggered.connect(self.Copy_url)
        self.navtb2.addAction(Copy_btn)

        Paste_btn = QAction("[Paste]", self)
        Paste_btn.setStatusTip("Open copied url if it's a link")
        Paste_btn.triggered.connect(self.Paste_url)
        self.navtb2.addAction(Paste_btn)

        self.urlbar = QLineEdit()
        self.urlbar.returnPressed.connect(self.navigate_to_url)
        self.navtb2.addWidget(self.urlbar)

 
        self.showMaximized()
 
    def update_title(self):
        title = self.browser.page().title()
        self.setWindowTitle("Aerlis Browser - % s" % title)
    
    def handle_fullscreen_requested(self, request, browser):
            request.accept()
            if request.toggleOn():
                #self.showFullScreen()
                self.statusBar().hide()
                self.navtb.hide()
                self.navtb2.hide()
            else:
                #self.showMaximized()
                self.navtb.show()
                self.navtb2.show()
                self.statusBar().show()
 
    def navigate_home(self):
        self.browser.setUrl(QUrl("https://www.google.com"))
 
    def navigate_youtube(self):
        self.browser.setUrl(QUrl("https://www.youtube.com"))

    def navigate_not_alone_tv(self):
        self.browser.setUrl(QUrl("https://notalone.tv"))

    def navigate_rezka(self):
        self.browser.setUrl(QUrl("https://rezka.ag/"))

    def navigate_sveet_tv(self):
        self.browser.setUrl(QUrl("https://sweet.tv"))

    def Copy_url(self):
        print('Coppied : ', self.urlbar.text())
        pyperclip.copy(self.urlbar.text())

    def Paste_url(self):
        l = re.findall("(?P<url>https?://[^\s]+)", pyperclip.paste())
        if l != []:
            self.browser.setUrl(QUrl(l[0]))

    def navigate_to_url(self):
        q = QUrl(self.urlbar.text())
        if q.scheme() == "":
            q.setScheme("https://")
        self.browser.setUrl(q)

    
 
    def update_urlbar(self, q):
        self.urlbar.setText(q.toString())
        self.urlbar.setCursorPosition(0)

    

app = QApplication(sys.argv)
 
app.setApplicationName("Aerlis Browser")
app.setWindowIcon(QtGui.QIcon('files/browser_icon.png'))
window = MainWindow()
app.exec_()
Latte
  • 5
  • 2
  • 1
    QWebEngineView cannot create new windows on its own: how should the new window be created? Where? And if you want to use tabs, how could it know about that? What if you have a custom browser that needs custom window features, like menus and toolbars? You have to implement it on your own, by overriding [`createWindow()`](https://doc.qt.io/qt-5/qwebengineview.html#createWindow). – musicamante Oct 01 '22 at 19:49

0 Answers0