Fix equalizer keybind and a temporary vlc fix

This commit is contained in:
Valentijn 2018-03-07 11:59:43 +01:00
parent 688ff915b2
commit dfe5198111
10 changed files with 58 additions and 26 deletions

View file

@ -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():

View file

@ -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

View file

@ -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

View file

@ -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):
"""

View file

@ -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

View file

@ -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):
"""

View file

@ -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):
"""

View file

@ -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
"""

View file

@ -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()

View file

@ -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