Problem: spinbutton adjustment “value” not displayed on otherwise functional 
floating-point and integer spinbuttons, built from builder.ui, using C language 
on Ubuntu 14.04, with Gtk+ 3.0. I have already built a gui coded in C without 
using a builder.ui file and am now attempting to reproduce this with a 
builder.ui to make the application. The interface opens, the 'hello' and 'quit' 
buttons work, the spinbuttons are active, can be changed and printed to the 
terminal via the callback functions, but the initial “value” is either 0.0 or 0 
for float and integer respectively, and not the intended initial value. The two 
run-time messages shown immediately below obviously refer to the two spinbutton 
adjustments. Sorry about the length of this email, if the code below is copied 
to your computer it should run, thanks,
Roger Matthews.

Written at terminal:---------------------------------------------------

/Roger_app2$ gedit spin_app.c
/Roger_app2$ make
/Roger_app2$ ./spin_app
(spin_app:3326): Gtk-CRITICAL **: gtk_buildable_add_child: assertion 
'iface->add_child != NULL' failed
(spin_app:3326): Gtk-CRITICAL **: gtk_buildable_add_child: assertion 
'iface->add_child != NULL' failed
float1 = 0.1
float1 = 0.2
float1 = 0.3
integer1 = 1
integer1 = 2
integer1 = 3
integer1 = 4
Hello World
/Roger_app2$

spin_app.c -----------------------------------------------------------------
compiled with:
gcc `pkg-config --cflags gtk+-3.0` -o spin_app spin_app.c `pkg-config --libs 
gtk+-3.0`

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

float float1 = 53.1;
int integer1 = 53;

static void
print_hello (GtkWidget *widget,
             gpointer   data)
{
  g_print ("Hello World\n");
}

static void get_new_number_float_float1(GtkWidget *widget, gpointer data)
{
float1 = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
printf("float1 = %.1f\n", float1);
}

static void get_new_number_int_integer1(GtkWidget *widget, gpointer data)
{
integer1 = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
printf("integer1 = %d\n", integer1);
}

static void do_drawing(cairo_t *, GtkWidget *);

static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
    gpointer user_data)
{
  do_drawing(cr, widget);
  return FALSE;
}

static void do_drawing(cairo_t *cr, GtkWidget *widget)
{
  GtkWidget *win = gtk_widget_get_toplevel(widget);

  int winwidth_draw1, winheight_draw1;
  gtk_window_get_size(GTK_WINDOW(win), &winwidth_draw1, &winheight_draw1);
  cairo_set_source_rgb(cr, 0.6, 0.0, 0.0);
  cairo_set_line_width(cr, 1.0);
  cairo_move_to(cr, 20, 20);
  cairo_line_to(cr, 70, 135);
  cairo_stroke(cr);
}

int
main (int   argc,
      char *argv[])
{
  GtkBuilder *builder;
  GObject *window;
  GObject *notebook;
  GObject *label1;
  GObject *spin_float1;
  GObject *label2;
  GObject *spin_int1;
  GObject *notebook_tab1;
  GObject *button_hello;
  GObject *notebook_tab2;
  GObject *button_quit;
  GObject *notebook_tab3;
  GObject *adjustment1;
  GObject *adjustment2;

  gtk_init (&argc, &argv);

  /* Construct a GtkBuilder instance and load our UI description */
  builder = gtk_builder_new ();
  gtk_builder_add_from_file (builder, "builder.ui", NULL);

  /* Connect signal handlers to the constructed widgets. */
  window = gtk_builder_get_object (builder, "window");
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  spin_float1 = gtk_builder_get_object (builder, "button1");
  g_signal_connect (spin_float1, "value-changed",
                    G_CALLBACK (get_new_number_float_float1), NULL);

  spin_int1 = gtk_builder_get_object (builder, "button2");
  g_signal_connect (spin_int1, "value-changed",
                    G_CALLBACK (get_new_number_int_integer1), NULL);

  button_hello = gtk_builder_get_object (builder, "button_hello");
  g_signal_connect (button_hello, "clicked", G_CALLBACK (print_hello), NULL);

  button_quit = gtk_builder_get_object (builder, "quit");
  g_signal_connect (button_quit, "clicked", G_CALLBACK (gtk_main_quit), NULL);

  gtk_main ();

  return 0;
}

builder.ui 
--------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object id="window" class="GtkWindow">
    <property name="visible">True</property>
    <property name="title">Roger's App</property>
    <property name="border-width">10</property>
    <property name="default-width">600</property>
    <property name="default-height">400</property>
    <child>
      <object id="notebook" class="GtkNotebook">
        <property name="visible">True</property>
        <property name="can_focus">True</property>

            <child>
              <object class="GtkLayout" id="content_layout">
                <property name="visible">True</property>
                <property name="width">1200</property>
                <property name="height">1200</property>
                  <child>
                    <object class="GtkLabel" id="label1">
                      <property name="label">Label1</property>
                      <property name="visible">True</property>
                    </object>
                      <packing>
                      <property name="x">1</property>
                      <property name="y">1</property>
                      </packing>
                  </child>
                  <child>
                    <object id="button1" class="GtkSpinButton">
                      <property name="visible">True</property>
                      <property name="numeric">True</property>
                      <property name="snap-to-ticks">True</property>
                      <!--<property name="value">53.1</property> -->
                      <property name="climb-rate">1</property>
                      <property name="digits">1</property>
                      <property name="adjustment">adjustment1</property>
                      <child>
                        <object id="adjustment1" class="GtkAdjustment">
                          <property name="value">53.1</property>
                          <property name="lower">0.0</property>
                          <property name="upper">112.0</property>
                          <property name="step-increment">0.1</property>
                          <property name="page-increment">1</property>
                          <property name="page-size">1</property>
                        </object>
                      </child>
                    </object>
                    <packing>
                      <property name="x">1</property>
                      <property name="y">20</property>
                    </packing>
                  </child>
                  <child>
                    <object class="GtkLabel" id="label2">
                      <property name="label">Label2</property>
                      <property name="visible">True</property>
                    </object>
                      <packing>
                      <property name="x">120</property>
                      <property name="y">1</property>
                      </packing>
                  </child>
                  <child>
                    <object id="button2" class="GtkSpinButton">
                      <property name="visible">True</property>
                      <property name="numeric">True</property>
                      <property name="snap-to-ticks">True</property>
                      <!--<property name="value">53</property> -->
                      <property name="climb-rate">1</property>
                      <property name="digits">0</property>
                      <property name="adjustment">adjustment2</property>
                     <child>
                       <object id="adjustment2" class="GtkAdjustment">
                         <property name="value">53</property>
                         <property name="lower">0</property>
                         <property name="upper">112</property>
                         <property name="step-increment">1</property>
                         <property name="page-increment">1</property>
                         <property name="page-size">1</property>
                       </object>
                     </child>
                    </object>
                    <packing>
                      <property name="x">120</property>
                      <property name="y">20</property>
                    </packing>
                  </child>
              </object>
            </child>

        <child type="tab">
          <object class="GtkLabel" id="notebook_tab1">
            <property name="label">Tab1</property>
          </object>
        </child>
        <child>
          <object id="button_hello" class="GtkButton">
            <property name="visible">True</property>
            <property name="label">Hello</property>
          </object>
          <packing>
          </packing>
        </child>
        <child type="tab">
          <object class="GtkLabel" id="notebook_tab2">
            <property name="label">Tab2</property>
          </object>
        </child>
        <child>
          <object id="quit" class="GtkButton">
            <property name="visible">True</property>
            <property name="label">Quit</property>
          </object>
          <packing>
          </packing>
        </child>
        <child type="tab">
          <object class="GtkLabel" id="notebook_tab3">
            <property name="label">Tab3</property>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to