Skip to content

Commit

Permalink
Add ajustable volume for earcons
Browse files Browse the repository at this point in the history
  • Loading branch information
mltony committed Nov 30, 2024
1 parent f4d4cf9 commit b02a69a
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions addon/globalPlugins/browserNav/quickJump.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ class QJBookmark(QJImmutable):
enableAutoSpeak: bool
autoSpeakMode: AutoSpeakMode
builtInWavFile: str
wavFileVolume: int

def __init__(self, d):
object.__setattr__(self, 'enabled', d['enabled'])
Expand Down Expand Up @@ -479,6 +480,10 @@ def __init__(self, d):
object.__setattr__(self, 'enableAutoSpeak', d.get('enableAutoSpeak', False))
object.__setattr__(self, 'autoSpeakMode', AutoSpeakMode(d.get('autoSpeakMode', AutoSpeakMode.OFF.value)))
object.__setattr__(self, 'builtInWavFile', d.get('builtInWavFile', None))
volume = d.get('wavFileVolume', 100)
if volume is None:
volume = 100.0
object.__setattr__(self, 'wavFileVolume', volume)

def asDict(self):
return {
Expand All @@ -499,6 +504,7 @@ def asDict(self):
'enableAutoSpeak': self.enableAutoSpeak,
'autoSpeakMode': self.autoSpeakMode.value,
'builtInWavFile': self.builtInWavFile,
'wavFileVolume': self.wavFileVolume,
}

def getDisplayName(self):
Expand Down Expand Up @@ -1037,8 +1043,10 @@ def diffAndExtractInterestingLines(s1, s2):
elif mode == 'old' and len(line) > 0 and line[0] in {'-'}:
yield line

def playBiw(bookmark=None, earcon=None):
volume = 100.0
def playBiw(bookmark=None, earcon=None, volume=None):
if volume is None:
volume = bookmark.wavFileVolume if bookmark is not None else 100
volume = 1.0 * volume
absPath = os.path.join(
utils.getSoundsPath(),
earcon or bookmark.builtInWavFile,
Expand Down Expand Up @@ -2503,6 +2511,11 @@ def __init__(self, parent, bookmark=None, config=None, site=None, allowSiteSelec
)
self.biwList.control.Bind(wx.EVT_CHOICE,self.onBiw)
self.setBiw(self.bookmark.builtInWavFile)
# Volume slider
label = _("Volume")
self.volumeSlider = sHelper.addLabeledControl(label, wx.Slider, minValue=0,maxValue=100)
self.volumeSlider.SetValue(100)
self.volumeSlider.SetValue(self.bookmark.wavFileVolume)
# Edit script button
self.editScriptButton = sHelper.addItem (wx.Button (self, label = _("Edit &script in new window; press Control+Enter when Done.")))
self.editScriptButton.Bind(wx.EVT_BUTTON, self.OnEditScriptClick)
Expand Down Expand Up @@ -2584,6 +2597,7 @@ def make(self, snippet=None, quiet=False):
#'enableAutoSpeak': self.autoSpeakEnabledCheckBox.Value,
'autoSpeakMode': self.getAutoSpeakMode(),
'builtInWavFile': self.getBiw(),
'wavFileVolume': self.volumeSlider.GetValue(),
})
return bookmark

Expand Down Expand Up @@ -2666,12 +2680,13 @@ def getAutoSpeakMode(self):
def onAutoSpeakMode(self, event):
asm = self.getAutoSpeakMode()
biwControls = [
self.biwCategory,
self.biwList,
self.biwCategory.control,
self.biwList.control,
self.volumeSlider,
]
[biw.control.Enable() for biw in biwControls] if (
[biw.Enable() for biw in biwControls] if (
asm.value.startswith("chime")
) else [biw.control.Disable() for biw in biwControls]
) else [biw.Disable() for biw in biwControls]

def OnEditScriptClick(self,evt):
_snippet = self.snippet
Expand Down Expand Up @@ -2788,8 +2803,9 @@ def setBiw(self, biw):
def onBiw(self, evt):
soundsPath = utils.getSoundsPath()
biw = self.getBiw()
fullPath = os.path.join(soundsPath, biw)
nvwave.playWaveFile(fullPath)
#fullPath = os.path.join(soundsPath, biw)
#nvwave.playWaveFile(fullPath)
playBiw(None, biw, self.volumeSlider.GetValue())

def getBiwCategory(self):
return self.getBiwCategories()[self.biwCategory.control.GetSelection()]
Expand Down

0 comments on commit b02a69a

Please sign in to comment.