Click here to Skip to main content
15,896,118 members
Articles / Programming Languages / C#

How we can write on C# in Linux: Implementing PanelApplet to Gnome Desktop

Rate me:
Please Sign up or sign in to vote.
4.86/5 (48 votes)
8 Mar 2010CPOL12 min read 85.3K   382   95  
This article describes how we can use our programming skills on the .NET framework to implement platform-independent code
using System;
using Gnome;
using Gtk;
using Gdk;

using System.Text;
using System.Threading;
using System.Diagnostics;

using WeatherApplet.Data;
using WeatherApplet.Model;

namespace WeatherApplet.View
{
	public class PanelAppletClass :  PanelApplet
	{
		
		static Label testLabel;
		
		//Thread thread; 
		static CurrentWeather weather;

		Timer timer;
		public static void TimerTick(object state)
		{
			string country = SettingsStore.Get("state").ToString();
			string city = SettingsStore.Get("city").ToString();
			weather = WeatherService.GetWeather(country,city);
			
			testLabel.Text = String.Format ("{0}", weather.Temperature);
		}
		
		public override void Creation()
		{
			
			testLabel = new Label ("Update..");
			this.Add (testLabel);
			this.ShowAll ();
			
			//construct right-click menu
			string menuItemTemplate = "<menuitem name=\"{0}\" verb=\"{1}\" _label=\"_{2}\" pixtype=\"stock\" pixname=\"gtk-properties\"/>";
			StringBuilder menuBuilder = new StringBuilder();
			menuBuilder.Append("<popup name=\"button3\">");
			menuBuilder.AppendFormat(menuItemTemplate,"Properties","About","About");
			menuBuilder.AppendFormat(menuItemTemplate,"Properties","Preferences","Preferences");
			menuBuilder.Append("</popup>");
			
			
			
			this.SetupMenu (menuBuilder.ToString(), new BonoboUIVerb [] 
			                { 
								new BonoboUIVerb ("About", new ContextMenuItemCallback (ShowAbout)),
								new BonoboUIVerb ("Preferences", new ContextMenuItemCallback (PreferenceMenuClicked))
							}
			);
			timer = new Timer(TimerTick,null,0,5000);
		}
		
		static TreeView tv;
		void PreferenceMenuClicked()
		{
			testLabel.Text = "Build tree..";
			if(tv!=null)
					tv.Destroy();
			
			
			tv = new TreeView();
		}
		
		private void ShowAbout()
		{
			
		}

		public override string IID {
			get { 
				Debug.WriteLine("IID");
				return "OAFIID:appletSource1";
			}
		}

		public override string FactoryIID {
			get { 
				Debug.WriteLine("FactoryIID");
				return "OAFIID:appletSource1_Factory"; 
			}
		}
		
		static MyWindow w;
		protected override bool OnButtonPressEvent (EventButton evnt)
		{
			//see http://www.go-mono.com/docs/index.aspx?link=P%3AGdk.EventButton.Time
			//1 - left
			//2 - middle
			//3 - right
			if(evnt.Button == 1)
			{
				if(w!=null)
					w.Destroy();
				w = new MyWindow();
				
				if(weather!= null)			
					w.ShowWeather(weather);
			}

			return base.OnButtonPressEvent (evnt);
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Nokia
Germany Germany
Interested in design/development of framework functionality using the best patterns and practices.

Comments and Discussions