widgets.webview: Add a cur_url property so the initial URL is available immediately.
This commit is contained in:
parent
f6b26f0d56
commit
157975b0d4
3
doc/BUGS
3
doc/BUGS
@ -15,9 +15,6 @@ Downloads
|
||||
Webview
|
||||
-------
|
||||
|
||||
- Concept of "current URL" should work better before urlChanged is emitted,
|
||||
e.g. loading a page and immediately yanking the (non-resolved) URL should
|
||||
work.
|
||||
- Hint positions wrong in wordpress admin interface
|
||||
- Rightclick -> Copy link copies relative links
|
||||
- F on duckduckgo result page opens in current page
|
||||
|
@ -482,7 +482,8 @@ class Application(QApplication):
|
||||
return pages
|
||||
for tab in self.mainwindow.tabs.widgets:
|
||||
try:
|
||||
url = tab.url().toString()
|
||||
# FIXME should that be encoded?
|
||||
url = tab.cur_url.toString()
|
||||
if url:
|
||||
pages.append(url)
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
@ -594,7 +595,8 @@ class Application(QApplication):
|
||||
if pages is None:
|
||||
pages = []
|
||||
for tab in self.mainwindow.tabs.widgets:
|
||||
urlstr = tab.url().toString()
|
||||
# FIXME should that be encoded?
|
||||
urlstr = tab.cur_url.toString()
|
||||
if urlstr:
|
||||
pages.append(urlstr)
|
||||
log.destroy.debug("sys.executable: {}".format(sys.executable))
|
||||
|
@ -201,5 +201,5 @@ class UrlText(TextBase):
|
||||
def on_tab_changed(self, tab):
|
||||
"""Update URL if the tab changed."""
|
||||
self.hover_url = None
|
||||
self.normal_url = tab.url_text
|
||||
self.normal_url = tab.cur_url.toDisplayString()
|
||||
self.on_load_status_changed(tab.load_status.name)
|
||||
|
@ -200,7 +200,7 @@ class TabbedBrowser(TabWidget):
|
||||
Raise:
|
||||
CommandError if the current URL is invalid.
|
||||
"""
|
||||
url = self.currentWidget().url()
|
||||
url = self.currentWidget().cur_url
|
||||
try:
|
||||
qt_ensure_valid(url)
|
||||
except QtValueError as e:
|
||||
@ -257,10 +257,9 @@ class TabbedBrowser(TabWidget):
|
||||
self._now_focused = None
|
||||
if tab is self.last_focused:
|
||||
self.last_focused = None
|
||||
url = tab.url()
|
||||
if not url.isEmpty():
|
||||
qt_ensure_valid(url)
|
||||
self.url_stack.append(url)
|
||||
if not tab.cur_url.isEmpty():
|
||||
qt_ensure_valid(tab.cur_url)
|
||||
self.url_stack.append(tab.cur_url)
|
||||
tab.shutdown()
|
||||
self._tabs.remove(tab)
|
||||
self.removeTab(idx)
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
"""The main browser widgets."""
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer, QUrl
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtWebKit import QWebSettings
|
||||
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
||||
@ -58,8 +58,7 @@ class WebView(QWebView):
|
||||
inspector: The QWebInspector used for this webview.
|
||||
open_target: Where to open the next tab ("normal", "tab", "tab_bg")
|
||||
_page: The QWebPage behind the view
|
||||
_url_text: The current URL as string.
|
||||
Accessed via url_text property.
|
||||
_cur_url: The current URL (accessed via cur_url property).
|
||||
_load_status: loading status of this page (index into LoadStatus)
|
||||
Accessed via load_status property.
|
||||
_has_ssl_errors: Whether SSL errors occured during loading.
|
||||
@ -99,7 +98,8 @@ class WebView(QWebView):
|
||||
self._zoom = None
|
||||
self._has_ssl_errors = False
|
||||
self._init_neighborlist()
|
||||
self._url_text = ''
|
||||
self._cur_url = None
|
||||
self.cur_url = QUrl()
|
||||
self.progress = 0
|
||||
self._page = BrowserPage(self)
|
||||
self.setPage(self._page)
|
||||
@ -153,19 +153,22 @@ class WebView(QWebView):
|
||||
self.load_status_changed.emit(val.name)
|
||||
|
||||
@property
|
||||
def url_text(self):
|
||||
"""Getter for url_text."""
|
||||
return self._url_text
|
||||
def cur_url(self):
|
||||
"""Getter for cur_url so we can define a setter."""
|
||||
return self._cur_url
|
||||
|
||||
@url_text.setter
|
||||
def url_text(self, val):
|
||||
"""Setter for url_text.
|
||||
@cur_url.setter
|
||||
def cur_url(self, url):
|
||||
"""Setter for cur_url to emit a signal..
|
||||
|
||||
Arg:
|
||||
url: The new URL as a QUrl.
|
||||
|
||||
Emit:
|
||||
url_text_changed
|
||||
url_text_changed: Always emitted.
|
||||
"""
|
||||
self._url_text = val
|
||||
self.url_text_changed.emit(val)
|
||||
self._cur_url = url
|
||||
self.url_text_changed.emit(url.toDisplayString())
|
||||
|
||||
def _init_neighborlist(self):
|
||||
"""Initialize the _zoom neighborlist."""
|
||||
@ -300,7 +303,7 @@ class WebView(QWebView):
|
||||
urlstr = url.toDisplayString()
|
||||
log.webview.debug("New title: {}".format(urlstr))
|
||||
self.titleChanged.emit(urlstr)
|
||||
self.url_text = urlstr
|
||||
self.cur_url = url
|
||||
return self.load(url)
|
||||
|
||||
def zoom_perc(self, perc, fuzzyval=True):
|
||||
@ -352,9 +355,9 @@ class WebView(QWebView):
|
||||
|
||||
@pyqtSlot('QUrl')
|
||||
def on_url_changed(self, url):
|
||||
"""Update url_text when URL has changed."""
|
||||
"""Update cur_url when URL has changed."""
|
||||
qt_ensure_valid(url)
|
||||
self.url_text = url.toDisplayString()
|
||||
self.cur_url = url
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def on_config_changed(self, section, option):
|
||||
|
Loading…
Reference in New Issue
Block a user