Utilize f-strings
This commit is contained in:
parent
ed2add42ff
commit
0d219f4767
|
@ -31,7 +31,7 @@ from .display import DispConfig, Display
|
||||||
CONTROL_ALIASES = (('Move left', 'left'), ('Move right', 'right'),
|
CONTROL_ALIASES = (('Move left', 'left'), ('Move right', 'right'),
|
||||||
('Move forward', 'forward'), ('Move backward', 'backward'),
|
('Move forward', 'forward'), ('Move backward', 'backward'),
|
||||||
('Primary', '1st'), ('Secondary', '2nd'))
|
('Primary', '1st'), ('Secondary', '2nd'))
|
||||||
MOUSE_PATTERN = 'MOUSE_BUTTON_[1-{}]'.format(glfw.MOUSE_BUTTON_LAST + 1)
|
MOUSE_PATTERN = f'MOUSE_BUTTON_[1-{glfw.MOUSE_BUTTON_LAST+1}]'
|
||||||
INVALID_CONTROL_ERR = '{}: {} is not recognized as a valid control key'
|
INVALID_CONTROL_ERR = '{}: {} is not recognized as a valid control key'
|
||||||
GLFW_VER_WARN = 'Your GLFW version appear to be lower than 3.3, '\
|
GLFW_VER_WARN = 'Your GLFW version appear to be lower than 3.3, '\
|
||||||
'which might cause stuttering camera rotation.'
|
'which might cause stuttering camera rotation.'
|
||||||
|
@ -55,21 +55,20 @@ class CtlConfig(DispConfig):
|
||||||
DispConfig.__init__(self)
|
DispConfig.__init__(self)
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--mouse-speed', type=float, dest='mouspeed',
|
'--mouse-speed', type=float, dest='mouspeed',
|
||||||
help='camera rotational speed (fallback: {:.1f})'.format(
|
help=f'camera rotational speed (fallback: {self._mouspeed:.1f})')
|
||||||
self.__mouspeed))
|
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--zoom-speed', type=float, dest='zmspeed',
|
'--zoom-speed', type=float, dest='zmspeed',
|
||||||
help='zoom speed (fallback: {:.1f})'.format(self.zmspeed))
|
help=f'zoom speed (fallback: {self.zmspeed:.1f})')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mouspeed(self) -> float:
|
def mouspeed(self) -> float:
|
||||||
"""Relative mouse speed."""
|
"""Relative mouse speed."""
|
||||||
# Standard to radians per inch for a 800 DPI mouse, at FOV of 60
|
# Standard to radians per inch for a 800 DPI mouse, at FOV of 60
|
||||||
return self.__mouspeed / 800
|
return self._mouspeed / 800
|
||||||
|
|
||||||
@mouspeed.setter
|
@mouspeed.setter
|
||||||
def mouspeed(self, value: float) -> None:
|
def mouspeed(self, value: float) -> None:
|
||||||
self.__mouspeed = value
|
self._mouspeed = value
|
||||||
|
|
||||||
def fallback(self) -> None:
|
def fallback(self) -> None:
|
||||||
"""Parse fallback configurations."""
|
"""Parse fallback configurations."""
|
||||||
|
@ -83,7 +82,7 @@ class CtlConfig(DispConfig):
|
||||||
self.mouse[alias] = getattr(glfw, i.upper())
|
self.mouse[alias] = getattr(glfw, i.upper())
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
self.key[alias] = getattr(glfw, 'KEY_{}'.format(i.upper()))
|
self.key[alias] = getattr(glfw, f'KEY_{i.upper()}')
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise ValueError(INVALID_CONTROL_ERR.format(cmd, i))
|
raise ValueError(INVALID_CONTROL_ERR.format(cmd, i))
|
||||||
|
|
||||||
|
|
|
@ -73,21 +73,19 @@ class DispConfig(PeerConfig):
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
PeerConfig.__init__(self)
|
PeerConfig.__init__(self)
|
||||||
|
x, y = self.size
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--size', type=int, nargs=2, metavar=('X', 'Y'),
|
'--size', type=int, nargs=2, metavar=('X', 'Y'),
|
||||||
help='the desired screen size (fallback: {}x{})'.format(
|
help=f'the desired screen size (fallback: {x}x{y})')
|
||||||
*self.size))
|
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--vsync', action='store_true', default=None,
|
'--vsync', action='store_true', default=None,
|
||||||
help='enable vertical synchronization (fallback: {})'.format(
|
help=f'enable vertical synchronization (fallback: {self.vsync})')
|
||||||
self.vsync))
|
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--no-vsync', action='store_false', dest='vsync',
|
'--no-vsync', action='store_false', dest='vsync',
|
||||||
help='disable vertical synchronization')
|
help='disable vertical synchronization')
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--fov', type=float, metavar='DEGREES',
|
'--fov', type=float, metavar='DEGREES',
|
||||||
help='horizontal field of view (fallback: {:})'.format(
|
help=f'horizontal field of view (fallback: {round(self.fov)})')
|
||||||
round(self.fov)))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fov(self) -> float:
|
def fov(self) -> float:
|
||||||
|
@ -328,7 +326,7 @@ class Display(Peer):
|
||||||
"""Pretty string for displaying average FPS."""
|
"""Pretty string for displaying average FPS."""
|
||||||
# Average over 5 seconds, like how glxgears do it, but less efficient
|
# Average over 5 seconds, like how glxgears do it, but less efficient
|
||||||
while len(self.fpses) > mean(self.fpses) * 5 > 0: self.fpses.pop()
|
while len(self.fpses) > mean(self.fpses) * 5 > 0: self.fpses.pop()
|
||||||
return '{} fps'.format(round(mean(self.fpses)))
|
return f'{round(mean(self.fpses))} fps'
|
||||||
|
|
||||||
def get_time(self) -> float:
|
def get_time(self) -> float:
|
||||||
"""Return the current time in seconds."""
|
"""Return the current time in seconds."""
|
||||||
|
|
10
axuy/peer.py
10
axuy/peer.py
|
@ -72,21 +72,21 @@ class PeerConfig:
|
||||||
self.options = ArgumentParser(usage='%(prog)s [options]',
|
self.options = ArgumentParser(usage='%(prog)s [options]',
|
||||||
formatter_class=RawTextHelpFormatter)
|
formatter_class=RawTextHelpFormatter)
|
||||||
self.options.add_argument('-v', '--version', action='version',
|
self.options.add_argument('-v', '--version', action='version',
|
||||||
version='Axuy {}'.format(__version__))
|
version=f'Axuy {__version__}')
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--write-config', nargs='?', const=stdout, type=FileType('w'),
|
'--write-config', nargs='?', const=stdout, type=FileType('w'),
|
||||||
metavar='PATH', dest='cfgout',
|
metavar='PATH', dest='cfgout',
|
||||||
help='write default config to PATH (fallback: stdout) and exit')
|
help='write default config to PATH (fallback: stdout) and exit')
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'-c', '--config', metavar='PATH',
|
'-c', '--config', metavar='PATH',
|
||||||
help='location of the configuration file (fallback: {})'.format(
|
help=('location of the configuration file'
|
||||||
pathsep.join(filenames)))
|
f' (fallback: {pathsep.join(filenames)})'))
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'--host',
|
'--host',
|
||||||
help='host to bind this peer to (fallback: {})'.format(self.host))
|
help=f'host to bind this peer to (fallback: {self.host})')
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'-p', '--port', type=int,
|
'-p', '--port', type=int,
|
||||||
help='port to bind this peer to (fallback: {})'.format(self.port))
|
help=f'port to bind this peer to (fallback: {self.port})')
|
||||||
self.options.add_argument(
|
self.options.add_argument(
|
||||||
'-s', '--seeder', metavar='ADDRESS',
|
'-s', '--seeder', metavar='ADDRESS',
|
||||||
help='address of the peer that created the map')
|
help='address of the peer that created the map')
|
||||||
|
|
Loading…
Reference in New Issue