[pygtk] Setting application name in pygtk?

Patrick K. O'Brien pobrien at orbtech.com
Wed Nov 8 02:53:43 WST 2006


Since I stuck my nose in this, I might as well get in all the way...

Dieter Verfaillie wrote:
> On Tue, 2006-11-07 at 11:08 -0500, Willie Walker wrote:
>> Hi Brian:
>>
>> Setting the window title works great for the window, but it doesn't set
>> the name of the application.  :-(  That is, if one were to look at the
>> hierarchy with an application like at-poke on GNOME, they'd see
>> something like this:
>>
>> app: "-c"
>>   window: "my window title here"
>>   window: "some other window title here"
>>
>> It's the "-c" that we're trying to make more human consumable.  It looks
>> like PyGtk is grabbing arg[0] as a default for the application name.
> 
> PyGtk has nothing to do with it. It's the python interpreter which
> populates the sys.argv list (1)

Agreed, which is why I sometimes mangle sys.argv to get things done.

>> It looks like we might be able to do this *before* the import of gtk:
>>
>> import sys
>> sys.argv[0] = "Orca"
> 
> Doing _only_ this leads to confusion as you are breaking simple commands
> like ps or killall. That's why the prctl stuff is necessary.

I hadn't thought about breaking those commands (that's what happens when
you spend too much time in *ahem* other operating systems).  On the
other hand, how does changing sys.argv[0] from "-c" to "Orca" break
anything?  Did ps or killall really work when sys.argv[0] was "-c"?

>> I tried this and it seems to work, but I feel a little strange about it.
> 
> You should. Read above ;)
> 
>> What crimes against humanity am I committing by doing this?
> 
> This whole thing is nothing more than a non-portable hack (3). It's up
> to you guys if you're willing to use it.

The hack is fairly portable, as far as I'm concerned, since I've done
similar things on Windows and other platforms.  And sometimes a hack is
all you've got.  So I think the real issue is: what does this hack
break?  I don't know the answer, but now I'm curious.  :-)

-- 
Patrick K. O'Brien
Orbtech       http://www.orbtech.com
Schevo        http://www.schevo.org
Louie         http://www.pylouie.org


More information about the pygtk mailing list