add scroll_pos to title-format
This commit is contained in:
parent
0de1e40f20
commit
717298e423
@ -534,7 +534,7 @@ def data(readonly=False):
|
||||
('title-format',
|
||||
SettingValue(typ.FormatString(
|
||||
fields=['perc', 'perc_raw', 'title', 'title_sep', 'index',
|
||||
'id']), '{index}: {title}'),
|
||||
'id', 'scroll_pos']), '{index}: {title}'),
|
||||
"The format to use for the tab title. The following placeholders "
|
||||
"are defined:\n\n"
|
||||
"* `{perc}`: The percentage as a string like `[10%]`.\n"
|
||||
|
@ -112,6 +112,15 @@ class TabWidget(QTabWidget):
|
||||
fields['index'] = idx + 1
|
||||
fields['id'] = widget.tab_id
|
||||
fields['title_sep'] = ' - ' if page_title else ''
|
||||
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'] = '{}'.format(scroll_pos)
|
||||
|
||||
fmt = config.get('tabs', 'title-format')
|
||||
self.tabBar().setTabText(idx, fmt.format(**fields))
|
||||
@ -158,6 +167,7 @@ class TabWidget(QTabWidget):
|
||||
text = text_or_empty
|
||||
new_idx = super().addTab(page, icon, '')
|
||||
self.set_page_title(new_idx, text)
|
||||
page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx))
|
||||
return new_idx
|
||||
|
||||
def insertTab(self, idx, page, icon_or_text, text_or_empty=None):
|
||||
@ -188,6 +198,7 @@ class TabWidget(QTabWidget):
|
||||
text = text_or_empty
|
||||
new_idx = super().insertTab(idx, page, icon, '')
|
||||
self.set_page_title(new_idx, text)
|
||||
page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx))
|
||||
return new_idx
|
||||
|
||||
@pyqtSlot(int)
|
||||
|
Loading…
Reference in New Issue
Block a user