简体   繁体   中英

How Do I Set the Class Name of a Python wxWidgets Application Window?

I need to set the class name of a Python wxWidgets application window on Linux (Ubuntu). By default it is set to "python."

I have tried calling the SetAppName() and SetClassName() methods on the app object, but this does not seem to have any effect.

Basically what I am trying to do is change the application window's class name to a custom value so I can associate it with its icon in Cairo dock.

The application is Pronterface ( https://github.com/kliment/Printrun ).

Some More Details


Basically right now I have a launcher icon on Cairo dock that has the correct icon for Pronterface (I can set the icon manually).

The problem is when I launch Pronterface Cairo dock doesn't associate the Pronterface window with the launcher. It creates a new icon on the launcher with the Python logo for the window.

There is a launcher option to enter a program class name (and a tool to grab it from an open window) so that Cairo dock can identify windows that belong to the launcher.

Problem is that the Pronterface's class name is "python" which, if I use it, causes the Pronterface launcher to be associated with any wxWidget python application (or probably any python UI application), not just Pronterface windows.

That's why I want to change the class name.

You may be looking for the wx.App's SetAppName() method. Alternatively, there's also the frame's SetTitle() method, but I am guessing you tried that already.

EDIT:

I asked about this on wxPython-dev and they reminded me of something I recall from Windows. You may need to freeze your application using something like PyInstaller to get it to work correctly. On the other hand, this is what Robin Dunn, creator of wxPython had to say:

Way down deep inside the X11 libraries applications and windows can be assigned a string to be used as a class name. In the olden days when the Motif toolkit was king it was very common to allow user customization of the UI elements in an application using their .Xdefaults file. It was much like how CSS is today, where you could set the colors, fonts or other attributes for an item. If the widget names and class names were set by the application programmer then the properties could be set for all elements of a certain type like a button, or all elements that have a specific class name, and you could also specify a widget or class (or all of them) within a certain containment hierarchy, etc.

All of that is still there under the covers down in the X and Xt libraries, but I'm not familiar with how (or if) GTK exposes that or makes use of it itself. In the old wxMotif port wx set the X widget name using whatever was passed to the SetName method, but I don't think it is doing anything special in the wxGTK port with the name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM