maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   HOWTO: C# compiling on the unit itself (https://talk.maemo.org/showthread.php?t=17119)

zybook 2008-03-25 03:13

Re: HOWTO: C# compiling on the unit itself
 
congratulation you, pipeline:

it is very great. how can u do it in vs2003?

zybook 2008-03-25 03:29

Re: HOWTO: C# compiling on the unit itself
 
pipeline:

I can compile the demo source sucessful in my xp2 mono, but i can not compile it in the n800. can u help me? thanks. here is the code.

// Canvas.cs - port of standard GNOME canvas demo
//
// Author: Rachel Hestilow <hestilow@ximian.com>
//
// (c) 2002 Rachel Hestilow

namespace GtkSamples {

using Gnome;
using Gtk;
using Gdk;
using System;

public class CanvasExample {
private int width = 400, height = 400;
private double remember_x = 0.0, remember_y = 0.0;

private Canvas canvas;
private Random random = new Random ();

public CanvasExample () {
Gtk.Window win = new Gtk.Window ("Canvas example");
win.DeleteEvent += new DeleteEventHandler (Window_Delete);

VBox vbox = new VBox (false, 0);
win.Add (vbox);

vbox.PackStart (new Label ("Drag - move object.\n" +
"Double click - change color\n" +
"Right click - delete object"),
false, false, 0);

canvas = new Canvas ();
canvas.SetSizeRequest (width, height);
canvas.SetScrollRegion (0.0, 0.0, (double) width, (double) height);
vbox.PackStart (canvas, false, false, 0);

HBox hbox = new HBox (false, 0);
vbox.PackStart (hbox, false, false, 0);

Button add_button = new Button ("Add an object");
add_button.Clicked += new EventHandler (AddObject);
hbox.PackStart (add_button, false, false, 0);

Button quit_button = new Button ("Quit");
quit_button.Clicked += new EventHandler (Quit);
hbox.PackStart (quit_button, false, false, 0);

win.ShowAll ();
}

void Swap (ref double a, ref double b) {
double tmp = a;
a = b;
b = tmp;
}

void AddObject (object obj, EventArgs args)
{
double x1 = random.Next (width);
double y1 = random.Next (height);
double x2 = random.Next (width);
double y2 = random.Next (height);

if (x1 > x2)
Swap (ref x1, ref x2);

if (y1 > y2)
Swap (ref y1, ref y2);

if ((x2 - x1) < 10)
x2 += 10;

if ((y2 - y1) < 10)
y2 += 10;

CanvasRE item = null;
if (random.Next (2) > 0)
item = new CanvasRect (canvas.Root ());
else
item = new CanvasEllipse (canvas.Root ());

item.X1 = x1;
item.Y1 = y1;
item.X2 = x2;
item.Y2 = y2;
item.FillColor = "white";
item.OutlineColor = "black";
item.WidthUnits = 1.0;

item.CanvasEvent += new Gnome.CanvasEventHandler (Item_Event);
}

void ChangeItemColor (CanvasRE item)
{
string[] colors = new string[] {"red", "yellow", "green", "cyan", "blue", "magenta"};
item.FillColor = colors[random.Next (colors.Length)];
}

void Item_Event (object obj, Gnome.CanvasEventArgs args) {
EventButton ev = new EventButton (args.Event.Handle);
CanvasRE item = (CanvasRE) obj;

switch (ev.Type) {
case EventType.ButtonPress:
if (ev.Button == 1) {
remember_x = ev.X;
remember_y = ev.Y;
args.RetVal = true;
return;
} else if (ev.Button == 3) {
item.Destroy ();
args.RetVal = true;
return;
}
break;
case EventType.TwoButtonPress:
ChangeItemColor (item);
args.RetVal = true;
return;
case EventType.MotionNotify:
Gdk.ModifierType state = (Gdk.ModifierType) ev.State;
if ((state & Gdk.ModifierType.Button1Mask) != 0) {
double new_x = ev.X, new_y = ev.Y;
item.Move (new_x - remember_x, new_y - remember_y);
remember_x = new_x;
remember_y = new_y;
args.RetVal = true;
return;
}
break;
case EventType.EnterNotify:
item.WidthUnits = 3.0;
args.RetVal = true;
return;
case EventType.LeaveNotify:
item.WidthUnits = 1.0;
args.RetVal = true;
return;
}

args.RetVal = false;
return;
}

void Quit (object obj, EventArgs args)
{
Application.Quit ();
}

void Window_Delete (object obj, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}

public static int Main (string[] args)
{
Application.Init ();

new CanvasExample ();

Application.Run ();
return 0;
}
}
}

b-man 2008-03-25 03:46

Re: HOWTO: C# compiling on the unit itself
 
I tryed thess steps but i got this compilation eror: home/user # cd /home/user/mcs
/home/user/mcs # mcs Hello.cs -pkg:gtk-sharp-2.0
error CS2001: Source file `Hello.cs' could not be found
Compilation failed: 1 error(s), 0 warnings
what did i do wrong?

speaking of witch this is my proogram: it's my own Hello.cs program i made my self frome those web sorses you provided:
using Gtk;
using System;

class Hello {

static void Main()
{
Application.Init ();

// Set up a button object.
Button btn = new Button ("Hello World");
// when this button is clicked, it'll run hello()
btn.Clicked += new EventHandler (hello);

Window window = new Window ("helloworld");
// when this window is deleted, it'll run delete_event()
window.DeleteEvent += delete_event;

// Add the button to the window and display everything
window.Add (btn);
window.ShowAll ();

Application.Run ();
}


// runs when the user deletes the window using the "close
// window" widget in the window frame.
static void delete_event (object obj, DeleteEventArgs args)
{
Application.Quit ();
}

// runs when the button is clicked.
static void hello (object obj, EventArgs args)
{
Console.WriteLine("Hello World");
Application.Quit ();
}
}

pipeline 2008-03-25 04:20

Re: HOWTO: C# compiling on the unit itself
 
bman : in /home/user/mcs type ls -l and post results

zybook : what is your error?

zybook 2008-03-25 04:39

Re: HOWTO: C# compiling on the unit itself
 
Quote:

Originally Posted by pipeline (Post 159769)
zybook : what is your error?

here is the error:
N800:/media/mmc1/cs# mcs CanvasExample.cs -pkg:gtk-sh arp-2.0 -pkg:glade-sharp-2.0
mono[2193]: GLIB ERROR ** default - file inssel.c: line 3645 ( mono_burg_emit): should not be reached
aborting...
Stacktrace:

at Mono.CSharp.Tokenizer.is_number (int) <0xffffffff>
at Mono.CSharp.Tokenizer.is_number (int) <0x0047c>
at Mono.CSharp.Tokenizer.xtoken () <0x0053f>
at Mono.CSharp.Tokenizer.token () <0x0001f>
at Mono.CSharp.CSharpParser.yyparse (Mono.CSharp.yyParser.yy Input) <0x00f5b>
at Mono.CSharp.CSharpParser.parse () <0x000a7>
at Mono.CSharp.Driver.parse (Mono.CSharp.SourceFile) <0x001e 3>
at Mono.CSharp.Driver.ProcessFiles () <0x0008f>
at Mono.CSharp.Driver.MainDriver (string[]) <0x0049f>
at Mono.CSharp.Driver.Main (string[]) <0x00087>
at (wrapper runtime-invoke) Mono.CSharp.Driver.runtime_invok e_int_string[] (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

/usr/bin/mono [0x10b924]
/usr/lib/libglib-2.0.so.0(g_logv+0x268) [0x4115b42d]

================================================== ============ ===
Got a SIGABRT while executing native code. This usually indica tes
a fatal error in the mono runtime or one of the native librari es
used by your application.
================================================== ============ ===

Aborted

pipeline 2008-03-25 04:53

Re: HOWTO: C# compiling on the unit itself
 
thats a legitimate bug... i suspect due to being version 1.2.5. i will verify this works tomorrow on 1.9.

pipeline 2008-03-25 10:55

Re: HOWTO: C# compiling on the unit itself
 
zybrook : although you should not have gotten that bug, it seems Gnome namespace has not been ported to maemo. Cairo has been ported though so maybe you could use samples here (i've tried these and they seem to work) :
http://www.mono-project.com/Mono.Cairo_Cookbook

As for how to do the image sample in vs2003, i just wrote the program and compiled it and copied the exe over. Its a simple program just using a timer and this (works only with winforms/gdi on 1.9) :
Code:

        public static Image ImageURIToImage(string url)
        {
                Image image = null;

                WebClient webClient = new WebClient();

                try
                {
                        MemoryStream ms = new MemoryStream();
                        Uri site = new Uri(url);
                               
                        Stream stream = webClient.OpenRead(url);
                        image = Image.FromStream(stream);
                        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        stream.Close();
                }
                catch (Exception ex)       
                {
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                }

                return image;
        }

Then timer will do something like :
pictureBox1.Image = ImageURIToImage("http://mysite.com/myimage.jpg");

b-man :
Your sample program runs fine for me. The file name is case-sensitive so if its named hello.cs then compile with :
mcs hello.cs -pkg:gtk-sharp-2.0

Soon i will set up a good samples page so show alot of simple programs.

zybook 2008-03-25 13:29

Re: HOWTO: C# compiling on the unit itself
 
Quote:

Originally Posted by pipeline (Post 159833)
zybrook : although you should not have gotten that bug, it seems Gnome namespace has not been ported to maemo. Cairo has been ported though so maybe you could use samples here (i've tried these and they seem to work) :
http://www.mono-project.com/Mono.Cairo_Cookbook

.

i uses "mcs CanvasExample.cs -pkg:mono-cairo" and "mcs CanvasExample.cs -pkg:mono-cairo -pkg:gtk-sharp-2.0" to compile it ,both error, the error message same like before. :-(

i also compile the demo "Drawing Rounded Rects" in the website http://www.mono-project.com/Mono.Cairo_Cookbook , also error message same.

psykosis 2008-03-25 13:31

Re: HOWTO: C# compiling on the unit itself
 
I successfully ran a couple WinForm based apps using .NET 2.0 - it seems there is still an issue with the default buttons under 2.0 (gdiplus blows up drawing the button) but reducing the button to a flat one works great.

The main issue I am seeing is the startup time - It was taking ~45 seconds to launch a simple winform - have you experienced similar delay Pipeline?

pipeline 2008-03-25 14:55

Re: HOWTO: C# compiling on the unit itself
 
thanks for 2.0 info

im seeing basic startup times of around 15 seconds for 1.0 winforms apps, around 5 seconds for gtk apps and probably around 4 seconds for console apps.

do you have alot of logic in form_load? or perhaps 2.0 is slower? i guess there's big hit with winforms/gdi initialization that will be very apparent on 400mhz arm. hasnt't been a problem yet for me... a bigger issue for me is that winforms dont have task tray icons like gtk apps do.


All times are GMT. The time now is 05:36.

vBulletin® Version 3.8.8