def __set_output_status(self):
        # if sinks list is empty, then can't set output volume
        current_sink = pypulse.get_fallback_sink_index()
        sinks = pypulse.PULSE.get_output_devices()
        if current_sink is None:
            self.label_widgets["speaker_port"].set_sensitive(False)
            self.label_widgets["speaker_mute"].set_sensitive(False)
            self.label_widgets["speaker_volume"].set_sensitive(False)
            self.label_widgets["speaker_balance"].set_sensitive(False)

            self.button_widgets["speaker_combo"].set_sensitive(False)
            self.button_widgets["speaker"].set_sensitive(False)
            self.scale_widgets["speaker"].set_sensitive(False)
            self.scale_widgets["balance"].set_sensitive(False)

            if self.button_widgets["speaker"].get_active() and not self.__first_time:
                self.button_widgets["speaker"].set_data("change-by-other", True)
            self.button_widgets["speaker"].set_active(False)
            self.scale_widgets["speaker"].set_enable(False)
            self.scale_widgets["balance"].set_enable(False)
        # set output volume
        elif current_sink in sinks:
            self.label_widgets["speaker_port"].set_sensitive(True)
            self.label_widgets["speaker_mute"].set_sensitive(True)
            self.label_widgets["speaker_volume"].set_sensitive(True)
            self.label_widgets["speaker_balance"].set_sensitive(True)

            self.button_widgets["speaker_combo"].set_sensitive(True)
            self.button_widgets["speaker"].set_sensitive(True)
            self.scale_widgets["speaker"].set_sensitive(True)
            self.scale_widgets["balance"].set_sensitive(True)

            is_mute = sinks[current_sink]['mute']
            if self.button_widgets["speaker"].get_active() == is_mute and not self.__first_time:
                self.button_widgets["speaker"].set_data("change-by-other", True)
            self.button_widgets["speaker"].set_active(not is_mute)
            self.scale_widgets["speaker"].set_enable(not is_mute)
            self.scale_widgets["balance"].set_enable(not is_mute)

            sink_volume = pypulse.PULSE.get_output_volume()
            sink_channel = pypulse.PULSE.get_output_channels_by_index(current_sink)
            balance = None
            if current_sink in sink_volume:
                volume = max(sink_volume[current_sink])
                if sink_channel and sink_channel['can_balance']:
                    balance = pypulse.get_volume_balance(sink_channel['channels'],
                                                         sink_volume[current_sink],
                                                         sink_channel['map'])
                if balance is None:
                    balance = 0
            else:
                volume = 0
                balance = 0
            self.scale_widgets["speaker"].set_value(volume * 100.0 / pypulse.NORMAL_VOLUME_VALUE)
            self.scale_widgets["balance"].set_value(balance)
 def speaker_value_changed_thread(self):
     ''' speaker hscale value changed callback thread'''
     if not self.speaker_mute_button.get_active():
         self.speaker_mute_button.set_active(True)
     current_sink = pypulse.get_fallback_sink_index()
     if current_sink is None:
         return
     volume_list = pypulse.PULSE.get_output_volume_by_index(current_sink)
     channel_list = pypulse.PULSE.get_output_channels_by_index(current_sink)
     if not volume_list or not channel_list:
         return
     balance = pypulse.get_volume_balance(channel_list['channels'], volume_list, channel_list['map'])
     volume = int((self.speaker_scale.get_value()) / 100.0 * pypulse.NORMAL_VOLUME_VALUE)
     pypulse.PULSE.set_output_volume_with_balance(current_sink, volume, balance)