mirror of
https://github.com/vale981/clay
synced 2025-03-05 17:41:42 -05:00
Properly exit gtk and listen to the x_hotkeys config option
This commit is contained in:
parent
16fb8e1589
commit
890e51bced
4 changed files with 24 additions and 7 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -376,3 +376,5 @@ class AbstractPlayer:
|
|||
Set a list of equalizer amplifications for each band.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
player = AbstractPlayer() # pylint: disable=invalid-name
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue