GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Nov 30, 2015 8:01 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: GtkHScale example with libglade and C/GTK+
PostPosted: Wed Mar 15, 2006 4:05 pm 
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Since I posted this in another forum... this example uses libglade and C/GTK+ to print the value of a horizontal scale widget to the terminal when it is changed.

Compiles on my system with:
gcc -o test -Wall -g main.c `pkg-config gtk+-2.0 --cflags --libs `-I/usr/include/libglade-2.0 -lglade-2.0
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "">


<widget class="GtkWindow" id="window1">
  <property name="visible">True</property>
  <property name="title" translatable="yes">window1</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="focus_on_map">True</property>
  <signal name="destroy" handler="on_window1_destroy" last_modification_time="Wed, 15 Mar 2006 15:55:53 GMT"/>

    <widget class="GtkVBox" id="vbox1">
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

   <widget class="GtkHScale" id="hscale1">
     <property name="visible">True</property>
     <property name="can_focus">True</property>
     <property name="draw_value">True</property>
     <property name="value_pos">GTK_POS_TOP</property>
     <property name="digits">0</property>
     <property name="update_policy">GTK_UPDATE_CONTINUOUS</property>
     <property name="inverted">False</property>
     <property name="adjustment">5 0 100 1 5 5</property>
     <signal name="value_changed" handler="on_hscale1_value_changed" last_modification_time="Wed, 15 Mar 2006 15:52:49 GMT"/>
     <property name="padding">0</property>
     <property name="expand">True</property>
     <property name="fill">True</property>

   <widget class="GtkLabel" id="label1">
     <property name="visible">True</property>
     <property name="label" translatable="yes"></property>
     <property name="use_underline">False</property>
     <property name="use_markup">False</property>
     <property name="justify">GTK_JUSTIFY_LEFT</property>
     <property name="wrap">False</property>
     <property name="selectable">False</property>
     <property name="xalign">0.5</property>
     <property name="yalign">0.5</property>
     <property name="xpad">5</property>
     <property name="ypad">10</property>
     <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
     <property name="width_chars">-1</property>
     <property name="single_line_mode">False</property>
     <property name="angle">0</property>
     <property name="padding">0</property>
     <property name="expand">False</property>
     <property name="fill">False</property>


#define GLADE_FILE ""

#include <gtk/gtk.h>
#include <glade/glade.h>

on_hscale1_value_changed (GtkWidget *widget, gpointer user_data)
        gdouble val;
        val = gtk_range_get_value (GTK_RANGE(widget));
        /* print to screen */
        g_print("Range value: %d\n", (guint)val);

on_window1_destroy (GtkWidget *widget, gpointer user_data)
        /* break gtk_main() loop */

main (int argc, char *argv[])
        GtkWidget *main_window; 
        GladeXML *gxml;
        /* initialize the GTK+ library */
        gtk_init (&argc, &argv);

        create an instance of the GladeXML object and build widgets within
        the window1 root node.
        gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
        /* get the window widget from the glade XML file */
        main_window = glade_xml_get_widget (gxml, "window1");
        /* connect signals */
        glade_xml_signal_connect (gxml, "on_window1_destroy",
        glade_xml_signal_connect (gxml, "on_hscale1_value_changed",

        /* show the main window */
        gtk_widget_show (main_window);

        /* begin main GTK loop */
        gtk_main ();
        return 0;     

Micah Carrick - Forum Administrator

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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