diff --git a/clay/app.py b/clay/app.py index dbde90f..cc1252e 100755 --- a/clay/app.py +++ b/clay/app.py @@ -223,7 +223,7 @@ class AppWidget(urwid.Frame): self.set_page(tab.page.__class__.__name__) return - hotkey_manager.keypress("global", self, AppWidget, size, key) + hotkey_manager.keypress("global", self, super(AppWidget, self), size, key) @staticmethod def seek_start(): diff --git a/clay/config.yaml b/clay/config.yaml index 2d0f8d2..e1591cf 100644 --- a/clay/config.yaml +++ b/clay/config.yaml @@ -7,7 +7,6 @@ hotkeys: next: XF86AudioNext prev: XF86AudioPrev - clay_hotkeys: global: seek_start: mod + q @@ -35,6 +34,9 @@ hotkeys: move_down: down hide_context_menu: meta + p + playlist_page: + start_playlist: enter + debug_page: copy_message: enter @@ -42,8 +44,8 @@ hotkeys: send_query: enter settings_page: - up: \+ - down: \- + equalizer_up: "+" + equalizer_down: "-" clay_settings: x_keybinds: false diff --git a/clay/gp.py b/clay/gp.py index 7df902d..825e816 100644 --- a/clay/gp.py +++ b/clay/gp.py @@ -16,7 +16,6 @@ from gmusicapi.clients import Mobileclient from clay.eventhook import EventHook from clay.log import logger - def asynchronous(func): """ Decorates a function to become asynchronous. @@ -49,6 +48,7 @@ def asynchronous(func): callback(result, None, **extra) Thread(target=process).start() + return wrapper diff --git a/clay/hotkeys.py b/clay/hotkeys.py index 57a585f..84b78cb 100644 --- a/clay/hotkeys.py +++ b/clay/hotkeys.py @@ -77,10 +77,11 @@ class _HotkeyManager(object): for hotkey_name, hotkey_dict in hotkey_config.items(): hotkeys[hotkey_name] = {} for action in hotkey_dict.keys(): - key_seq = settings.get(action, 'hotkeys', 'clay_hotkeys', hotkey_name).replace(' ', '') + key_seq = settings.get(action, 'hotkeys', 'clay_hotkeys', hotkey_name)\ + .replace(' ', '') for key in key_seq.split(','): - hotkey = key.split('+') + hotkey = key.split('+') if key != '+' else key if hotkey[0] == 'mod': hotkey[0] = mod_key @@ -106,15 +107,21 @@ class _HotkeyManager(object): return hotkeys - def keypress(self, name, caller, root, size, key): + def keypress(self, name, caller, super_, size, key): + """ + Process the pressed key by looking it up in the configuration file + + """ method_name = self._hotkeys[name].get(key) if method_name: - return getattr(caller, method_name)() - elif root is not None: - return super(root, caller).keypress(size, key) + ret = getattr(caller, method_name)() + elif super_ is not None: + ret = super_.keypress(size, key) else: - return key + ret = key + + return ret def initialize(self): """ diff --git a/clay/pages/debug.py b/clay/pages/debug.py index 7072859..9293fd0 100644 --- a/clay/pages/debug.py +++ b/clay/pages/debug.py @@ -40,6 +40,7 @@ class DebugItem(urwid.AttrMap): return hotkey_manager.keypress("debug_page", self, None, None, key) def copy_message(self): + """Copy the selected error message to the clipboard""" copy(self.log_record.formatted_message) return None diff --git a/clay/pages/myplaylists.py b/clay/pages/myplaylists.py index 0958a6c..4d7a000 100644 --- a/clay/pages/myplaylists.py +++ b/clay/pages/myplaylists.py @@ -34,7 +34,8 @@ class MyPlaylistListItem(urwid.Columns): """ Handle keypress. """ - return hotkey_manager.keypress("playlist_page", self, MyPlaylistListItem, size, key) + return hotkey_manager.keypress("playlist_page", self, super(MyPlaylistListItem, self), + size, key) def start_playlist(self): """ diff --git a/clay/pages/search.py b/clay/pages/search.py index 48e29c2..f76604c 100644 --- a/clay/pages/search.py +++ b/clay/pages/search.py @@ -36,7 +36,7 @@ class SearchBox(urwid.Columns): """ Handle keypress. """ - return hotkey_manager.keypress("search_page", self, SearchBox, size, key) + return hotkey_manager.keypress("search_page", self, super(SearchBox, self), size, key) def send_query(self): """ diff --git a/clay/pages/settings.py b/clay/pages/settings.py index 1590eb6..5bc9813 100644 --- a/clay/pages/settings.py +++ b/clay/pages/settings.py @@ -81,7 +81,7 @@ class Slider(urwid.Widget): """ return hotkey_manager.keypress("settings_page", self, None, None, key) - def up(self): + def equalizer_up(self): """ Turn the equalizer band up """ @@ -91,7 +91,7 @@ class Slider(urwid.Widget): return None - def down(self): + def equalizer_down(self): """ Turn the equalizer band down """ diff --git a/clay/player.py b/clay/player.py index c24589d..93b308d 100644 --- a/clay/player.py +++ b/clay/player.py @@ -4,6 +4,7 @@ Media player built using libVLC. # pylint: disable=too-many-instance-attributes # pylint: disable=too-many-public-methods from random import randint +from ctypes import CFUNCTYPE, c_void_p, c_int, c_char_p import json import os @@ -133,6 +134,14 @@ class _Queue(object): """ return self.tracks +#+pylint: disable=unused-argument +def _dummy_log(data, level, ctx, fmt, args): + """ + A dummy callback function for VLC so it doesn't write to stdout. + Should probably do something in the future + """ + pass +#+pylint: disable=unused-argument class _Player(object): """ @@ -151,6 +160,15 @@ class _Player(object): def __init__(self): self.instance = vlc.Instance() + print_func = CFUNCTYPE(c_void_p, + c_void_p, # data + c_int, # level + c_void_p, # context + c_char_p, # fmt + c_void_p) #args + + self.instance.log_set(print_func(_dummy_log), None) + self.instance.set_user_agent( meta.APP_NAME, meta.USER_AGENT @@ -176,9 +194,7 @@ class _Player(object): ) self.equalizer = vlc.libvlc_audio_equalizer_new() - self.media_player.set_equalizer(self.equalizer) - self._create_station_notification = None self._is_loading = False self.queue = _Queue() diff --git a/clay/songlist.py b/clay/songlist.py index 4ee06ee..a9c41b9 100644 --- a/clay/songlist.py +++ b/clay/songlist.py @@ -144,7 +144,7 @@ class SongListItem(urwid.Pile): """ Handle keypress. """ - return hotkey_manager.keypress("library_item", self, SongListItem, size, key) + return hotkey_manager.keypress("library_item", self, super(SongListItem, self), size, key) def mouse_event(self, size, event, button, col, row, focus): """ @@ -527,7 +527,7 @@ class SongListBox(urwid.Frame): """ Hide context menu. """ - if self.popup is not None and self.is_context_menu_visible(): + if self.popup is not None and self.is_context_menu_visible: self.contents['body'] = (self.content, None) self.app.unregister_cancel_action(self.popup.close) self.popup = None @@ -610,11 +610,15 @@ class SongListBox(urwid.Frame): elif key == 'backspace': self.perform_filtering(key) elif self._is_filtering: - return hotkey_manager.keypress("library_view", self, SongListBox, size, key) + return hotkey_manager.keypress("library_view", self, super(SongListBox, self), + size, key) else: return super(SongListBox, self).keypress(size, key) + return None + def _get_filtered(self): + """Get filtered list of items""" matches = self.get_filtered_items() if not matches: @@ -625,24 +629,25 @@ class SongListBox(urwid.Frame): return (matches, index) def move_to_beginning(self): - """Move to the beginning of the songlist""" - matches, index = self._get_filtered() + """Move to the focus to beginning of the songlist""" + matches, _ = self._get_filtered() self.list_box.set_focus(matches[0].index, 'below') return False def move_to_end(self): - """Move to the end of the songlist""" - matches, index = self._get_filtered() + """Move to the focus to end of the songlist""" + matches, _ = self._get_filtered() self.list_box.set_focus(matches[-1].index, 'above') return False def move_up(self): - """Move an item up in the playlist""" + """Move the focus an item up in the playlist""" matches, index = self._get_filtered() self.list_box.set_focus(*self.get_prev_item(matches, index)) return False def move_down(self): + """Move the focus an item down in the playlist """ matches, index = self._get_filtered() self.list_box.set_focus(*self.get_next_item(matches, index)) return False