qutebrowser / qutebrowser

A keyboard-driven, vim-like browser based on Python and Qt.
https://www.qutebrowser.org/
GNU General Public License v3.0
9.69k stars 1.01k forks source link

Support arbitrary QWidgets as browser tabs #724

Open The-Compiler opened 9 years ago

The-Compiler commented 9 years ago

Just noticed there wasn't an open issue for this yet.

There should probably some Tab class which is the class of all tabs in the TabbedBrowser.

Then there could be a WebViewTab or so which is the glue between a QWebView and that tab "protocol" (in the Python sense of protocol), and there could also be some kind of WidgetTab or ScrollAreaTab or so.

This will also be useful for #666, then there can be a WebEngineViewTab.

qute:settings and others should then probably migrate to that instead of using a web page (cc @iggy)

The-Compiler commented 9 years ago

I spent some time finding out how to create a wrapper widget for QWebView so it's completely decoupled - this is what works:

from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication, QWidget, QLayout
from PyQt5.QtWebKitWidgets import QWebView

class WrapperLayout(QLayout):

    def __init__(self, widget, parent=None):
        super().__init__(parent)
        self._widget = widget

    def addItem(self, w):
        assert False

    def sizeHint(self):
        return self._widget.sizeHint()

    def itemAt(self, i):
        assert False

    def takeAt(self, i):
        assert False

    def setGeometry(self, r):
        self._widget.setGeometry(r)

class Wrapper(QWidget):

    def __init__(self, widget, parent=None):
        super().__init__(parent)
        self._layout = WrapperLayout(widget, self)
        self._widget = widget
        widget.setParent(self)

app = QApplication([])
wv = QWebView()
w = Wrapper(wv)
w.show()
w._widget.load(QUrl('http://cmpl.cc/'))

app.exec_()

Now the next question is what the API of this will look like, and what functionality the rest of the code needs.

iggy commented 9 years ago

Use cases I can think of: configuration/settings downloads (eventually) plugins view source (most other browsers have this, not sure it'd be a requirement though) developer tools informational (qute:version, etc) bookmarks release notes?

The-Compiler commented 9 years ago

Thanks for the useful list!

For display-only things (qute:version, release notes) I guess a webpage is preferable/easier.

:view-source already exists and uses pygments to generate HTML, so that should be fine as well.

The-Compiler commented 8 years ago

https://github.com/dhamaniasad/HeadlessBrowsers has some inspiration for APIs probably