def test_ext_stream_restore(self):
        sr_name1 = 'sink-input-by-application-name:pulsectl-test-1'
        sr_name2 = 'sink-input-by-application-name:pulsectl-test-2'

        with pulsectl.Pulse('t', server=self.sock_unix) as pulse:
            self.assertIsNotNone(pulse.stream_restore_test())

            pulse.stream_restore_write(sr_name1, volume=0.5, mute=True)
            pulse.stream_restore_write(pulsectl.PulseExtStreamRestoreInfo(
                sr_name2, volume=0.3, channel_list='mono'),
                                       apply_immediately=True)

            sr_list = pulse.stream_restore_list()
            self.assertIsInstance(sr_list, list)
            self.assertTrue(sr_list)
            sr_dict = dict((sr.name, sr) for sr in sr_list)
            self.assertEqual(sr_dict[sr_name1].volume.value_flat, 0.5)
            self.assertEqual(sr_dict[sr_name1].mute, 1)
            self.assertEqual(sr_dict[sr_name1].channel_list,
                             ['front-left', 'front-right'])
            self.assertIn(sr_name2, sr_dict)
            self.assertEqual(sr_dict[sr_name2].channel_list, ['mono'])

            pulse.stream_restore_delete(sr_name1)
            sr_dict = dict((sr.name, sr) for sr in pulse.stream_restore_list())
            self.assertNotIn(sr_name1, sr_dict)
            self.assertIn(sr_name2, sr_dict)

            pulse.stream_restore_write([
                pulsectl.PulseExtStreamRestoreInfo(
                    sr_name1,
                    volume=0.7,
                    channel_list=['front-left', 'front-right']),
                sr_dict[sr_name2]
            ],
                                       mode='merge')
            pulse.stream_restore_write(sr_name1,
                                       volume=0.3,
                                       channel_list='mono',
                                       mute=True)
            sr_dict = dict((sr.name, sr) for sr in pulse.stream_restore_list())
            self.assertEqual(sr_dict[sr_name1].volume.value_flat, 0.7)
            self.assertEqual(sr_dict[sr_name1].mute, 0)
            self.assertEqual(sr_dict[sr_name1].channel_list,
                             ['front-left', 'front-right'])

            pulse.stream_restore_write(sr_name1, volume=0.4, mode='replace')
            sr_dict = dict((sr.name, sr) for sr in pulse.stream_restore_list())
            self.assertEqual(sr_dict[sr_name1].volume.value_flat, 0.4)

            pulse.stream_restore_write(sr_name2, volume=0.9, mode='set')
            sr_dict = dict((sr.name, sr) for sr in pulse.stream_restore_list())
            self.assertEqual(sr_dict[sr_name2].volume.value_flat, 0.9)
            self.assertEqual(list(sr_dict.keys()), [sr_name2])

            pulse.stream_restore_write([], mode='set')  # i.e. remove all
            sr_dict = dict((sr.name, sr) for sr in pulse.stream_restore_list())
            self.assertNotIn(sr_name1, sr_dict)
            self.assertNotIn(sr_name2, sr_dict)
Beispiel #2
0
    def on_add_new_rule_clicked(self, widget):
        dialog = DialogNewRoutingRule(self)
        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            rule_type = dialog.type_combo.get_active_text()
            rule_name = dialog.name_entry.get_text()
            vol = float(dialog.volume_entry.get_text()) / 100.0
            device = None if dialog.device_entry.get_text(
            ) == "None" else dialog.device_entry.get_text()
            muted = dialog.mute_switch.get_state()
            new_rule = pulsectl.PulseExtStreamRestoreInfo(
                struct_or_name=rule_type + ":" + rule_name,
                device=device,
                volume=[vol, vol],
                mute=muted,
                channel_list=['front-left', 'front-right'])
            pulse.stream_restore_write(new_rule, mode='replace')
            self.on_refreshed_listbox(None)

        dialog.destroy()