[Pythonmac-SIG] python program in menu bar

Dethe Elza delza at livingcode.org
Sun Sep 30 07:16:32 CEST 2007


Dan wrote:

> Thanks so much for that.  It was quite easy to adapt it to my needs,
> even though I don't understand the Cocoa side of the code.  A few
> questions:

Glad it helped.  I recommend getting familiar with the Cocoa
libraries, they are quite rich, and PyObjC makes it very easy to
experiment.  The AppKiDo application makes it very easy to browse and
search the documentation.

> 1) I noticed that my code runs fine directly from the shell prompt, so
> I'm curious what the advantage of making a real .app is.  I guess this
> would allow me to add the program as a "Startup Item".  (Or can one
> run any command as a Startup Item?)

Making it a real application makes it double-clickable from the Finder
and may make it behave better with other Cocoa applications.  You will
see your application's name when you switch to it, rather than
"Python."  And I think Startup Items are expected to be .app
applications, although I wouldn't swear to it. It's relatively easy to
make it a .app with py2app, and good practice for when you develop a
killer app that you want to distribute far and wide.

> 2) It is easy to change the colour of the title text that appears
> in the menu bar?

It should be.  I'm borrowing my wife's computer right now (mine was
stolen recently) so I don't actually have the docs handy, but it
should be easy to figure out.  I think NSAttributedString is the
relevant class to start with.

> 3) Is it easy to generate a beep of some sort?

NSBeep is your friend.

> I plan to look over some of the PyObjC documentation and examples, and I
> apologize if some of this is answered there.  Thanks again for pointing
> out your code to me, as it is almost exactly what I was looking for!

All of it is answerd in the Cocoa docs, but the hard part is knowing
where to start.  I hope I've been able to give you some good starting
points.  I'm glad the code example was helpful.  One of these days I'm
going to get my weblog working again, and I'll post it as a tutorial.

--Dethe


More information about the Pythonmac-SIG mailing list