GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Oct 21, 2014 8:49 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Textview how to fill in data from a button.
PostPosted: Mon Nov 26, 2007 3:14 pm 
Offline
Familiar Face

Joined: Sun Nov 18, 2007 11:41 pm
Posts: 14
Hello,

I am new , so please forgive me for all the mistakes I did in the following code.. I created a GUI with glade hello.glade and I have my hello.c code which I took from the exapmle of the codes area. I tryed to take the data from a gtkentry box , convert it in floating , do my calculation an print it back to the gtkentry. This works , I am not sure if I did it in elegant way.. (probably not) , but it works.
My real problem is that I want to collect the data from 4 gtk entry , do my calculations and print the text in the textview area. This does not work and I did a lot of testing but I am doing something worng..
I particular If i initialize the gtk_buffe_set_text into the main , i can write text in the GUI textview , but I do not know how I can do it while pressing the button_clicked...

hello.c

Code:

#include <gtk/gtk.h>
#include <glade/glade.h>
#include <stdlib.h>   // very important to do the data type conversion

#define GLADE_FILE "hello.glade"

// se non diciharo questi widget ,quando compile restituisce undeclared...
void on_button1_clicked (GtkButton *button, GtkWidget *entry);
void on_button2_clicked (GtkButton *button, GtkWidget *entry);
void gtk_text_buffer_set_text (GtkTextBuffer *buffer, const gchar *text,
                                                 gint length);

int
main (int argc, char *argv[])  {
    GladeXML        *gxml = NULL;
    GtkWidget       *window = NULL;
    GtkWidget       *entry = NULL;
    GtkWidget       *entry2 = NULL;
    GtkWidget       *entry3 = NULL;
    GtkWidget       *entry4 = NULL;
    GtkWidget       *textview = NULL;
    GtkTextBuffer   *buffer;
   
   
    /* initialize GTK+ libraries */
    gtk_init (&argc, &argv);
   
    /* build from Glade XML file */
    gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
    g_assert (gxml);
   
    /* inserisco la lista dei widget da estrarre dal file .glade (XML)*/
    window = glade_xml_get_widget (gxml, "window1");
    entry  = glade_xml_get_widget (gxml, "entry1");
    entry2 = glade_xml_get_widget (gxml, "entry2");
    entry3 = glade_xml_get_widget (gxml, "entry3");
    entry4 = glade_xml_get_widget (gxml, "entry4");
    textview = glade_xml_get_widget (gxml, "textview1");
    buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
   
   
   
    /* call gtk_main_quit() when the window's "x" is clicked */
    glade_xml_signal_connect (gxml, "on_window1_destroy",
            G_CALLBACK (gtk_main_quit));
   
    /* call on_button1_clicked() when button1 is clicked, passing the text
    entry widget to the function as the user_data */
    glade_xml_signal_connect_data (gxml, "on_button1_clicked",
            G_CALLBACK (on_button1_clicked), entry);
   
    /* call gtk_main_quit() when the "chiudi" button  is clicked */
    glade_xml_signal_connect_data (gxml, "on_button2_clicked",
            G_CALLBACK (on_button2_clicked), entry);
           
   
    // impostare testodi default negli entry box quando carica il programma
     gtk_entry_set_text (GTK_ENTRY(entry2), "scrivi" );
     gtk_text_buffer_set_text (buffer, "Your 1st GtkTextView widget!", -1);

   
    /* free Glade XML object */
    g_object_unref (G_OBJECT (gxml));
       
    /* begin GTK+ main loop */                   
    gtk_main ();

    return 0;
}

//------------------------------------------------------------------------------

void on_button1_clicked (GtkButton *button, GtkWidget *entry)
{

/* prima di tutto, nota che ho fatto  #include <stdlib.h> , questo serve per
gestire le conversion stringhe a interi , poi ho usato aoti , posso usare anche
atof per passare da stringa a floating etc.. vedi
http://cboard.cprogramming.com/archive/index.php/t-6410.html
*/
    float  i;
    char *string;
    char buffer [12]; // testo max di 12 caratteri! compreso "." e decimali...
    int h; // conto il numero di caratteri usati
   
    string  = gtk_entry_get_text (GTK_ENTRY(entry));   
    i = atof(string);   
    i = (i* 2);   
    printf("%.2f", i);
    printf(" cm\n");
   
    // converto da floating a string
    h = sprintf(buffer,"%.2f",i);
 
    printf("string vale in string  :%s\n",buffer);
    printf("la stringa é lunga %d\n", h);

    gtk_entry_set_text (GTK_ENTRY(entry), buffer );
   
   //  gtk_text_buffer_set_text ( buffer, "change text in textview while pressing button", -1);
}

//------------------------------------------------------------------------------

/* lancio la chiusura della finestra chiamando gtk_main_quit() */

void on_button2_clicked (GtkButton *button, GtkWidget *entry)
{
gtk_main_quit();
}
//------------------------------------------------------------------------------



Can you please just do an example , how I have to set the code if after pressing the button1_clicked the textview should display the buffer , as i am doing with this : gtk_entry_set_text (GTK_ENTRY(entry), buffer );

hello.glade

Code:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--*- mode: xml -*-->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="width_request">600</property>
    <property name="height_request">500</property>
    <property name="visible">True</property>
    <property name="border_width">10</property>
    <property name="title" translatable="yes">Calcolatore Preventivi 1.0</property>
    <property name="resizable">False</property>
    <property name="icon">gnome-finance.png</property>
    <signal name="destroy" handler="on_window1_destroy"/>
    <child>
      <widget class="GtkVBox" id="vbox2">
        <property name="visible">True</property>
        <property name="spacing">5</property>
        <property name="homogeneous">True</property>
        <child>
          <widget class="GtkMenuBar" id="menubar1">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <child>
              <widget class="GtkMenuItem" id="menuitem1">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="label" translatable="yes">_File</property>
                <property name="use_underline">True</property>
                <child>
                  <widget class="GtkMenu" id="menu1">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem1">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-new</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem2">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-open</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem3">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-save</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem4">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-save-as</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem5">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-quit</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                  </widget>
                </child>
              </widget>
            </child>
            <child>
              <widget class="GtkMenuItem" id="menuitem2">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="label" translatable="yes">_Edit</property>
                <property name="use_underline">True</property>
                <child>
                  <widget class="GtkMenu" id="menu2">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem6">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-cut</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem7">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-copy</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem8">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-paste</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem9">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-delete</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                  </widget>
                </child>
              </widget>
            </child>
            <child>
              <widget class="GtkMenuItem" id="menuitem3">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="label" translatable="yes">_View</property>
                <property name="use_underline">True</property>
              </widget>
            </child>
            <child>
              <widget class="GtkMenuItem" id="menuitem4">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="label" translatable="yes">_Help</property>
                <property name="use_underline">True</property>
                <child>
                  <widget class="GtkMenu" id="menu3">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem10">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-about</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                  </widget>
                </child>
              </widget>
            </child>
          </widget>
          <packing>
            <property name="expand">False</property>
          </packing>
        </child>
        <child>
          <widget class="GtkHBox" id="hbox1">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <child>
              <widget class="GtkVBox" id="vbox1">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="homogeneous">True</property>
                <child>
                  <widget class="GtkLabel" id="label1">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0.40000000596046448</property>
                    <property name="label" translatable="yes">Altezza :</property>
                  </widget>
                </child>
                <child>
                  <widget class="GtkLabel" id="label2">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0.4400000274181366</property>
                    <property name="label" translatable="yes">Lunghezza :</property>
                  </widget>
                  <packing>
                    <property name="position">1</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label3">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0.73000001907348633</property>
                    <property name="label" translatable="yes">Valore materiale €  m^2 :</property>
                  </widget>
                  <packing>
                    <property name="position">2</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label4">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0.52999997138977051</property>
                    <property name="label" translatable="yes">Numero Etichette :</property>
                  </widget>
                  <packing>
                    <property name="position">3</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkButton" id="button1">
                    <property name="height_request">10</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="label" translatable="yes">Calcola</property>
                    <property name="use_underline">True</property>
                    <signal name="clicked" handler="on_button1_clicked"/>
                  </widget>
                  <packing>
                    <property name="position">4</property>
                  </packing>
                </child>
              </widget>
            </child>
            <child>
              <widget class="GtkVBox" id="vbox3">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="homogeneous">True</property>
                <child>
                  <widget class="GtkEntry" id="entry1">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="has_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="tooltip" translatable="yes">usa il (pnto) per separare le decine es. 7.20 cm</property>
                  </widget>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry2">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">1</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry3">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">2</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry4">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">3</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkButton" id="button2">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="label" translatable="yes">Chiudi</property>
                    <signal name="clicked" handler="on_button2_clicked"/>
                  </widget>
                  <packing>
                    <property name="position">4</property>
                  </packing>
                </child>
              </widget>
              <packing>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <widget class="GtkTextView" id="textview1">
                <property name="width_request">250</property>
                <property name="height_request">100</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
              </widget>
              <packing>
                <property name="position">2</property>
              </packing>
            </child>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <widget class="GtkStatusbar" id="statusbar1">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <property name="spacing">2</property>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="position">2</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>


Hope i explained well.

thank you
Ben


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 10:30 am 
Offline
Familiar Face

Joined: Sun Nov 18, 2007 11:41 pm
Posts: 14
Hi all,

I saw on the foundamental book and example on how to manage the data on the textview, the problem is that I am not writing the code for the GUI but I am using the galde designer. To insert text to the textview on the button clicked event , should I declare the widget *textview outside the main ?
I tryed in may ways but I get always errors , I do not understand how to structure it.

I copy the code example below :

Code:

#include <gtk/gtk.h>
typedef struct
{
  GtkWidget *entry, *textview;
} Widgets;
static void insert_text (GtkButton*, Widgets*);
static void retrieve_text (GtkButton*, Widgets*)


int main (int argc,  char *argv[])
{

   // declare the widget
  GtkWidget *window, *scrolled_win, *hbox, *vbox, *insert, *retrieve;
  Widgets *w = g_slice_new (Widgets);
  gtk_init (&argc, &argv);
 
  // write the code for the main window and set the title
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Text Iterators");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  gtk_widget_set_size_request (window, -1, 200);
  w->textview = gtk_text_view_new ();
  w->entry = gtk_entry_new ();
 
  //create the label of the 2 buttons
  insert = gtk_button_new_with_label ("Insert Text");
  retrieve = gtk_button_new_with_label ("Get Text");


  // prepare the callbacks for the the functions that handle the button_clicked
  g_signal_connect (G_OBJECT (insert), "clicked",
                     G_CALLBACK (insert_text),
                     (gpointer) w);
  g_signal_connect (G_OBJECT (retrieve), "clicked",
                     G_CALLBACK (retrieve_text),
                     (gpointer) w);
                     
  //prepare the scroll window of the textview                 
  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_container_add (GTK_CONTAINER (scrolled_win), w->textview);
  hbox = gtk_hbox_new (FALSE,  5);
  gtk_box_pack_start_defaults  (GTK_BOX (hbox), w->entry);
  gtk_box_pack_start_defaults  (GTK_BOX (hbox), insert);
  gtk_box_pack_start_defaults  (GTK_BOX (hbox), retrieve);
  vbox = gtk_vbox_new (FALSE, 5);
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show_all (window);
  gtk_main();
  return 0;
}
/* Insert the text from the GtkEntry into the GtkTextView. */
static void  insert_text (GtkButton *button,  Widgets *w)
{
  GtkTextBuffer *buffer;
  GtkTextMark *mark;
  GtkTextIter iter;
  const gchar *text;
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w->textview));
  text = gtk_entry_get_text (GTK_ENTRY (w->entry));
  mark = gtk_text_buffer_get_insert (buffer);
  gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
  gtk_text_buffer_insert (buffer, &iter, text, -1);
}
                                                   
/* Retrieve the selected text from the GtkTextView and display it
  * to the user. */
static void  retrieve_text (GtkButton *button, Widgets *w)
{
   GtkTextBuffer *buffer;
   GtkTextIter start, end;
   gchar *text;
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w->textview));
   gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
   text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
   g_print ("%s\n", text);
}


Please give me some hint..

Thanks
Ben


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 10:48 am 
Offline
Familiar Face

Joined: Sun Nov 18, 2007 11:41 pm
Posts: 14
I declared the GtkWidget *textview;
outside of the main and wrote the code to set the text buffer in the button_clicked event but it does not work . I compile without errors , but when I click the button it shows:

Code:

(hello:6744): Gtk-CRITICAL **: gtk_text_view_get_buffer: assertion `GTK_IS_TEXT_VIEW (text_view)' failed

(hello:6744): Gtk-CRITICAL **: gtk_text_buffer_set_text: assertion `GTK_IS_TEXT_BUFFER (buffer)' failed





Here is what I did

Code:

#include <gtk/gtk.h>
#include <glade/glade.h>
#include <stdlib.h>   // very important to do the data type conversion

#define GLADE_FILE "hello.glade"


GtkWidget *textview;


// se non dichiaro questi widget ,quando compile restituisce undeclared...
void on_button1_clicked (GtkButton *button, GtkWidget *entry);
void on_button2_clicked (GtkButton *button, GtkWidget *entry);
void gtk_text_buffer_set_text (GtkTextBuffer *buffer, const gchar *text,
                                                 gint length);

int
main (int argc, char *argv[])  {
    GladeXML        *gxml = NULL;
    GtkWidget       *window = NULL;
    GtkWidget       *entry = NULL;
    GtkWidget       *entry2 = NULL;
    GtkWidget       *entry3 = NULL;
    GtkWidget       *entry4 = NULL;
    GtkWidget       *textview = NULL;
    GtkTextBuffer   *buffer;
   
   
    /* initialize GTK+ libraries */
    gtk_init (&argc, &argv);
   
    /* build from Glade XML file */
    gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
    g_assert (gxml);
   
    /* inserisco la lista dei widget da estrarre dal file .glade (XML)*/
    window = glade_xml_get_widget (gxml, "window1");
    entry  = glade_xml_get_widget (gxml, "entry1");
    entry2 = glade_xml_get_widget (gxml, "entry2");
    entry3 = glade_xml_get_widget (gxml, "entry3");
    entry4 = glade_xml_get_widget (gxml, "entry4");
    textview = glade_xml_get_widget (gxml, "textview1");
    buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
   
   
   
    /* call gtk_main_quit() when the window's "x" is clicked */
    glade_xml_signal_connect (gxml, "on_window1_destroy",
            G_CALLBACK (gtk_main_quit));
   
    /* call on_button1_clicked() when button1 is clicked, passing the text
    entry widget to the function as the user_data */
    glade_xml_signal_connect_data (gxml, "on_button1_clicked",
            G_CALLBACK (on_button1_clicked), entry);
   
    /* call gtk_main_quit() when the "chiudi" button  is clicked */
    glade_xml_signal_connect_data (gxml, "on_button2_clicked",
            G_CALLBACK (on_button2_clicked), entry);
           
   
    // impostare testo di default negli entry box quando carica il programma
     gtk_entry_set_text (GTK_ENTRY(entry2), "scrivi" );
     gtk_text_buffer_set_text (buffer, "Your 1st GtkTextView widget!", -1);

   
    /* free Glade XML object */
    g_object_unref (G_OBJECT (gxml));
       
    /* begin GTK+ main loop */                   
    gtk_main ();

    return 0;
}

//------------------------------------------------------------------------------

void on_button1_clicked (GtkButton *button, GtkWidget *entry)
{

/*  This let's you write a message in the textview box once the button1_clicked
    event starts.
*/
     
  GtkTextBuffer *buffer;
  const gchar *text;

  text = "test message";
 
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));

   gtk_text_buffer_set_text ( buffer, text , -1);
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 4:53 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Rather than using global variables, we often use structures to hold references to our widgets that we will need to reference and pass those to callbacks as user_data. Try this code instead:



Code:
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <stdlib.h>   // very important to do the data type conversion

#define GLADE_FILE "hello.glade"


typedef struct
{
    GtkWidget       *window;
    GtkWidget       *textview;
    GtkWidget       *entry;
    GtkWidget       *entry2;
    GtkWidget       *entry3;
    GtkWidget       *entry4;
    /* etc.... */
} MyWidgets;

// se non dichiaro questi widget ,quando compile restituisce undeclared...
void on_button1_clicked (GtkButton *button, gpointer user_data);


int
main (int argc, char *argv[])  {
    GladeXML        *gxml = NULL;
    MyWidgets       *widgets;
    GtkTextBuffer   *buffer;
   
   
    /* initialize GTK+ libraries */
    gtk_init (&argc, &argv);
   
    /* build from Glade XML file */
    gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
    g_assert (gxml);
   
    /* allocate storage for MyWidgets structure */
    widgets = g_slice_new (MyWidgets);
   
    /* inserisco la lista dei widget da estrarre dal file .glade (XML)*/
    widgets->window = glade_xml_get_widget (gxml, "window1");
    widgets->entry  = glade_xml_get_widget (gxml, "entry1");
    widgets->entry2 = glade_xml_get_widget (gxml, "entry2");
    widgets->entry3 = glade_xml_get_widget (gxml, "entry3");
    widgets->entry4 = glade_xml_get_widget (gxml, "entry4");
    widgets->textview = glade_xml_get_widget (gxml, "textview1");
    buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widgets->textview));
   
   
   
    /* call gtk_main_quit() when the window's "x" is clicked */
    glade_xml_signal_connect (gxml, "on_window1_destroy",
            G_CALLBACK (gtk_main_quit));
   
    /* call on_button1_clicked() when button1 is clicked, passing the widgets
       struct to the function as the user_data */
    glade_xml_signal_connect_data (gxml, "on_button1_clicked",
            G_CALLBACK (on_button1_clicked), widgets);
           
   
    // impostare testo di default negli entry box quando carica il programma
     gtk_entry_set_text (GTK_ENTRY(widgets->entry2), "scrivi" );
     gtk_text_buffer_set_text (buffer, "Your 1st GtkTextView widget!", -1);

   
    /* free Glade XML object */
    g_object_unref (G_OBJECT (gxml));
       
    /* begin GTK+ main loop */                   
    gtk_main ();
   
    /* even though we are exiting now, this is how you cleanup the struct */
    g_slice_free (MyWidgets, widgets);

    return 0;
}

//------------------------------------------------------------------------------

void on_button1_clicked (GtkButton *button, gpointer user_data)
{

/*  This let's you write a message in the textview box once the button1_clicked
    event starts.
*/
  MyWidgets   *widgets = (MyWidgets*)user_data;   
  GtkTextBuffer *buffer;
  const gchar *text;

  text = "test message";

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widgets->textview));

   gtk_text_buffer_set_text ( buffer, text , -1);
}

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 4:57 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
And just as a tip regarding aesthetics, in your glade file, you may want to set "homogeneous" to False for vbox2 so that the menu and status bar are on the top and bottom and the contents of your app "expand and fill" to the remaining area.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 12:18 am 
Offline
Familiar Face

Joined: Sun Nov 18, 2007 11:41 pm
Posts: 14
Thank you Micah for your reply , it helped me a lot and my little program is working. On both linux and windows now :D

The software does some simple calculation on the stickers that I can print on a given area and the realted costs. I just only have some doubts...
I am reading the values from the entry and converting them with atof , i do my calculation and i convert them in string and put them in the textview. The software works well, just i get a warning when compiling and i am not sure if what i do is completly correct...

hello.c:131: warning: assignment discards qualifiers from pointer target type
hello.c:134: warning: assignment discards qualifiers from pointer target type
........


Also the way I am doing in writing every calculation to the textview i am not sure it is correct , I do not know if I can get the same by putting only one call to gtk_text_buffer_insert

Last thing , I would like to print the text which is available in the textview after my calculations.... is there any function I can use to print_textview buffer ?

I copy below the code , I appreciate any suggestion.

Thanks
Ben




Code:

#include <gtk/gtk.h>
#include <glade/glade.h>
#include <stdlib.h>   // very important to do the data type conversion
#include <stdio.h>
#include <string.h>

#define GLADE_FILE "hello.glade"

/*  Rather than using global variables, we often use structures to hold
references to our widgets that we will need to reference and pass those
to callbacks as user_data.  Quindi dichiaro la struttura (furoi dal main
per definizione) , cosi posso usare le variabili senza doverle dichiarare
anche furoi per essere usate dai bottoni.
*/

typedef struct
{
    GtkWidget       *window;
    GtkWidget       *textview;
    GtkWidget       *entry1;
    GtkWidget       *entry2;
    GtkWidget       *entry3;
    GtkWidget       *entry4;
    GtkWidget       *entry5;
    GtkWidget       *entry6;
    GtkWidget       *entry7;
    GtkWidget       *entry8;
   
    /* etc.... */
} MyWidgets;  //questo è il nome che ho dato alla mia struttura

/* se non dichiaro questi widget ,quando compile restituisce undeclared...
ricorda che void significa la funzione non restituisce nessun valore.
*/

void on_button1_clicked (GtkButton *button, gpointer user_data);
void on_button2_clicked (GtkButton *button, gpointer user_data);


int
main (int argc, char *argv[])  {
    GladeXML        *gxml = NULL;
    MyWidgets       *widgets;
    GtkTextBuffer   *buffer;
   
   
    /* initialize GTK+ libraries */
    gtk_init (&argc, &argv);
   
    /* build from Glade XML file */
    gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
    g_assert (gxml);
   
    /* allocate storage for MyWidgets structure */
    widgets = g_slice_new (MyWidgets);
   
    /* inserisco la lista dei widget da estrarre dal file .glade (XML)*/
    widgets->window = glade_xml_get_widget (gxml, "window1");
    widgets->entry1 = glade_xml_get_widget (gxml, "entry1");
    widgets->entry2 = glade_xml_get_widget (gxml, "entry2");
    widgets->entry3 = glade_xml_get_widget (gxml, "entry3");
    widgets->entry4 = glade_xml_get_widget (gxml, "entry4");
    widgets->entry5 = glade_xml_get_widget (gxml, "entry5");
    widgets->entry6 = glade_xml_get_widget (gxml, "entry6");
    widgets->entry7 = glade_xml_get_widget (gxml, "entry7");
    widgets->entry8 = glade_xml_get_widget (gxml, "entry8");
   

    widgets->textview = glade_xml_get_widget (gxml, "textview");
    buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widgets->textview));
   
    //widgets->textview = glade_xml_get_widget (gxml, "textview2");
     
    /* call gtk_main_quit() when the window's "x" is clicked */
    glade_xml_signal_connect (gxml, "on_window1_destroy",
            G_CALLBACK (gtk_main_quit));
   
    /* call on_button1_clicked() when button1 is clicked, passing the widgets
       struct to the function as the user_data */
    glade_xml_signal_connect_data (gxml, "on_button1_clicked",
            G_CALLBACK (on_button1_clicked), widgets);
           
   
   /* call gtk_main_quit() when the "chiudi" button  is clicked */
    glade_xml_signal_connect_data (gxml, "on_button2_clicked",
            G_CALLBACK (on_button2_clicked), widgets);
           

    //impostare testo di default negli entry box quando carica il programma
   
     gtk_entry_set_text (GTK_ENTRY(widgets->entry1), "125" );
     gtk_entry_set_text (GTK_ENTRY(widgets->entry7), "0.2" );
    // gtk_text_buffer_set_text (buffer, "Your 1st GtkTextView widget!", -1);
      
   
    /* free Glade XML object */
    g_object_unref (G_OBJECT (gxml));
       
    /* begin GTK+ main loop */                   
    gtk_main ();
   
    /* even though we are exiting now, this is how you cleanup the struct */
    g_slice_free (MyWidgets, widgets);

    return 0;
}

//------------------------------------------------------------------------------

void on_button1_clicked (GtkButton *button, gpointer user_data)
{
       
    MyWidgets   *widgets = (MyWidgets*)user_data;   

    //----------------------Gestione calcolo valore inserito nel textview-------
      float ab, bb, ae, be, margsupp;
      float nstick, nstickm2; // numero adesivi richiesti
      float areastick , areabob; // area adesivi e area bobina
      float eurom2 , supptaglio , totale, iva , totivato; // costo stampa m2 e supplemento taglio
   
    char *string1, *string2, *string3, *string4 , *string5, *string6, *string7;
    char *string8;
   
    // testo max di 5 caratteri! compresa "," e decimali...
    char buffer1 [15] , buffer2 [15] , buffer3 [15] , buffer4 [15];
    char buffer5 [15], buffer6 [15];

   
    int h1, h2, h3, h4 , h5 , h6;
     
    string1  = gtk_entry_get_text (GTK_ENTRY(widgets->entry1));   
    ab = atof(string1);
           
    string2  = gtk_entry_get_text (GTK_ENTRY(widgets->entry2));   
    bb = atof(string2); 
     
    string3  = gtk_entry_get_text (GTK_ENTRY(widgets->entry3));   
    ae = atof(string3); 
         
    string4  = gtk_entry_get_text (GTK_ENTRY(widgets->entry4));   
    be = atof(string4); 
   
    string5  = gtk_entry_get_text (GTK_ENTRY(widgets->entry5));   
    eurom2 = atof(string5);
   
    string6  = gtk_entry_get_text (GTK_ENTRY(widgets->entry6));   
    nstick = atof(string6);
   
    string7  = gtk_entry_get_text (GTK_ENTRY(widgets->entry7));   
    margsupp = atof(string7);
   
    string8  = gtk_entry_get_text (GTK_ENTRY(widgets->entry8));   
    supptaglio = atof(string8);

       
      if ((ab > 0) && (ae > 0) && (be > 0) && (nstick > 0) && (eurom2 > 0))     
        {
          areastick = ((ae+margsupp) * (be+margsupp));
          nstickm2 = (10000/areastick);
          areabob = ((nstick*10000)/nstickm2);
          bb = (areabob/ab);
     
          totale = (areabob*eurom2/10000)+supptaglio;
          iva = (totale * 0.2);
          totivato = (totale + iva);
         
        }                     
      else
        {
         // printf("verifica che ci siano tutti i dati nei campi obbligatori!\n");   
        }
     
     //-------------------------------------------------------------------------

       
       

        // converto da floating a string
        h1 = sprintf(buffer1,"%.0f cm^2\n\n",areabob);
        h2 = sprintf(buffer2,"%.0f cm^2\n\n", areastick);
        h3 = sprintf(buffer3,"%.0f \n\n", nstick);       
        h4 = sprintf(buffer4,"%.2f €\n\n", totale);
        h5 = sprintf(buffer5,"%.2f €\n\n", iva);
        h6 = sprintf(buffer6,"%.2f €\n", totivato);
       
       
        nstick = 0; //this to clear the var in case button1_clicked is pressed
                    // again while GUI is open.         
       
       GtkTextBuffer *buffer;
         GtkTextMark *mark;
         GtkTextIter iter;
         const gchar *text;
         
         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widgets->textview));      
         mark = gtk_text_buffer_get_insert (buffer);
         gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
            
         
         text = "PREVENTIVO STAMPA ETICHETTE\n\n";                  
         gtk_text_buffer_insert (buffer, &iter, text, -1);
         
         char str1[50] =  "Area di Stampa totale :\t\t\t";
        strcat(str1, buffer1);
        gtk_text_buffer_insert (buffer, &iter, str1, -1);
        
        char str2[50] =  "Area singola etichetta  :\t\t\t";
        strcat(str2, buffer2);
        gtk_text_buffer_insert (buffer, &iter, str2, -1);
        
        char str3[50] =  "Quantità etichette stampate :\t";
        strcat(str3, buffer3);
        gtk_text_buffer_insert (buffer, &iter, str3, -1);
                         
        char str4[50] =  "Valore totale stampa :\t\t\t";
        strcat(str4, buffer4);
        gtk_text_buffer_insert (buffer, &iter, str4, -1);
        
        char str5[50] =  "IVA  20%  su  totale :\t\t\t";
        strcat(str5, buffer5);
        gtk_text_buffer_insert (buffer, &iter, str5, -1);
        
        char str6[50] =  "Valore totale + iva 20%:\t\t";
        strcat(str6, buffer6);
        gtk_text_buffer_insert (buffer, &iter, str6, -1);
        
        ab = ae = be = eurom2 = nstick = supptaglio = margsupp = 0;

}



//------------------------------------------------------------------------------

/* lancio la chiusura della finestra chiamando gtk_main_quit() */

void on_button2_clicked (GtkButton *button, gpointer user_data)
{
gtk_main_quit();
}
//------------------------------------------------------------------------------





hello.glade
Code:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--*- mode: xml -*-->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="visible">True</property>
    <property name="border_width">8</property>
    <property name="title" translatable="yes">Calcolatore Preventivi 1.0</property>
    <property name="resizable">False</property>
    <property name="window_position">GTK_WIN_POS_CENTER</property>
    <property name="icon">gnome-finance.png</property>
    <signal name="destroy" handler="on_window1_destroy"/>
    <child>
      <widget class="GtkVBox" id="vbox2">
        <property name="visible">True</property>
        <property name="spacing">10</property>
        <child>
          <widget class="GtkMenuBar" id="menubar1">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <child>
              <widget class="GtkMenuItem" id="menuitem1">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="label" translatable="yes">_File</property>
                <property name="use_underline">True</property>
                <child>
                  <widget class="GtkMenu" id="menu1">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem1">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-new</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem2">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-open</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem3">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-save</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem4">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-save-as</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem5">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-quit</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                  </widget>
                </child>
              </widget>
            </child>
            <child>
              <widget class="GtkMenuItem" id="menuitem2">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="label" translatable="yes">_Edit</property>
                <property name="use_underline">True</property>
                <child>
                  <widget class="GtkMenu" id="menu2">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem6">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-cut</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem7">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-copy</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem8">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-paste</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem9">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-delete</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                  </widget>
                </child>
              </widget>
            </child>
            <child>
              <widget class="GtkMenuItem" id="menuitem3">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="label" translatable="yes">_View</property>
                <property name="use_underline">True</property>
              </widget>
            </child>
            <child>
              <widget class="GtkMenuItem" id="menuitem4">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="label" translatable="yes">_Help</property>
                <property name="use_underline">True</property>
                <child>
                  <widget class="GtkMenu" id="menu3">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <child>
                      <widget class="GtkImageMenuItem" id="imagemenuitem10">
                        <property name="visible">True</property>
                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                        <property name="label" translatable="yes">gtk-about</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </widget>
                    </child>
                  </widget>
                </child>
              </widget>
            </child>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
          </packing>
        </child>
        <child>
          <widget class="GtkScrolledWindow" id="scrolledwindow1">
            <property name="width_request">700</property>
            <property name="height_request">300</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
            <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
            <child>
              <widget class="GtkViewport" id="viewport1">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="resize_mode">GTK_RESIZE_QUEUE</property>
                <child>
                  <widget class="GtkTextView" id="textview">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                </child>
              </widget>
            </child>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <widget class="GtkHBox" id="hbox1">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <property name="homogeneous">True</property>
            <child>
              <widget class="GtkVBox" id="vbox1">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="homogeneous">True</property>
                <child>
                  <widget class="GtkLabel" id="label1">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Misure Area Stampa </property>
                  </widget>
                </child>
                <child>
                  <widget class="GtkLabel" id="label2">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Altezza [cm] :</property>
                  </widget>
                  <packing>
                    <property name="position">1</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label3">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Base [cm] :</property>
                  </widget>
                  <packing>
                    <property name="position">2</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHSeparator" id="hseparator1">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="expand">False</property>
                    <property name="position">3</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label5">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Misure Etichetta</property>
                  </widget>
                  <packing>
                    <property name="position">4</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label6">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Altezza [cm] :</property>
                  </widget>
                  <packing>
                    <property name="position">5</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label7">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Base [cm] :</property>
                  </widget>
                  <packing>
                    <property name="position">6</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHSeparator" id="hseparator3">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="expand">False</property>
                    <property name="position">7</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label9">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Stampa €-m^2 :</property>
                  </widget>
                  <packing>
                    <property name="position">8</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label10">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Numero Etichette :</property>
                  </widget>
                  <packing>
                    <property name="position">9</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label11">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Margine Taglio [cm] :</property>
                  </widget>
                  <packing>
                    <property name="position">10</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label12">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="xalign">0</property>
                    <property name="label" translatable="yes">Supp. Taglio €/quantità:</property>
                  </widget>
                  <packing>
                    <property name="position">11</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHSeparator" id="hseparator5">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="expand">False</property>
                    <property name="position">12</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkButton" id="button1">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="label" translatable="yes">Calcola</property>
                    <property name="use_underline">True</property>
                    <signal name="clicked" handler="on_button1_clicked"/>
                  </widget>
                  <packing>
                    <property name="position">13</property>
                  </packing>
                </child>
              </widget>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
              </packing>
            </child>
            <child>
              <widget class="GtkVBox" id="vbox3">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="homogeneous">True</property>
                <child>
                  <widget class="GtkLabel" id="label4">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry1">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="tooltip" translatable="yes">campo obbligatorio </property>
                  </widget>
                  <packing>
                    <property name="position">1</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry2">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">2</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHSeparator" id="hseparator2">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="expand">False</property>
                    <property name="position">3</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkLabel" id="label8">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">4</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry3">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">5</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry4">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">6</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHSeparator" id="hseparator4">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="expand">False</property>
                    <property name="position">7</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry5">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">8</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry6">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">9</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry7">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">10</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkEntry" id="entry8">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="position">11</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHSeparator" id="hseparator6">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                  <packing>
                    <property name="expand">False</property>
                    <property name="position">12</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkButton" id="button2">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <property name="label" translatable="yes">Chiudi</property>
                    <signal name="clicked" handler="on_button2_clicked"/>
                  </widget>
                  <packing>
                    <property name="position">13</property>
                  </packing>
                </child>
              </widget>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <widget class="GtkViewport" id="viewport2">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="resize_mode">GTK_RESIZE_QUEUE</property>
                <child>
                  <widget class="GtkTextView" id="textview2">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                  </widget>
                </child>
              </widget>
              <packing>
                <property name="position">2</property>
              </packing>
            </child>
          </widget>
          <packing>
            <property name="fill">False</property>
            <property name="position">2</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>



Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 2:48 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Quote:
hello.c:131: warning: assignment discards qualifiers from pointer target type


Try declaring the strings which hold values from gtk_entry_get_text as const char rather than char. You do not want to modify those strings, they are owned by the GtkEntry.

Quote:
Last thing , I would like to print the text which is available in the textview after my calculations.... is there any function I can use to print_textview buffer


GTK now supports printing, but it can be confusing at first. My best suggestion is to read the chapter on printing with GTK in Andrew's book: Foundations of GTK+ Development

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


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