summaryrefslogtreecommitdiffstats
path: root/pulsecaster/ui.py
blob: b60a5d172cd6b7065a7810d2ecc532667aff4dec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/python
#
# Copyright (C) 2009 Paul W. Frields
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Author: Paul W. Frields <stickster@gmail.com>


import gtk
import gtk.glade
from config import *
from pulseaudio.PulseObj import PulseObj
import os

# FIXME
fname = os.getcwd() + '/data/pulsecaster.glade'
logofile = os.getcwd() + '/data/icons/scalable/pulsecaster.svg'
_debug = True

def _debugPrint(text):
    if _debug:
        print (text)

class PulseCatcherUI:
    def __init__(self, runlib=True):
        self.xml = gtk.glade.XML(fname)
        self.logo = gtk.gdk.pixbuf_new_from_file(logofile)
        
        # Main dialog basics
        self.main = self.xml.get_widget('main_dialog')
        self.main.set_title(NAME)
        self.main_title = self.xml.get_widget('main_title')
        self.main_title.set_label('<big><big><big><b><i>' +
                                  NAME + '</i></b></big></big></big>')
        self.main.connect('delete_event', self.on_close)
        self.about_button = self.xml.get_widget('about_button')
        self.about_button.connect('clicked', self.showAbout)
        self.close = self.xml.get_widget('close_button')
        self.close.connect('clicked', self.on_close)
        
        # About dialog basics
        self.about = self.xml.get_widget('about_dialog')
        self.about.connect('delete_event', self.hideAbout)
        self.about.connect('response', self.hideAbout)
        self.about.set_name(NAME)
        self.about.set_version(VERSION)
        self.about.set_copyright(COPYRIGHT)
        self.about.set_comments(DESCRIPTION)
        self.about.set_license(LICENSE_TEXT)
        self.about.set_website(URL)
        self.about.set_website_label(URL)
        self.authors = [AUTHOR + ' <' + AUTHOR_EMAIL + '>']
        for contrib in CONTRIBUTORS:
            self.authors.append(contrib)
        self.about.set_authors(self.authors)
        self.about.set_logo(self.logo)
        self.about.set_program_name(NAME)

        # Create PulseAudio backing
        self.pa = PulseObj(clientName=NAME)

        # Create and populate combo boxes
        self.combo_vbox = self.xml.get_widget('combo_vbox')
        self.user_vox = gtk.combo_box_new_text()
        self.subject_vox = gtk.combo_box_new_text()
        self.combo_vbox.add(self.user_vox)
        self.combo_vbox.add(self.subject_vox)

        # FIXME: Rather than find a signal here, use PulseAudio event
        # subscription. The signal used here isn't the right one in
        # any case, and without a proper event subscription, this will
        # cause big problems if devices are removed while the app is
        # running.
        self.user_vox.connect('button-press-event', self.repop_sources)
        self.subject_vox.connect('button-press-event', self.repop_sources)

        # Fill the combo boxes initially
        self.repop_sources()

        if not runlib:
            self.main.show_all()
            gtk.main()
        

    def repop_sources(self, *args):
        self.sources = self.pa.pulse_source_list()
        l = self.user_vox.get_model()
        l.clear()
        l = self.subject_vox.get_model()
        l.clear()
        for source in self.sources:
            if source.monitor_of_sink_name == None:
                self.user_vox.append_text(source.description)
            else:
                self.subject_vox.append_text(source.description)
        self.user_vox.set_active(0)
        self.subject_vox.set_active(0)
        self.combo_vbox.reorder_child(self.user_vox, 0)
        self.combo_vbox.reorder_child(self.subject_vox, 1)
        self.combo_vbox.show_all()


    def on_close(self, *args):
        try:
            self.pa.disconnect()
        except:
            pass
        gtk.main_quit()

    def showAbout(self, *args):
        self.about.show()

    def hideAbout(self, *args):
        self.about.hide()


if __name__ == '__main__':
    pulseCatcher = PulseCatcherUI(False)