|
From: Jim R. <i....@ji...> - 2007-01-25 16:31:49
|
Thomas Leonard wrote:
> On 1/11/07, Jim Ramsay <i....@ji...> wrote:
> > Here's another useful one, which allows you to clear the filename in
> > the filechooser:
>=20
> I've added that to the existing widget. If you can set something, you
> should be able to clear it too.
>=20
> (note: also needed to call update_widget() after clearing)
I just took a look at the code in the svn version of rox-lib2, and I
didn't see this... have you not yet checked it in? I have a new
version anyway that adds the clear box *and* it will revert to being a
textbox if the GTK version is <2.6.
I also wasn't sure about what you meant by calling update_widget() -
I'm using the clear button callback to change the value of the
filechooser widget directly, which will update itself and call its own
'selection-changed' callback which will update the actual 'option'
value.
Here's the new builder:
def build_filechooser(self, node, label, option):
"""<filechooser name=3D'...' label=3D'...'/>Tooltip</filechooser>.
Lets the user choose a file (using a GtkFileChooser or by drag-and-drop).
Note: Since the FileChooserButton widget requires GTK >=3D 2.6, lesser GTK
versions will just show a normal text entry box, which should work with DN=
D.
"""
if g.gtk_version >=3D (2,6,0):
filebutton =3D g.FileChooserButton(label)
eb =3D g.EventBox()
eb.add(filebutton)
clearbutton =3D g.Button("Clear")
self.may_add_tip(eb, node)
hbox =3D g.HBox(False, 4)
if label:
hbox.pack_start(g.Label(label + ":"), False, True, 0)
hbox.pack_start(eb, True, True, 0)
hbox.pack_start(clearbutton, False, True, 0)
self.handlers[option] =3D (
lambda: filebutton.get_filename(),
lambda: filebutton.set_filename(option.value))
filebutton.connect('selection-changed', lambda w: self.check_widget(optio=
n))
clearbutton.connect('clicked', lambda w: filebutton.set_filename("") )
return [hbox]
else:
# Fallback to text input
return self.build_entry(node, label, option)
--=20
Jim Ramsay
"Me fail English? That's unpossible!"
|