Display temporary messages in statusbar.
For some odd reason, old messages still don't get cleared properly.
This commit is contained in:
parent
4b91915090
commit
c57e78b765
1
TODO
1
TODO
@ -36,7 +36,6 @@ Mode handling?
|
|||||||
Bookmarks
|
Bookmarks
|
||||||
Internationalization
|
Internationalization
|
||||||
Marks
|
Marks
|
||||||
show infos in statusline, temporary/longer
|
|
||||||
set settings/colors/bindings via commandline
|
set settings/colors/bindings via commandline
|
||||||
more completions (URLs, ...)
|
more completions (URLs, ...)
|
||||||
SSL handling
|
SSL handling
|
||||||
|
@ -72,6 +72,8 @@ class TabbedBrowser(TabWidget):
|
|||||||
cur_scroll_perc_changed: Scroll percentage of current tab changed.
|
cur_scroll_perc_changed: Scroll percentage of current tab changed.
|
||||||
arg 1: x-position in %.
|
arg 1: x-position in %.
|
||||||
arg 2: y-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.
|
keypress: A key was pressed.
|
||||||
arg: The QKeyEvent leading to the keypress.
|
arg: The QKeyEvent leading to the keypress.
|
||||||
shutdown_complete: The shuttdown is completed.
|
shutdown_complete: The shuttdown is completed.
|
||||||
@ -90,6 +92,7 @@ class TabbedBrowser(TabWidget):
|
|||||||
cur_link_hovered = pyqtSignal(str, str, str)
|
cur_link_hovered = pyqtSignal(str, str, str)
|
||||||
cur_scroll_perc_changed = pyqtSignal(int, int)
|
cur_scroll_perc_changed = pyqtSignal(int, int)
|
||||||
set_cmd_text = pyqtSignal(str)
|
set_cmd_text = pyqtSignal(str)
|
||||||
|
disp_tmp_msg = pyqtSignal(str)
|
||||||
keypress = pyqtSignal('QKeyEvent')
|
keypress = pyqtSignal('QKeyEvent')
|
||||||
shutdown_complete = pyqtSignal()
|
shutdown_complete = pyqtSignal()
|
||||||
quit = pyqtSignal()
|
quit = pyqtSignal()
|
||||||
@ -505,12 +508,16 @@ class TabbedBrowser(TabWidget):
|
|||||||
Args:
|
Args:
|
||||||
sel: True to use primary selection, False to use clipboard
|
sel: True to use primary selection, False to use clipboard
|
||||||
|
|
||||||
|
Emit:
|
||||||
|
disp_tmp_message to display a temporary message.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
clip = QApplication.clipboard()
|
clip = QApplication.clipboard()
|
||||||
url = urlutils.urlstring(self.currentWidget().url())
|
url = urlutils.urlstring(self.currentWidget().url())
|
||||||
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
||||||
clip.setText(url, mode)
|
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):
|
def cur_yank_title(self, sel=False):
|
||||||
"""Yank the current title to the clipboard or primary selection.
|
"""Yank the current title to the clipboard or primary selection.
|
||||||
@ -520,12 +527,16 @@ class TabbedBrowser(TabWidget):
|
|||||||
Args:
|
Args:
|
||||||
sel: True to use primary selection, False to use clipboard
|
sel: True to use primary selection, False to use clipboard
|
||||||
|
|
||||||
|
Emit:
|
||||||
|
disp_tmp_message to display a temporary message.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
clip = QApplication.clipboard()
|
clip = QApplication.clipboard()
|
||||||
title = self.tabText(self.currentIndex())
|
title = self.tabText(self.currentIndex())
|
||||||
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
mode = QClipboard.Selection if sel else QClipboard.Clipboard
|
||||||
clip.setText(title, mode)
|
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):
|
def switch_prev(self, count=1):
|
||||||
"""Switch to the ([count]th) previous tab.
|
"""Switch to the ([count]th) previous tab.
|
||||||
|
@ -74,6 +74,7 @@ class MainWindow(QWidget):
|
|||||||
|
|
||||||
self.status.resized.connect(self.completion.resize_to_bar)
|
self.status.resized.connect(self.completion.resize_to_bar)
|
||||||
self.status.moved.connect(self.completion.move_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.resized.connect(self.completion.on_browser_resized)
|
||||||
self.tabs.cur_progress.connect(self.status.prog.setValue)
|
self.tabs.cur_progress.connect(self.status.prog.setValue)
|
||||||
self.tabs.cur_load_finished.connect(lambda *args:
|
self.tabs.cur_load_finished.connect(lambda *args:
|
||||||
|
@ -127,12 +127,12 @@ class StatusBar(QWidget):
|
|||||||
def disp_error(self, text):
|
def disp_error(self, text):
|
||||||
"""Display an error in the statusbar."""
|
"""Display an error in the statusbar."""
|
||||||
self.error = True
|
self.error = True
|
||||||
self.txt.set_error(text)
|
self.txt.error = text
|
||||||
|
|
||||||
def clear_error(self):
|
def clear_error(self):
|
||||||
"""Clear a displayed error from the status bar."""
|
"""Clear a displayed error from the status bar."""
|
||||||
self.error = False
|
self.error = False
|
||||||
self.txt.clear_error()
|
self.txt.error = ''
|
||||||
|
|
||||||
def resizeEvent(self, e):
|
def resizeEvent(self, e):
|
||||||
"""Extend resizeEvent of QWidget to emit a resized signal afterwards.
|
"""Extend resizeEvent of QWidget to emit a resized signal afterwards.
|
||||||
@ -477,28 +477,53 @@ class _Text(TextBase):
|
|||||||
|
|
||||||
"""Text displayed in the statusbar.
|
"""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:
|
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):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
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):
|
def __setattr__(self, name, value):
|
||||||
"""Display an error message and save current text in old_text.
|
"""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:
|
Args:
|
||||||
text: The text to set (string).
|
txt: The text to display, or an empty string to clear.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self._old_text = self.text()
|
self.temporary = txt
|
||||||
self.setText(text)
|
|
||||||
|
|
||||||
def clear_error(self):
|
|
||||||
"""Clear a displayed error message."""
|
|
||||||
self.setText(self._old_text)
|
|
||||||
|
|
||||||
|
|
||||||
class _KeyString(TextBase):
|
class _KeyString(TextBase):
|
||||||
|
Loading…
Reference in New Issue
Block a user