From 906bd7b2954023eecdcf50f29cff17e035899466 Mon Sep 17 00:00:00 2001 From: Valentijn Date: Thu, 15 Feb 2018 14:21:09 +0100 Subject: [PATCH] Cleanup the code --- clay/app.py | 23 +++++------------------ clay/player.py | 3 ++- clay/settings.py | 6 +++++- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/clay/app.py b/clay/app.py index a472388..1fc97f4 100755 --- a/clay/app.py +++ b/clay/app.py @@ -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() diff --git a/clay/player.py b/clay/player.py index bd6ac20..b7fe376 100644 --- a/clay/player.py +++ b/clay/player.py @@ -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: diff --git a/clay/settings.py b/clay/settings.py index c407177..996a826 100644 --- a/clay/settings.py +++ b/clay/settings.py @@ -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)