feat: add mute button with sad dialog
Mute button in headerbar kills mpv process and shows :( dialog. Button becomes disabled and shows muted speaker icon after use.
This commit is contained in:
+36
-3
@@ -241,17 +241,50 @@ class Hello(Gtk.Window):
|
|||||||
|
|
||||||
self.window.show()
|
self.window.show()
|
||||||
self.play_welcome_song()
|
self.play_welcome_song()
|
||||||
|
self.setup_mute_button()
|
||||||
|
|
||||||
def play_welcome_song(self):
|
def play_welcome_song(self):
|
||||||
song = "/usr/share/cnchi-memes/its-raining-tacos.opus"
|
song = "/usr/share/cnchi-memes/its-raining-tacos.opus"
|
||||||
|
self.mpv_process = None
|
||||||
if os.path.isfile(song):
|
if os.path.isfile(song):
|
||||||
try:
|
try:
|
||||||
subprocess.Popen(["mpv", "--really-quiet", "--volume=55", song],
|
self.mpv_process = subprocess.Popen(
|
||||||
stdout=subprocess.DEVNULL,
|
["mpv", "--really-quiet", "--volume=55", song],
|
||||||
stderr=subprocess.DEVNULL)
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def setup_mute_button(self):
|
||||||
|
mute_btn = self.builder.get_object("mute")
|
||||||
|
icon = Gtk.Image.new_from_icon_name("audio-volume-high", Gtk.IconSize.BUTTON)
|
||||||
|
mute_btn.set_image(icon)
|
||||||
|
|
||||||
|
def on_mute_clicked(self, btn):
|
||||||
|
if self.mpv_process and self.mpv_process.poll() is None:
|
||||||
|
self.mpv_process.terminate()
|
||||||
|
try:
|
||||||
|
self.mpv_process.wait(timeout=3)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
self.mpv_process.kill()
|
||||||
|
|
||||||
|
btn.set_sensitive(False)
|
||||||
|
icon = Gtk.Image.new_from_icon_name("audio-volume-muted", Gtk.IconSize.BUTTON)
|
||||||
|
btn.set_image(icon)
|
||||||
|
|
||||||
|
dialog = Gtk.MessageDialog(
|
||||||
|
transient_for=self.window,
|
||||||
|
flags=0,
|
||||||
|
message_type=Gtk.MessageType.INFO,
|
||||||
|
buttons=Gtk.ButtonsType.OK,
|
||||||
|
text=":(",
|
||||||
|
)
|
||||||
|
dialog.format_secondary_text(
|
||||||
|
"You muted the welcome song...\n\nThe program is sad now."
|
||||||
|
)
|
||||||
|
dialog.run()
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
def get_best_locale(self):
|
def get_best_locale(self):
|
||||||
"""Choose locale, based on user's preferences.
|
"""Choose locale, based on user's preferences.
|
||||||
:return: locale to use
|
:return: locale to use
|
||||||
|
|||||||
@@ -585,6 +585,19 @@ We, the Antergos NeXT Developers, hope that you will enjoy using Antergos NeXT a
|
|||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
<property name="title">Antergos NeXT Hello</property>
|
<property name="title">Antergos NeXT Hello</property>
|
||||||
<property name="show-close-button">True</property>
|
<property name="show-close-button">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="mute">
|
||||||
|
<property name="name">mute</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="receives-default">True</property>
|
||||||
|
<property name="tooltip-text" translatable="yes">Mute welcome song</property>
|
||||||
|
<signal name="clicked" handler="on_mute_clicked" swapped="yes"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="pack-type">end</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="about">
|
<object class="GtkButton" id="about">
|
||||||
<property name="name">about</property>
|
<property name="name">about</property>
|
||||||
|
|||||||
Reference in New Issue
Block a user