Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 2.80 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. GtkBuilder ignores .ui file
  2. #include <gtk/gtk.h>
  3.  
  4. int
  5. main (int   argc,
  6.       char *argv[])
  7. {
  8.   GtkBuilder *builder;
  9.   GObject *window;
  10.   GObject *button;
  11.  
  12.   gtk_init (&argc, &argv);
  13.  
  14.   /* Construct a GtkBuilder instance and load our UI description */
  15.   builder = gtk_builder_new ();
  16.   gtk_builder_add_from_file (builder, "builder.ui", NULL);
  17.  
  18.  
  19.   gtk_main ();
  20.  
  21.   return 0;
  22. }
  23.        
  24. <interface>
  25.   <object id="window" class="GtkWindow">
  26.     <property name="visible">True</property>
  27.     <property name="title">Grid</property>
  28.     <property name="border-width">10</property>
  29.     <child>
  30.       <object id="grid" class="GtkGrid">
  31.         <property name="visible">True</property>
  32.         <child>
  33.           <object id="button1" class="GtkButton">
  34.             <property name="visible">True</property>
  35.             <property name="label">Button 1</property>
  36.           </object>
  37.           <packing>
  38.             <property name="left-attach">0</property>
  39.             <property name="top-attach">0</property>
  40.           </packing>
  41.         </child>
  42.         <child>
  43.           <object id="button2" class="GtkButton">
  44.             <property name="visible">True</property>
  45.             <property name="label">Button 2</property>
  46.           </object>
  47.           <packing>
  48.             <property name="left-attach">1</property>
  49.             <property name="top-attach">0</property>
  50.           </packing>
  51.         </child>
  52.         <child>
  53.           <object id="quit" class="GtkButton">
  54.             <property name="visible">True</property>
  55.             <property name="label">Quit</property>
  56.           </object>
  57.           <packing>
  58.             <property name="left-attach">0</property>
  59.             <property name="top-attach">1</property>
  60.             <property name="width">2</property>
  61.           </packing>
  62.         </child>
  63.       </object>
  64.       <packing>
  65.       </packing>
  66.     </child>
  67.   </object>
  68. </interface>
  69.        
  70. <?xml version="1.0" encoding="UTF-8"?>
  71. <interface>
  72.   <!-- interface-requires gtk+ 3.0 -->
  73.   <object class="GtkWindow" id="Window">
  74.     <property name="can_focus">False</property>
  75.     <property name="border_width">15</property>
  76.     <child>
  77.       <object class="GtkLabel" id="fooLabel">
  78.         <property name="visible">True</property>
  79.         <property name="can_focus">False</property>
  80.         <property name="label" translatable="yes">foobar</property>
  81.       </object>
  82.     </child>
  83.   </object>
  84. </interface>
  85.        
  86. int main (int   argc, char *argv[])
  87. {
  88.   GtkBuilder      *builder;
  89.   GtkWidget       *window;
  90.  
  91.   gtk_init (&argc, &argv);
  92.  
  93.   builder = gtk_builder_new ();
  94.   gtk_builder_add_from_file (builder, "tutorial.xml", NULL);
  95.   window = GTK_WIDGET (gtk_builder_get_object (builder, "Window"));
  96.   g_object_unref (G_OBJECT (builder));
  97.   gtk_widget_show (window);                
  98.   gtk_main ();
  99.  
  100.   return 0;
  101. }
  102.        
  103. <property name="visible">True</property>
  104.        
  105. gtk_widget_show (window);