Viewing file: soundcard.py (15.6 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
## soundcard.py - Contains the UI code needed for system-config-soundcard ## Copyright (C) 2002, 2003 Red Hat, Inc. ## Copyright (C) 2002, 2003 Brent Fox <bfox@redhat.com> ## Copyright (C) 2004, 2005 Bastien Nocera <hadess@hadess.net>
## 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 2 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, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import string import gtk import gobject import string import sys import os import time import commands sys.path.append('/usr/share/system-config-soundcard/') import soundcardBackend
## ## I18N ## from rhpl.translate import _, N_ import rhpl.translate as translate translate.textdomain ("system-config-soundcard")
## ## Icon for windows ##
iconPixbuf = None try: iconPixbuf = gtk.gdk.pixbuf_new_from_file("/usr/share/system-config-soundcard/pixmaps/system-config-soundcard.png") except: pass
class childWindow: #You must specify a runPriority for the order in which you wish your module to run runPriority = 64 moduleName = _("Soundcard Detection") commentTag = _("Auto-detect and configure soundcard")
def destroy(self, args): gtk.main_quit() def __init__(self, doDebug=None, backend=None): self.doDebug = doDebug
if backend == None: self.soundcardBackend = soundcardBackend.soundcardBackend() else: self.soundcardBackend = backend self.cardList = self.soundcardBackend.probeCards()
if self.doDebug: print "Kudzu detected %d cards" % len(self.cardList)
self.toplevel = gtk.VBox() self.icon_box = gtk.HBox() self.title = gtk.Label(_("Sound Card Selection")) self.title.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse ("white"))
#Create an internal box that will contain a list if there's multiple cards #Or just a box if there's only one. self.box = gtk.VBox(False, 8) self.notebook = gtk.Notebook()
if self.cardList == []: #There are no cards available self.label = gtk.Label(_("No soundcards were detected.")) label = gtk.Label("") else: #Kudzu has found some cards for card in self.cardList: self.device, self.module, self.maker, self.model = self.soundcardBackend.getData(card) self.table = gtk.Table(2, 3) self.table.set_border_width(6) self.table.set_col_spacings(4) self.table.set_row_spacings(4)
label = gtk.Label(_(" %s" % (self.maker)))
self.notebook.append_page(self.table, label) self.maker_label = gtk.Label("") self.maker_label.set_markup("<span><b>" "%s</b></span>" % _("Vendor:")) self.maker_label.set_alignment(0.0, 0.5) self.maker_label2 = gtk.Label(self.maker) self.maker_label2.set_alignment(0.0, 0.5)
self.model_label = gtk.Label("") self.model_label.set_markup("<span><b>" "%s</b></span>" % _("Model:")) self.model_label.set_alignment(0.0, 0.5)
self.model_label2 = gtk.Label(self.model) self.model_label2.set_alignment(0.0, 0.5)
self.module_label = gtk.Label("") self.module_label.set_markup("<span><b>" "%s</b></span>" % _("Module:")) self.module_label.set_alignment(0.0, 0.5)
self.module_label2 = gtk.Label(_(self.module)) self.module_label2.set_alignment(0.0, 0.5)
self.test_button = gtk.Button(_("Play test sound")) self.test_button.connect("clicked", self.testButtonClicked)
align = gtk.Alignment(0.0, 0.0, 1.0, 1.0) align.add(self.test_button)
self.table.attach(self.maker_label, 0, 1, 0, 1, gtk.FILL, gtk.FILL) self.table.attach(self.maker_label2, 1, 2, 0, 1, gtk.FILL, gtk.FILL) self.table.attach(self.model_label, 0, 1, 1, 2, gtk.FILL, gtk.FILL) self.table.attach(self.model_label2, 1, 2, 1, 2, gtk.FILL, gtk.FILL) self.table.attach(self.module_label, 0, 1, 2, 3, gtk.FILL, gtk.FILL) self.table.attach(self.module_label2, 1, 2, 2, 3, gtk.FILL, gtk.FILL) self.table.attach(align, 1, 2, 3, 4)
deviceTopBox = gtk.VBox(False, 8)
if len(self.cardList) == 1: #There is only one card, so hide the tab and border self.notebook.set_show_tabs(False) self.notebook.set_show_border(False) self.label = gtk.Label(_("The following audio device was detected."))
self.soundcardBackend.setDefaultCard(0)
else: #There is more than one card, so show the primary device option menu self.label = gtk.Label(_("The following audio devices were detected."))
#Create a menu with primary card deviceBox = gtk.HBox(False, 8)
self.primaryDeviceOptionMenu = gtk.OptionMenu() self.primaryDeviceMenu = gtk.Menu()
for card in self.cardList: self.device, self.module, self.maker, self.model = self.soundcardBackend.getData(card) item = gtk.MenuItem(self.model) self.primaryDeviceMenu.append(item)
selected_card = self.cardList.index(self.soundcardBackend.getDefaultCard()) self.primaryDeviceMenu.set_active(selected_card) self.primaryDeviceOptionMenu.set_menu(self.primaryDeviceMenu) deviceBox.pack_start(gtk.Label(_("Default audio card:")), False) deviceBox.pack_start(self.primaryDeviceOptionMenu, True)
self.primaryDeviceOptionMenu.connect("changed", self.changeDefaultCard)
deviceTopBox.pack_start(deviceBox)
#Create a menu with primary card deviceBox = gtk.HBox(False, 8)
self.primarySubDeviceOptionMenu = gtk.OptionMenu() self.refreshDeviceList() deviceBox.pack_start(gtk.Label(_("Default PCM device:")), False) deviceBox.pack_start(self.primarySubDeviceOptionMenu, True)
self.primarySubDeviceOptionMenu.connect("changed", self.changeDefaultDevice)
deviceTopBox.pack_start(deviceBox)
#Create a check-box for hw/sw config button = gtk.CheckButton(_("Disable software mixing (dmix, dsnoop)")) button.set_active(self.soundcardBackend.getHardwareDevice()) button.connect("toggled", self.changeHW) button.show()
deviceTopBox.pack_start(button)
#Create a check-box for key config button = gtk.CheckButton(_("Dynamic keys for software mixer (more secure)")) button.set_active(self.soundcardBackend.getDynamicKeys()) button.connect("toggled", self.changeDynKeys) button.show() deviceTopBox.pack_start(button)
self.box.pack_start(self.notebook) self.box.pack_start(deviceTopBox)
#Add icon to the top frame p = None try: p = gtk.gdk.pixbuf_new_from_file("../pixmaps/system-config-soundcard.png") except: try: p = gtk.gdk.pixbuf_new_from_file("/usr/share/system-config-soundcard/pixmaps/system-config-soundcard.png") except: pass
if p: self.icon = gtk.Image() self.icon.set_from_pixbuf(p) def refreshDeviceList(self):
selected_card = self.soundcardBackend.getDefaultCardNum() self.primarySubDeviceMenu = gtk.Menu()
comp_string = string.join(['card ',`selected_card`,':'],"") comp_string_len = len(comp_string) devices = commands.getoutput('/usr/bin/aplay -l') devices = string.split(devices,'\n') self.subdevices = [] for line in devices: if not cmp(line[:comp_string_len],comp_string): dev = string.split((string.split(line,',')[1]),':') self.subdevices.append([int(string.split(dev[0])[1]),(dev[1])[1:]]); default = self.soundcardBackend.getDefaultDevice() pos = 0 itm = 0 for sub in self.subdevices: item = gtk.MenuItem(sub[1]) self.primarySubDeviceMenu.append(item) item.show() if sub[0] == default: pos = itm itm += 1 self.primarySubDeviceMenu.set_active(pos) self.primarySubDeviceOptionMenu.set_menu(self.primarySubDeviceMenu) self.primarySubDeviceOptionMenu.show() def closeClicked(self, *args): self.apply() gtk.main_quit()
def changeDefaultCard(self, *args): self.soundcardBackend.setDefaultCard(self.primaryDeviceOptionMenu.get_history()) self.soundcardBackend.setDefaultDevice(0) self.soundcardBackend.writeConfig() self.refreshDeviceList()
def changeDefaultDevice(self, *args): self.soundcardBackend.setDefaultDevice(self.subdevices[self.primarySubDeviceOptionMenu.get_history()][0]) self.soundcardBackend.writeConfig()
def changeHW(self, widget, data=None): self.soundcardBackend.setHardwareDevice(widget.get_active()) self.soundcardBackend.writeConfig()
def changeDynKeys(self, widget, data=None): self.soundcardBackend.setDynamicKeys(widget.get_active()) self.soundcardBackend.writeConfig() self.soundcardBackend.reconfigureDynamicKeys()
def apply(self, *args): if self.doDebug: return
pageNum = self.notebook.get_current_page() page = self.notebook.get_nth_page(pageNum)
if page: module = page.get_children()[1].get_text()
selectedItem = self.getSelectedCard() ## if selectedItem != None: ## self.writeUnloadReload(selectedItem, module) self.mainWindow.destroy()
def testButtonClicked(self, button): pageNum = self.notebook.get_current_page() page = self.notebook.get_nth_page(pageNum) module = page.get_children()[1].get_text() index = self.cardList[self.notebook.get_current_page()].position
selectedItem = self.getSelectedCard()
if selectedItem != None: # self.writeUnloadReload(selectedItem, module) self.soundcardBackend.playTestSound(module, index)
text = (_("Did you hear the sample sound?")) dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO,text)
dlg.set_title("") dlg.set_default_size(100, 100) dlg.set_position (gtk.WIN_POS_CENTER_ON_PARENT) dlg.set_border_width(2) dlg.set_modal(True) rc = dlg.run() dlg.destroy()
if rc == gtk.RESPONSE_NO: #Oh well, they couldn't hear the sound. Notify the user and then quit. We did our best self.showErrorDialog(_("Automatic detection of the sound card did not work. " \ "Audio will not be available on the system.\n" \ "You can inspect %s and " \ "file a new bug\nat http://bugzilla.redhat.com.\n\nPlease click " \ "OK to continue.") % "/root/scsound.log") try: self.mainWindow.destroy() except: #We must be in firstboot mode pass
def getSelectedCard(self): if len(self.cardList) == 1: #There is one sound card present. This is the common case selectedCard = self.soundcardBackend.getData(self.cardList[0]) device, module, maker, model = selectedCard return 0
elif len(self.cardList) > 1: #There are more than one soundcards. Figure out which is supposed the be the default selectedItem = self.primaryDeviceOptionMenu.get_history() selectedCard = self.soundcardBackend.getData(self.cardList[selectedItem]) device, module, maker, model = selectedCard return selectedItem
else: #There are no soundcards. Do nothing return None
def writeUnloadReload(self, selectedItem, module): self.soundcardBackend.writeFile(selectedItem) self.soundcardBackend.unloadModules() result = self.soundcardBackend.loadModules()
if result != 0: #Loading the module failed. Notify the user that things are broken self.showErrorDialog(_("The %s driver could not be loaded." % module)) else: self.soundcardBackend.setVolume()
def launch(self): self.mainVBox = gtk.VBox() self.internalVBox = gtk.VBox(False, 10) self.internalVBox.set_border_width(10)
eventBox = gtk.EventBox() eventBox.add(self.icon_box) eventBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse ("#cc0000"))
self.icon_box.pack_start(self.icon, False, True) self.icon_box.pack_start(self.title) self.mainVBox.pack_start(eventBox, False) self.msg_label.set_size_request(500, -1) self.internalVBox.pack_start(self.msg_label, False) self.mainVBox.pack_start(self.internalVBox, True) return self.mainVBox, eventBox
def stand_alone(self): self.mainWindow = gtk.Dialog() self.mainWindow.vbox.set_spacing(5) self.mainWindow.connect("destroy", self.destroy) self.mainWindow.set_title(_("Audio Devices")) self.mainWindow.set_border_width(10) self.mainWindow.set_position(gtk.WIN_POS_CENTER) self.mainWindow.set_icon(iconPixbuf) self.okButton = self.mainWindow.add_button('gtk-close', 0) self.okButton.connect("clicked", self.closeClicked)
self.toplevel.set_spacing(5) self.icon_box.pack_start(self.icon, False) self.icon_box.pack_start(self.label, False) self.toplevel.pack_start(self.icon_box, False)
self.toplevel.pack_start(self.box, False)
#Remove the hsep from the dialog. It's ugly hsep = self.mainWindow.get_children()[0].get_children()[0] self.mainWindow.get_children()[0].remove(hsep) self.mainWindow.vbox.pack_start(self.toplevel) self.mainWindow.show_all() gtk.main()
def showErrorDialog(self, text): dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, text)
dlg.set_title(_("Error")) dlg.set_default_size(100, 100) dlg.set_position (gtk.WIN_POS_CENTER_ON_PARENT) dlg.set_border_width(2) dlg.set_modal(True) rc = dlg.run() dlg.destroy() return
def getSoundcardBox(self): return self.box
|