=== 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_dawn | hi | 16:00 |
---|---|---|
nishant_the_dawn | hi class | 16:00 |
=== bgs000 is now known as bgs100 | ||
=== apachelogger is now known as brokenl00gR | ||
Tiibiidii | someone knows where i can get yesterday's log? i can't find it here: https://wiki.ubuntu.com/Classroom | 20:39 |
pleia2 | Tiibiidii: http://irclogs.ubuntu.com/2010/06/23/%23ubuntu-classroom.html | 20:40 |
Tiibiidii | thank you pleia2 | 20:40 |
pleia2 | sure thing | 20:40 |
sirmacik | Hi! | 20:58 |
luxor | Hi sirmacik. | 21:00 |
sirmacik | Can'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 | ||
juju2143 | ohai | 21:02 |
juju2143 | Right, Day 2. | 21:02 |
sirmacik | Hi juju2143 | 21:02 |
juju2143 | hi sirmacik | 21:02 |
juju2143 | So open your MonoDevelop and create a new GTK# project. | 21:04 |
pedro3005 | Oh just in time | 21:04 |
juju2143 | yep pedro3005 | 21:04 |
pedro3005 | juju2143, btw I did my homework | 21:04 |
zkriesse | class time? | 21:05 |
juju2143 | ok | 21:05 |
sirmacik | done (: | 21:05 |
juju2143 | Everyone played with console apps | 21:05 |
sirmacik | yep | 21:06 |
juju2143 | cool then | 21:06 |
juju2143 | Today we'll do graphics. | 21:06 |
juju2143 | So you have your GTK# app. | 21:07 |
juju2143 | You will see some files in your left | 21:08 |
juju2143 | Generally, it's a good idea to make one file per class/window. | 21:09 |
juju2143 | In the user interface, you will see MainWindow, who is an empty window | 21:10 |
juju2143 | Now you would put some buttons in it | 21:10 |
pedro3005 | I only see Main.cs | 21:11 |
pedro3005 | :( | 21:11 |
juju2143 | ah... | 21:11 |
sirmacik | pedro3005: have You installed gtk-sharp2? | 21:11 |
juju2143 | maybe you have it wrong | 21:11 |
pedro3005 | sirmacik, yes | 21:12 |
sirmacik | For me this lib was missing | 21:12 |
pedro3005 | god I hate monodevelop | 21:12 |
juju2143 | me too | 21:12 |
pedro3005 | juju2143, is there anything else I can use? | 21:13 |
juju2143 | I can't find the buttons and textboxes to drag into the window | 21:13 |
juju2143 | like on Visual Studio | 21:13 |
meebey | pedro3005: have you used New Solution -> C# -> GTK# 2.0 Project? | 21:13 |
juju2143 | pedro3005, your favorite text editor | 21:13 |
pedro3005 | meebey, yes | 21:13 |
pedro3005 | juju2143, wouldn't that be harder? | 21:14 |
juju2143 | lol | 21:14 |
juju2143 | nope | 21:14 |
juju2143 | oh I found them | 21:14 |
juju2143 | Ok so you have a window. | 21:16 |
pedro3005 | I'll just install it over | 21:16 |
juju2143 | ok | 21:17 |
juju2143 | now ill move on | 21:17 |
juju2143 | So you have your main window. | 21:17 |
juju2143 | right? | 21:18 |
meebey | pedro3005: oh you are not on -chat, I was trying to give you some test commands | 21:18 |
sirmacik | yes <: | 21:18 |
sirmacik | can we move on? | 21:19 |
juju2143 | yes | 21:20 |
juju2143 | Now you would want to put things in it right? | 21:20 |
juju2143 | Alt-Shift-B | 21:20 |
juju2143 | You will see lots of widgets to drag into your window. | 21:21 |
sirmacik | a lot (: | 21:22 |
juju2143 | But in GTK, everything must be in a contener. | 21:22 |
juju2143 | or sth | 21:22 |
juju2143 | First, put a Fixed, then a Button | 21:22 |
juju2143 | Now we will want to rename the button | 21:23 |
juju2143 | Alt+Shift+P | 21:24 |
juju2143 | Now you can edit its properties. | 21:24 |
juju2143 | So you will see its name is button1, we will use it as a variable name to access it. | 21:24 |
juju2143 | in Button Properties, you will want to change the text. | 21:25 |
juju2143 | Now we will want to make it do something | 21:25 |
juju2143 | In the signals tabs, Buttpn Signals > Clicked | 21:26 |
juju2143 | double clich where it says Click here | 21:27 |
juju2143 | ti will create a new function in MainWindow.cs | 21:27 |
juju2143 | named OnButton1Clicked | 21:27 |
sirmacik | got it | 21:28 |
airborn | ncie | 21:28 |
airborn | nice* | 21:28 |
sirmacik | what's next? | 21:30 |
juju2143 | hm lemme test something | 21:30 |
sirmacik | (: | 21:30 |
juju2143 | hmmm | 21:31 |
juju2143 | ok | 21:32 |
juju2143 | Now in the function add this code: | 21:34 |
juju2143 | MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "Hello World!"); | 21:35 |
juju2143 | dialog.Show(); | 21:35 |
juju2143 | between the {}'s. | 21:35 |
juju2143 | now compile and run | 21:36 |
juju2143 | you see something? | 21:37 |
sirmacik | works great | 21:37 |
juju2143 | Cool. | 21:38 |
juju2143 | So you seen how to show some hello world. | 21:39 |
sirmacik | juju2143: but how to program that dialog to close on click on ok button? | 21:39 |
juju2143 | hmmmm idk | 21:39 |
juju2143 | it's not like Windows Forms. | 21:39 |
meebey | you can call dialog.Run(); instead of Show() | 21:40 |
juju2143 | hm maybe you have to create a class based on MessageDialog or sth | 21:40 |
meebey | then it will close if you give a response (clicking a button) | 21:40 |
juju2143 | meebey, right | 21:40 |
meebey | else you have to implement for each button and window event yourself, Run() is much simpler | 21:41 |
* meebey is the developer of Smuxi which is written in C# and available in Ubuntu and has lots of GTK# experience because of that | 21:43 | |
juju2143 | Now looks like my MainWindow crashed | 21:43 |
pedro3005 | run() seems to do the same | 21:43 |
juju2143 | meebey, oh cool. | 21:43 |
meebey | the dialog is not automatically closing? | 21:43 |
juju2143 | hmmm | 21:43 |
meebey | let me try... maybe MessageDialog works differently than Dialog | 21:43 |
juju2143 | hm yeah... | 21:44 |
juju2143 | so the important is that you put omething in a variable of type MessageDialog | 21:44 |
juju2143 | so you create a class, then you can instanciade it in a variable. | 21:45 |
meebey | ok, you need to add dialog.Destroy() after .Run() | 21:45 |
meebey | .Run() returns the reponse but is not automatically destroying the dialog with it | 21:45 |
juju2143 | yight | 21:45 |
sirmacik | thanks meebey (: | 21:46 |
pedro3005 | Oh cool :) | 21:46 |
sirmacik | ok, juju2143 whats next? (; | 21:46 |
juju2143 | Now you will want inputting | 21:47 |
juju2143 | Return in designer | 21:48 |
juju2143 | and add 2 Entry | 21:49 |
juju2143 | Or maybe just one. | 21:49 |
sirmacik | done | 21:49 |
juju2143 | Return in the source, instead of "Hello world", type entry1.Text | 21:50 |
juju2143 | compile and run | 21:50 |
sirmacik | works perfect | 21:51 |
juju2143 | good | 21:51 |
juju2143 | type something in your textbox | 21:51 |
juju2143 | then click the button | 21:51 |
pedro3005 | yeah runs good | 21:52 |
juju2143 | Now the problem is that maybe you want to, say, multiply by 2 the number. | 21:52 |
juju2143 | But you can't multiply by 2 a number | 21:52 |
juju2143 | entry1.Text * 2 | 21:53 |
juju2143 | I mean, you can't do that on a string. | 21:53 |
pedro3005 | I mean, it's all nice with visuals but I don't understand the code | 21:53 |
juju2143 | yeah | 21:53 |
pedro3005 | it's full of things I don't know | 21:54 |
juju2143 | Most of the code, you will not care about that because it works. | 21:54 |
juju2143 | So it works, yay. | 21:55 |
juju2143 | So this code added automatically by the IDE, you will not care unless you are on some advanced level. | 21:56 |
juju2143 | Now you will want to convert entry1.Text in a number | 21:56 |
juju2143 | int number = Convert.ToInt32(entry1.Text); | 21:58 |
juju2143 | then put number * 2 instead of entry1.Text | 21:59 |
juju2143 | in your long MessageDialog line. | 21:59 |
juju2143 | Compile and run. | 21:59 |
sirmacik | hmm | 21:59 |
sirmacik | where I should put that int number line? | 21:59 |
juju2143 | before the MessageDialog line | 22:00 |
juju2143 | In fact, instead of number * 2 it's (number*2).ToString() | 22:01 |
juju2143 | because it needs a string | 22:01 |
juju2143 | Compile and run. | 22:02 |
juju2143 | now put a number, it should multiply it successfully | 22:03 |
sirmacik | works (; | 22:03 |
juju2143 | But what if you put s non-number? | 22:03 |
juju2143 | It crashes. | 22:04 |
juju2143 | With an exception. | 22:04 |
sirmacik | yep | 22:05 |
juju2143 | You may want to do something when it does that: we will do that wit Try/catach | 22:06 |
juju2143 | Try this: | 22:06 |
juju2143 | int number; | 22:06 |
juju2143 | try { | 22:06 |
juju2143 | number = Convert.ToInt32(entry1.Text); | 22:06 |
juju2143 | } | 22:07 |
juju2143 | catch { | 22:07 |
juju2143 | entry2.Text = "OMG we got an error"; | 22:07 |
juju2143 | } | 22:07 |
juju2143 | before the } you would put a return; to stop the function. | 22:08 |
juju2143 | then after } you would put entry2.Text = (number*2).ToString(); | 22:08 |
juju2143 | Compile and run | 22:08 |
sirmacik | witch } | 22:08 |
sirmacik | 'x | 22:08 |
juju2143 | mh | 22:09 |
sirmacik | argh... witch '}'? * | 22:09 |
juju2143 | yeah | 22:09 |
juju2143 | catch { | 22:09 |
juju2143 | entry2.Text = "OMG we got an error"; | 22:09 |
sirmacik | for return and witch for that entry2? | 22:09 |
juju2143 | return; | 22:09 |
juju2143 | } | 22:09 |
sirmacik | oh (; | 22:09 |
pleia2 | [/g 67 | 22:10 |
pleia2 | sorry | 22:10 |
juju2143 | and entry2 you would put a second Entry in your Designer | 22:10 |
juju2143 | oh damn my laptop bacame laggy, i'll Ctrl-alt-Backspace. | 22:11 |
sirmacik | works (; | 22:12 |
juju2143 | :D | 22:12 |
juju2143 | so you learnt the try/catch | 22:12 |
juju2143 | maybe if you put (Exception ex) fter the catch keyword | 22:13 |
juju2143 | the ex variable containing all sorts of infos about the exception becomes available in the catch block | 22:13 |
pedro3005 | so this 'ex' variable already exists? | 22:14 |
juju2143 | nope, you defined it | 22:16 |
juju2143 | then the compilers when it enters in the catch, like a function, it will pul all the infos in the var | 22:17 |
juju2143 | now that you made your 1st app in GTK+ | 22:18 |
juju2143 | GTK#* | 22:18 |
sirmacik | (; | 22:19 |
meebey | C# is hot! sexiest programming language I have seen ^^ | 22:19 |
juju2143 | You may try to make a method. | 22:19 |
juju2143 | meebey, hehe | 22:20 |
sebner | loool meebey | 22:20 |
meebey | sebner: you are late stefan, now quickly take a seat! | 22:20 |
sebner | meebey: sure :), bouncer is dead :( | 22:21 |
juju2143 | lol. | 22:21 |
juju2143 | last theory today, methods | 22:21 |
juju2143 | tomorrow we'll do whole classes | 22:21 |
juju2143 | between the 2 } at the end. | 22:22 |
juju2143 | private string MultiplyBy2(string number) | 22:22 |
juju2143 | { | 22:22 |
juju2143 | / This is a comment | 22:23 |
juju2143 | // This is a comment | 22:23 |
juju2143 | / This is NOT a comment and won't compile. | 22:23 |
juju2143 | /* But this is a comment | 22:23 |
juju2143 | a multiline | 22:23 |
juju2143 | comment */ | 22:24 |
juju2143 | / Insert here the try/catch block of the last example | 22:24 |
juju2143 | return (num * 2).ToString(); | 22:25 |
juju2143 | } | 22:25 |
juju2143 | I write / instead of // because the way IRC handles lines beginning by / | 22:25 |
pedro3005 | juju2143, why is the first line a comment and the third not one? | 22:26 |
meebey | / test | 22:26 |
meebey | oh funny | 22:26 |
sebner | / | 22:26 |
sebner | juju2143: just use a whitespace before the / | 22:26 |
juju2143 | because I wanted to write // but I failed and it showed up as / | 22:26 |
pedro3005 | ok | 22:27 |
juju2143 | sebner, usually I put a Ctrl-O | 22:27 |
juju2143 | // there | 22:27 |
pedro3005 | juju2143, so only // and /* */ right? | 22:27 |
juju2143 | pedro3005, yep | 22:27 |
sebner | 22:27 | |
sebner | nice | 22:28 |
juju2143 | so in your try{} block you would put int num = Convert.ToString(number); | 22:29 |
juju2143 | and in catch, a MessageDialog saying that the function failed then a return 0; | 22:30 |
airborn | juju2143, does C# use finally{} blocks? | 22:30 |
juju2143 | airborn, yes | 22:30 |
airborn | thx | 22:30 |
juju2143 | return "oh noes it failed"; | 22:30 |
juju2143 | now in your OnButton1Clicked you would put entry2.Text = MultiplyBy2(entry1.Text); | 22:32 |
juju2143 | now compile and run | 22:32 |
juju2143 | now you would see your number multiplied by 2 | 22:34 |
juju2143 | Now you got an introduction to GTK#. Tomorrow we will see classes and these private/protected/public/static keywords. | 22:35 |
juju2143 | If you have questions, just ask here. | 22:36 |
juju2143 | And you got an intro to methods :P | 22:36 |
sirmacik | (; | 22:36 |
sirmacik | thanks for today juju2143 | 22:36 |
juju2143 | yw :P | 22:37 |
pedro3005 | yes, thank you :) | 22:37 |
juju2143 | :) | 22:37 |
meebey | only 2 new C# hackers? who will hack all the cool features then into smuxi? ^^ | 22:39 |
meebey | 20:25:39 <meebey> and day3 will be hacking cool smuxi features? | 22:40 |
meebey | :-P | 22:40 |
sebner | meebey: lol | 22:41 |
sebner | meebey: me in summer ;D | 22:41 |
meebey | sebner: yay | 22:41 |
meebey | sebner: I will get vacation end of july | 22:41 |
sebner | meebey: we are speaking about 2011 though :P | 22:42 |
meebey | sebner: oh noez | 22:42 |
sebner | meebey: gsoc :P you promised me | 22:42 |
meebey | moah C# hackaz plx | 22:42 |
meebey | sebner: hrhrhr | 22:42 |
sebner | meebey: but I'll take a look this summer too ;) | 22:42 |
meebey | sebner: I still have to find a gsoc organization... | 22:42 |
sebner | meebey: mono | 22:43 |
meebey | I dont think they will have much interest in smuxi... they have so many cool mono projects you know... | 22:43 |
sebner | meebey: pfff, smuxi is the best :P | 22:43 |
sirmacik | hmm | 22:44 |
sirmacik | juju2143: I've a little problem with understanding of this methods thing. Could You paste somewhere example of working code from todays lesson? | 22:45 |
juju2143 | yeah of course | 22:46 |
juju2143 | protected virtual void OnButton1Clicked(...) { | 22:47 |
juju2143 | entry2.Text = MultiplyBy2(entry1.Text); | 22:47 |
juju2143 | } | 22:47 |
juju2143 | private string MultiplyBy2(string text) { | 22:48 |
juju2143 | int number; | 22:48 |
juju2143 | try { | 22:48 |
juju2143 | number = Convert.ToInt32(text); | 22:48 |
juju2143 | } | 22:48 |
juju2143 | catch { | 22:48 |
juju2143 | return "OMG something happenned"; | 22:48 |
juju2143 | } | 22:48 |
juju2143 | return (number*2).ToString(); | 22:49 |
juju2143 | } | 22:49 |
juju2143 | there it should work | 22:49 |
sirmacik | thanks (: | 22:49 |
juju2143 | :) | 22:51 |
sirmacik | now I see where I failed ;f | 22:51 |
sirmacik | works great [; | 22:53 |
sirmacik | see You tomorrow \o | 23: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!