Make statusbar widgets configurable
This commit is contained in:
parent
f51ac8ab6e
commit
715cc7b7dd
@ -1171,6 +1171,23 @@ statusbar.position:
|
|||||||
default: bottom
|
default: bottom
|
||||||
desc: Position of the status bar.
|
desc: Position of the status bar.
|
||||||
|
|
||||||
|
statusbar.widgets:
|
||||||
|
type:
|
||||||
|
name: List
|
||||||
|
valtype:
|
||||||
|
name: String
|
||||||
|
valid_values:
|
||||||
|
- url: "Current page URL."
|
||||||
|
- scroll: "Percentage of the current page position like `10%`."
|
||||||
|
- scroll_raw: "Raw percentage of the current page position like `10`."
|
||||||
|
- history: "Display an arrow when possible to go back/forward in history."
|
||||||
|
- tabs: "Current active tab, e.g. `2`."
|
||||||
|
- keypress: "Display pressed keys when composing a vi command."
|
||||||
|
- progress: "Progress bar for the current page loading."
|
||||||
|
none_ok: true
|
||||||
|
default: ['keypress', 'url', 'scroll', 'history', 'tabs', 'progress']
|
||||||
|
desc: List of widgets displayed in the statusbar.
|
||||||
|
|
||||||
## tabs
|
## tabs
|
||||||
|
|
||||||
tabs.background:
|
tabs.background:
|
||||||
|
@ -26,6 +26,10 @@ class Backforward(textbase.TextBase):
|
|||||||
|
|
||||||
"""Shows navigation indicator (if you can go backward and/or forward)."""
|
"""Shows navigation indicator (if you can go backward and/or forward)."""
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.enabled = False
|
||||||
|
|
||||||
def on_tab_cur_url_changed(self, tabs):
|
def on_tab_cur_url_changed(self, tabs):
|
||||||
"""Called on URL changes."""
|
"""Called on URL changes."""
|
||||||
tab = tabs.currentWidget()
|
tab = tabs.currentWidget()
|
||||||
@ -45,4 +49,4 @@ class Backforward(textbase.TextBase):
|
|||||||
if text:
|
if text:
|
||||||
text = '[' + text + ']'
|
text = '[' + text + ']'
|
||||||
self.setText(text)
|
self.setText(text)
|
||||||
self.setVisible(bool(text))
|
self.setVisible(bool(text) and self.enabled)
|
||||||
|
@ -182,26 +182,13 @@ class StatusBar(QWidget):
|
|||||||
self.cmd.hide_cmd.connect(self._hide_cmd_widget)
|
self.cmd.hide_cmd.connect(self._hide_cmd_widget)
|
||||||
self._hide_cmd_widget()
|
self._hide_cmd_widget()
|
||||||
|
|
||||||
self.keystring = keystring.KeyString()
|
|
||||||
self._hbox.addWidget(self.keystring)
|
|
||||||
|
|
||||||
self.url = url.UrlText()
|
self.url = url.UrlText()
|
||||||
self._hbox.addWidget(self.url)
|
|
||||||
|
|
||||||
self.percentage = percentage.Percentage()
|
self.percentage = percentage.Percentage()
|
||||||
self._hbox.addWidget(self.percentage)
|
|
||||||
|
|
||||||
self.backforward = backforward.Backforward()
|
self.backforward = backforward.Backforward()
|
||||||
self._hbox.addWidget(self.backforward)
|
|
||||||
|
|
||||||
self.tabindex = tabindex.TabIndex()
|
self.tabindex = tabindex.TabIndex()
|
||||||
self._hbox.addWidget(self.tabindex)
|
self.keystring = keystring.KeyString()
|
||||||
|
|
||||||
# We add a parent to Progress here because it calls self.show() based
|
|
||||||
# on some signals, and if that happens before it's added to the layout,
|
|
||||||
# it will quickly blink up as independent window.
|
|
||||||
self.prog = progress.Progress(self)
|
self.prog = progress.Progress(self)
|
||||||
self._hbox.addWidget(self.prog)
|
self._draw_widgets()
|
||||||
|
|
||||||
config.instance.changed.connect(self._on_config_changed)
|
config.instance.changed.connect(self._on_config_changed)
|
||||||
QTimer.singleShot(0, self.maybe_hide)
|
QTimer.singleShot(0, self.maybe_hide)
|
||||||
@ -215,6 +202,48 @@ class StatusBar(QWidget):
|
|||||||
self.maybe_hide()
|
self.maybe_hide()
|
||||||
elif option == 'statusbar.padding':
|
elif option == 'statusbar.padding':
|
||||||
self._set_hbox_padding()
|
self._set_hbox_padding()
|
||||||
|
elif option == 'statusbar.widgets':
|
||||||
|
self._draw_widgets()
|
||||||
|
|
||||||
|
def _draw_widgets(self):
|
||||||
|
"""Draw statusbar widgets."""
|
||||||
|
# Start with widgets hidden and show them when needed
|
||||||
|
for widget in [self.url, self.percentage,
|
||||||
|
self.backforward, self.tabindex,
|
||||||
|
self.keystring, self.prog]:
|
||||||
|
widget.hide()
|
||||||
|
self._hbox.removeWidget(widget)
|
||||||
|
|
||||||
|
tab = self._current_tab()
|
||||||
|
|
||||||
|
# Read the list and set widgets accordingly
|
||||||
|
for segment in config.val.statusbar.widgets:
|
||||||
|
if segment == 'url':
|
||||||
|
self._hbox.addWidget(self.url)
|
||||||
|
self.url.show()
|
||||||
|
elif segment == 'scroll':
|
||||||
|
self._hbox.addWidget(self.percentage)
|
||||||
|
self.percentage.show()
|
||||||
|
elif segment == 'scroll_raw':
|
||||||
|
self._hbox.addWidget(self.percentage)
|
||||||
|
self.percentage.raw = True
|
||||||
|
self.percentage.show()
|
||||||
|
elif segment == 'history':
|
||||||
|
self._hbox.addWidget(self.backforward)
|
||||||
|
self.backforward.enabled = True
|
||||||
|
if tab:
|
||||||
|
self.backforward.on_tab_changed(tab)
|
||||||
|
elif segment == 'tabs':
|
||||||
|
self._hbox.addWidget(self.tabindex)
|
||||||
|
self.tabindex.show()
|
||||||
|
elif segment == 'keypress':
|
||||||
|
self._hbox.addWidget(self.keystring)
|
||||||
|
self.keystring.show()
|
||||||
|
elif segment == 'progress':
|
||||||
|
self._hbox.addWidget(self.prog)
|
||||||
|
self.prog.enabled = True
|
||||||
|
if tab:
|
||||||
|
self.prog.on_tab_changed(tab)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def maybe_hide(self):
|
def maybe_hide(self):
|
||||||
|
@ -32,6 +32,7 @@ class Percentage(textbase.TextBase):
|
|||||||
"""Constructor. Set percentage to 0%."""
|
"""Constructor. Set percentage to 0%."""
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.set_perc(0, 0)
|
self.set_perc(0, 0)
|
||||||
|
self.raw = False
|
||||||
|
|
||||||
@pyqtSlot(int, int)
|
@pyqtSlot(int, int)
|
||||||
def set_perc(self, x, y): # pylint: disable=unused-argument
|
def set_perc(self, x, y): # pylint: disable=unused-argument
|
||||||
@ -48,7 +49,8 @@ class Percentage(textbase.TextBase):
|
|||||||
elif y is None:
|
elif y is None:
|
||||||
self.setText('[???]')
|
self.setText('[???]')
|
||||||
else:
|
else:
|
||||||
self.setText('[{:2}%]'.format(y))
|
text = '[{:02}]' if self.raw else '[{:02}%]'
|
||||||
|
self.setText(text.format(y))
|
||||||
|
|
||||||
def on_tab_changed(self, tab):
|
def on_tab_changed(self, tab):
|
||||||
"""Update scroll position when tab changed."""
|
"""Update scroll position when tab changed."""
|
||||||
|
@ -46,6 +46,7 @@ class Progress(QProgressBar):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
config.set_register_stylesheet(self)
|
config.set_register_stylesheet(self)
|
||||||
|
self.enabled = False
|
||||||
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
||||||
self.setTextVisible(False)
|
self.setTextVisible(False)
|
||||||
self.hide()
|
self.hide()
|
||||||
@ -57,12 +58,12 @@ class Progress(QProgressBar):
|
|||||||
def on_load_started(self):
|
def on_load_started(self):
|
||||||
"""Clear old error and show progress, used as slot to loadStarted."""
|
"""Clear old error and show progress, used as slot to loadStarted."""
|
||||||
self.setValue(0)
|
self.setValue(0)
|
||||||
self.show()
|
self.setVisible(self.enabled)
|
||||||
|
|
||||||
def on_tab_changed(self, tab):
|
def on_tab_changed(self, tab):
|
||||||
"""Set the correct value when the current tab changed."""
|
"""Set the correct value when the current tab changed."""
|
||||||
self.setValue(tab.progress())
|
self.setValue(tab.progress())
|
||||||
if tab.load_status() == usertypes.LoadStatus.loading:
|
if self.enabled and tab.load_status() == usertypes.LoadStatus.loading:
|
||||||
self.show()
|
self.show()
|
||||||
else:
|
else:
|
||||||
self.hide()
|
self.hide()
|
||||||
|
Loading…
Reference in New Issue
Block a user