GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GtkHScale example with libglade and C/GTK+

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 407
Location: Portland, OR USA

PostPosted: Wed Mar 15, 2006 4:05 pm    Post subject: GtkHScale example with libglade and C/GTK+ Reply with quote

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:
Code: (Plaintext)
1
gcc -o test -Wall -g main.c `pkg-config gtk+-2.0 --cflags --libs `-I/usr/include/libglade-2.0 -lglade-2.0


gui.glade
Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<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"/>

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

      <child>
    <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"/>
    </widget>
    <packing>
      <property name="padding">0</property>
      <property name="expand">True</property>
      <property name="fill">True</property>
    </packing>
      </child>

      <child>
    <widget class="GtkLabel" id="label1">
      <property name="visible">True</property>
      <property name="label" translatable="yes">www.micahcarrick.com</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>
    </widget>
    <packing>
      <property name="padding">0</property>
      <property name="expand">False</property>
      <property name="fill">False</property>
    </packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>


main.c
Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#define GLADE_FILE "gui.glade"

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

void
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);
}

void
on_window1_destroy (GtkWidget *widget, gpointer user_data)
{
        /* break gtk_main() loop */
        gtk_main_quit();                       
}

int
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",
                G_CALLBACK(on_window1_destroy));
       
        glade_xml_signal_connect (gxml, "on_hscale1_value_changed",
                G_CALLBACK(on_hscale1_value_changed));

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

        /* begin main GTK loop */
        gtk_main ();
       
        return 0;     
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP