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

Tagged as

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 Gtk;
using GConf;

using WeatherApplet.Model;

namespace WeatherApplet.View
{

	public class TreeView:Window
	{


	Label filterEntry;
	public TreeView ():base("asdasd")
	{
			
		//Create window
		ScrolledWindow sw = new Gtk.ScrolledWindow ();
		this.SetSizeRequest (500,200);
		 
		// Create an Entry used to filter the tree
		filterEntry = new Gtk.Label ();
 
		// Fire off an event when the text in the Entry changes
		//filterEntry.Changed += OnFilterEntryTextChanged;
		
		// Create a nice label describing the Entry
		Gtk.Label filterLabel = new Gtk.Label ("Selected country:");
		
		// Put them both into a little box so they show up side by side
		Gtk.HBox filterBox = new Gtk.HBox ();
			
		filterBox.PackStart (filterLabel, false, false, 5);
		filterBox.PackStart (filterEntry, true, true, 5);
 
		// Create our TreeView
		Gtk.TreeView tree = new Gtk.TreeView ();
 
		// Create a box to hold the Entry and Tree
		Gtk.VBox box = new Gtk.VBox ();
 
		// Add the widgets to the box
		box.PackStart (filterBox, false, false, 5);
		sw.Add (tree);
		box.PackStart (sw, true, true, 5);

		
		//Create column	
		Gtk.TreeViewColumn countriesColumn = new Gtk.TreeViewColumn ();
		countriesColumn.Title = "Countries";
 		Gtk.CellRendererText countriesNameCell = new Gtk.CellRendererText ();
		countriesColumn.PackStart (countriesNameCell, true);
		tree.AppendColumn (countriesColumn);
 		countriesColumn.AddAttribute(countriesNameCell, "text", 0);
			
		//Create list of countries	
		tree.Model = BuildTree();
		
		tree.Selection.Changed += OnSelectionChanged; 	
			
 		this.Add(box);
		this.ShowAll ();
	}
		
		private TreeStore BuildTree()
		{
			Gtk.TreeStore countryListStore = new Gtk.TreeStore(typeof (string));
			
			Gtk.TreeIter europe = countryListStore.AppendValues ("Europe");
		
			SetCountryCities("Belarus", europe, ref countryListStore);
			SetCountryCities("Russia", europe, ref countryListStore);
						
			return countryListStore;
		}
			        
		private void SetCountryCities(string country,TreeIter region, ref TreeStore store)
		{
			TreeIter countryIter = store.AppendNode(region);
			store.SetValue(countryIter,0, country);
		
			foreach(var city in WeatherService.GetCitiesByCountry(country))
				store.AppendValues (countryIter, city);
			
		}
		
		 void OnSelectionChanged (object o, EventArgs args)
        {
			try
			{
                TreeIter iter;
                TreeModel model;
 
                if (((TreeSelection)o).GetSelected (out model, out iter))
                {
					if(model.IterHasChild(iter)) return;
						
						TreeIter parent;
						model.IterParent(out parent, iter);
					
						string state = (string) model.GetValue (parent, 0);
                        string city = (string) model.GetValue (iter, 0);
						filterEntry.Text = String.Format("{0}-{1} was selected", state, city);
						
						SettingsStore.Set("state", state);
						SettingsStore.Set("city", city);
                }
			}
			catch
			{
			}
        }


	}
}

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
Web01 | 2.8.140827.1 | Last Updated 9 Mar 2010
Article Copyright 2010 by Ilya Builuk
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid