How to tell if invoked through IDLE or command line?

2005-05-02 Thread Robert D. Young
I've probably asked this before, but how can I tell within the program I'm
running if the .py files was involved by "run module" in IDLE or by using
the .py assoication with the python.exe program? I'd like to prevent running
under certain circumstances, or pop-up warnings, or change character
displays (some look different when run under IDLE).

- Robert


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Quick and dirty dialogs?

2005-05-02 Thread Robert D. Young
I use quick-and-dirty code like this:


# Get source directory and text file

Root = Tkinter.Tk()
Root.title(programname)
srcdir = tkFileDialog.askdirectory(title='Choose the source directory',
initialdir='C:\\')
srcfile = tkFileDialog.askopenfilename(title='Choose the text file',
initialdir=srcdir)
Root.destroy()



- Robert


<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> What's the easiest way for a script to throw up simple dialogs such as
> file select and alerts?
>
> I thought there was something in the standard library that didn't need
> TK and was cross-platform but I can't seem to get my Google-fu working
> well enough to find it.
>


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to tell if invoked through IDLE or command line?

2005-05-02 Thread Robert D. Young
Poi-fect - thanks!

import sys
if sys.modules.has_key("idlelib"):
 print "Running under idle"
else:
 print "Not running under idle"


- Robert

"Michael Hoffman" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Robert D. Young wrote:
> > I've probably asked this before, but how can I tell within the program
I'm
> > running if the .py files was involved by "run module" in IDLE or by
using
> > the .py assoication with the python.exe program? I'd like to prevent
running
> > under certain circumstances, or pop-up warnings, or change character
> > displays (some look different when run under IDLE).
>
> sys.modules.keys() contains "idlelib" is a simple way of doing it,
> assuming you never import idlelib otherwise (and why would you?)
> -- 
> Michael Hoffman


-- 
http://mail.python.org/mailman/listinfo/python-list