On Fri, 25 Feb 2000, Aaron Optimizer Digulla wrote:
> On Fri, Feb 25, 2000 at 01:41:04PM +0200, Moshe Zadka wrote:
>
> > This maybe slightly off-topic, since it's more about UI design then about
> > PyGTK specifically, but the alternative I'm considering is to make
> > it into a dialog which replaces an entry field. Is that considered all
> > right? I'm squimish, because it might clobber someone's carefully crafted
> > text, but I *have* to allow inputting both via the file dialog and the
> > entry field.
>
> What do you mean by "replaces an entry field" ? Remove the field
> from the GUI and insert the Dialog instead of it ? That doesn't
> work: A Dialog is always a "toplevel" window (ie. a window
> which has a window border and which is handled by the window
> manager).
I'm sorry, I meant of course "replaces the *contents* of the entry field
by whatever file selected from the dialog".
Here's an example of what I mean:
------ cut here ----------------
#!/usr/bin/env python
# Problem: if you type anything in the entry
# field, and then select a file from the dialog
# your typing is overwritten.
# Is that acceptable?
import gtk
class LabeledEntry(gtk.GtkHBox):
def __init__(self, label, *args, **kw):
apply(gtk.GtkHBox.__init__, (self,)+args, kw)
label = gtk.GtkLabel(label)
self.entry = gtk.GtkEntry()
map(self.pack_start, (label, self.entry))
class LabeledFileEntry(LabeledEntry):
def __init__(self, label):
LabeledEntry.__init__(self, label)
b = gtk.GtkButton("...")
b.connect("clicked", self.browse)
self.pack_end(b)
def set_file(self, *args):
self.entry.set_text(self.file_dialog.get_filename())
def close_dialog(self, *args):
self.file_dialog.destroy()
del self.file_dialog
def browse(self, *args):
if hasattr(self, 'file_dialog'):
return
fd = self.file_dialog = gtk.GtkFileSelection()
fd.ok_button.connect("clicked", self.set_file)
fd.ok_button.connect("clicked", self.close_dialog)
fd.cancel_button.connect("clicked", self.close_dialog)
fd.show()
def main():
window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
window.connect("destroy", lambda *args: gtk.mainquit())
window.add(LabeledFileEntry('File'))
window.show_all()
gtk.mainloop()
if __name__=='__main__':
main()
-------------- cut here -------------------
--
Moshe Zadka <[EMAIL PROTECTED]>.
INTERNET: Learn what you know.
Share what you don't.
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]