[Gtk-sharp-list] Glade and Dialog Windows

Andrea Colanicchia Andrea Colanicchia <andrea.colanicchia@gmail.com>
Mon, 25 Oct 2004 20:54:03 +0200


I designed a dialog window with glade and I included it in my application.

The compilations gone without errors and warnings, but when I ran the
applications the output was:

Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object
in (unmanaged) (wrapper managed-to-native)
Glade.XML:glade_xml_new_from_buffer (byte[],int,string,string)
in <0x00004> (wrapper managed-to-native)
Glade.XML:glade_xml_new_from_buffer (byte[],int,string,string)
in <0x00133> Glade.XML:.ctor (System.Reflection.Assembly,string,string,string)
in [0x00030] (at
/home/andrea/MonoDevelopProjects/Mybrowser/Main.cs:30) GladeApp:.ctor
(string[])
in [0x00001] (at
/home/andrea/MonoDevelopProjects/Mybrowser/Main.cs:20) GladeApp:Main
(string[])


------------------
MAIN FILES
------------------
-----------------------------------------------------------
Main.cs
-----------------------------------------------------------

// project created on 20/10/2004 at 16:32
using System;
using System.IO;
using Gtk;
using Glade;
using Gecko;

public class GladeApp
{
        [Widget] Frame frame1;
        [Widget] Window window1;
        [Widget] Dialog dialog1, dialog2;
        [Widget] Button closebutton1;
        
        WebControl web;
        
        public static void Main (string[] args)
        {
                new GladeApp (args);
        }

        public GladeApp (string[] args) 
        {
                Application.Init();

                Glade.XML gxml = new Glade.XML(null, "gui.glade",
"window1", null);
                gxml.Autoconnect(this);
 
                Glade.XML gxml2 = new Glade.XML(null,
"about_dialog.glade", "dialog1", null);
                gxml2.Autoconnect(this); // line 31
               
                web = new WebControl();
                web.Show();
                
                frame1.Add(web);                
                
                Application.Run();
        }

        /* Connect the Signals defined in Glade */
        public void OnWindowDeleteEvent (object o, DeleteEventArgs args) 
        {
                Application.Quit ();
                args.RetVal = true;
        }
        
        void on_open1_activate (object source, EventArgs args)
        {
			FileSelection fs = new FileSelection ("Choose a file");
			fs.Run ();
			
			if (File.Exists(fs.Filename))
			{
				web.LoadUrl(fs.Filename);
			}
			
			fs.Hide ();
        }
        
        void on_quit1_activate (object source, EventArgs args)
        {
                Application.Quit ();
        }
        
        void on_about1_activate (object source, EventArgs args)
        {
            dialog2 = new Dialog("About", window1,
Gtk.DialogFlags.DestroyWithParent);
            dialog2.Modal = true;
            dialog2.AddButton ("gtk-close", ResponseType.Close);          	
            dialog2.Run ();
            dialog2.Destroy ();
        }
       
        public void on_dialog1_delete_event (object o, DeleteEventArgs args) 
        {
            dialog1.Destroy ();
        }
        
        
        void on_closebutton1_clicked (object source, EventArgs args)
        {
            dialog1.Destroy ();
        }
}

-----------------------------------------------------------
about_dialog.glade
-----------------------------------------------------------

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<requires lib="gnome"/>

<widget class="GtkDialog" id="dialog1">
  <property name="visible">True</property>
  <property name="title" translatable="yes">About</property>
  <property name="type">GTK_WINDOW_POPUP</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">True</property>
  <property name="resizable">False</property>
  <property name="destroy_with_parent">True</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="has_separator">True</property>
  <signal name="delete_event" handler="on_dialog1_delete_event"
last_modification_time="Mon, 25 Oct 2004 18:13:08 GMT"/>

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

      <child internal-child="action_area">
	<widget class="GtkHButtonBox" id="dialog-action_area1">
	  <property name="visible">True</property>
	  <property name="layout_style">GTK_BUTTONBOX_DEFAULT_STYLE</property>

	  <child>
	    <widget class="GtkButton" id="closebutton1">
	      <property name="visible">True</property>
	      <property name="can_default">True</property>
	      <property name="can_focus">True</property>
	      <property name="label">gtk-close</property>
	      <property name="use_stock">True</property>
	      <property name="relief">GTK_RELIEF_NORMAL</property>
	      <property name="focus_on_click">True</property>
	      <property name="response_id">-7</property>
	      <signal name="clicked" handler="on_closebutton1_clicked"
last_modification_time="Mon, 25 Oct 2004 18:11:01 GMT"/>
	    </widget>
	  </child>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">True</property>
	  <property name="pack_type">GTK_PACK_END</property>
	</packing>
      </child>

      <child>
	<widget class="GtkImage" id="image1">
	  <property name="width_request">300</property>
	  <property name="height_request">150</property>
	  <property name="visible">True</property>
	  <property name="pixbuf">EB_com_big_n01.gif</property>
	  <property name="xalign">0.5</property>
	  <property name="yalign">0.5</property>
	  <property name="xpad">0</property>
	  <property name="ypad">0</property>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>

      <child>
	<widget class="GtkLabel" id="label1">
	  <property name="visible">True</property>
	  <property name="label" translatable="yes">
Sviluppatore: Andrea Colanicchia
Coordinatore: Ruggero Montalto</property>
	  <property name="use_underline">False</property>
	  <property name="use_markup">False</property>
	  <property name="justify">GTK_JUSTIFY_LEFT</property>
	  <property name="wrap">False</property>
	  <property name="selectable">False</property>
	  <property name="xalign">0.5</property>
	  <property name="yalign">0.5</property>
	  <property name="xpad">0</property>
	  <property name="ypad">0</property>
	</widget>
	<packing>
	  <property name="padding">0</property>
	  <property name="expand">False</property>
	  <property name="fill">False</property>
	</packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>