[Gtk-sharp-list] Gnome# Hello World

Charles Iliya Krempeaux charles@reptile.ca
05 Feb 2003 10:02:36 -0800


Hello,

IMO, this is more of an "Intermediate Level" or "Advanced Level"
example.  (It's too complex for someone who is just starting.)

(It's a good example though; but just not appropriate for
a beginner, IMO.)


See ya

On Wed, 2003-02-05 at 09:22, George Farris wrote:
> How about something like this:
> Possibly a smaller glade file for the example would be better.
> 
> 
> Makefile ------------------------------------------------
> 
> MCS = mcs
> RESOURCES = /resource:./hello.glade,hello.glade
> REFERENCES = -r gnome-sharp -r gtk-sharp -r glib-sharp -r glade-sharp -r
> gdk-sharp
> SOURCES = hello.cs
> 
> all: hello.exe
> 
> hello.exe: $(SOURCES)
> 	$(MCS) $(RESOURCES) -o $@ $(SOURCES) $(REFERENCES)
> 
> clean:
> 	-rm *.exe *.bak *~
> 
> 
> hello.cs file -------------------------------------------------
> 
> namespace hello {
> 	using System;
>         using System.IO;
> 	using GLib;
> 	using Gtk;
> 	using Gnome;
> 	using Glade;
> 	using GtkSharp;
> 	
> 	public class hello : Program
> 	{
> 		Glade.XML gxml;
> 
> 		public static void Main (string[] args) 
> 		{
> 			hello a = new hello (args);
> 			
> 		}
> 
> 		public hello (string[] args) 
> 			: base ("hello", "0.1", Modules.UI, args, new object [0])
> 		{
> 			Application.Init ();
> 			gxml = new Glade.XML (null, "hello.glade", "app1", null);
> 			gxml.Autoconnect (this);
> 			Application.Run ();
> 		}
> 		
> 		//
> 		// Glade callbacks that are auto connected
> 		//
> 		private void on_quit1_activate (object o, EventArgs args)
> 		{
> 			Console.WriteLine("Goodbye...");
> 			Application.Quit ();
> 		}
> 		
> 		private void on_app1_delete_event (object o, DeleteEventArgs args) 
> 		{
> 			Application.Quit ();
> 			args.RetVal = true;
> 		}
>     
> 		private void on_about1_activate (object o, EventArgs args)
> 		{
> 			Gdk.Pixbuf icon = new Gdk.Pixbuf ("/usr/share/pixmaps" +
> Path.DirectorySeparatorChar + "gnome-logo-icon.png");
> 			string[] authors = new string[] { "Your Name <email@anon.com>" };
> 			string[] documentors = new string[] {};
> 			About about = new About ("", "", "Copyright (C) 2003 Your Name
> <email@anon.com>", "A Test application for GNOME", authors, documentors,
> "", icon);
> 			about.Show ();
> 			
> 		}
> 		
> 		private void on_newButton_clicked (object o, EventArgs args)
> 		{
> 			Console.WriteLine("[New] button clicked");
> 		}
> 		
> 		private void on_openButton_clicked (object o, EventArgs args)
> 		{
> 			Console.WriteLine("[Open] button clicked");
> 		}
> 
> 		private void on_saveButton_clicked (object o, EventArgs args)
> 		{
> 			Console.WriteLine("[Save] button clicked");
> 		}
> 	}
> }   
> 
> 
> 
> Glade file ------------------------------------------
> 
> <?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"/>
> <requires lib="bonobo"/>
> 
> <widget class="GnomeApp" id="app1">
>   <property name="visible">True</property>
>   <property name="title" translatable="yes">Test.glade</property>
>   <property name="type">GTK_WINDOW_TOPLEVEL</property>
>   <property name="window_position">GTK_WIN_POS_NONE</property>
>   <property name="modal">False</property>
>   <property name="resizable">True</property>
>   <property name="destroy_with_parent">False</property>
>   <property name="enable_layout_config">True</property>
>   <signal name="delete_event" handler="on_app1_delete_event"
> last_modification_time="Mon, 27 Jan 2003 21:23:47 GMT"/>
> 
>   <child internal-child="dock">
>     <widget class="BonoboDock" id="bonobodock1">
>       <property name="visible">True</property>
>       <property name="allow_floating">True</property>
> 
>       <child>
> 	<widget class="BonoboDockItem" id="bonobodockitem1">
> 	  <property name="visible">True</property>
> 	  <property name="shadow_type">GTK_SHADOW_NONE</property>
> 
> 	  <child>
> 	    <widget class="GtkMenuBar" id="menubar1">
> 	      <property name="visible">True</property>
> 
> 	      <child>
> 		<widget class="GtkMenuItem" id="file1">
> 		  <property name="visible">True</property>
> 		  <property name="stock_item">GNOMEUIINFO_MENU_FILE_TREE</property>
> 
> 		  <child>
> 		    <widget class="GtkMenu" id="file1_menu">
> 
> 		      <child>
> 			<widget class="GtkMenuItem" id="separator1">
> 			  <property name="visible">True</property>
> 			</widget>
> 		      </child>
> 
> 		      <child>
> 			<widget class="GtkImageMenuItem" id="quit1">
> 			  <property name="visible">True</property>
> 			  <property name="stock_item">GNOMEUIINFO_MENU_EXIT_ITEM</property>
> 			  <signal name="activate" handler="on_quit1_activate"
> last_modification_time="Mon, 27 Jan 2003 21:10:35 GMT"/>
> 			</widget>
> 		      </child>
> 		    </widget>
> 		  </child>
> 		</widget>
> 	      </child>
> 
> 	      <child>
> 		<widget class="GtkMenuItem" id="help1">
> 		  <property name="visible">True</property>
> 		  <property name="stock_item">GNOMEUIINFO_MENU_HELP_TREE</property>
> 
> 		  <child>
> 		    <widget class="GtkMenu" id="help1_menu">
> 
> 		      <child>
> 			<widget class="GtkImageMenuItem" id="about1">
> 			  <property name="visible">True</property>
> 			  <property name="stock_item">GNOMEUIINFO_MENU_ABOUT_ITEM</property>
> 			  <signal name="activate" handler="on_about1_activate"
> last_modification_time="Mon, 27 Jan 2003 21:10:35 GMT"/>
> 			</widget>
> 		      </child>
> 		    </widget>
> 		  </child>
> 		</widget>
> 	      </child>
> 	    </widget>
> 	  </child>
> 	</widget>
> 	<packing>
> 	  <property name="placement">BONOBO_DOCK_TOP</property>
> 	  <property name="band">0</property>
> 	  <property name="position">0</property>
> 	  <property name="offset">0</property>
> 	  <property
> name="behavior">BONOBO_DOCK_ITEM_BEH_EXCLUSIVE|BONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL|BONOBO_DOCK_ITEM_BEH_LOCKED</property>
> 	</packing>
>       </child>
> 
>       <child>
> 	<widget class="BonoboDockItem" id="bonobodockitem2">
> 	  <property name="visible">True</property>
> 	  <property name="shadow_type">GTK_SHADOW_OUT</property>
> 
> 	  <child>
> 	    <widget class="GtkToolbar" id="toolbar1">
> 	      <property name="border_width">1</property>
> 	      <property name="visible">True</property>
> 	      <property
> name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
> 	      <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
> 	      <property name="tooltips">True</property>
> 
> 	      <child>
> 		<widget class="button" id="newButton">
> 		  <property name="visible">True</property>
> 		  <property name="tooltip" translatable="yes">New File</property>
> 		  <property name="label">gtk-new</property>
> 		  <property name="use_stock">True</property>
> 		  <signal name="clicked" handler="on_newButton_clicked"
> last_modification_time="Wed, 29 Jan 2003 04:31:30 GMT"/>
> 		</widget>
> 	      </child>
> 
> 	      <child>
> 		<widget class="button" id="openButton">
> 		  <property name="visible">True</property>
> 		  <property name="tooltip" translatable="yes">Open File</property>
> 		  <property name="label">gtk-open</property>
> 		  <property name="use_stock">True</property>
> 		  <signal name="clicked" handler="on_openButton_clicked"
> last_modification_time="Wed, 29 Jan 2003 04:31:08 GMT"/>
> 		</widget>
> 	      </child>
> 
> 	      <child>
> 		<widget class="button" id="saveButton">
> 		  <property name="visible">True</property>
> 		  <property name="tooltip" translatable="yes">Save File</property>
> 		  <property name="label">gtk-save</property>
> 		  <property name="use_stock">True</property>
> 		  <signal name="clicked" handler="on_saveButton_clicked"
> last_modification_time="Wed, 29 Jan 2003 04:31:49 GMT"/>
> 		</widget>
> 	      </child>
> 	    </widget>
> 	  </child>
> 	</widget>
> 	<packing>
> 	  <property name="placement">BONOBO_DOCK_TOP</property>
> 	  <property name="band">1</property>
> 	  <property name="position">0</property>
> 	  <property name="offset">0</property>
> 	  <property name="behavior">BONOBO_DOCK_ITEM_BEH_EXCLUSIVE</property>
> 	</packing>
>       </child>
> 
>       <child>
> 	<widget class="GtkLabel" id="label1">
> 	  <property name="visible">True</property>
> 	  <property name="label" translatable="yes">Hello World</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>
>       </child>
>     </widget>
>     <packing>
>       <property name="padding">0</property>
>       <property name="expand">True</property>
>       <property name="fill">True</property>
>     </packing>
>   </child>
> 
>   <child internal-child="appbar">
>     <widget class="GnomeAppBar" id="appbar1">
>       <property name="visible">True</property>
>       <property name="has_progress">True</property>
>       <property name="has_status">True</property>
>     </widget>
>     <packing>
>       <property name="padding">0</property>
>       <property name="expand">True</property>
>       <property name="fill">True</property>
>     </packing>
>   </child>
> </widget>
> 
> </glade-interface>
> 
> 
> 
> On Tue, 2003-02-04 at 23:52, Charles Iliya Krempeaux wrote:
> > Hello,
> > 
> > I don't know if anyone has done this yet (on the MonkeyGuide),
> > but they might find this useful.  Also, people just getting
> > into Gtk# might find this useful too.  It is a Hello World program
> > for Gnome#.  (Similar to the Gtk# one.)
> > 
> >     class Hello
> >     {
> >         static Main()
> >         {
> >             Gtk.Application.Init();
> > 
> >             Gnome.App app = new Gnome.App("Hello World", "Hello World");
> >             app.Show();
> > 
> >             Gtk.Application.Run();
> >         }
> >     }
> > 
> > 
> > Although I am not really sure if "Gtk.Application.Init()" and
> > "Gtk.Application.Run()" are suppose to be called.  (Or if a
> > GNOME equivalent is suppose to be called.)
> > 
> > (BTW, does anyone know when the GNOME 2 API docs are going to be
> > put on the developer.gnome.org website???)
> > 
> > 
> > See ya
-- 
     Charles Iliya Krempeaux, BSc
     charles@reptile.ca

________________________________________________________________________
 Reptile Consulting & Services    604-REPTILE    http://www.reptile.ca/