[Pythonmac-SIG] #! line and simple dialogs
Kevin Altis
altis at semi-retired.com
Fri Oct 1 23:30:21 CEST 2004
On Oct 1, 2004, at 12:51 PM, Nathaniel Gray wrote:
> Hello MacPythons,
>
> I'm having trouble getting my python scripts to launch from the
> command line under OS X 10.3. The usual #! lines don't work as I
> expect. Neither '#!/usr/bin/pythonw' nor '#!/usr/bin/python' work --
> they are ignored and the script is treated as a bash script. OTOH,
> '#!/usr/bin/env python' does work, but I want to be assured of getting
> the system python version instead of, for example, the Fink version.
> Any ideas what's going wrong?
>
> Also, I'd like a simple way to put up dialogs. EasyDialogs would be
> perfect but the 255 character limit on the message length is *way* too
> short. It's also annoying that the resulting dialogs are not keyboard
> navigable, but that's less important of an issue. Is there anything
> similar that allows larger messages?
>
> Cheers,
> -n8
Hmm, I don't know what the explanation of the #! line not working is,
but I found the same thing, I had to use /usr/bin/env pythonw to make
it work as expected. The error message I received is for tcsh since my
system was upgraded from Jaguar and I never bothered to switch to bash.
tcsh: import: Command not found.
from: can't read /var/mail/wx.lib
tcsh: Badly placed ()'s.
I don't like having to do a chmod such as chmod a+x on my Python
scripts on the Mac, so typically I just run everything as a script
argument to pythonw or run the script from the Finder via
double-clicking, so I hadn't run into this before.
As for doing simple dialogs I don't know all the Mac-specific options,
but wxPython provides all the system dialogs and then some and of
course it works the same on Linux, Mac OS X, and Windows. The
dialogs.py module provides function wrappers for all of the dialogs so
you don't have to worry about creating an instance of the dialog
classes, showing the dialog, and then destroying it, instead you just
make a function call which is a nice match for modal dialogs. It would
be tough to get much simpler than this.
If you install wxPython, you'll find the module at
/Library/Python/2.3/wx/lib/dialogs.py. Below is a simple example of
using the function wrappers, but dialogs.py contains a full if __name__
== '__main__' block to demonstrate use of all of the dialogs and
results. I used the named args just to make the examples clearer.
#!/usr/bin/env pythonw
##!/usr/bin/pythonw
import wx
from wx.lib import dialogs
app = wx.PySimpleApp()
#dialogs.alertDialog(None, message='hello')
dialogs.scrolledMessageDialog(None, title='Multi-line message',
message='one\ntwo\three\nfour')
ka
More information about the Pythonmac-SIG
mailing list