From 19ad8c18561dbc04af85f04d821f607c2c187465 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Sat, 16 Mar 2024 14:34:33 +0100 Subject: [PATCH] add separate volume button --- melon/widgets/player.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/melon/widgets/player.py b/melon/widgets/player.py index 0853099..0328976 100644 --- a/melon/widgets/player.py +++ b/melon/widgets/player.py @@ -142,8 +142,6 @@ class VideoPlayer(Gtk.Overlay): self.volume_display = VolumeDisplay(self.volume) overlay.add_overlay(self.volume_display) self.volume_display.hide() - self.change_brightness(self.brightness) - self.change_volume(self.volume) self.controls = Gtk.Box() overlay.add_overlay(self.controls) @@ -170,11 +168,14 @@ class VideoPlayer(Gtk.Overlay): # [pos] ---o-- [dur] self.position_display = Gtk.Label() self.controls.append(self.position_display) - self.progress_display = Gtk.Scale.new(Gtk.Orientation.HORIZONTAL, None) + + self.progress_display = Gtk.Scale() # highlight section left of playhead self.progress_display.set_has_origin(True) # TODO: fix progress bar width + self.progress_display.set_hexpand(True) self.controls.append(self.progress_display) + self.duration_display = Gtk.Label() self.controls.append(self.duration_display) self._update_playhead() @@ -194,6 +195,26 @@ class VideoPlayer(Gtk.Overlay): # unreachable if len(streams) == 0 # which is why we don't need an additinal check self.select_stream(self.streams[0]) + + # volume control slider + # (as an alternative to the slide gesture) + # mapped to 0-100 scale + self.volume_ctr = Gtk.ScaleButton.new(0, 100, 2, [ + # The first item in the array will be used in the button when the current value is the lowest value, + "audio-volume-muted-symbolic", + # the second item for the highest value + "audio-volume-high-symbolic", + # All the subsequent icons will be used for all the other values, spread evenly over the range of values. + "audio-volume-low-symbolic", + "audio-volume-medium-symbolic", + ]) + # self.volume uses the [0,1] interval, but the slider uses [0,100] + self.volume_ctr.set_value(self.volume * 100) + self.volume_ctr.connect("value-changed", lambda w, val: self.change_volume(val/100)) + self.volume_ctr.set_direction(Gtk.ArrowType.UP) + self.volume_ctr.get_popup().set_position(Gtk.PositionType.TOP) + self.controls.append(self.volume_ctr) + # hide controls by default # (after a timeout of 5seconds) self._schedule_hide_controls(5) @@ -214,6 +235,10 @@ class VideoPlayer(Gtk.Overlay): self.swipe_ctr.connect("swipe", self._end_swipe) self.add_controller(self.swipe_ctr) + # initialize volume & brightness + self.change_brightness(self.brightness) + self.change_volume(self.volume) + def connect_update(self, callback=None): self.update_callback = callback def connect_ended(self, callback=None): @@ -268,9 +293,11 @@ class VideoPlayer(Gtk.Overlay): def change_volume(self, vol): self.volume = clamp(0.0, vol, 1.0) self.volume_display.update(self.volume) - # TODO: update player volume + # update player volume self.source.set_property("volume", self.volume) - # TODO: update volume button value (once implemented) + # update volume button value (once implemented) + # self.volume uses the [0,1] interval, but the slider uses [0,100] + self.volume_ctr.set_value(self.volume * 100) def change_brightness(self, bright): self.brightness = clamp(0.0, bright, 1.0) @@ -293,7 +320,6 @@ class VideoPlayer(Gtk.Overlay): def _mouse_leave(self, w): self._schedule_hide_controls() - offset = 50 def _onclick(self): # single click toggles focus # because floats are a thing we can't use == -- 2.38.5