Re: Destroying spin button on value change



On Sun, Jan 07, 2001 at 02:44:20PM -0500, Jay Bloodworth wrote:
> I'm writing gtk code in which I want to destroy a spin button whenever
> the user lowers it's value to zero.  So I connect the 'value-changed'
> signal of the spin button's adjustment to a callback.  The callback
> checks the value of the adjustment - if it is zero, it
> gtk_widget_destroy()s the spinbutton (along with it's container and a
> sister widget, but I don't think thats relevant).

First question I have is why are you doing this?  I assume you must have a
reason, but from a usability standpoint this is a nightmare most of the
time.  What's the reason?


> When I run the prog and lower the spin value to 0 (using the down
> arrow), the following error loops on the console until I terminate the
> app (WM close works fine):
> 
> Gtk-CRITICAL **: file gtkspinbutton.c: line 1275
> (gtk_spin_button_real_spin): assertion `GTK_IS_SPIN_BUTTON
> (spin_button)' failed.
> 
> From looking through the source, it appears that the handler for the
> button press event emits the adjustment value changed signal before
> updating the spin button; thus the spin button is gone before it get's
> to that code, hence the error in real_spin.

That's correct.


> So how can I fix it?  I couldn't find an entry point between the
> value-changed emmision and real_spin to head off the error.  I could use
> the value changed handler to set a flag or set up another signal handler
> to delete the spin button 'later', but what can I hook into that will be
> called immediately after the spin button has finished updating but not
> before.

You could possibly add a timeout callback to check to see if the value is
0 and destroy the widget in that case.  I'm sure there are other ways, but
none come immediately to mind.


> This is all gtk+ v1.2.8.  Actually, it is through PyGTK, but I don't
> think the python layer has a great deal to do with it.

It's not relevant.

-- 
Joseph Carter <knghtbrd debian org>                Free software developer

I sat laughing snidely into my notebook until they showed me a PC running
Linux. And oh! It was as though the heavens opened and God handed down a
client-side OS so beautiful, so graceful, and so elegant that a million
Microsoft developers couldn't have invented it even if they had a hundred
years and a thousand crates of Jolt cola.
        -- LAN Times

Attachment: pgpuCL7na4o8e.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]