Search code examples
pythonlinuxqtpyqtacpi

Execute a PyQt app from an acpi event in linux


I want to use a PyQt application to display an image when some acpi event is triggered under linux.

I already setting up the configuration for the event and the python scrip is executed when the event is triggered, but when program reach the creation of the QApplication

app = QApplication(sys.argv)

it stops without error. I tried setting up the same DISPLAY and PATH environment variables as my current user but it doesn't work.

This is my event file:

event=sony/hotkey SNC 00000001 00000011
action=/etc/acpi/vaio-tools/brightness/sonybright.sh up 2>&1>/tmp/vaio-tools_brightness.log

I tried to find some error in the /tmp/vaio-tools_brightness.log but it doesn't log anything after it reach the QApp creation in code.

any hints??


Solution

  • Your application is run by root who doesn't have access to your users's X display.

    Either set $XAUTHORITY to the path of the X authority file used by your user or use something like this (untested):

    su your_user -l -c "xauth extract - $DISPLAY" | xauth merge -
    

    See the man pages for xauth and Xsecurity for more about this.

    A better solution would be to have the ACPI event to send a message via DBus and run your application in the user's session listening to that message.