Disable volume slider if volume can't be set

This commit is contained in:
karxi 2017-01-09 18:59:57 -05:00
parent e78bb31249
commit 43e8a589f1
2 changed files with 46 additions and 5 deletions

View file

@ -2,7 +2,7 @@ from PyQt4 import QtGui, QtCore
import re, ostools
from os import remove
from generic import RightClickList, RightClickTree, MultiTextDialog
from generic import RightClickList, RightClickTree, MultiTextDialog, NoneSound
from dataobjs import pesterQuirk, PesterProfile
from memos import TimeSlider, TimeInput
from version import _pcVersion
@ -1065,7 +1065,18 @@ class PesterOptions(QtGui.QDialog):
self.volume.setValue(self.config.volume())
self.connect(self.volume, QtCore.SIGNAL('valueChanged(int)'),
self, QtCore.SLOT('printValue(int)'))
self.currentVol = QtGui.QLabel(str(self.config.volume())+"%", self)
# Disable the volume slider if we can't actually use it.
if parent.canSetVolume():
self.currentVol = QtGui.QLabel(
"{0!s}%".format(self.config.volume()), self)
# We don't need to explicitly set this, but it helps drive the
# point home
self.volume.setEnabled(True)
else:
# We can't set the volume....
self.currentVol = QtGui.QLabel(
"(Disabled: Sound Mixer Error)", self)
self.volume.setEnabled(False)
self.currentVol.setAlignment(QtCore.Qt.AlignHCenter)
@ -1233,6 +1244,7 @@ class PesterOptions(QtGui.QDialog):
self.notifyChange(self.notifycheck.checkState())
if parent.advanced:
# NOTE: This doesn't do anything right now - so change it!
self.modechange = QtGui.QLineEdit(self)
layout_change = QtGui.QHBoxLayout()
layout_change.addWidget(QtGui.QLabel("Change:"))
@ -1308,7 +1320,13 @@ class PesterOptions(QtGui.QDialog):
layout_indent.setContentsMargins(22,0,0,0)
layout_sound.addLayout(layout_indent)
layout_sound.addSpacing(15)
layout_sound.addWidget(QtGui.QLabel("Master Volume:", self))
mvol = QtGui.QLabel("Master Volume:", self)
# If we can't set the volume, grey this out as well
#~mvol.setEnabled(parent.canSetVolume())
# Normally we'd grey this out, but that presently makes things
# rather unreadable
# Later we can look into changing the color to a theme[] entry
layout_sound.addWidget(mvol)
layout_sound.addWidget(self.volume)
layout_sound.addWidget(self.currentVol)
self.pages.addWidget(widget)

View file

@ -1086,6 +1086,13 @@ class PesterWindow(MovingWindow):
self.tabconvo = None
self.tabmemo = None
self.shortcuts = AttrDict()
# karxi: For the record, these are set via commandline arguments. By
# default, they aren't usable any other way - you can't set them via
# the config files.
# ...which means the flag for disabling honking is also hidden and
# impossible to set via pesterchum.js.
#
# This was almost certainly intentional.
if "advanced" in options:
self.advanced = options["advanced"]
else: self.advanced = False
@ -1108,12 +1115,14 @@ class PesterWindow(MovingWindow):
self.theme = self.userprofile.getTheme()
self.modes = ""
self.sound_type = None
self.randhandler = RandomHandler(self)
try:
themeChecker(self.theme)
except ThemeException as inst:
print "Caught: " + inst.parameter
logging.error("Caught: " + inst.parameter)
themeWarning = QtGui.QMessageBox(self)
themeWarning.setText("Theme Error: %s" % inst)
themeWarning.exec_()
@ -1814,6 +1823,8 @@ class PesterWindow(MovingWindow):
# We don't have any options...just use fillers.
soundclass = NoneSound
self.sound_type = soundclass
# Use the class we chose to build the sound set.
try:
# karxi: These all seem to be created using local paths.
@ -1825,7 +1836,7 @@ class PesterWindow(MovingWindow):
self.ceasesound = soundclass(self.theme["main/sounds/ceasesound"])
self.honksound = soundclass("themes/honk.wav")
except Exception as err:
print "Warning: Error loading sounds!"
logging.error("Warning: Error loading sounds! ({0!r})".format(err))
self.alarm = NoneSound()
self.memosound = NoneSound()
self.namesound = NoneSound()
@ -1852,6 +1863,18 @@ class PesterWindow(MovingWindow):
except Exception as err:
logging.info("Couldn't set volume: {}".format(err))
def canSetVolume(self):
"""Returns the state of volume setting capabilities."""
# If the volume can be changed by Pesterchum.
if self.sound_type is None:
# We haven't initialized yet.
return False
if pygame and pygame.mixer:
# pygame lets us set the volume, thankfully
return True
# Aside from that, we don't have any alternatives at the moment.
return False
def changeTheme(self, theme):
# check theme
try: