From 58a31f8abb95d781c7d54ff74b73d6adc80c4205 Mon Sep 17 00:00:00 2001 From: Joe R Date: Mon, 3 May 2021 23:33:19 -0400 Subject: [PATCH] Added enable/disable music option. --- pysollib/actions.py | 3 ++- pysollib/options.py | 3 +++ pysollib/pysolaudio.py | 12 +++++++----- pysollib/tile/soundoptionsdialog.py | 8 ++++++++ pysollib/ui/tktile/menubar.py | 10 ++-------- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/pysollib/actions.py b/pysollib/actions.py index 6f135482..0bd29959 100644 --- a/pysollib/actions.py +++ b/pysollib/actions.py @@ -848,7 +848,8 @@ class PysolMenubar(PysolMenubarTk): def mPlayNextMusic(self, *args): if self._cancelDrag(break_pause=False): return - if self.app.audio and self.app.opt.sound_music_volume > 0: + if (self.app.audio and self.app.music and + self.app.opt.sound_music_volume > 0): self.app.audio.playNextMusic() if 1 and DEBUG: index = self.app.audio.getMusicInfo() diff --git a/pysollib/options.py b/pysollib/options.py index 68bd716d..172ff645 100644 --- a/pysollib/options.py +++ b/pysollib/options.py @@ -119,6 +119,7 @@ sound = boolean sound_mode = integer(0, 1) sound_sample_volume = integer(0, 128) sound_sample_buffer_size = integer(1, 4) +music = boolean tabletile_name = string recent_gameid = int_list favorite_gameid = int_list @@ -261,6 +262,7 @@ class Options: ('sound_sample_volume', 'int'), ('sound_music_volume', 'int'), ('sound_sample_buffer_size', 'int'), + ('music', 'bool'), ('tabletile_name', 'str'), ('translate_game_names', 'bool'), ('solver_presets', 'list'), @@ -353,6 +355,7 @@ class Options: self.sound_sample_volume = 75 self.sound_music_volume = 100 self.sound_sample_buffer_size = 1 # 1 - 4 (1024 - 4096 bytes) + self.music = True self.sound_samples = { 'areyousure': True, 'autodrop': True, diff --git a/pysollib/pysolaudio.py b/pysollib/pysolaudio.py index 1f399b8f..009cbf3d 100644 --- a/pysollib/pysolaudio.py +++ b/pysollib/pysolaudio.py @@ -225,7 +225,7 @@ class PysolSoundServerModuleClient(AbstractAudioClient): return -1 def playContinuousMusic(self, music_list): - if self.audiodev is None or not self.app: + if self.audiodev is None or not self.app or not self.app.opt.music: return try: loop = 999999 @@ -248,7 +248,8 @@ class PysolSoundServerModuleClient(AbstractAudioClient): s, m = 0, 0 if self.app.opt.sound: s = self.app.opt.sound_sample_volume - m = self.app.opt.sound_music_volume + if self.app.opt.music: + m = self.app.opt.sound_music_volume try: self.cmd("setwavvol %d" % s) self.cmd("setmusvol %d" % m) @@ -565,10 +566,10 @@ class PyGameAudioClient(AbstractAudioClient): if not music_list: return while True: - if not self.music: + if not self.music or not self.app.opt.music: break for m in music_list: - if not self.music: + if not self.music or not self.app.opt.music: break vol = self.app.opt.sound_music_volume/128.0 try: @@ -603,7 +604,8 @@ class PyGameAudioClient(AbstractAudioClient): th.start() def updateSettings(self): - if not self.app.opt.sound or self.app.opt.sound_music_volume == 0: + if (not self.app.opt.sound or not self.app.opt.music or + self.app.opt.sound_music_volume == 0): if self.music: self.music.stop() self.music = None diff --git a/pysollib/tile/soundoptionsdialog.py b/pysollib/tile/soundoptionsdialog.py index 8072b7e8..3f4e05ca 100644 --- a/pysollib/tile/soundoptionsdialog.py +++ b/pysollib/tile/soundoptionsdialog.py @@ -52,6 +52,8 @@ class SoundOptionsDialog(MfxDialog): self.sound_mode.set(app.opt.sound_mode != 0) self.sample_volume = tkinter.IntVar() self.sample_volume.set(app.opt.sound_sample_volume) + self.music = tkinter.BooleanVar() + self.music.set(app.opt.music != 0) self.music_volume = tkinter.IntVar() self.music_volume.set(app.opt.sound_music_volume) self.samples = [ @@ -110,6 +112,11 @@ class SoundOptionsDialog(MfxDialog): length="3i", # label=_('Sample volume'), variable=self.sample_volume) w.grid(row=row, column=1, sticky='w', padx=5) + row += 1 + w = ttk.Checkbutton(frame, variable=self.music, + text=_("Music enabled")) + w.grid(row=row, column=0, columnspan=2, sticky='ew') + row += 1 ttk.Label(frame, text=_('Music volume:'), anchor='w' ).grid(row=row, column=0, sticky='ew') @@ -159,6 +166,7 @@ class SoundOptionsDialog(MfxDialog): self.app.opt.sound_mode = int(self.sound_mode.get()) self.app.opt.sound_sample_volume = self.sample_volume.get() self.app.opt.sound_music_volume = self.music_volume.get() + self.app.opt.music = self.music.get() for n, t, v in self.samples: self.app.opt.sound_samples[n] = v.get() elif button == 2: diff --git a/pysollib/ui/tktile/menubar.py b/pysollib/ui/tktile/menubar.py index 351cfb0e..294f0649 100644 --- a/pysollib/ui/tktile/menubar.py +++ b/pysollib/ui/tktile/menubar.py @@ -516,14 +516,8 @@ class PysolMenubarTkCommon: command=self.mOptShisenShowHint) menu.add_separator() label = n_("&Sound...") - if not self.app.audio.CAN_PLAY_SOUND: - menu.add_checkbutton( - label=label, variable=self.tkopt.sound, - command=self.mOptSoundDialog, state='disabled') - else: - menu.add_checkbutton( - label=label, variable=self.tkopt.sound, - command=self.mOptSoundDialog) + menu.add_command( + label=label, command=self.mOptSoundDialog) # cardsets if USE_PIL: submenu = MfxMenu(menu, label=n_("Card si&ze"))