diff --git a/clay/core/gp.py b/clay/core/gp.py index bf0f712..b281602 100644 --- a/clay/core/gp.py +++ b/clay/core/gp.py @@ -12,6 +12,9 @@ try: from PIL import Image except ImportError: Image = None + +import sys + from io import BytesIO from hashlib import sha1 from threading import Thread, Lock @@ -19,7 +22,8 @@ from uuid import UUID from gmusicapi.clients import Mobileclient from clay.core.log import logger -from . import EventHook, settings +from .settings import settings_manager +from . import EventHook STATION_FETCH_LEN = 50 @@ -73,8 +77,9 @@ def synchronized(func): """ Inner function. """ + lock.acquire() + try: - lock.acquire() return func(*args, **kwargs) finally: lock.release() @@ -227,7 +232,7 @@ class Track(object): if self.artist_art_url is None: return None - if not settings.get_is_file_cached(self.artist_art_filename): + if not settings_manager.get_is_file_cached(self.artist_art_filename): response = urlopen(self.artist_art_url) data = response.read() if Image: @@ -236,9 +241,9 @@ class Track(object): out = BytesIO() image.save(out, format='JPEG') data = out.getvalue() - settings.save_file_to_cache(self.artist_art_filename, data) + settings_manager.save_file_to_cache(self.artist_art_filename, data) - return settings.get_cached_file_path(self.artist_art_filename) + return settings_manager.get_cached_file_path(self.artist_art_filename) # get_artist_arg_filename_async = asynchronous(get_artist_art_filename) diff --git a/clay/playback/abstract.py b/clay/playback/abstract.py index 25ff247..c4d2b02 100644 --- a/clay/playback/abstract.py +++ b/clay/playback/abstract.py @@ -376,3 +376,5 @@ class AbstractPlayer: Set a list of equalizer amplifications for each band. """ raise NotImplementedError + +player = AbstractPlayer() # pylint: disable=invalid-name diff --git a/clay/ui/urwid/__init__.py b/clay/ui/urwid/__init__.py index a28ccce..a2c69c5 100644 --- a/clay/ui/urwid/__init__.py +++ b/clay/ui/urwid/__init__.py @@ -1,5 +1,6 @@ import urwid import sys +import threading from clay.core import gp, settings_manager from clay.playback.vlc import player @@ -305,6 +306,7 @@ class AppWidget(urwid.Frame): Quit app. """ self.loop = None + hotkey_manager.quit() sys.exit(0) def handle_escape(self): diff --git a/clay/ui/urwid/hotkeys.py b/clay/ui/urwid/hotkeys.py index 4148e58..29a2833 100644 --- a/clay/ui/urwid/hotkeys.py +++ b/clay/ui/urwid/hotkeys.py @@ -3,8 +3,10 @@ Hotkeys management. Requires "gi" package and "Gtk" & "Keybinder" modules. """ # pylint: disable=broad-except +import os import threading + from clay.core import EventHook, settings_manager, logger from .notifications import notification_area @@ -51,11 +53,12 @@ class _HotkeyManager(object): self.next = EventHook() self.prev = EventHook() - if IS_INIT: + if IS_INIT and os.environ.get("DISPLAY") is not None and \ + settings_manager.get('x_keybinds', 'clay_settings'): Keybinder.init() self.initialize() threading.Thread(target=Gtk.main).start() - else: + elif not IS_INIT: logger.debug("Not loading the global shortcuts.") notification_area.notify( ERROR_MESSAGE + @@ -125,6 +128,10 @@ class _HotkeyManager(object): return hotkeys + def quit(self): + """Quits the keybinder""" + Gtk.main_quit() + def keypress(self, name, caller, super_, size, key): """ Process the pressed key by looking it up in the configuration file @@ -161,4 +168,5 @@ class _HotkeyManager(object): getattr(self, operation).fire() + hotkey_manager = _HotkeyManager() # pylint: disable=invalid-name