[SOLVED}Making noises when buttons get pushed.



  • I want to get a button to make a noise when it gets pushed so I know it's sent an email, someone previously told me I need Phonon, but I can't find it anywhere, is there any other way of doing it that doesn't require additional modules?
    This is the script I've got so far

    [code]
    from PyQt4 import QtGui, QtCore

    import smtplib
    import wave

    from email.mime.text import MIMEText

    class Window(QtGui.QWidget):
    def init(self):
    QtGui.QWidget.init(self)
    self.button = QtGui.QPushButton('', self)
    self.button.clicked.connect(self.handleButton)
    self.button.setIcon(QtGui.QIcon("./z.jpg"))
    self.button.setIconSize(QtCore.QSize(300,250))
    layout = QtGui.QVBoxLayout(self)
    layout.addWidget(self.button)

    def handleButton(self):
        fp = open('Firetruck.txt', 'r')
        msg = MIMEText(fp.read())
        fp.close()
    
        msg['Subject'] = 'Subject'
        msg['From'] = 'ajames@brecon-hs.powys.sch.uk'
        msg['To'] = 'swilliams@brecon-hs.powys.sch.uk'
    
        s = smtplib.SMTP('BHS-MAIL')
        s.send_message(msg)
    

    if name == 'main':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())
    

    [/code]

    I'm assuming the code for the sound goes under
    [code] def handleButton(self): [/code]
    Right?



  • QApplication::beep()
    That's in basic sounds the PC buzzer or other system used device. If you want specific sounds to be played a bit more work is needed.



  • Yeah that'd be fine :D
    What do I need to import to get that to work?



  • Because I'm just getting invalid syntax and it's pointing to the first ":"



  • hmm,
    (not tested! But something like this)
    // source file:
    @#include <QApplication>

    void YourObject::beeping(void)
    {
    QApplication::beep();
    }@



  • Because it's a static function of QApplication you don't need an object to be created or to use the qApp pointer. Just don't forget to include the QApplication module.
    Think that this should work.



  • Ah I just found this - http://docs.python.org/2/library/winsound.html

    [code]
    import winsound

    winsound.Beep(3500, 1000)
    [/code]
    Seems to work c:



  • Hmm, tried the beep() function here, but no sound on my laptop, so there might be an issue with it. (using Qt5.0.1 btw). It is only stated that it's not available on Embedded Linux.



  • If fall you want is a beep then just use:

    @
    QApplication.beep()
    @

    [quote author="swilliams2" date="1369304282"]Because I'm just getting invalid syntax and it's pointing to the first ":"[/quote]

    This is because the example (QApplication::beep()) is for c++ and you're using Python.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.