Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED}Making noises when buttons get pushed.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED}Making noises when buttons get pushed.

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 5.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swilliams2
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      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.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • S Offline
        S Offline
        swilliams2
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          swilliams2
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

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

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

            Greetz, Jeroen

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              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.

              Greetz, Jeroen

              1 Reply Last reply
              0
              • S Offline
                S Offline
                swilliams2
                wrote on last edited by
                #7

                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:

                1 Reply Last reply
                0
                • JeroentjehomeJ Offline
                  JeroentjehomeJ Offline
                  Jeroentjehome
                  wrote on last edited by
                  #8

                  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.

                  Greetz, Jeroen

                  1 Reply Last reply
                  0
                  • jazzycamelJ Offline
                    jazzycamelJ Offline
                    jazzycamel
                    wrote on last edited by
                    #9

                    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.

                    For the avoidance of doubt:

                    1. All my code samples (C++ or Python) are tested before posting
                    2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved