GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Jul 26, 2014 11:10 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Possibility of a gtk_progress_bar on a button?
PostPosted: Tue Jan 28, 2014 7:49 am 
Offline
GTK+ Geek

Joined: Wed Mar 18, 2009 2:26 pm
Posts: 62
Is it possible and safe to have a gtk_progress_bar in a button set as custom content?
Has anyone done such a thing on GTK 2.0 in C on Ubuntu 11.10.

Reason is I am trying to create a volume button for touch screen so i would like the volume to be present on the button?

_________________
Hello, העלו, Здравствулте!


Top
 Profile  
 
 Post subject: Re: Possibility of a gtk_progress_bar on a button?
PostPosted: Wed Jan 29, 2014 1:15 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 733
Location: UK
Hello,

I can not see why not, although it may look ugly. There is a widget just for this called GtkVolumeButton with the documentation at https://developer.gnome.org/gtk2/stable/GtkVolumeButton.html. This was introduced with GTK+ v2.12.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Possibility of a gtk_progress_bar on a button?
PostPosted: Mon Feb 03, 2014 8:57 am 
Offline
GTK+ Geek

Joined: Wed Mar 18, 2009 2:26 pm
Posts: 62
Well the reason I need a button like that is because this is for a special touch screen application and the button servers many purposes one of which is displaying some information and the volume level as well.
I have tried to do that and it seems to work, except that if the progress bar is hidden and shown then it fails to respond to any button clicks.

I have shown a simple example below that has a progress bar in a button.

Code:
/* Compile with
* gcc -Wall -Werror -g progress_bar_in_button.c -o progress_bar_in_button -export-dynamic `pkg-config --cflags --libs gtk+-2.0`
* */
#include <gtk/gtk.h>

/* Update the value of the progress bar so that we get
* some movement */
gint progress_timeout(gpointer data)
{
    gfloat new_val;
    GtkAdjustment *adj;

    new_val = gtk_progress_get_value(GTK_PROGRESS(data))+1;

    adj = GTK_PROGRESS(data)->adjustment;
    if(new_val > adj->upper)
      new_val = adj->lower;

    gtk_progress_set_value(GTK_PROGRESS(data), new_val);

    return(TRUE);
}

static gboolean button_pressed(GtkWidget *button,
                                GdkEventButton *event, GtkWidget *pbar)
{
    g_print("BAR PRESS %f\n", gtk_progress_get_value(GTK_PROGRESS(pbar)));
    // comment the bottom line and the progress bar will respond to button clicks
    gtk_widget_hide(pbar);
    return FALSE;
}

static gboolean button_released(GtkWidget *button,
                                 GdkEventButton *event, GtkWidget *pbar)
{
    g_print("BAR RELEASE %f\n", gtk_progress_get_value(GTK_PROGRESS(pbar)));
    gtk_widget_show(pbar);
    return FALSE;
}

int main( int   argc,
          char *argv[])
{
    GtkAdjustment *adj;
    GtkWidget *vbox;
    GtkWidget *window;
    GtkWidget *pbar;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, TRUE);
    gtk_widget_set_size_request(window, 200, 200);
    gtk_signal_connect(GTK_OBJECT(window), "destroy",
                        GTK_SIGNAL_FUNC(gtk_main_quit),
                        NULL);
    gtk_window_set_title(GTK_WINDOW(window), "GtkProgressBar");
    gtk_container_set_border_width(GTK_CONTAINER(window), 0);

    vbox = gtk_vbox_new(FALSE, 5);
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
    gtk_container_add(GTK_CONTAINER(window), vbox);
    gtk_widget_show(vbox);

    adj =(GtkAdjustment *) gtk_adjustment_new(0, 1, 150, 0, 0, 0);

    /* Create the GtkProgressBar using the adjustment */
    pbar = gtk_progress_bar_new_with_adjustment(adj);
    GtkWidget * butx = gtk_button_new();
    gtk_widget_set_size_request(butx, 50, 50);
    gtk_container_add(GTK_CONTAINER(butx), pbar);
    gtk_box_pack_start(GTK_BOX(vbox), butx, FALSE, FALSE, 5);
    gtk_widget_show(butx);
    gtk_widget_show(pbar);

    g_signal_connect(G_OBJECT(butx), "button_press_event",
                      G_CALLBACK(button_pressed),(gpointer) pbar);
    g_signal_connect(G_OBJECT(butx), "button_release_event",
                      G_CALLBACK(button_released),(gpointer) pbar);

    gtk_timeout_add(100, progress_timeout, pbar);
    gtk_widget_show(window);

    gtk_main();

    return(0);
}


Thank you in advance

_________________
Hello, העלו, Здравствулте!


Top
 Profile  
 
 Post subject: Re: Possibility of a gtk_progress_bar on a button?
PostPosted: Sun Feb 09, 2014 7:52 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 733
Location: UK
I tried out your code and can replicate your problem, although the interface does look ugly.

A few notes, the version of Ubuntu that you are using is no longer supported with support being removed in May 2013. Your code uses many deprecated functions, macros and structures. Some of these that you are using were deprecated with the transition from GTK v1 to GTK v2. Deprecated functions are only there to help support old software and to aid transition. Not for use by new software.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Possibility of a gtk_progress_bar on a button?
PostPosted: Tue Feb 18, 2014 10:11 am 
Offline
Familiar Face

Joined: Wed Jul 03, 2013 4:52 am
Posts: 9
add button press and release events to the progress bar so they get passed thru to the button underneath


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group