Problem when using FileDialog from PMW Dialog. Quick fixes?
Chad Netzer
chad at vision.arc.nasa.gov
Wed Aug 11 21:01:21 EDT 1999
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