def pa_source_changed_cb(self, obj, index):
     obj.get_devices()
     current_source = pypulse.get_fallback_source_index()
     if current_source is None or current_source != index:
         return
     self.__set_input_status()
     self.__set_input_port_status()
 def microphone_port_changed(self, combo, content, value, index):
     current_source = pypulse.get_fallback_source_index()
     if current_source is None:
         return
     if value in self.__current_source_ports:
         port = self.__current_source_ports[value][0]
         pypulse.PULSE.set_input_active_port(current_source, port)
         self.set_status_text(_("Set input port to %s") % content)
 def microphone_value_changed_cb(self, widget, value):
     if not self.button_widgets["microphone"].get_active():
         self.button_widgets["microphone"].set_active(True)
     current_source = pypulse.get_fallback_source_index()
     if current_source is None:
         return
     channel_list = pypulse.PULSE.get_input_channels_by_index(current_source)
     if not channel_list:
         return
     volume = int((value) / 100.0 * pypulse.NORMAL_VOLUME_VALUE)
     pypulse.PULSE.set_input_volume(current_source, [volume] * channel_list['channels'])
    def microphone_value_changed_thread(self):
        ''' microphone value changed callback thread'''
        if not self.microphone_mute_button.get_active():
            self.microphone_mute_button.set_active(True)
        current_source = pypulse.get_fallback_source_index()
        if current_source is None:
            return
        channel_list = pypulse.PULSE.get_input_channels_by_index(current_source)
        if not channel_list:
            return

        volume = int((self.microphone_scale.get_value()) / 100.0 * pypulse.NORMAL_VOLUME_VALUE)
        pypulse.PULSE.set_input_volume(current_source, [volume] * channel_list['channels'])
 def microphone_toggled_cb(self, button):
     if button.get_data("change-by-other"):
         button.set_data("change-by-other", False)
         return
     active = button.get_active()
     current_source = pypulse.get_fallback_source_index()
     self.scale_widgets["microphone"].set_enable(active)
     if current_source is not None:
         pypulse.PULSE.set_input_mute(current_source, not active)
     if not active:
         self.label_widgets["microphone_volume"].set_text("<span foreground=\"%s\">%s</span>" % (MUTE_TEXT_COLOR, _("Input Volume")))
         self.set_status_text(_("Muted input"))
     else:
         self.label_widgets["microphone_volume"].set_text("%s" % _("Input Volume"))
         self.set_status_text(_("Unmuted input"))
 def __set_input_treeview_status(self):
     current_source = pypulse.get_fallback_source_index()
     sources = pypulse.PULSE.get_input_devices()
     input_list = []
     i = 0
     selected_row = -1
     for idx in sources:
         if current_source is not None and current_source == idx:
             selected_row = i
         if 'device.description' in sources[idx]['proplist']:
             description = sources[idx]['proplist']['device.description'].strip('\x00')
         else:
             description = ""
         input_list.append(TreeItem(self.image_widgets["device"], description, sources[idx]['name'], idx))
         i += 1
     self.view_widgets["ad_input"].add_items(input_list, clear_first=True)
     if not (selected_row < 0):
         self.view_widgets["ad_input"].set_select_rows([selected_row])
 def pa_server_changed_cb(self, obj):
     obj.get_devices()
     self.__set_output_status()
     self.__set_output_port_status()
     current_sink = pypulse.get_fallback_sink_index()
     if current_sink is not None:
         for item in self.view_widgets["ad_output"].get_items():
             if item.device_index == current_sink:
                 self.view_widgets["ad_output"].select_items([item])
                 break
     self.__set_input_status()
     self.__set_input_port_status()
     current_source = pypulse.get_fallback_source_index()
     if current_source is not None:
         for item in self.view_widgets["ad_input"].get_items():
             if item.device_index == current_source:
                 self.view_widgets["ad_input"].select_items([item])
                 break
 def __set_input_port_status(self):
     current_source = pypulse.get_fallback_source_index()
     sources = pypulse.PULSE.get_input_devices()
     self.__current_source_ports= {}
     if current_source is None:
         return
     elif current_source in sources:
         ports = sources[current_source]['ports']
         active_port = pypulse.PULSE.get_input_active_ports_by_index(current_source)
         if active_port is None:
             select_index = 0
         i = 0
         items = []
         for p in ports:
             self.__current_source_ports[i] = (p[0], p[1])
             items.append((p[1], i))
             if active_port and active_port[0] == p[0]:
                 select_index = i
             i += 1
         if not items:
             items.append((" ", 0))
         self.button_widgets["microphone_combo"].add_items(items, select_index)
 def __set_input_status(self):
     # if sources list is empty, then can't set input volume
     current_source = pypulse.get_fallback_source_index()
     sources = pypulse.PULSE.get_input_devices()
     if current_source is None:
         self.microphone_scale.set_sensitive(False)
         self.microphone_mute_button.set_sensitive(False)
         self.microphone_scale.set_enable(False)
         self.microphone_mute_button.set_active(False)
     # set input volume
     elif current_source in sources:
         self.microphone_scale.set_sensitive(True)
         self.microphone_mute_button.set_sensitive(True)
         is_mute = sources[current_source]['mute']
         self.microphone_mute_button.set_active(not is_mute)
         self.microphone_scale.set_enable(not is_mute)
         source_volume = pypulse.PULSE.get_input_volume()
         if current_source in source_volume:
             volume = max(source_volume[current_source])
         else:
             volume = 0
         self.microphone_scale.set_value(volume * 100.0 / pypulse.NORMAL_VOLUME_VALUE)
    def __set_input_status(self):
        # if sources list is empty, then can't set input volume
        current_source = pypulse.get_fallback_source_index()
        sources = pypulse.PULSE.get_input_devices()
        if current_source is None:
            self.label_widgets["microphone_port"].set_sensitive(False)
            self.label_widgets["microphone_mute"].set_sensitive(False)
            self.label_widgets["microphone_volume"].set_sensitive(False)

            self.button_widgets["microphone_combo"].set_sensitive(False)
            self.button_widgets["microphone"].set_sensitive(False)
            self.scale_widgets["microphone"].set_sensitive(False)

            if self.button_widgets["microphone"].get_active() and not self.__first_time:
                self.button_widgets["microphone"].set_data("change-by-other", True)
            self.button_widgets["microphone"].set_active(False)
            self.scale_widgets["microphone"].set_enable(False)
        # set input volume
        elif current_source in sources:
            self.label_widgets["microphone_port"].set_sensitive(True)
            self.label_widgets["microphone_mute"].set_sensitive(True)
            self.label_widgets["microphone_volume"].set_sensitive(True)

            self.button_widgets["microphone_combo"].set_sensitive(True)
            self.button_widgets["microphone"].set_sensitive(True)
            self.scale_widgets["microphone"].set_sensitive(True)

            is_mute = sources[current_source]['mute']
            if self.button_widgets["microphone"].get_active() == is_mute and not self.__first_time:
                self.button_widgets["microphone"].set_data("change-by-other", True)
            self.button_widgets["microphone"].set_active(not is_mute)
            self.scale_widgets["microphone"].set_enable(not is_mute)
            source_volume = pypulse.PULSE.get_input_volume()
            if current_source in source_volume:
                volume = max(source_volume[current_source])
            else:
                volume = 0
            self.scale_widgets["microphone"].set_value(volume * 100.0 / pypulse.NORMAL_VOLUME_VALUE)
 def input_treeview_clicked(self, tree_view, item, row, *args):
     if item.device_index == pypulse.get_fallback_source_index():
         return
     pypulse.PULSE.set_fallback_source(item.device_name)
     self.set_status_text(_("Input device %s selected") % item.content)
 def microphone_toggled(self, button):
     active = button.get_active()
     current_source = pypulse.get_fallback_source_index()
     self.microphone_scale.set_enable(active)
     if current_source is not None:
         pypulse.PULSE.set_input_mute(current_source, not active)