LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-25-2012, 05:32 AM   #1
Keith Hedger
Member
 
Registered: Jun 2010
Location: Devon,UK
Distribution: Linux From Scratch, Slackware64,
Posts: 837

Rep: Reputation: 167Reputation: 167
deprecated gtk_range_set_update_policy replacement?


I am trying to make a small app gtk3 compliant and the gtk_range_set_update_policy has been removed from the GtkRange widget, what I need is to get only the value of the range at the end ( on mouse up ) not continuously, ie I want to be able to do
Code:
gtk_range_set_update_policy((GtkRange*)advancedRange,GTK_UPDATE_DISCONTINUOUS);
Been googling but cant seem to find a solution.
The value is queried in a callback, the value is then used in a relatively long routine hence I only need the last value from the range widget NOT the intermediate value.
I'm using 'C'
 
Old 04-25-2012, 05:59 AM   #2
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 239

Rep: Reputation: 23
For better chances to find an answer, you could also ask on one of GTK mailing lists:
http://www.gtk.org/mailing-lists.php

Last edited by manu-tm; 04-25-2012 at 06:22 AM. Reason: typo
 
Old 04-25-2012, 06:17 AM   #3
Keith Hedger
Member
 
Registered: Jun 2010
Location: Devon,UK
Distribution: Linux From Scratch, Slackware64,
Posts: 837

Original Poster
Rep: Reputation: 167Reputation: 167
Thanks for the suggestion but there seems to be no recent references to gtk_range_set_update_policy and I don't really want to sign up for yet another mailing list for one question which I would have thought would be quite common, but I guess not, if I can't find a solution soon I guess I'll have to sign up.
 
Old 04-27-2012, 06:13 AM   #4
Keith Hedger
Member
 
Registered: Jun 2010
Location: Devon,UK
Distribution: Linux From Scratch, Slackware64,
Posts: 837

Original Poster
Rep: Reputation: 167Reputation: 167
No one? I can't be the only one with this problem, surely?
 
Old 04-27-2012, 12:40 PM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,758

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
Isn't there a doc on the gtk site about how to port code from gtk2 to gtk3?
 
Old 04-28-2012, 06:03 AM   #6
Keith Hedger
Member
 
Registered: Jun 2010
Location: Devon,UK
Distribution: Linux From Scratch, Slackware64,
Posts: 837

Original Poster
Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by gnashley View Post
Isn't there a doc on the gtk site about how to port code from gtk2 to gtk3?
Yeah had a look at that but it just says that the function is deprecated and that there is no replacement.
 
Old 04-28-2012, 11:40 AM   #7
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,758

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
Well, then you might copy the parts you need from the gtk2 sources.
 
Old 04-28-2012, 02:54 PM   #8
Keith Hedger
Member
 
Registered: Jun 2010
Location: Devon,UK
Distribution: Linux From Scratch, Slackware64,
Posts: 837

Original Poster
Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by gnashley View Post
Well, then you might copy the parts you need from the gtk2 sources.
Seriously?
 
Old 04-28-2012, 03:36 PM   #9
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by Keith Hedger View Post
what I need is to get only the value of the range at the end ( on mouse up ) not continuously
Okay. So, connect the button-release-event and key-release-event signals of the GtkScale or GtkRange object (inherited from GtkWidget) to a function which remembers the previous state. Query the current state (using e.g gtk_range_get_value()). If the current state differs, then trigger the long routine. Pick the set of signals based on how your widget can be accessed.
 
Old 04-28-2012, 04:56 PM   #10
Keith Hedger
Member
 
Registered: Jun 2010
Location: Devon,UK
Distribution: Linux From Scratch, Slackware64,
Posts: 837

Original Poster
Rep: Reputation: 167Reputation: 167
Tried "button-release-event" the range widget doesn't seem to respond to this haven't looked at "key-release-event", will try tomorrow.
 
Old 04-28-2012, 08:41 PM   #11
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by Keith Hedger View Post
Tried "button-release-event" the range widget doesn't seem to respond to this haven't looked at "key-release-event", will try tomorrow.
That is strange, as it works fine for me. Perhaps I'm using different library version? On my machine, both libgtk-3-0 and libgtk-3-dev are version 3.2.0-0ubuntu6.

Please try the following example program, to see if it works for you too:
Code:
#include <gtk/gtk.h>
#include <stdio.h>

void value_changed(GtkRange *range, gpointer user_data)
{
    /* This does get called:
        fputs("value_changed\n", stdout);
        fflush(stdout);
    */
}

gboolean button_release_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
    gdouble saved = *(gdouble *)user_data;
    gdouble value = gtk_range_get_value((GtkRange *)widget);

    if (saved != value) {
        *(gdouble *)user_data = value;
        fprintf(stdout, "button_release_event at %g\n", (double)value);
        fflush(stdout);
    } else {
        fprintf(stdout, "button_release_event ignored\n");
        fflush(stdout);
    }

    /* Do propagate this event further. */
    return FALSE;
}

gboolean focus_out_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
    gdouble saved = *(gdouble *)user_data;
    gdouble value = gtk_range_get_value((GtkRange *)widget);

    if (saved != value) {
        *(gdouble *)user_data = value;
        fprintf(stdout, "focus_out_event at %g\n", (double)value);
        fflush(stdout);
    } else {
        fprintf(stdout, "focus_out_event ignored\n");
        fflush(stdout);
    }

    /* Do propagate this event further. */
    return FALSE;
}

gboolean key_release_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
    gdouble saved = *(gdouble *)user_data;
    gdouble value = gtk_range_get_value((GtkRange *)widget);

    if (saved != value) {
        *(gdouble *)user_data = value;
        fprintf(stdout, "key_release_event at %g\n", (double)value);
        fflush(stdout);
    } else {
        fprintf(stdout, "key_release_event ignored\n");
        fflush(stdout);
    }

    /* Do propagate this event further. */
    return FALSE;
}

int main(int argc, char *argv[])
{
    GtkWidget   *window;
    GtkWidget   *scale;
    gdouble      scale_old;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 50);
    gtk_window_set_title(GTK_WINDOW(window), "Range");
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    scale_old = -1.0;
    scale = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, 0.0, 100.0, 0.1);
    gtk_container_add(GTK_CONTAINER(window), scale);
    g_signal_connect(scale, "value-changed", G_CALLBACK(value_changed), NULL);
    g_signal_connect(scale, "button-release-event", G_CALLBACK(button_release_event), &scale_old);
    g_signal_connect(scale, "focus-out-event", G_CALLBACK(focus_out_event), &scale_old);
    g_signal_connect(scale, "key-release-event", G_CALLBACK(key_release_event), &scale_old);

    gtk_widget_show(scale);
    gtk_widget_show(window);
    gtk_main();

    return 0;
}
For those not familiar with building GTK+ C programs, save the above as range.c, and compile using
Code:
gcc range.c `pkg-config gtk+-3.0 --cflags --libs` -o range
When you move the slider, the value is updated immediately (since the relevant callback, value_change, does nothing). You can uncomment the output in the value_change function to check.

When you release the slider, by releasing the mouse button, or releasing the key, or just by focusing elsewhere, one of the three callback functions (*_event) gets called to trigger the desired action. The example program will just output the new value to standard output.

Note that all three signals could have been wired to the same callback function. I used separate functions, so I could easily observe that all desired signals do in fact occur.

Note how I used the user data pointer to point to a gdouble containing the last acted-upon value. Only when it is different to the current value, is there any work to do. When the last acted-upon value is still the same, there is nothing to do, and the signal can be ignored.

When there is work to do, the last acted-upon value should be updated. You most likely want to update it before starting the work (rather than when completing the work), so that you update it to the value you used for the large work. Otherwise you'd likely miss updates in between; the users see a different value than the other effects are.

Last edited by Nominal Animal; 04-28-2012 at 08:47 PM.
 
1 members found this post helpful.
Old 04-29-2012, 05:58 AM   #12
Keith Hedger
Member
 
Registered: Jun 2010
Location: Devon,UK
Distribution: Linux From Scratch, Slackware64,
Posts: 837

Original Poster
Rep: Reputation: 167Reputation: 167
Thanks Nominal Animal!

That works just fine, when I tried using the "button-release-event" I used "g_signal_connect_after" instead of "g_signal_connect" to connect the callback which is why it did not work. I mostly always use the "_after" variant and no problems up 'till now, odd.

Thanks again, marking thread as solved.
 
  


Reply

Tags
gtk+, gtk3, gtkrange


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cp --reply=yes deprecated!! fredsub Linux - General 1 08-25-2008 09:43 PM
deprecated function in C++ knobby67 Programming 5 08-11-2008 06:26 PM
initlog is deprecated powah Linux - Software 0 11-12-2007 01:30 PM
initlog is deprecated powah Linux - General 0 10-31-2007 03:32 PM
rc.modules deprecated? hussar Slackware 2 09-23-2006 01:46 PM


All times are GMT -5. The time now is 05:21 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration