Problem when using FileDialog from PMW Dialog. Quick fixes?

Robert J. Roy rjroyNoSpam at magma.ca
Thu Aug 12 09:43:41 EDT 1999


What you are trying to do is common practice.

If this code snippet is accurate, the problem is in your use of global
dialog. In CreatePMWDialog you assign dialog to the Pmw.Dialog
then in ListFiles, you chage the binding of the global dialog variable
to point to the FileDialog. So your subsequent call to DialogAction is
trying to act on a non-existing widget. 

If you changeListFiles to the following, everything works fine. 

def ListFiles():
    global dialog
    dlg = LoadFileDialog(dialog.parent)
    file = dlg.go("")
    print file

You might want to look at using tkFileDialog instead. It brings up the
standard file dialogs, presenting a more familiar interface to Windows
users.

check out http>//www.pythonware.com/library/tkinter/introduction/ for
more info on how to use. (Sorry I can't give you more info, I can't
get through to pythonware just now)

Good Luck!
Robert Roy




On Thu, 12 Aug 1999 01:01:21 +0000, Chad Netzer
<chad at vision.arc.nasa.gov> wrote:

>I have an application where I open a Python Mega Widget dialog (local,
>not global) and within it I later open a FileDialog() for file selection
>(Don't ask, why, but calling a nested dialog makes sense for the app.)
>In any case, it doesn't work.  When the FileDialog exits, the Pmw Dialog
>cannot get focus back (even with some code to try to force it.)
>
>Before I pursue this further, can anyone tell me if it is even worth
>trying?  It is nice to use the canned FileDialog, but its implementation
>is somewhat crufty (IMHO) and I can probably work around it in other
>ways (Creating my own FileDialog from PMW widgets is a nice possibility.
>)   But if there is a quick fix, I'd like to hear it.
>
>Below you'll find  some psuedo-code to show roughly what I'm doing.  Run
>the code, click on the "List" button to activate the FileDialog, then
>exit the FileDialog.  Hitting the PMW Dialog "Cancel" button doesn't
>work (as it does if you never open the FileDialog).  Pardon the rough
>code :)  You will probably have to kill the process if you trigger
>the problem, so be warned.
>
>Chad Netzer
>chad at vision.arc.nasa.gov
>
>------------------------------ [ Cut Here ]
>------------------------------
>from Tkinter import *
>import Pmw
>from FileDialog import LoadFileDialog
>
>def CreatePMWDialog(parent):
>    global dialog
>    dialog = Pmw.Dialog(parent,
>                        buttons = ('OK', 'Cancel'),
>                        defaultbutton = 'OK',
>                        title = 'A test: The FileDialog will steal focus
>forever',
>                        command = DialogAction)
>    dialog.parent = parent
>
>    interior = dialog.interior()
>    entry_frame = Frame(interior)
>    list_but = Button(entry_frame, text="List", command=ListFiles)
>
>    list_but.grid(row=0, column=1, sticky=N+S)
>    entry_frame.pack(side=TOP, anchor=NW)
>
>    # Now execute the dialog
>    dialog.activate()
>    return
>
>def ListFiles():
>    global dialog
>    dialog = LoadFileDialog(dialog.parent)
>    file = dialog.go("")
>    print file
>
>def DialogAction(button_name):
>    global dialog
>    if button_name == 'Cancel':
>        dialog.deactivate()
>    elif button_name == 'Ok':
>        dialog.deactivate()
>    return
>
># Test it by parsing a prm file
>if __name__ == '__main__':
>    tk_root = Tk()
>    foo = CreatePMWDialog(tk_root)
>    tk_root.mainloop()
>
>





More information about the Python-list mailing list