Activity Team/Creating Activity Using Mono

From Sugar Labs
< Activity Team
Revision as of 15:21, 12 February 2009 by Llaske (talk | contribs) (New page: The objective of this Lab is to develop a new Sugar activity using C# and Mono. You will learn consecutively how to use MonoDevelop to write the source code of your activity, build a packa...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The objective of this Lab is to develop a new Sugar activity using C# and Mono. You will learn consecutively how to use MonoDevelop to write the source code of your activity, build a package, test your activity on Sugar and on a XO.

Step 1: Create your MonoDevelop project

  • Launch MonoDevelop (Applications/Programming/MonoDevelop)
  • Create a new solution (File/New Solution…)
  • Choose a "C# / Gtk# 2.0 Project" template. Fill the form with "LabActivity" as name. Uncheck the "Create separate Solution Directory"

Lab1 1.png

  • Click the "Forward" button.
  • In the next window, don't change any option. Don't change the Gtk# version suggested. Don't check any checkbox. Then click on "OK".

The solution is now created. We're going to setup it.

  • Add reference on Sugar. Right click on References, "Edit References…", choose the ".Net Assemblies" sheet. Select "Sugar.dll" in the "/home/user/Prerequisites" directory. Click on the "+Add" button then OK.

Lab1 2.png

  • Remove the file "Main.cs" from the solution: right click on the Main.cs file, then choose "Remove" and check the "Delete from disk" box.


Step 2: Create a simple Window

  • Update the content of the file MainWindow.cs like below. Note than this file is available on the "/home/user/LabSource/lab1/step2" directory.
	using System;
	using System.Collections;
	using Gtk;
	using Sugar;
	
	namespace LabActivity
	{
		public class MainWindow : Sugar.Window
		{	
			public new static string activityId="";
			public new static string bundleId="";
	
			public MainWindow(string activityId, string bundleId) : base("Lab",activityId, bundleId)
			{
				this.SetDefaultSize(400, 400);
				this.Maximize();
				this.DeleteEvent += new DeleteEventHandler(OnMainWindowDelete);
	
				VBox vbox=new VBox();
				vbox.BorderWidth = 8;
				Label _text = new Label("Hello Lab Activity");
				vbox.Add(_text);
				Button _button = new Button();
				_button.Label = "Quit";
				_button.Clicked += new EventHandler(OnClick);
				vbox.Add(_button);
			
				this.Add(vbox);
	
				ShowAll();
			}
		
			void OnMainWindowDelete (object sender, DeleteEventArgs a)
			{
				Application.Quit();
				a.RetVal = true;
			}
			
			void OnClick(object sender, EventArgs a)
			{
				Application.Quit();
			}
		
			public static void Main(string[] args)
			{
				System.Console.Out.WriteLine("Lab Activity for OLPC");
				
				if (args.Length>0) {
					IEnumerator en= args.GetEnumerator();
					while (en.MoveNext()) {
 						if (en.Current.ToString().Equals("-s ugarActivityId")) { 
			 				if (en.MoveNext()) {
								activityId=en.Current.ToString();
							}
						}
						if (en.Current.ToString().Equals("-sugarBundleId")) {
							if (en.MoveNext()) {
								bundleId=en.Current.ToString();
							}
						}
					}
				}		
				
				Application.Init();
				new MainWindow(activityId, bundleId);
				Application.Run();
			}
	
		}
	}
  • Save the file: "File/Save"
  • Open the "User Interface" part of the solution, remove the file "LabActivity.MainWindow": right clic, choose "Delete", UNCHECK THE BOX "Also remove the 'MainWindow.cs'.
  • Launch the build "Project/Build Solution"
  • You don't any any error. Don't run the project for the moment.

Then copy libraries need to run the activity:

  • Open a Terminal window (Applications/Accessories/Terminal).
  • Change path to the binary directory (in /home/user/LabActivity/bin/Debug).
  • Create a new subdirectory named "bin" using command "mkdir bin". Change path to this new directory.
  • Copy in this directory all the shared libraries (.so) found in the "/home/user/Prerequisites" directory. For example with the command "cp /home/user/Prerequisites/*.so .":
    • libgdksharpglue-2.so
    • libgladesharpglue-2.so
    • libglibsharpglue-2.so
    • libgtksharpglue-2.so
    • libMonoPosixHelper.so
    • libpangosharpglue-2.so
    • uiX11Util.so
  • Run the new application: "Project/Run", you should obtain this:

Lab1 3.png

  • Click on the button to quit.