Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize WM_NAME and WM_CLASS (as shown by xprop) in PyQt4

Tags:

python

pyqt4

How can I customize the strings WM_NAME and WM_CLASS of a PyQt4 program as shown by xprop?

Consider for example:

from PyQt4 import QtGui, QtCore
import sys

if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    app.setStyle("plastique")


    listView = QtGui.QListView()    
    listView.show()

    combobox = QtGui.QComboBox()
    combobox.show()    

    sys.exit(app.exec_())

If I run this (the file is called xprop_test.py) via python xprop_test.py and invoke the linux tool xprop either for the ListView Or for the ComboBox, it shows

WM_NAME(STRING) = "xprop_test.py"

and

WM_CLASS(STRING) = "xprop_test.py", "Xprop_test.py"

How can I set the strings WM_NAME and WM_CLASS to another custom value (different from the filename)?

How can I set it for the whole program? How can I adjust it for each individual GUI element?

like image 521
student Avatar asked Aug 07 '12 12:08

student


1 Answers

The WM_NAME string is simply the title-bar caption, which can be set like this:

listView.setWindowTitle('listview')

giving:

WM_NAME(STRING) = "listView"

The WM_CLASS is harder to affect. By default, it's constructed from argv[0], and there does not appear to be a way to change this programmatically using the Qt APIs. However, the first part of the string can be changed by running the program with a -name option like this:

python xprop_test.py -name FooBar

giving:

WM_CLASS(STRING) = "FooBar", "Xprop_test.py"
like image 140
ekhumoro Avatar answered Oct 19 '22 04:10

ekhumoro