Move config transforming of to Qt values to configtypes.

This is a preparation for #46.
This commit is contained in:
Florian Bruhin 2014-10-07 19:58:30 +02:00
parent 4092c48f92
commit 72a92c09dd
2 changed files with 27 additions and 15 deletions

View File

@ -29,6 +29,7 @@ import sre_constants
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QColor, QFont
from PyQt5.QtNetwork import QNetworkProxy
from PyQt5.QtWidgets import QTabWidget, QTabBar
from qutebrowser.commands import cmdutils
@ -1146,6 +1147,18 @@ class Position(BaseType):
valid_values = ValidValues('north', 'south', 'east', 'west')
MAPPING = {
'north': QTabWidget.North,
'south': QTabWidget.South,
'west': QTabWidget.West,
'east': QTabWidget.East,
}
def transform(self, value):
if not value:
return None
return self.MAPPING[value]
class SelectOnRemove(BaseType):
@ -1156,6 +1169,17 @@ class SelectOnRemove(BaseType):
('right', "Select the tab on the right."),
('previous', "Select the previously selected tab."))
MAPPING = {
'left': QTabBar.SelectLeftTab,
'right': QTabBar.SelectRightTab,
'previous': QTabBar.SelectPreviousTab,
}
def transform(self, value):
if not value:
return None
return self.MAPPING[value]
class LastClose(BaseType):

View File

@ -57,26 +57,14 @@ class TabWidget(QTabWidget):
def init_config(self):
"""Initialize attributes based on the config."""
position_conv = {
'north': QTabWidget.North,
'south': QTabWidget.South,
'west': QTabWidget.West,
'east': QTabWidget.East,
}
select_conv = {
'left': QTabBar.SelectLeftTab,
'right': QTabBar.SelectRightTab,
'previous': QTabBar.SelectPreviousTab,
}
tabbar = self.tabBar()
self.setMovable(config.get('tabs', 'movable'))
self.setTabsClosable(False)
posstr = config.get('tabs', 'position')
selstr = config.get('tabs', 'select-on-remove')
position = position_conv[posstr]
position = config.get('tabs', 'position')
selection_behaviour = config.get('tabs', 'select-on-remove')
self.setTabPosition(position)
tabbar.vertical = position in (QTabWidget.West, QTabWidget.East)
tabbar.setSelectionBehaviorOnRemove(select_conv[selstr])
tabbar.setSelectionBehaviorOnRemove(selection_behaviour)
tabbar.refresh()