Fix some other small bugs with new signal implementation

This commit is contained in:
Florian Bruhin 2014-05-15 22:31:01 +02:00
parent a70aa212e0
commit b91274cfcf
5 changed files with 43 additions and 21 deletions

2
TODO
View File

@ -59,8 +59,6 @@ Improvements / minor features
- configurable warning when closing window with multiple tabs open
- Hide statusbar messages after timeout, not on keypress
- Reimplement tabbar to paint it by ourselves to look like dwb
- We probably should rewrite all the signal cache stuff to save state
internally instead. (also see bugs)
- Save cookies in Netscape format so it can be used by wget.
http://www.cookiecentral.com/faq/#3.5
https://docs.python.org/3.4/library/http.cookies.html

View File

@ -408,7 +408,7 @@ class QuteBrowser(QApplication):
tabs.cur_statusbar_message.connect(status.txt.on_statusbar_message)
tabs.currentChanged.connect(status.url.on_tab_changed)
tabs.cur_url_changed.connect(status.url.set_url)
tabs.cur_url_text_changed.connect(status.url.set_url)
tabs.cur_link_hovered.connect(status.url.set_hover_url)
# command input / completion

View File

@ -62,7 +62,7 @@ class TabbedBrowser(TabWidget):
cur_load_finished: Current tab finished loading (loadFinished)
cur_statusbar_message: Current tab got a statusbar message
(statusBarMessage)
cur_url_changed: Current URL changed (urlChanged)
cur_url_text_changed: Current URL text changed.
cur_link_hovered: Link hovered in current tab (linkHovered)
cur_scroll_perc_changed: Scroll percentage of current tab changed.
arg 1: x-position in %.
@ -80,7 +80,7 @@ class TabbedBrowser(TabWidget):
cur_load_started = pyqtSignal()
cur_load_finished = pyqtSignal(bool)
cur_statusbar_message = pyqtSignal(str)
cur_url_changed = pyqtSignal('QUrl')
cur_url_text_changed = pyqtSignal(str)
cur_link_hovered = pyqtSignal(str, str, str)
cur_scroll_perc_changed = pyqtSignal(int, int)
hint_strings_updated = pyqtSignal(list)
@ -144,8 +144,9 @@ class TabbedBrowser(TabWidget):
self._filter.create(self.cur_statusbar_message))
tab.scroll_pos_changed.connect(
self._filter.create(self.cur_scroll_perc_changed))
tab.urlChanged.connect(self.on_url_changed)
tab.urlChanged.connect(self._filter.create(self.cur_url_changed))
tab.url_text_changed.connect(
self._filter.create(self.cur_url_text_changed))
tab.url_text_changed.connect(self.on_url_text_changed)
# hintmanager
tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated)
tab.hintmanager.openurl.connect(self.cur.openurl_slot)
@ -234,12 +235,10 @@ class TabbedBrowser(TabWidget):
tab = WebView(self)
self._connect_tab_signals(tab)
self._tabs.append(tab)
self.addTab(tab, "")
if url is not None:
url = urlutils.qurl(url)
self.addTab(tab, "")
tab.openurl(url)
else:
self.addTab(tab, "")
if background is None:
background = config.get('general', 'background-tabs')
if not background:
@ -489,7 +488,7 @@ class TabbedBrowser(TabWidget):
@pyqtSlot()
def on_load_started(self, tab):
"""Clear signal cache and icon when a tab started loading.
"""Clear icon when a tab started loading.
Args:
tab: The tab where the signal belongs to.
@ -511,12 +510,12 @@ class TabbedBrowser(TabWidget):
else:
logging.debug("ignoring title change")
@pyqtSlot('QUrl')
def on_url_changed(self, url):
@pyqtSlot(str)
def on_url_text_changed(self, url):
"""Set the new URL as title if there's no title yet."""
idx = self.indexOf(self.sender())
if not self.tabText(idx):
self.setTabText(idx, urlutils.urlstring(url))
self.setTabText(idx, url)
@pyqtSlot()
def on_icon_changed(self):
@ -537,7 +536,7 @@ class TabbedBrowser(TabWidget):
@pyqtSlot(int)
def on_current_changed(self, idx):
"""Set last_focused and replay signal cache if focus changed."""
"""Set last_focused when focus changed."""
tab = self.widget(idx)
self.last_focused = self.now_focused
self.now_focused = tab

View File

@ -112,9 +112,9 @@ class Url(TextBase):
"""Setter to be used as a Qt slot.
Args:
s: The URL to set.
s: The URL to set as string.
"""
self.setText(urlstring(s))
self.setText(s)
self.urltype = 'normal'
@pyqtSlot(str, str, str)
@ -146,7 +146,7 @@ class Url(TextBase):
def on_tab_changed(self, idx):
"""Update URL if the tab changed."""
tab = self.sender().widget(idx)
self.setText(urlstring(tab.url()))
self.setText(tab.url_text)
status = LoadStatus[tab.load_status]
if status in ['success', 'error', 'warn']:
self.urltype = status

View File

@ -54,7 +54,8 @@ class WebView(QWebView):
work.
progress: loading progress of this page.
scroll_pos: The current scroll position as (x%, y%) tuple.
url: The current URL as QUrl.
_url_text: The current URL as string.
Accessed via url_text 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.
@ -72,11 +73,13 @@ class WebView(QWebView):
arg 2: y-position in %.
linkHovered: QWebPages linkHovered signal exposed.
load_status_changed: The loading status changed
url_text_changed: Current URL string changed.
"""
scroll_pos_changed = pyqtSignal(int, int)
linkHovered = pyqtSignal(str, str, str)
load_status_changed = pyqtSignal(str)
url_text_changed = pyqtSignal(str)
def __init__(self, parent):
super().__init__(parent)
@ -91,6 +94,7 @@ class WebView(QWebView):
self._zoom = None
self._has_ssl_errors = False
self._init_neighborlist()
self._url_text = ''
self.progress = 0
self.page_ = BrowserPage(self)
self.setPage(self.page_)
@ -101,6 +105,7 @@ class WebView(QWebView):
self.page_.linkHovered.connect(self.linkHovered)
self.linkClicked.connect(self.on_link_clicked)
self.page_.mainFrame().loadStarted.connect(self.on_load_started)
self.urlChanged.connect(self.on_url_changed)
self.loadFinished.connect(self.on_load_finished)
self.loadProgress.connect(lambda p: setattr(self, 'progress', p))
self.page_.networkAccessManager().sslErrors.connect(
@ -122,6 +127,21 @@ class WebView(QWebView):
self._load_status = val
self.load_status_changed.emit(LoadStatus[val])
@property
def url_text(self):
"""Getter for url_text."""
return self._url_text
@url_text.setter
def url_text(self, val):
"""Setter for url_text.
Emit:
url_text_changed
"""
self._url_text = val
self.url_text_changed.emit(val)
def _init_neighborlist(self):
"""Initialize the _zoom neighborlist."""
self._zoom = NeighborList(
@ -256,7 +276,7 @@ class WebView(QWebView):
Return status of self.load
Emit:
titleChanged and urlChanged
titleChanged
"""
try:
u = urlutils.fuzzy_url(url)
@ -264,7 +284,7 @@ class WebView(QWebView):
raise CommandError(e)
logging.debug("New title: {}".format(urlutils.urlstring(u)))
self.titleChanged.emit(urlutils.urlstring(u))
self.urlChanged.emit(urlutils.qurl(u))
self.url_text = urlutils.urlstring(u)
return self.load(u)
def zoom_perc(self, perc, fuzzyval=True):
@ -334,6 +354,11 @@ class WebView(QWebView):
self.deleteLater()
logging.debug("Tab shutdown scheduled")
@pyqtSlot('QUrl')
def on_url_changed(self, url):
"""Update url_text when URL has changed."""
self.url_text = urlutils.urlstring(url)
@pyqtSlot(str)
def on_link_clicked(self, url):
"""Handle a link.