""" Combined widget for channel and volume, see toolbar_widget.ui """ ## MODULE IMPORTS ######################################################## import sys, os KBTV_MAINPATH = os.path.dirname(os.path.abspath(sys.argv[0])) if not KBTV_MAINPATH in sys.path: sys.path.append(KBTV_MAINPATH) import btcopyright, bthardware from toolbar_widget import ToolbarWidget from qt import QObject, QTimer, SIGNAL ## MODULE COPYRIGHT ###################################################### MODULE_AUTHOR = btcopyright.MY_NAME MODULE_AUTHOR_EMAIL = btcopyright.MY_EMAIL MODULE_COPYRIGHT = btcopyright.MY_COPYRIGHT MODULE_LICENSE = btcopyright.BSD_LICENSE MODULE_LICENSE_TEXT = btcopyright.BSD_LICENSE_TEXT ## KBTVTOOLBARWIDGET CLASS ############################################### class KbtvToolbarWidget(ToolbarWidget): """ Describes a combined toolbar widget consisting of a restricted line edit (restricted to numbers) and a volume slider. """ def __init__(self, mainpart, *args): """ -> KbtvToolbarWidget Creates a widget with on the left a fixed sized restricted line edit and on the right an extending slider for setting the volume. Uses the bthardware module for volume adjustment, and the current channel list object for changing channels. Pass the main window/part as the first argument. Inherits ToolbarWidget, generated from toolbar_widget.ui. """ ToolbarWidget.__init__(self, *args) self.part = mainpart self.channelbox.setText("0") # index self.mixerchan = bthardware.MIXER_CHANNEL_NAMES.index(self.part.mixerchan) # Note use of max() on the volume tuple self.volumeslider.setValue(max(bthardware.mixer_volume(self.mixerchan))) # Keep track of the actual volume self.timer = QTimer(self) QObject.connect(self.timer, SIGNAL("timeout()"), self.updateVolume) self.timer.start(250) def setVolume(self): """ -> void SLOT. Sets the volume (left = right) to the slider's value. """ val = self.volumeslider.value() bthardware.mixer_volume_set(self.mixerchan, (val ,val)) def setChannel(self): """ -> void SLOT. Sets and tunes to the channel in the line edit. """ self.part.tuneTo(int(str(self.channelbox.text()))) def updateVolume(self): """ -> void Timer SLOT. If the volume has changed the volume slider's value is adjusted. """ vol = max(bthardware.mixer_volume(self.mixerchan)) if self.volumeslider.value() != vol: self.volumeslider.setValue(vol) ## END ################################################################### if __name__ == "__main__": print "This is a module. Import it instead."