Display temporary messages in statusbar.

For some odd reason, old messages still don't get cleared properly.
This commit is contained in:
Florian Bruhin 2014-02-19 13:21:30 +01:00
parent 4b91915090
commit c57e78b765
4 changed files with 52 additions and 16 deletions

1
TODO
View File

@ -36,7 +36,6 @@ Mode handling?
Bookmarks
Internationalization
Marks
show infos in statusline, temporary/longer
set settings/colors/bindings via commandline
more completions (URLs, ...)
SSL handling

View File

@ -72,6 +72,8 @@ class TabbedBrowser(TabWidget):
cur_scroll_perc_changed: Scroll percentage of current tab changed.
arg 1: x-position in %.
arg 2: y-position in %.
disp_tmp_msg: A temporary message should be shown in the statusbar.
arg: The message to display as string.
keypress: A key was pressed.
arg: The QKeyEvent leading to the keypress.
shutdown_complete: The shuttdown is completed.
@ -90,6 +92,7 @@ class TabbedBrowser(TabWidget):
cur_link_hovered = pyqtSignal(str, str, str)
cur_scroll_perc_changed = pyqtSignal(int, int)
set_cmd_text = pyqtSignal(str)
disp_tmp_msg = pyqtSignal(str)
keypress = pyqtSignal('QKeyEvent')
shutdown_complete = pyqtSignal()
quit = pyqtSignal()
@ -505,12 +508,16 @@ class TabbedBrowser(TabWidget):
Args:
sel: True to use primary selection, False to use clipboard
Emit:
disp_tmp_message to display a temporary message.
"""
clip = QApplication.clipboard()
url = urlutils.urlstring(self.currentWidget().url())
mode = QClipboard.Selection if sel else QClipboard.Clipboard
clip.setText(url, mode)
# FIXME provide visual feedback
self.disp_tmp_msg.emit('URL yanked to {}'.format(
'primary selection' if sel else 'clipboard'))
def cur_yank_title(self, sel=False):
"""Yank the current title to the clipboard or primary selection.
@ -520,12 +527,16 @@ class TabbedBrowser(TabWidget):
Args:
sel: True to use primary selection, False to use clipboard
Emit:
disp_tmp_message to display a temporary message.
"""
clip = QApplication.clipboard()
title = self.tabText(self.currentIndex())
mode = QClipboard.Selection if sel else QClipboard.Clipboard
clip.setText(title, mode)
# FIXME provide visual feedbac
self.disp_tmp_msg.emit('Title yanked to {}'.format(
'primary selection' if sel else 'clipboard'))
def switch_prev(self, count=1):
"""Switch to the ([count]th) previous tab.

View File

@ -74,6 +74,7 @@ class MainWindow(QWidget):
self.status.resized.connect(self.completion.resize_to_bar)
self.status.moved.connect(self.completion.move_to_bar)
self.tabs.disp_tmp_msg.connect(self.status.txt.disp_tmp)
self.tabs.resized.connect(self.completion.on_browser_resized)
self.tabs.cur_progress.connect(self.status.prog.setValue)
self.tabs.cur_load_finished.connect(lambda *args:

View File

@ -127,12 +127,12 @@ class StatusBar(QWidget):
def disp_error(self, text):
"""Display an error in the statusbar."""
self.error = True
self.txt.set_error(text)
self.txt.error = text
def clear_error(self):
"""Clear a displayed error from the status bar."""
self.error = False
self.txt.clear_error()
self.txt.error = ''
def resizeEvent(self, e):
"""Extend resizeEvent of QWidget to emit a resized signal afterwards.
@ -477,28 +477,53 @@ class _Text(TextBase):
"""Text displayed in the statusbar.
There are three types of texts which can be displayed:
The current normal text displayed for a longer time,
the current temporary text displayed until the next keystroke,
the current error text displayed until statusbar is focused.
Attributes:
_old_text: The text displayed before the temporary error message.
normal: The text normally displayed, accessed via property normal.
temporary: The temporary text, accessed via property temporary.
error: The error text accessed via property error.
_initialized: True when initialization is done, to avoid calling
callback when still in __init__.
"""
def __init__(self, parent=None):
super().__init__(parent)
self._old_text = ''
self._initialized = False
self.normal = ''
self.temporary = ''
self.error = ''
self._initialized = True
self._update_text()
def set_error(self, text):
"""Display an error message and save current text in old_text.
def __setattr__(self, name, value):
"""Override __setattr__ to call _update_text() if texts changed."""
super().__setattr__(name, value)
if name in ['normal', 'temporary', 'error'] and self._initialized:
self._update_text()
def _update_text(self):
"""Callback called when texts are updated. Display appropriate text."""
for t in [self.error, self.temporary, self.normal]:
if t:
self.setText(t)
break
else:
self.setText('')
@pyqtSlot(str)
def disp_tmp(self, txt):
"""Display a temporary text.
Args:
text: The text to set (string).
txt: The text to display, or an empty string to clear.
"""
self._old_text = self.text()
self.setText(text)
def clear_error(self):
"""Clear a displayed error message."""
self.setText(self._old_text)
self.temporary = txt
class _KeyString(TextBase):