mirror of
https://github.com/SoongNoonien/mpdevil.git
synced 2023-08-10 21:12:44 +03:00
allow text zooming in lyrics window
This commit is contained in:
parent
1b743c96ee
commit
cf22013983
@ -2453,7 +2453,14 @@ class LyricsWindow(Gtk.ScrolledWindow):
|
||||
# text buffer
|
||||
self._text_buffer=self._text_view.get_buffer()
|
||||
|
||||
# css zoom
|
||||
self._scale=100
|
||||
self._provider=Gtk.CssProvider()
|
||||
self._text_view.get_style_context().add_provider(self._provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
||||
|
||||
# connect
|
||||
self._text_view.connect("scroll-event", self._on_scroll_event)
|
||||
self._text_view.connect("key-press-event", self._on_key_press_event)
|
||||
self._client.emitter.connect("disconnected", self._on_disconnected)
|
||||
self._song_changed=self._client.emitter.connect("current_song", self._refresh)
|
||||
self._client.emitter.handler_block(self._song_changed)
|
||||
@ -2474,6 +2481,11 @@ class LyricsWindow(Gtk.ScrolledWindow):
|
||||
def disable(self, *args):
|
||||
self._client.emitter.handler_block(self._song_changed)
|
||||
|
||||
def _zoom(self, scale):
|
||||
if 30 <= scale <= 500:
|
||||
self._provider.load_from_data(bytes(f"textview{{font-size: {scale}%}}", "utf-8"))
|
||||
self._scale=scale
|
||||
|
||||
def _get_lyrics(self, title, artist):
|
||||
title=urllib.parse.quote_plus(title)
|
||||
artist=urllib.parse.quote_plus(artist)
|
||||
@ -2508,6 +2520,25 @@ class LyricsWindow(Gtk.ScrolledWindow):
|
||||
self._displayed_song_file=None
|
||||
self._text_buffer.set_text("", -1)
|
||||
|
||||
def _on_scroll_event(self, widget, event):
|
||||
if event.state & Gdk.ModifierType.CONTROL_MASK:
|
||||
if event.delta_y < 0:
|
||||
self._zoom(self._scale+10)
|
||||
elif event.delta_y > 0:
|
||||
self._zoom(self._scale-10)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def _on_key_press_event(self, widget, event):
|
||||
if event.state & Gdk.ModifierType.CONTROL_MASK:
|
||||
if event.keyval == Gdk.keyval_from_name("plus"):
|
||||
self._zoom(self._scale+10)
|
||||
elif event.keyval == Gdk.keyval_from_name("minus"):
|
||||
self._zoom(self._scale-10)
|
||||
elif event.keyval == Gdk.keyval_from_name("0"):
|
||||
self._zoom(100)
|
||||
|
||||
def _on_disconnected(self, *args):
|
||||
self._displayed_song_file=None
|
||||
self._text_buffer.set_text("", -1)
|
||||
|
Loading…
Reference in New Issue
Block a user