Refactor tab and window title update methods
This commit is contained in:
parent
054e9ab439
commit
bf32c544a2
@ -161,31 +161,8 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
# (e.g. last tab removed)
|
# (e.g. last tab removed)
|
||||||
log.webview.debug("Not updating window title because index is -1")
|
log.webview.debug("Not updating window title because index is -1")
|
||||||
return
|
return
|
||||||
tabtitle = self.page_title(idx)
|
fields = self.get_tab_fields(idx)
|
||||||
widget = self.widget(idx)
|
|
||||||
|
|
||||||
fields = {}
|
|
||||||
if widget.load_status == webview.LoadStatus.loading:
|
|
||||||
fields['perc'] = '[{}%] '.format(widget.progress)
|
|
||||||
else:
|
|
||||||
fields['perc'] = ''
|
|
||||||
fields['perc_raw'] = widget.progress
|
|
||||||
fields['title'] = tabtitle
|
|
||||||
fields['title_sep'] = ' - ' if tabtitle else ''
|
|
||||||
fields['id'] = self._win_id
|
fields['id'] = self._win_id
|
||||||
y = widget.scroll_pos[1]
|
|
||||||
if y <= 0:
|
|
||||||
scroll_pos = 'top'
|
|
||||||
elif y >= 100:
|
|
||||||
scroll_pos = 'bot'
|
|
||||||
else:
|
|
||||||
scroll_pos = '{:2}%'.format(y)
|
|
||||||
|
|
||||||
fields['scroll_pos'] = scroll_pos
|
|
||||||
try:
|
|
||||||
fields['host'] = self.current_url().host()
|
|
||||||
except qtutils.QtValueError:
|
|
||||||
fields['host'] = ''
|
|
||||||
|
|
||||||
fmt = config.get('ui', 'window-title-format')
|
fmt = config.get('ui', 'window-title-format')
|
||||||
self.window().setWindowTitle(fmt.format(**fields))
|
self.window().setWindowTitle(fmt.format(**fields))
|
||||||
|
@ -99,19 +99,34 @@ class TabWidget(QTabWidget):
|
|||||||
|
|
||||||
def update_tab_title(self, idx):
|
def update_tab_title(self, idx):
|
||||||
"""Update the tab text for the given tab."""
|
"""Update the tab text for the given tab."""
|
||||||
|
fields = self.get_tab_fields(idx)
|
||||||
|
fields['title'] = fields['title'].replace('&', '&&')
|
||||||
|
fields['index'] = idx + 1
|
||||||
|
|
||||||
|
fmt = config.get('tabs', 'title-format')
|
||||||
|
self.tabBar().setTabText(idx, fmt.format(**fields))
|
||||||
|
|
||||||
|
def get_tab_fields(self, idx):
|
||||||
|
"""Get the tab field data."""
|
||||||
widget = self.widget(idx)
|
widget = self.widget(idx)
|
||||||
page_title = self.page_title(idx).replace('&', '&&')
|
page_title = self.page_title(idx)
|
||||||
|
|
||||||
fields = {}
|
fields = {}
|
||||||
|
fields['id'] = widget.tab_id
|
||||||
|
fields['title'] = page_title
|
||||||
|
fields['title_sep'] = ' - ' if page_title else ''
|
||||||
|
fields['perc_raw'] = widget.progress
|
||||||
|
|
||||||
if widget.load_status == webview.LoadStatus.loading:
|
if widget.load_status == webview.LoadStatus.loading:
|
||||||
fields['perc'] = '[{}%] '.format(widget.progress)
|
fields['perc'] = '[{}%] '.format(widget.progress)
|
||||||
else:
|
else:
|
||||||
fields['perc'] = ''
|
fields['perc'] = ''
|
||||||
fields['perc_raw'] = widget.progress
|
|
||||||
fields['title'] = page_title
|
try:
|
||||||
fields['index'] = idx + 1
|
fields['host'] = self.tab_url(idx).host()
|
||||||
fields['id'] = widget.tab_id
|
except qtutils.QtValueError:
|
||||||
fields['title_sep'] = ' - ' if page_title else ''
|
fields['host'] = ''
|
||||||
|
|
||||||
y = widget.scroll_pos[1]
|
y = widget.scroll_pos[1]
|
||||||
if y <= 0:
|
if y <= 0:
|
||||||
scroll_pos = 'top'
|
scroll_pos = 'top'
|
||||||
@ -121,13 +136,7 @@ class TabWidget(QTabWidget):
|
|||||||
scroll_pos = '{:2}%'.format(y)
|
scroll_pos = '{:2}%'.format(y)
|
||||||
|
|
||||||
fields['scroll_pos'] = scroll_pos
|
fields['scroll_pos'] = scroll_pos
|
||||||
try:
|
return fields
|
||||||
fields['host'] = self.tab_url(idx).host()
|
|
||||||
except qtutils.QtValueError:
|
|
||||||
fields['host'] = ''
|
|
||||||
|
|
||||||
fmt = config.get('tabs', 'title-format')
|
|
||||||
self.tabBar().setTabText(idx, fmt.format(**fields))
|
|
||||||
|
|
||||||
@config.change_filter('tabs', 'title-format')
|
@config.change_filter('tabs', 'title-format')
|
||||||
def update_tab_titles(self):
|
def update_tab_titles(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user