Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Enabling Extensions on PyQt
Forum Updated to NodeBB v4.3 + New Features

Enabling Extensions on PyQt

Scheduled Pinned Locked Moved Unsolved Qt WebKit
9 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Slim Shady
    wrote on 24 Oct 2021, 19:19 last edited by
    #1

    Hi, I've been trying to make a browser in PyQt and I would like to be able to get extensions for it.
    Any tips are helpful!
    Thanks in advance!
    Here is the code:

    import sys
    from PyQt5.QtCore import *
    from PyQt5.QtWidgets import *
    from PyQt5.QtWebEngineWidgets import *
    
    
    class MainWindow(QMainWindow):
        def __init__(self):
            super(MainWindow, self).__init__()
            self.browser = QWebEngineView()
            self.browser.setUrl(QUrl('http://google.com'))
            self.tab_wgt = QTabWidget()
            self.tab_wgt.addTab(self.browser, "home")
            self.tab_wgt.setTabsClosable(True)
            self.tab_wgt.tabCloseRequested.connect(lambda i: self.tab_wgt.removeTab(i))
            self.tab_wgt.currentChanged.connect(self.tab_changed)
            self.setCentralWidget(self.tab_wgt)
            self.showMaximized()
    
            # nav bar
            navbar = QToolBar()
            self.addToolBar(navbar)
    
            back_btn = QAction('Back', self)
            back_btn.triggered.connect(self.browser.back)
            navbar.addAction(back_btn)
    
            forward_btn = QAction('Forward', self)
            forward_btn.triggered.connect(self.browser.forward)
            navbar.addAction(forward_btn)
    
            reload_btn = QAction('Reload', self)
            reload_btn.triggered.connect(self.browser.reload)
            navbar.addAction(reload_btn)
    
            home_btn = QAction('Home', self)
            home_btn.triggered.connect(self.navigate_home)
            navbar.addAction(home_btn)
    
            new_btn = QAction('New Tab', self)
            new_btn.triggered.connect(self.newtab)
            navbar.addAction(new_btn)
    
            self.url_bar = QLineEdit()
            self.url_bar.returnPressed.connect(self.navigate_to_url)
            navbar.addWidget(self.url_bar)
    
            self.browser.urlChanged.connect(self.update_url)
    
        def navigate_home(self):
            self.browser.setUrl(QUrl('http://google.com'))
    
        def newtab(self):
            browser = QWebEngineView()
            self.tab_wgt.addTab(browser, "about:blank")
            self.tab_wgt.setCurrentWidget(browser)
            self.url_bar.setText("about:blank")
            browser.titleChanged.connect(self.update_title)
            browser.urlChanged.connect(self.update_url)
    
        def tab_changed(self, i):
            browser: QWebEngineView = self.tab_wgt.widget(i)
            if browser:
                text = browser.url().toString()
                if text:
                    self.url_bar.setText(text)
                else:
                    self.url_bar.setText("about:blank")
    
        def navigate_to_url(self):
            if "https://www." in self.url_bar.text():
                url = self.url_bar.text()
            else:
                url = "https://www." + self.url_bar.text()
            browser: QWebEngineView = self.tab_wgt.currentWidget()
            browser.setUrl(QUrl(url))
    
        def update_url(self, url):
            self.url_bar.setText(url.toString())
    
        def update_title(self, title):
            self.tab_wgt.setTabText(self.tab_wgt.currentIndex(), title)
    
    class WebPage(QWebEnginePage):
    
        adblocker = Filter(open('easylist.txt', encoding="utf8"))
    
        def __init__(self, parent=None):
            super().__init__(parent)
    
        def acceptNavigationRequest(self, url,  _type, isMainFrame):
    
            urlString = url.toString()
            resp = False
            resp = WebPage.adblocker.match(url.toString())
    
            if resp:
                print("Blocking url --- "+url.toString())
                return False
            else:
                print("TYPE", _type)
                return True
    
            return QWebEnginePage.acceptNavigationRequest(self, url,  _type, isMainFrame)
    
    
    
    app = QApplication(sys.argv)
    QApplication.setApplicationName("Jeswwws")
    window = MainWindow()
    app.exec_()
    
    
    E 1 Reply Last reply 24 Oct 2021, 19:23
    0
    • S Slim Shady
      24 Oct 2021, 19:19

      Hi, I've been trying to make a browser in PyQt and I would like to be able to get extensions for it.
      Any tips are helpful!
      Thanks in advance!
      Here is the code:

      import sys
      from PyQt5.QtCore import *
      from PyQt5.QtWidgets import *
      from PyQt5.QtWebEngineWidgets import *
      
      
      class MainWindow(QMainWindow):
          def __init__(self):
              super(MainWindow, self).__init__()
              self.browser = QWebEngineView()
              self.browser.setUrl(QUrl('http://google.com'))
              self.tab_wgt = QTabWidget()
              self.tab_wgt.addTab(self.browser, "home")
              self.tab_wgt.setTabsClosable(True)
              self.tab_wgt.tabCloseRequested.connect(lambda i: self.tab_wgt.removeTab(i))
              self.tab_wgt.currentChanged.connect(self.tab_changed)
              self.setCentralWidget(self.tab_wgt)
              self.showMaximized()
      
              # nav bar
              navbar = QToolBar()
              self.addToolBar(navbar)
      
              back_btn = QAction('Back', self)
              back_btn.triggered.connect(self.browser.back)
              navbar.addAction(back_btn)
      
              forward_btn = QAction('Forward', self)
              forward_btn.triggered.connect(self.browser.forward)
              navbar.addAction(forward_btn)
      
              reload_btn = QAction('Reload', self)
              reload_btn.triggered.connect(self.browser.reload)
              navbar.addAction(reload_btn)
      
              home_btn = QAction('Home', self)
              home_btn.triggered.connect(self.navigate_home)
              navbar.addAction(home_btn)
      
              new_btn = QAction('New Tab', self)
              new_btn.triggered.connect(self.newtab)
              navbar.addAction(new_btn)
      
              self.url_bar = QLineEdit()
              self.url_bar.returnPressed.connect(self.navigate_to_url)
              navbar.addWidget(self.url_bar)
      
              self.browser.urlChanged.connect(self.update_url)
      
          def navigate_home(self):
              self.browser.setUrl(QUrl('http://google.com'))
      
          def newtab(self):
              browser = QWebEngineView()
              self.tab_wgt.addTab(browser, "about:blank")
              self.tab_wgt.setCurrentWidget(browser)
              self.url_bar.setText("about:blank")
              browser.titleChanged.connect(self.update_title)
              browser.urlChanged.connect(self.update_url)
      
          def tab_changed(self, i):
              browser: QWebEngineView = self.tab_wgt.widget(i)
              if browser:
                  text = browser.url().toString()
                  if text:
                      self.url_bar.setText(text)
                  else:
                      self.url_bar.setText("about:blank")
      
          def navigate_to_url(self):
              if "https://www." in self.url_bar.text():
                  url = self.url_bar.text()
              else:
                  url = "https://www." + self.url_bar.text()
              browser: QWebEngineView = self.tab_wgt.currentWidget()
              browser.setUrl(QUrl(url))
      
          def update_url(self, url):
              self.url_bar.setText(url.toString())
      
          def update_title(self, title):
              self.tab_wgt.setTabText(self.tab_wgt.currentIndex(), title)
      
      class WebPage(QWebEnginePage):
      
          adblocker = Filter(open('easylist.txt', encoding="utf8"))
      
          def __init__(self, parent=None):
              super().__init__(parent)
      
          def acceptNavigationRequest(self, url,  _type, isMainFrame):
      
              urlString = url.toString()
              resp = False
              resp = WebPage.adblocker.match(url.toString())
      
              if resp:
                  print("Blocking url --- "+url.toString())
                  return False
              else:
                  print("TYPE", _type)
                  return True
      
              return QWebEnginePage.acceptNavigationRequest(self, url,  _type, isMainFrame)
      
      
      
      app = QApplication(sys.argv)
      QApplication.setApplicationName("Jeswwws")
      window = MainWindow()
      app.exec_()
      
      
      E Offline
      E Offline
      eyllanesc
      wrote on 24 Oct 2021, 19:23 last edited by
      #2

      @Slim-Shady If you mean chrome extensions then it is not possible because that does not implement chromium.

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      S 1 Reply Last reply 24 Oct 2021, 19:30
      0
      • E eyllanesc
        24 Oct 2021, 19:23

        @Slim-Shady If you mean chrome extensions then it is not possible because that does not implement chromium.

        S Offline
        S Offline
        Slim Shady
        wrote on 24 Oct 2021, 19:30 last edited by
        #3

        @eyllanesc Not only Chrome extensions, any browser as long as it at least has any kind of ad blocker

        E 1 Reply Last reply 24 Oct 2021, 19:33
        0
        • S Slim Shady
          24 Oct 2021, 19:30

          @eyllanesc Not only Chrome extensions, any browser as long as it at least has any kind of ad blocker

          E Offline
          E Offline
          eyllanesc
          wrote on 24 Oct 2021, 19:33 last edited by
          #4

          @Slim-Shady One thing is the adblock and another the extensions. An adblock can be implemented through extensions. On the other hand, extensions are popular so each browser implements it but it is not a technology that chromium implements. If you want to implement an ad blocker then check https://stackoverflow.com/questions/53330056/pyqt5-pyside2-adblock/53330741#53330741

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          S 1 Reply Last reply 24 Oct 2021, 19:45
          2
          • E eyllanesc
            24 Oct 2021, 19:33

            @Slim-Shady One thing is the adblock and another the extensions. An adblock can be implemented through extensions. On the other hand, extensions are popular so each browser implements it but it is not a technology that chromium implements. If you want to implement an ad blocker then check https://stackoverflow.com/questions/53330056/pyqt5-pyside2-adblock/53330741#53330741

            S Offline
            S Offline
            Slim Shady
            wrote on 24 Oct 2021, 19:45 last edited by
            #5

            @eyllanesc Thanks for that. I've checked it out but I don't know how to implement it with my code. Could you give me a hand, please?

            E 1 Reply Last reply 24 Oct 2021, 19:50
            0
            • S Slim Shady
              24 Oct 2021, 19:45

              @eyllanesc Thanks for that. I've checked it out but I don't know how to implement it with my code. Could you give me a hand, please?

              E Offline
              E Offline
              eyllanesc
              wrote on 24 Oct 2021, 19:50 last edited by
              #6

              @Slim-Shady In my answer there is a complete example, I do not know what more help you are waiting for, bye. Try something and when something fails then just ask for help. Bye.

              If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

              1 Reply Last reply
              1
              • S Offline
                S Offline
                Slim Shady
                wrote on 25 Oct 2021, 12:57 last edited by
                #7

                Yes, I've seen the example, I just don't know how to make it run with my code. That's the "more help" that I need.

                E 1 Reply Last reply 25 Oct 2021, 13:06
                0
                • S Slim Shady
                  25 Oct 2021, 12:57

                  Yes, I've seen the example, I just don't know how to make it run with my code. That's the "more help" that I need.

                  E Offline
                  E Offline
                  eyllanesc
                  wrote on 25 Oct 2021, 13:06 last edited by
                  #8

                  @Slim-Shady I expect some effort on the part of the OP, if there is not then he does not ask for help but wants them to do their work so he must pay for it. So it's one thing to help and another to want them to work for you for free.

                  If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Slim Shady
                    wrote on 25 Oct 2021, 13:51 last edited by
                    #9

                    I'm sorry if that's how you see it, but I don't want you to do the work for me, I just need a little help.

                    1 Reply Last reply
                    0

                    1/9

                    24 Oct 2021, 19:19

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved