Thanks Lucky B. C. for replying to my email, I have already tried

                  <property name="width">4000</property>

                  <property name="height">1000</property>

without success (see code below).

     I am attempting to draw a Cairo line from two points entered with spin 
buttons that is built with 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 (now) working correctly, but I am encountering two or three 
problems with drawing that may or may not be connected:

1) I cannot work out how to set the size of the GtkDrawingArea in the 
builder.ui file, which is a simple thing to do in the program using, for 
example:



  darea = gtk_drawing_area_new();

  gtk_widget_set_size_request (darea, 800, 500);

  gtk_fixed_put (GTK_FIXED (fixed), darea, 0, 0);

  g_signal_connect(G_OBJECT(darea), "draw", G_CALLBACK(on_draw_event), NULL);



2) Despite the warnings the Cairo drawing is drawn when I click on tab2, 
although ultimately I would like to use a GtkLayout to contain spinbuttons and 
the drawing within the same notebook page, and to have the drawing updated as 
the spinbutton values are changed, so far with no success, but for now let's 
deal with the sizing of the GtkDrawingArea, so that my pre-existing gui program 
can be converted into an application.



Any help with these problems would be greatly appreciated, sorry about the 
length of this email, if the code below is copied to your computer it should 
run, thanks, Roger.



With the drawing area “width” and “height” <properties> commented-out in 
builder.ui these are the commands, errors and warnings:



$ gedit darea_widthheight.c

$ make

gcc -mcmodel=large `pkg-config --cflags gtk+-3.0` -o darea_widthheight 
darea_widthheight.c `pkg-config --libs gtk+-3.0` -lm

$ ./darea_widthheight

(darea_widthheight:2787): Gtk-CRITICAL **: gtk_buildable_add_child: assertion 
'iface->add_child != NULL' failed

(darea_widthheight:2787): Gtk-CRITICAL **: gtk_buildable_add_child: assertion 
'iface->add_child != NULL' failed

(darea_widthheight:2787): GLib-GObject-WARNING **: invalid unclassed pointer in 
cast to 'GtkWindow'

(darea_widthheight:2787): Gtk-CRITICAL **: gtk_window_get_size: assertion 
'GTK_IS_WINDOW (window)' failed

winwidth_draw1 = 1734702190, winheight_draw1 = 741438053

Hello World

$



Then when the drawing area “width” and “height” <properties> are uncommented in 
builder.ui, note that “width” and “height” <properties> are not recognised.



$ ./darea_widthheight

(darea_widthheight:2928): Gtk-CRITICAL **: gtk_buildable_add_child: assertion 
'iface->add_child != NULL' failed

(darea_widthheight:2928): Gtk-CRITICAL **: gtk_buildable_add_child: assertion 
'iface->add_child != NULL' failed

(darea_widthheight:2928): Gtk-WARNING **: Unknown property: GtkDrawingArea.width

(darea_widthheight:2928): Gtk-WARNING **: Unknown property: 
GtkDrawingArea.height

(darea_widthheight:2928): GLib-GObject-WARNING **: invalid unclassed pointer in 
cast to 'GtkWindow'

(darea_widthheight:2928): Gtk-CRITICAL **: gtk_window_get_size: assertion 
'GTK_IS_WINDOW (window)' failed

winwidth_draw1 = 1734702190, winheight_draw1 = 741438053

Hello World

$



darea_widthheight.c----------------------------------------------------------------------------:

#include <stdio.h>

#include <math.h>

#include <errno.h>

#include <sys/time.h>

#include <sys/resource.h>

#include <unistd.h>

#include <stdlib.h>

#include <string.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));

write_file2();

}



static void get_new_number_int_integer1(GtkWidget *widget, gpointer data)

{

integer1 = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));

write_file2();

}



static void do_drawing1(cairo_t *, GtkWidget *);



static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,

    gpointer user_data)

{

do_drawing1(cr, widget);

return FALSE;

}



static void do_drawing1(cairo_t *cr, GtkWidget *widget)

{

  GtkWidget *win = gtk_widget_get_toplevel(widget);



char paramname1, paramname2;

 FILE* infile_file2 = fopen("file2", "r");

 fscanf(infile_file2,"%s %f\n%s %d\n", &paramname1, &float1, &paramname2, 
&integer1);

 fclose(infile_file2);



  int winwidth_draw1, winheight_draw1;

  gtk_window_get_size(GTK_WINDOW(win), &winwidth_draw1, &winheight_draw1);

printf("winwidth_draw1 = %d, winheight_draw1 = %d\n", 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, float1, float1);

  cairo_line_to(cr, integer1, integer1);

  cairo_stroke(cr);

}



static void activate (GtkApplication *app, gpointer user_data)

{

int   argc;

char **argv;



  GtkBuilder *builder1;

  GObject *window, *notebook;

  GObject *label1, *spin_float1, *adjustment1;

  GObject *label2, *spin_int1, *adjustment2;

  GObject *notebook_tab1;

  GObject *drawing1;

  GObject *notebook_tab2;

  GObject *button_hello;

  GObject *notebook_tab3;

  GObject *button_quit;

  GObject *notebook_tab4;



  gtk_init (&argc, &argv);



  /* Construct a GtkBuilder instance and load our UI description */

  builder1 = gtk_builder_new ();

  gtk_builder_add_from_file (builder1, "builder2.ui", NULL);



  /* Connect signal handlers to the constructed widgets. */

  window = gtk_builder_get_object (builder1, "window");

  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);



  spin_float1 = gtk_builder_get_object (builder1, "button1");

  g_signal_connect (spin_float1, "value-changed", G_CALLBACK 
(get_new_number_float_float1), NULL);

  g_signal_connect (spin_float1, "scroll-event", G_CALLBACK(gtk_true), NULL);



  spin_int1 = gtk_builder_get_object (builder1, "button2");

  g_signal_connect (spin_int1, "value-changed", G_CALLBACK 
(get_new_number_int_integer1), NULL);

  g_signal_connect (spin_int1, "scroll-event", G_CALLBACK(gtk_true), NULL);



  drawing1 = gtk_builder_get_object (builder1, "drawing1");

  g_signal_connect (G_OBJECT (drawing1), "draw", G_CALLBACK (on_draw_event), 
NULL);



  button_hello = gtk_builder_get_object (builder1, "button_hello");

  g_signal_connect (button_hello, "clicked", G_CALLBACK (print_hello), NULL);

  g_signal_connect (button_hello, "scroll-event", G_CALLBACK(gtk_true), NULL);



  button_quit = gtk_builder_get_object (builder1, "quit");

  g_signal_connect (button_quit, "clicked", G_CALLBACK (gtk_main_quit), NULL);

  g_signal_connect (button_quit, "scroll-event", G_CALLBACK(gtk_true), NULL);



write_file2();

gtk_main ();

}



int main (int argc, char **argv)

{

  GtkApplication *app;

  int status;



  app = gtk_application_new ("com.hotmail.matthews.roger.dareawidthheight",

        G_APPLICATION_FLAGS_NONE);

  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);

  status = g_application_run (G_APPLICATION (app), argc, argv);

  g_object_unref (app);

  return status;

}



int write_file2()

{

 FILE* outfile_file2 = fopen("file2", "w");

 fprintf(outfile_file2,"float1, %f\ninteger1, %d\n", float1, integer1);

 fclose(outfile_file2);

return;

}



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

<?xml version="1.0" encoding="UTF-8"?>

<interface>

  <!-- interface-requires gtk+ 3.8 -->

<!--<template class="ExampleAppWindow" parent="GtkApplicationWindow">

    <property name="title" translatable="yes">Example Application</property> -->

  <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 id="swin" class="GtkScrolledWindow">

            <property name="visible">True</property>

            <child>

              <object class="GtkLayout" id="layout1">

                <property name="visible">True</property>

                <property name="width">2000</property>

                <property name="height">2000</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="upper">121.0</property>

                          <property name="lower">-10.0</property>

                          <property name="value">53.1</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="climb-rate">1</property>

                      <property name="digits">0</property>

                      <property name="adjustment">adjustment2</property>

                     <child>

                       <object id="adjustment2" class="GtkAdjustment">

                         <property name="upper">101</property>

                         <property name="lower">0</property>

                         <property name="value">53</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>

          </object>

        </child>

        <child type="tab">

          <object class="GtkLabel" id="notebook_tab1">

            <property name="label">Tab1</property>

          </object>

        </child>

        <child>

          <object id="swin2" class="GtkScrolledWindow">

            <property name="visible">True</property>

              <child>

                <object class="GtkDrawingArea" id="drawing1">

                  <property name="visible">True</property>

                  <property name="width">4000</property>

                  <property name="height">1000</property>

                </object>

                  <packing>

                    <property name="left-attach">1</property>

                    <property name="top-attach">1</property>

                  </packing>

              </child>

          </object>

        </child>

        <child type="tab">

          <object class="GtkLabel" id="notebook_tab2">

            <property name="label">Tab2</property>

          </object>

        </child>

        <child>

          <object id="swin3" class="GtkScrolledWindow">

            <property name="visible">True</property>

            <child>

              <object class="GtkLayout" id="layout2">

                <property name="visible">True</property>

                <property name="width">2000</property>

                <property name="height">2000</property>

                <child>

                  <object id="button_hello" class="GtkButton">

                    <property name="visible">True</property>

                    <property name="label">Hello World</property>

                  </object>

                  <packing>

                    <property name="x">120</property>

                    <property name="y">20</property>

                  </packing>

                </child>

              </object>

            </child>

          </object>

        </child>

        <child type="tab">

          <object class="GtkLabel" id="notebook_tab3">

            <property name="label">Tab3</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_tab4">

            <property name="label">Tab4</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