Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

Go to top

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

, 8 Mar 2010
This article describes how we can use our programming skills on the .NET framework to implement platform-independent code
appletSource1.zip
appletSource1
appletSource1.pidb
appletSource1.userprefs
appletSource1_Factory.server
bin
Debug
appletSource1.exe
appletSource1.exe.mdb
Data
weather.wsdl
Model
View
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)

Share

About the Author

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 9 Mar 2010
Article Copyright 2010 by Ilya Builuk
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid