PyQt4 QtGui.QSound play as a command line program? - qt

How might one blast QSound from a command line?
Under PyQt4, playSound.py could be as simple as this:
QtGui.QSound('start.wav').play()
Except it doesn't play without an .exec() style event dispatcher available.
So what's the simplest dispatch queue that doesn't pop a window up and quits on time?

QSound doesn't have a reliable and portable way to signal when the sound is done.
You could use phonon instead (code example in C++) and connect the MediaObject::finished() signal to the quit() slot of the application.

Why using PyQt for a CLI app? It seems overkill, you should embrace Python's batteries and use PyQt for the UI, that way is more portable if you need both CLI and GUI versions.
There are plenty of options for playing audio in plain Python. [1]
[1] http://wiki.python.org/moin/Audio/
Also check these here on SO:
Play audio with Python
Play a Sound with Python

The following standalone code works fine for me, without any windows popping up:
from PyQt4 import QtGui
s = QtGui.QSound('test.wav')
s.play()
while not s.isFinished():
sleep(0.1)
The s.isFinished() check is required because otherwise the script will immediately exit without having played the wav, because play() doesn't block.
http://doc.qt.io/qt-5/qsound.html

from PyQt4.QtGui import QSound
QSound.play("Filename")

Related

Maximise a windows application using Robot Framework

I am trying to maximize a desktop application with robot framework. I read somewhere that i could use key combinations Windows + Up Arrow but how do i implement it ? Can someone share the code for it please ?
You might use the PyAutoGui library for this.
import pyautogui
def maximize_window():
pyautogui.hotkey('win','up')
and import this function as a library to your Robot Framework file.
Maybe pressing F11 (pyautogui.press('f11')) might also work, instead of Windows key + Up.

Modify Qt's shared library code while application starts

I'm trying to create some kind of a server which allows me to start Qt's applications on remote machine via web browser.
I'm wondering it is possible to change/hide some symbols from Qt library (I thought about QApplication or QCoreApplication) without making any changes in code of application (I assume that it is already compiled and uses Qt shared library) and compiling my whole tailor-made Qt libs?
The reason why I need to do this is because I want to install my own specific EventFilter to QApplication and also be able to push my own created events to Qt application.
It also would be great if the solution could be used on all platforms :D
P.S. I know that it will not be possible I could subclass QApplication and modify all Qt apps to use my derived class but I would like to do this more craftily. ;-)
The tool GammaRay does all kinds of injecting code into Qt methods at runtime to attach and debug running Qt applications. You might want to have a look at its code base to see how it is done.

Python editor in a PyQt4 application

I need to integrate an editor into a window/dialog in my PyQt4 application.
It needs to support syntax highlighting for Python, Java and C++. It should run under Linux and ideally windows.
What would you suggest and where can I find the API and instructions?
I was thinking about Katepart, but I can't find instructions for it.
http://www.riverbankcomputing.co.uk/software/qscintilla/intro
http://www.riverbankcomputing.co.uk/static/Docs/QScintilla2/index.html
http://eli.thegreenplace.net/2011/04/01/sample-using-qscintilla-with-pyqt/

Play sound file on Qt+Mac

I need to play sounds under Qt with control of volume and panning. QSound doesn't do it, phonon may be too much for only this so I thought I'd try the native api.
eeermm, in Mac I have no idea, is there some simple interface to invoke on c++? (I've seen all this NSSound stuff but I am not familar with Objective C and I am not sure if it's possible to mix code (under QtCreator)) my idea would be to a module with simple native api calls to system features not found on Qt.
Thanks!
Qt AudioEngine in Qt5 will do this.
If you're using Qt4, making a single 'Objective-C++' file (extension .mm) which can be called from Qt, but makes NSFoo calls, is easy and works well. The header file should be plain C++, and everything will work together.

Are there any PyQt sqlite browser/manager?

I'm developing a program using PyQt4 and sqlite,
I want to include a small sqlite browser/editor/manager, just like sqliteman or sqlitebrowser,
are there any one written by pyqt?
You might want to take a look at the C++ SQL Browser demo shipped with Qt, and perhaps port it to Python.
The Eric Python IDE has a sql browser. It is open source and it's been written by pyqt.

Resources