Cleanup the code

This commit is contained in:
Valentijn 2018-02-15 14:21:09 +01:00
parent b6605b5576
commit 906bd7b295
3 changed files with 12 additions and 20 deletions

View file

@ -26,12 +26,6 @@ from clay.notifications import notification_area
from clay.gp import gp
def create_palette(transparent=False):
config = settings.get_section('colours')
return [(name, '', '', '', config[name]['foreground'], config[name]['background'])
for name in config]
class AppWidget(urwid.Frame):
"""
Root widget.
@ -130,11 +124,8 @@ class AppWidget(urwid.Frame):
Request user authorization.
"""
username, password, device_id, authtoken = [
settings.get(x)
for x
in ('username', 'password', 'device_id', 'authtoken')
]
authtoken, device_id, _, password, username = settings.get_section("play_settings").values()
if self._login_notification:
self._login_notification.close()
if use_token and authtoken:
@ -361,12 +352,6 @@ def main():
action='store_true'
)
parser.add_argument(
"--transparent",
help="use transparent background",
action='store_true'
)
args = parser.parse_args()
if args.version:
@ -376,8 +361,10 @@ def main():
player.enable_xorg_bindings()
# Run the actual program
palette = [(name, '', '', '', colour['foreground'], colour['background'])
for name, colour in settings.get_section('colours').items()]
app_widget = AppWidget()
loop = urwid.MainLoop(app_widget, create_palette(args.transparent))
loop = urwid.MainLoop(app_widget, palette)
app_widget.set_loop(loop)
loop.screen.set_terminal_properties(256)
loop.run()

View file

@ -331,7 +331,8 @@ class _Player(object):
self.broadcast_state()
self.track_changed.fire(track)
if settings.get('download_tracks', default=False) or settings.get_is_file_cached(track.filename):
if settings.get('download_tracks', default=False) \
or settings.get_is_file_cached(track.filename):
path = settings.get_cached_file_path(track.filename)
if path is None:

View file

@ -101,6 +101,10 @@ class _Settings(object):
settings_file.write(yaml.dump(self._config, default_flow_style=False))
def get(self, key, section="play_settings", default=None):
"""
Return their configuration key in a specified section
By default it looks in play_settings.
"""
if section not in self._config:
return default
@ -108,7 +112,7 @@ class _Settings(object):
def get_section(self, key, default=None):
"""
Return config value.
Return configuration section
"""
return self._config.get(key, default)