From 407ca6b4ed2357ed6d35cd93ee3191761a9b65c5 Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Tue, 8 Sep 2020 13:15:06 -0500 Subject: show response status in statusbar --- browser.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/browser.py b/browser.py index 16f1c29..625f4b1 100755 --- a/browser.py +++ b/browser.py @@ -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 = '

{} {}

'.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()) -- cgit v1.2.3