diff options
-rwxr-xr-x | browser.py | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -9,6 +9,7 @@ import gemini class GViewport(QtWidgets.QTextBrowser): hoverUrlChanged = QtCore.Signal(str) + resourceLoadedStatus = QtCore.Signal(str) def __init__(self, address_bar): self.address_bar = address_bar @@ -18,7 +19,8 @@ class GViewport(QtWidgets.QTextBrowser): def mouseMoveEvent(self, event): cur = self.cursorForPosition(event.localPos().toPoint()) hover_url = cur.charFormat().anchorHref() - hover_url = gemini.urljoin(self.address_bar.text(), hover_url) + if hover_url: + hover_url = gemini.urljoin(self.address_bar.text(), hover_url) if hover_url != self._hover_url: self._hover_url = hover_url self.hoverUrlChanged.emit(self._hover_url) @@ -30,6 +32,7 @@ class GViewport(QtWidgets.QTextBrowser): html = gemini.gem2html(gem['body']) else: html = '<h1>{} {}</h1>'.format(gem['status'], gem['meta']) + self.resourceLoadedStatus.emit('{status} {meta}'.format(status=gem['status'], meta=gem['meta'])) return html def setRawSource(self): @@ -50,7 +53,8 @@ class GBrowser(QtWidgets.QMainWindow): self.init_ui() def init_ui(self): - self.statusBar().showMessage('Ready') + request_status = QtWidgets.QLabel() + self.statusBar().addWidget(request_status) back = QtWidgets.QPushButton("back") forward = QtWidgets.QPushButton("forward") @@ -66,7 +70,8 @@ class GBrowser(QtWidgets.QMainWindow): forward.clicked.connect(browser.forward) browser.sourceChanged.connect(address.setUrl) address.returnPressed.connect(browser.setRawSource) - browser.hoverUrlChanged.connect(self.statusBar().showMessage) + browser.hoverUrlChanged.connect(self.set_status_url) + browser.resourceLoadedStatus.connect(request_status.setText) self.addToolBar(toolbar) self.setCentralWidget(browser) @@ -79,6 +84,12 @@ class GBrowser(QtWidgets.QMainWindow): self.setWindowTitle('Gemini Browser') self.show() + def set_status_url(self, url): + if url: + self.statusBar().showMessage(url) + else: + self.statusBar().clearMessage() + def closeEvent(self, event): settings = QtCore.QSettings("xcolour.net", "GeminiBrowser") settings.setValue("geometry", self.saveGeometry()) |