/srv/irclogs.ubuntu.com/2010/06/24/#ubuntu-classroom.txt

=== bgs100 is now known as bgs000
=== BlackZ_ is now known as BlackZ
=== yofel_ is now known as yofel
=== keffie_jayx_ is now known as keffie_jayx
=== Raven is now known as Guest56837
nishant_the_dawnhi16:00
nishant_the_dawnhi class16:00
=== bgs000 is now known as bgs100
=== apachelogger is now known as brokenl00gR
Tiibiidiisomeone knows where i can get yesterday's log? i can't find it here: https://wiki.ubuntu.com/Classroom20:39
pleia2Tiibiidii: http://irclogs.ubuntu.com/2010/06/23/%23ubuntu-classroom.html20:40
Tiibiidiithank you pleia220:40
pleia2sure thing20:40
sirmacikHi!20:58
luxorHi sirmacik.21:00
sirmacikCan't wait for today class (:21:01
=== ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - http://wiki.ubuntu.com/Classroom || Support in #ubuntu || Current Class: Introduction to C# Day 2
juju2143ohai21:02
juju2143Right, Day 2.21:02
sirmacikHi juju214321:02
juju2143hi sirmacik21:02
juju2143So open your MonoDevelop and create a new GTK# project.21:04
pedro3005Oh just in time21:04
juju2143yep pedro300521:04
pedro3005juju2143, btw I did my homework21:04
zkriesseclass time?21:05
juju2143ok21:05
sirmacikdone (:21:05
juju2143Everyone played with console apps21:05
sirmacikyep21:06
juju2143cool then21:06
juju2143Today we'll do graphics.21:06
juju2143So you have your GTK# app.21:07
juju2143You will see some files in your left21:08
juju2143Generally, it's a good idea to make one file per class/window.21:09
juju2143In the user interface, you will see MainWindow, who is an empty window21:10
juju2143Now you would put some buttons in it21:10
pedro3005I only see Main.cs21:11
pedro3005:(21:11
juju2143ah...21:11
sirmacikpedro3005: have You installed gtk-sharp2?21:11
juju2143maybe you have it wrong21:11
pedro3005sirmacik, yes21:12
sirmacikFor me this lib was missing21:12
pedro3005god I hate monodevelop21:12
juju2143me too21:12
pedro3005juju2143, is there anything else I can use?21:13
juju2143I can't find the buttons and textboxes to drag into the window21:13
juju2143like on Visual Studio21:13
meebeypedro3005: have you used New Solution -> C# -> GTK# 2.0 Project?21:13
juju2143pedro3005, your favorite text editor21:13
pedro3005meebey, yes21:13
pedro3005juju2143, wouldn't that be harder?21:14
juju2143lol21:14
juju2143nope21:14
juju2143oh I found them21:14
juju2143Ok so you have a window.21:16
pedro3005I'll just install it over21:16
juju2143ok21:17
juju2143now ill move on21:17
juju2143So you have your main window.21:17
juju2143right?21:18
meebeypedro3005: oh you are not on -chat, I was trying to give you some test commands21:18
sirmacikyes <:21:18
sirmacikcan we move on?21:19
juju2143yes21:20
juju2143Now you would want to put things in it right?21:20
juju2143Alt-Shift-B21:20
juju2143You will see lots of widgets to drag into your window.21:21
sirmacika lot (:21:22
juju2143But in GTK, everything must be in a contener.21:22
juju2143or sth21:22
juju2143First, put a Fixed, then a Button21:22
juju2143Now we will want to rename the button21:23
juju2143Alt+Shift+P21:24
juju2143Now you can edit its properties.21:24
juju2143So you will see its name is button1, we will use it as a variable name to access it.21:24
juju2143in Button Properties, you will want to change the text.21:25
juju2143Now we will want to make it do something21:25
juju2143In the signals tabs, Buttpn Signals > Clicked21:26
juju2143double clich where it says Click here21:27
juju2143ti will create a new function in MainWindow.cs21:27
juju2143named OnButton1Clicked21:27
sirmacikgot it21:28
airbornncie21:28
airbornnice*21:28
sirmacikwhat's next?21:30
juju2143hm lemme test something21:30
sirmacik(:21:30
juju2143hmmm21:31
juju2143ok21:32
juju2143Now in the function add this code:21:34
juju2143MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello World!");21:35
juju2143dialog.Show();21:35
juju2143between the {}'s.21:35
juju2143now compile and run21:36
juju2143you see something?21:37
sirmacikworks great21:37
juju2143Cool.21:38
juju2143So you seen how to show some hello world.21:39
sirmacikjuju2143: but how to program that dialog to close on click on ok button?21:39
juju2143hmmmm idk21:39
juju2143it's not like Windows Forms.21:39
meebeyyou can call dialog.Run(); instead of Show()21:40
juju2143hm maybe you have to create a class based on MessageDialog or sth21:40
meebeythen it will close if you give a response (clicking a button)21:40
juju2143meebey, right21:40
meebeyelse you have to implement for each button and window event yourself, Run() is much simpler21:41
* meebey is the developer of Smuxi which is written in C# and available in Ubuntu and has lots of GTK# experience because of that21:43
juju2143Now looks like my MainWindow crashed21:43
pedro3005run() seems to do the same21:43
juju2143meebey, oh cool.21:43
meebeythe dialog is not automatically closing?21:43
juju2143hmmm21:43
meebeylet me try... maybe MessageDialog works differently than Dialog21:43
juju2143hm yeah...21:44
juju2143so the important is that you put omething in a variable of type MessageDialog21:44
juju2143so you create a class, then you can instanciade it in a variable.21:45
meebeyok, you need to add dialog.Destroy() after .Run()21:45
meebey.Run() returns the reponse but is not automatically destroying the dialog with it21:45
juju2143yight21:45
sirmacikthanks meebey (:21:46
pedro3005Oh cool :)21:46
sirmacikok, juju2143 whats next? (;21:46
juju2143Now you will want inputting21:47
juju2143Return in designer21:48
juju2143and add 2 Entry21:49
juju2143Or maybe just one.21:49
sirmacikdone21:49
juju2143Return in the source, instead of "Hello world", type entry1.Text21:50
juju2143compile and run21:50
sirmacikworks perfect21:51
juju2143good21:51
juju2143type something in your textbox21:51
juju2143then click the button21:51
pedro3005yeah runs good21:52
juju2143Now the problem is that maybe you want to, say, multiply by 2 the number.21:52
juju2143But you can't multiply by 2 a number21:52
juju2143entry1.Text * 221:53
juju2143I mean, you can't do that on a string.21:53
pedro3005I mean, it's all nice with visuals but I don't understand the code21:53
juju2143yeah21:53
pedro3005it's full of things I don't know21:54
juju2143Most of the code, you will not care about that because it works.21:54
juju2143So it works, yay.21:55
juju2143So this code added automatically by the IDE, you will not care unless you are on some advanced level.21:56
juju2143Now you will want to convert entry1.Text in a number21:56
juju2143int number = Convert.ToInt32(entry1.Text);21:58
juju2143then put number * 2 instead of entry1.Text21:59
juju2143in your long MessageDialog line.21:59
juju2143Compile and run.21:59
sirmacikhmm21:59
sirmacikwhere I should put that int number line?21:59
juju2143before the MessageDialog line22:00
juju2143In fact, instead of number * 2 it's (number*2).ToString()22:01
juju2143because it needs a string22:01
juju2143Compile and run.22:02
juju2143now put a number, it should multiply it successfully22:03
sirmacikworks (;22:03
juju2143But what if you put s non-number?22:03
juju2143It crashes.22:04
juju2143With an exception.22:04
sirmacikyep22:05
juju2143You may want to do something when it does that: we will do that wit Try/catach22:06
juju2143Try this:22:06
juju2143int number;22:06
juju2143try {22:06
juju2143number = Convert.ToInt32(entry1.Text);22:06
juju2143}22:07
juju2143catch {22:07
juju2143entry2.Text = "OMG we got an error";22:07
juju2143}22:07
juju2143before the } you would put a return; to stop the function.22:08
juju2143then after } you would put entry2.Text = (number*2).ToString();22:08
juju2143Compile and run22:08
sirmacikwitch }22:08
sirmacik'x22:08
juju2143mh22:09
sirmacikargh... witch '}'? *22:09
juju2143yeah22:09
juju2143catch {22:09
juju2143entry2.Text = "OMG we got an error";22:09
sirmacikfor return and witch for that entry2?22:09
juju2143return;22:09
juju2143}22:09
sirmacikoh (;22:09
pleia2[/g 6722:10
pleia2sorry22:10
juju2143and entry2 you would put a second Entry in your Designer22:10
juju2143oh damn my laptop bacame laggy, i'll Ctrl-alt-Backspace.22:11
sirmacikworks (;22:12
juju2143:D22:12
juju2143so you learnt the try/catch22:12
juju2143maybe if you put (Exception ex) fter the catch keyword22:13
juju2143the ex variable containing all sorts of infos about the exception becomes available in the catch block22:13
pedro3005so this 'ex' variable already exists?22:14
juju2143nope, you defined it22:16
juju2143then the compilers when it enters in the catch, like a function, it will pul all the infos in the var22:17
juju2143now that you made your 1st app in GTK+22:18
juju2143GTK#*22:18
sirmacik(;22:19
meebeyC# is hot! sexiest programming language I have seen ^^22:19
juju2143You may try to make a method.22:19
juju2143meebey, hehe22:20
sebnerloool meebey22:20
meebeysebner: you are late stefan, now quickly take a seat!22:20
sebnermeebey: sure :), bouncer is dead :(22:21
juju2143lol.22:21
juju2143last theory today, methods22:21
juju2143tomorrow we'll do whole classes22:21
juju2143between the 2 } at the end.22:22
juju2143private string MultiplyBy2(string number)22:22
juju2143{22:22
juju2143/ This is a comment22:23
juju2143// This is a comment22:23
juju2143/ This is NOT a comment and won't compile.22:23
juju2143/* But this is a comment22:23
juju2143a multiline22:23
juju2143comment */22:24
juju2143/ Insert here the try/catch block of the last example22:24
juju2143return (num * 2).ToString();22:25
juju2143}22:25
juju2143I write / instead of // because the way IRC handles lines beginning by /22:25
pedro3005juju2143, why is the first line a comment and the third not one?22:26
meebey/ test22:26
meebeyoh funny22:26
sebner /22:26
sebnerjuju2143: just use a whitespace before the /22:26
juju2143because I wanted to write // but I failed and it showed up as /22:26
pedro3005ok22:27
juju2143sebner, usually I put a Ctrl-O22:27
juju2143// there22:27
pedro3005juju2143, so only // and /* */ right?22:27
juju2143pedro3005, yep22:27
sebner22:27
sebnernice22:28
juju2143so in your try{} block you would put int num = Convert.ToString(number);22:29
juju2143and in catch, a MessageDialog saying that the function failed then a return 0;22:30
airbornjuju2143, does C# use finally{} blocks?22:30
juju2143airborn, yes22:30
airbornthx22:30
juju2143return "oh noes it failed";22:30
juju2143now in your OnButton1Clicked you would put entry2.Text = MultiplyBy2(entry1.Text);22:32
juju2143now compile and run22:32
juju2143now you would see your number multiplied by 222:34
juju2143Now you got an introduction to GTK#. Tomorrow we will see classes and these private/protected/public/static keywords.22:35
juju2143If you have questions, just ask here.22:36
juju2143And you got an intro to methods :P22:36
sirmacik(;22:36
sirmacikthanks for today juju214322:36
juju2143yw :P22:37
pedro3005yes, thank you :)22:37
juju2143:)22:37
meebeyonly 2 new C# hackers? who will hack all the cool features then into smuxi? ^^22:39
meebey20:25:39 <meebey> and day3 will be hacking cool smuxi features?22:40
meebey:-P22:40
sebnermeebey: lol22:41
sebnermeebey: me in summer ;D22:41
meebeysebner: yay22:41
meebeysebner: I will get vacation end of july22:41
sebnermeebey: we are speaking about 2011 though :P22:42
meebeysebner: oh noez22:42
sebnermeebey: gsoc :P you promised me22:42
meebeymoah C# hackaz plx22:42
meebeysebner: hrhrhr22:42
sebnermeebey: but I'll take a look this summer too ;)22:42
meebeysebner: I still have to find a gsoc organization...22:42
sebnermeebey: mono22:43
meebeyI dont think they will have much interest in smuxi... they have so many cool mono projects you know...22:43
sebnermeebey: pfff, smuxi is the best :P22:43
sirmacikhmm22:44
sirmacikjuju2143: I've a little problem with understanding of this methods thing. Could You paste somewhere example of working code from todays lesson?22:45
juju2143yeah of course22:46
juju2143protected virtual void OnButton1Clicked(...) {22:47
juju2143entry2.Text = MultiplyBy2(entry1.Text);22:47
juju2143}22:47
juju2143private string MultiplyBy2(string text) {22:48
juju2143int number;22:48
juju2143try {22:48
juju2143number = Convert.ToInt32(text);22:48
juju2143}22:48
juju2143catch {22:48
juju2143return "OMG something happenned";22:48
juju2143}22:48
juju2143return (number*2).ToString();22:49
juju2143}22:49
juju2143there it should work22:49
sirmacikthanks (:22:49
juju2143:)22:51
sirmaciknow I see where I failed ;f22:51
sirmacikworks great [;22:53
sirmaciksee You tomorrow \o23:00
=== ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - http://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi
=== seymour is now known as Guest8762

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!