Can't quite get my head around this, can anyone help?

2009-08-10 Thread Boggess Rod
I've got a bunch of entry boxes and an HScale widget.  If the user
changes something on the form and clicks the HScale Widget before
clicking the save button, I popup a message box.  If the user clicks Ok,
the HScale should ignore the changes and procede.  If the user clicks
Cancel, the HScale should stop.

Ok, so I can't can't use the value-changed signal for the HScale.  I
belive I can use the change-value, but I can't quite get it to work
right.  If I return TRUE when the user clicks Cancel, that works.  But
whether I return TRUE or FALSE on the OK button, it doesn't work.  It
either ignores the change or it calls itself repeatedly.

Can someone point me to some example code in Gtk that intercepts a
signal, prompts the user, and either continues or aborts the signal,
depending on user response?  A button wouldn't do this, but I'm sure
there are other widgets that would.  I've Googled everything I can think
of, but I either receive an overwhelming, unapplicable list of results
or none.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Can't quite get my head around this, can anyone help?

2009-08-10 Thread Michael Torrie
Boggess Rod wrote:
 Can someone point me to some example code in Gtk that intercepts a
 signal, prompts the user, and either continues or aborts the signal,
 depending on user response?  A button wouldn't do this, but I'm sure
 there are other widgets that would.  I've Googled everything I can think
 of, but I either receive an overwhelming, unapplicable list of results
 or none.

Well inside a callback you can return TRUE which stops signal
propagation right here.  Or FALSE, which lets it continue.  So you could
do it two ways.  One would be to to display a GtkDialog, and use
gtk_dialog_run() from within your callback [1].  The other would be to
create new gtk main loop instance from within your callback to allow
another window to be displayed and run, and then based have that
window's event callbacks set a flag and end the main loop, which you can
then use in the original callback to end the propagation.

Not example code, but if I understand what you're asking for, it's
relatively doable.

Why wouldn't a button be be able to do this?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Can't quite get my head around this, can anyone help?

2009-08-10 Thread Michael Torrie
Michael Torrie wrote:
 Well inside a callback you can return TRUE which stops signal
 propagation right here.  Or FALSE, which lets it continue.  So you could
 do it two ways.  One would be to to display a GtkDialog, and use
 gtk_dialog_run() from within your callback [1].  The other would be to
 create new gtk main loop instance from within your callback to allow
 another window to be displayed and run, and then based have that
 window's event callbacks set a flag and end the main loop, which you can
 then use in the original callback to end the propagation.

Forgot the references.

[1] http://library.gnome.org/devel/gtk/stable/GtkDialog.html#gtk-dialog-run

Also the glib main loop documentation is here:
http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html
specifically, g_main_loop_new()
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Can't quite get my head around this, can anyone help?

2009-08-10 Thread Michael Torrie
Boggess Rod wrote:
 I guess I wasn't clear.  The messagebox is working fine.  It returns
 whether the user clicked Ok or Cancel.  I'm calling the
 gtk_dialog_run(...) from within the callback of the
 on_hscale_valuechanged(...) (or _changevalue) event handler.  It's the
 hscale's event handler that I can't get to work.
 
 The valuechanged signal is only raised after the hscale value has been
 changed.  That's too late, because if the form contains unsaved changes,
 clicking message box's cancel button should prevent the hscale from
 changing on the parent form.

Interesting.  I have no idea what would work in this case.

I wonder if you could just punt and set the scale value back to the
original value that it had before the valuechanged signal was emitted.
Would be a bit of a hacks since you'd have to keep track of the value in
an external variable.  But maybe a bit of visual feedback (the scale
moving and then going back) might be good from a usability standpoint.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


RE: Can't quite get my head around this, can anyone help?

2009-08-10 Thread Boggess Rod
BTDT.  Won't work because by then, the user-value I'm trying not to
loose would already be lost.

I would have thought this was a somewhat popular function, especially
when processing records from a database.  But I don't seem to know what
to search for.  I can seem to find one single example anywhere that
makes use of the change-value signal.

 -Original Message-
 From: gtk-app-devel-list-boun...@gnome.org 
 [mailto:gtk-app-devel-list-boun...@gnome.org] On Behalf Of 
 Michael Torrie
 Sent: Monday, August 10, 2009 2:44 PM
 To: Gtk app list
 Subject: Re: Can't quite get my head around this, can anyone help?
 
 Boggess Rod wrote:
  I guess I wasn't clear.  The messagebox is working fine.  
 It returns 
  whether the user clicked Ok or Cancel.  I'm calling the
  gtk_dialog_run(...) from within the callback of the
  on_hscale_valuechanged(...) (or _changevalue) event 
 handler.  It's the 
  hscale's event handler that I can't get to work.
  
  The valuechanged signal is only raised after the hscale 
 value has been 
  changed.  That's too late, because if the form contains unsaved 
  changes, clicking message box's cancel button should prevent the 
  hscale from changing on the parent form.
 
 Interesting.  I have no idea what would work in this case.
 
 I wonder if you could just punt and set the scale value back 
 to the original value that it had before the valuechanged 
 signal was emitted.
 Would be a bit of a hacks since you'd have to keep track of 
 the value in an external variable.  But maybe a bit of visual 
 feedback (the scale moving and then going back) might be good 
 from a usability standpoint.
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
 
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Can't quite get my head around this, can anyone help?

2009-08-10 Thread David Nečas
On Mon, Aug 10, 2009 at 02:52:56PM -0400, Boggess Rod wrote:
 BTDT.  Won't work because by then, the user-value I'm trying not to
 loose would already be lost.

It would not if you kept the original value elsewhere as suggested.

 I would have thought this was a somewhat popular function, especially
 when processing records from a database.  But I don't seem to know what
 to search for.  I can seem to find one single example anywhere that
 makes use of the change-value signal.

Databases have commit/rollback mechanisms so you usually don't need to
implement your own in Gtk+.  Even if they don't they can always serve as
the `elsehwere' that contains the original value.

The 'change-value' signal is not what you need.  The signal is something
few people need that's why you cannot find examples...

1) You have the original value because you had it when the dialog was
created.  You just need to keep it somewhere.  The simplest method is to
work on a copy of the dialog model (in MVC sense), leaving the original
intact.

2) When the user moves the slider, it should really move (so, no
'change-value').  Signal 'value-changed' is emitted and you change the
value in the dialog model working copy.

3) If the user accepts the changes replace the original model with the
values from the working copy.  If he does not just discard it.

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Can't quite get my head around this, can anyone help?

2009-08-10 Thread Michael Torrie
Boggess Rod wrote:
 BTDT.  Won't work because by then, the user-value I'm trying not to
 loose would already be lost.

Guess I don't understand the problem, then, as I don't see why this
would be if you kept track of it in an external variable between
callbacks.  Maybe a very small, self-contained example would be appropriate.

 I would have thought this was a somewhat popular function, especially
 when processing records from a database.  But I don't seem to know what
 to search for.  I can seem to find one single example anywhere that
 makes use of the change-value signal.

How would it be used in a database-driven app?  Not having written any,
it's not something I'm familiar with.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


RE: Can't quite get my head around this, can anyone help?

2009-08-10 Thread Boggess Rod
The last one is easy to answer: there are lots of fields to work with,
and many times, records are shown in a parent-child relationship.  The
lots of fields makes it easy for the user to forget if they've made a
change.  The parent-child relationship makes it meaningful to have a
parent set of entry-boxes, and a child set of entry-boxes with a scroll
widget to page through all the child records.

The example is little more difficult.  Technically speaking, it's not
impossible to save the current value.  As it stands, every entry box
shares one common changed event handler which simply sets a flag to say
the data on the form has changed.  If there were only one or two, I
could write a custom handler, and store the value there.  At least, I
think I could.  Much of this isn't working the way I expected, so my
confidence is waning.

Anyway, the problem is that I have lots and lots of entry boxes.  Worse,
I don't really know how many I have until the application runs.  Writing
individual changed event handlers would be impossible.  So, where would
I store the value?

When you click on the trough, the new value is already set, which causes
the lookup of the new child-record, replacing all of the values in the
entry-boxes, including any that the user may have changed.  At this
point, all you'd be doing is telling the luser what an idiot they were
because they forgot to save their data that they forgot they changed.

What I need is an event that triggers before the hscale value has
changed.  One that I could intercept, prompt the user, and choose to
cancel or continue.

I suppose I could save every value on the form before I lookup the data
for the new child record.  But that's not a small amount of data.  And,
as I said, I can't believe I'm the only one that has ever done this
before.  If there isn't a way to intercept and stop these signals, then
there's a major piece missing from GTK.  And I would have thought
(perhaps mistakenly) that it was mature enough to have this type of
functionality.  Not that I'm opposed to contributing to the effort, but
I won't have time to do it before I have to release this application.
Which means I'll have to work around this.

I see some examples of code where the programmer performs a
g_signal_handlers_block_by_func call to disable callbacks, and I thought
they were doing exactly this -- but even that doesn't seem to prevent
the recursion of my callback.  And perhaps worse, a set_value on the
range from within the change-value handler, doesn't (set the value, that
is).

I'll see if I can't post an example that's stripped down to just one
entrybox.  But as I said above, in such a trivial case, it's nothing to
save a single value in the entry-changed event handler.

 -Original Message-
 From: gtk-app-devel-list-boun...@gnome.org 
 [mailto:gtk-app-devel-list-boun...@gnome.org] On Behalf Of 
 Michael Torrie
 Sent: Monday, August 10, 2009 3:14 PM
 Cc: Gtk app list
 Subject: Re: Can't quite get my head around this, can anyone help?
 
 Boggess Rod wrote:
  BTDT.  Won't work because by then, the user-value I'm trying not to 
  loose would already be lost.
 
 Guess I don't understand the problem, then, as I don't see 
 why this would be if you kept track of it in an external 
 variable between callbacks.  Maybe a very small, 
 self-contained example would be appropriate.
 
  I would have thought this was a somewhat popular function, 
 especially 
  when processing records from a database.  But I don't seem to know 
  what to search for.  I can seem to find one single example anywhere 
  that makes use of the change-value signal.
 
 How would it be used in a database-driven app?  Not having 
 written any, it's not something I'm familiar with.
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
 
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list