add scroll_pos to title-format

This commit is contained in:
Alexey Nabrodov 2015-09-25 19:06:44 +03:00
parent 0de1e40f20
commit 717298e423
2 changed files with 12 additions and 1 deletions

View File

@ -534,7 +534,7 @@ def data(readonly=False):
('title-format', ('title-format',
SettingValue(typ.FormatString( SettingValue(typ.FormatString(
fields=['perc', 'perc_raw', 'title', 'title_sep', 'index', 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 " "The format to use for the tab title. The following placeholders "
"are defined:\n\n" "are defined:\n\n"
"* `{perc}`: The percentage as a string like `[10%]`.\n" "* `{perc}`: The percentage as a string like `[10%]`.\n"

View File

@ -112,6 +112,15 @@ class TabWidget(QTabWidget):
fields['index'] = idx + 1 fields['index'] = idx + 1
fields['id'] = widget.tab_id fields['id'] = widget.tab_id
fields['title_sep'] = ' - ' if page_title else '' 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') fmt = config.get('tabs', 'title-format')
self.tabBar().setTabText(idx, fmt.format(**fields)) self.tabBar().setTabText(idx, fmt.format(**fields))
@ -158,6 +167,7 @@ class TabWidget(QTabWidget):
text = text_or_empty text = text_or_empty
new_idx = super().addTab(page, icon, '') new_idx = super().addTab(page, icon, '')
self.set_page_title(new_idx, text) self.set_page_title(new_idx, text)
page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx))
return new_idx return new_idx
def insertTab(self, idx, page, icon_or_text, text_or_empty=None): def insertTab(self, idx, page, icon_or_text, text_or_empty=None):
@ -188,6 +198,7 @@ class TabWidget(QTabWidget):
text = text_or_empty text = text_or_empty
new_idx = super().insertTab(idx, page, icon, '') new_idx = super().insertTab(idx, page, icon, '')
self.set_page_title(new_idx, text) self.set_page_title(new_idx, text)
page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx))
return new_idx return new_idx
@pyqtSlot(int) @pyqtSlot(int)