Use a list as items-argument for usertypes.enum
This commit is contained in:
parent
8636562579
commit
0fadf6b091
2
doc/TODO
2
doc/TODO
@ -128,8 +128,6 @@ style
|
|||||||
- Stuff under scripts/ (especially generate_doc and run_checks) could use a
|
- Stuff under scripts/ (especially generate_doc and run_checks) could use a
|
||||||
rewrite.
|
rewrite.
|
||||||
- Always use a list as argument for namedtuple?
|
- Always use a list as argument for namedtuple?
|
||||||
- Refactor enum() so it uses a list as second argument (like python
|
|
||||||
enum/namedtuple).
|
|
||||||
- Use separate logger for config
|
- Use separate logger for config
|
||||||
- Use unittest.Mock and especially unittest.patch more.
|
- Use unittest.Mock and especially unittest.patch more.
|
||||||
- Use decorators for on_config_changed
|
- Use decorators for on_config_changed
|
||||||
|
@ -37,9 +37,9 @@ from qutebrowser.utils import usertypes, log, qtutils, message, objreg
|
|||||||
ElemTuple = collections.namedtuple('ElemTuple', 'elem, label')
|
ElemTuple = collections.namedtuple('ElemTuple', 'elem, label')
|
||||||
|
|
||||||
|
|
||||||
Target = usertypes.enum('Target', 'normal', 'tab', 'tab_bg', 'yank',
|
Target = usertypes.enum('Target', ['normal', 'tab', 'tab_bg', 'yank',
|
||||||
'yank_primary', 'fill', 'rapid', 'download',
|
'yank_primary', 'fill', 'rapid', 'download',
|
||||||
'userscript', 'spawn')
|
'userscript', 'spawn'])
|
||||||
|
|
||||||
|
|
||||||
@pyqtSlot(usertypes.KeyMode)
|
@pyqtSlot(usertypes.KeyMode)
|
||||||
|
@ -37,8 +37,8 @@ from qutebrowser.config import config
|
|||||||
from qutebrowser.utils import log, usertypes, utils
|
from qutebrowser.utils import log, usertypes, utils
|
||||||
|
|
||||||
|
|
||||||
Group = usertypes.enum('Group', 'all', 'links', 'images', 'url', 'prevnext',
|
Group = usertypes.enum('Group', ['all', 'links', 'images', 'url', 'prevnext',
|
||||||
'focus')
|
'focus'])
|
||||||
|
|
||||||
|
|
||||||
SELECTORS = {
|
SELECTORS = {
|
||||||
|
@ -58,7 +58,7 @@ class Command:
|
|||||||
|
|
||||||
AnnotationInfo = collections.namedtuple('AnnotationInfo',
|
AnnotationInfo = collections.namedtuple('AnnotationInfo',
|
||||||
'kwargs, typ, name, flag')
|
'kwargs, typ, name, flag')
|
||||||
ParamType = usertypes.enum('ParamType', 'flag', 'positional')
|
ParamType = usertypes.enum('ParamType', ['flag', 'positional'])
|
||||||
|
|
||||||
def __init__(self, name, split, hide, instance, completion, modes,
|
def __init__(self, name, split, hide, instance, completion, modes,
|
||||||
not_modes, needs_js, is_debug, ignore_args,
|
not_modes, needs_js, is_debug, ignore_args,
|
||||||
|
@ -35,7 +35,7 @@ from PyQt5.QtCore import QStandardPaths
|
|||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.utils import usertypes, utils
|
from qutebrowser.utils import usertypes, utils
|
||||||
|
|
||||||
MapType = usertypes.enum('MapType', 'attribute', 'setter', 'static_setter')
|
MapType = usertypes.enum('MapType', ['attribute', 'setter', 'static_setter'])
|
||||||
|
|
||||||
|
|
||||||
MAPPINGS = {
|
MAPPINGS = {
|
||||||
|
@ -69,9 +69,9 @@ class BaseKeyParser(QObject):
|
|||||||
keystring_updated = pyqtSignal(str)
|
keystring_updated = pyqtSignal(str)
|
||||||
do_log = True
|
do_log = True
|
||||||
|
|
||||||
Match = usertypes.enum('Match', 'partial', 'definitive', 'ambiguous',
|
Match = usertypes.enum('Match', ['partial', 'definitive', 'ambiguous',
|
||||||
'none')
|
'none'])
|
||||||
Type = usertypes.enum('Type', 'chain', 'special')
|
Type = usertypes.enum('Type', ['chain', 'special'])
|
||||||
|
|
||||||
def __init__(self, parent=None, supports_count=None,
|
def __init__(self, parent=None, supports_count=None,
|
||||||
supports_chains=False):
|
supports_chains=False):
|
||||||
|
@ -32,7 +32,7 @@ from qutebrowser.utils import usertypes, log, objreg, utils
|
|||||||
|
|
||||||
|
|
||||||
STARTCHARS = ":/?"
|
STARTCHARS = ":/?"
|
||||||
LastPress = usertypes.enum('LastPress', 'none', 'filtertext', 'keystring')
|
LastPress = usertypes.enum('LastPress', ['none', 'filtertext', 'keystring'])
|
||||||
|
|
||||||
|
|
||||||
class NormalKeyParser(keyparser.CommandKeyParser):
|
class NormalKeyParser(keyparser.CommandKeyParser):
|
||||||
|
@ -29,7 +29,8 @@ from PyQt5.QtGui import QStandardItemModel, QStandardItem
|
|||||||
from qutebrowser.utils import usertypes, qtutils
|
from qutebrowser.utils import usertypes, qtutils
|
||||||
|
|
||||||
|
|
||||||
Role = usertypes.enum('Role', 'marks', 'sort', start=Qt.UserRole, is_int=True)
|
Role = usertypes.enum('Role', ['marks', 'sort'], start=Qt.UserRole,
|
||||||
|
is_int=True)
|
||||||
|
|
||||||
|
|
||||||
class BaseCompletionModel(QStandardItemModel):
|
class BaseCompletionModel(QStandardItemModel):
|
||||||
|
@ -26,7 +26,7 @@ from qutebrowser.config import config
|
|||||||
from qutebrowser.utils import usertypes, qtutils, objreg, utils
|
from qutebrowser.utils import usertypes, qtutils, objreg, utils
|
||||||
|
|
||||||
|
|
||||||
Role = usertypes.enum('Role', 'item', start=Qt.UserRole, is_int=True)
|
Role = usertypes.enum('Role', ['item'], start=Qt.UserRole, is_int=True)
|
||||||
|
|
||||||
|
|
||||||
class DownloadModel(QAbstractListModel):
|
class DownloadModel(QAbstractListModel):
|
||||||
|
@ -35,7 +35,7 @@ class EnumTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.enum = usertypes.enum('Enum', 'one', 'two')
|
self.enum = usertypes.enum('Enum', ['one', 'two'])
|
||||||
|
|
||||||
def test_values(self):
|
def test_values(self):
|
||||||
"""Test if enum members resolve to the right values."""
|
"""Test if enum members resolve to the right values."""
|
||||||
@ -54,7 +54,7 @@ class EnumTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_start(self):
|
def test_start(self):
|
||||||
"""Test the start= argument."""
|
"""Test the start= argument."""
|
||||||
e = usertypes.enum('Enum', 'three', 'four', start=3)
|
e = usertypes.enum('Enum', ['three', 'four'], start=3)
|
||||||
self.assertEqual(e.three.value, 3)
|
self.assertEqual(e.three.value, 3)
|
||||||
self.assertEqual(e.four.value, 4)
|
self.assertEqual(e.four.value, 4)
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ class DocstringParser:
|
|||||||
arg_descs: A dict of argument names to their descriptions
|
arg_descs: A dict of argument names to their descriptions
|
||||||
"""
|
"""
|
||||||
|
|
||||||
State = usertypes.enum('State', 'short', 'desc', 'desc_hidden',
|
State = usertypes.enum('State', ['short', 'desc', 'desc_hidden',
|
||||||
'arg_start', 'arg_inside', 'misc')
|
'arg_start', 'arg_inside', 'misc'])
|
||||||
|
|
||||||
def __init__(self, func):
|
def __init__(self, func):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
|
@ -35,12 +35,12 @@ from qutebrowser.utils import log, qtutils, utils
|
|||||||
_UNSET = object()
|
_UNSET = object()
|
||||||
|
|
||||||
|
|
||||||
def enum(name, *items, start=1, is_int=False):
|
def enum(name, items, start=1, is_int=False):
|
||||||
"""Factory for simple enumerations.
|
"""Factory for simple enumerations.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: Name of the enum
|
name: Name of the enum
|
||||||
*items: Items to be sequentally enumerated.
|
items: Iterable of ttems to be sequentally enumerated.
|
||||||
start: The number to use for the first value.
|
start: The number to use for the first value.
|
||||||
We use 1 as default so enum members are always True.
|
We use 1 as default so enum members are always True.
|
||||||
is_init: True if the enum should be a Python IntEnum
|
is_init: True if the enum should be a Python IntEnum
|
||||||
@ -65,7 +65,7 @@ class NeighborList(collections.abc.Sequence):
|
|||||||
_mode: The current mode.
|
_mode: The current mode.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Modes = enum('Modes', 'block', 'wrap', 'exception')
|
Modes = enum('Modes', ['block', 'wrap', 'exception'])
|
||||||
|
|
||||||
def __init__(self, items=None, default=_UNSET, mode=Modes.exception):
|
def __init__(self, items=None, default=_UNSET, mode=Modes.exception):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
@ -224,21 +224,21 @@ class NeighborList(collections.abc.Sequence):
|
|||||||
|
|
||||||
|
|
||||||
# The mode of a Question.
|
# The mode of a Question.
|
||||||
PromptMode = enum('PromptMode', 'yesno', 'text', 'user_pwd', 'alert')
|
PromptMode = enum('PromptMode', ['yesno', 'text', 'user_pwd', 'alert'])
|
||||||
|
|
||||||
|
|
||||||
# Where to open a clicked link.
|
# Where to open a clicked link.
|
||||||
ClickTarget = enum('ClickTarget', 'normal', 'tab', 'tab_bg')
|
ClickTarget = enum('ClickTarget', ['normal', 'tab', 'tab_bg'])
|
||||||
|
|
||||||
|
|
||||||
# Key input modes
|
# Key input modes
|
||||||
KeyMode = enum('KeyMode', 'normal', 'hint', 'command', 'yesno', 'prompt',
|
KeyMode = enum('KeyMode', ['normal', 'hint', 'command', 'yesno', 'prompt',
|
||||||
'insert', 'passthrough')
|
'insert', 'passthrough'])
|
||||||
|
|
||||||
|
|
||||||
# Available command completions
|
# Available command completions
|
||||||
Completion = enum('Completion', 'command', 'section', 'option', 'value',
|
Completion = enum('Completion', ['command', 'section', 'option', 'value',
|
||||||
'helptopic')
|
'helptopic'])
|
||||||
|
|
||||||
|
|
||||||
class Question(QObject):
|
class Question(QObject):
|
||||||
|
@ -32,7 +32,8 @@ from qutebrowser.widgets.statusbar import (command, progress, keystring,
|
|||||||
from qutebrowser.widgets.statusbar import text as textwidget
|
from qutebrowser.widgets.statusbar import text as textwidget
|
||||||
|
|
||||||
|
|
||||||
PreviousWidget = usertypes.enum('PreviousWidget', 'none', 'prompt', 'command')
|
PreviousWidget = usertypes.enum('PreviousWidget', ['none', 'prompt',
|
||||||
|
'command'])
|
||||||
|
|
||||||
|
|
||||||
class StatusBar(QWidget):
|
class StatusBar(QWidget):
|
||||||
|
@ -39,7 +39,7 @@ class Text(textbase.TextBase):
|
|||||||
available. If not, the permanent text is shown.
|
available. If not, the permanent text is shown.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Text = usertypes.enum('Text', 'normal', 'temp', 'js')
|
Text = usertypes.enum('Text', ['normal', 'temp', 'js'])
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
@ -28,8 +28,8 @@ from qutebrowser.utils import usertypes
|
|||||||
|
|
||||||
|
|
||||||
# Note this has entries for success/error/warn from widgets.webview:LoadStatus
|
# Note this has entries for success/error/warn from widgets.webview:LoadStatus
|
||||||
UrlType = usertypes.enum('UrlType', 'success', 'error', 'warn', 'hover',
|
UrlType = usertypes.enum('UrlType', ['success', 'error', 'warn', 'hover',
|
||||||
'normal')
|
'normal'])
|
||||||
|
|
||||||
|
|
||||||
class UrlText(textbase.TextBase):
|
class UrlText(textbase.TextBase):
|
||||||
|
@ -33,8 +33,8 @@ from qutebrowser.browser import webpage, hints, webelem
|
|||||||
from qutebrowser.commands import cmdexc
|
from qutebrowser.commands import cmdexc
|
||||||
|
|
||||||
|
|
||||||
LoadStatus = usertypes.enum('LoadStatus', 'none', 'success', 'error', 'warn',
|
LoadStatus = usertypes.enum('LoadStatus', ['none', 'success', 'error', 'warn',
|
||||||
'loading')
|
'loading'])
|
||||||
|
|
||||||
|
|
||||||
tab_id_gen = itertools.count(0)
|
tab_id_gen = itertools.count(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user