/srv/irclogs.ubuntu.com/2010/03/03/#ubuntu-classroom.txt

=== Zami_ is now known as Zami
qwasedhow can i look at past irc classroom logs?10:05
mbuddehttp://irclogs.ubuntu.com/10:06
qwasedthanks10:06
=== tux_race1 is now known as tux_racer
=== yofel_ is now known as yofel
=== screen-x is now known as hds
=== hds is now known as screen-x
=== ghost is now known as Guest97661
reida010s16:08
didrocksjono: did you receive my slides? (and for generating the translation string, just quickly package or quickly share/release)16:18
jonodidrocks, yep, they are in there :)16:20
jonodidrocks, isnt there an argument to pass setup.py if I remember right?16:20
jonoI remember dpm did something16:20
RainCTnot sure if it's related at all with what you are talking about, but there is:  python setup.py build_i18n16:21
jonoRainCT, thats it!16:22
jonowoo!16:22
didrocksjono: if you want to do that outside of quickly yes (but the previous command calls that). It's ./setup.py --build-i18n16:22
didrockslet me check for the syntax exactly :)16:22
didrocksone sec16:22
jonothats cool for updating the translations template without packaging16:22
jonothanks RainCT, didrocks!16:22
=== 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 || Event: Ubuntu Opportunistic Developer Week - Current Session: Creating stunning interfaces with Cairo - Laszlo Pandy - Instructor: laszlok || Questions in #ubuntu-classroom-chat
laszlokHello everyone, i'm gonna be talking about using cairo with python today17:01
laszlokI haven't prepared any slides, but I'll be using some links17:02
laszlokand it will be less structured than usual, so feel free to shout out or ask questions at any time in #ubuntu-classroom-chat17:02
laszlokI won't mind taking a large detour, we'll probably have plenty of time for it17:03
laszlokSo cairo is a drawing API17:03
laszlokif you know about SVG graphics, it does the same sort of thing17:04
laszlokit has strokes, fills, gradients, etc17:04
laszlokIts also a very modern drawing api17:04
laszlokthe library was written quite recently17:04
laszlokI mean modern in that it has good alpha support, and really good antialiasing17:05
laszlokso when you draw graphics they scale well and look very clean17:05
laszlokunlike previous generation APIs like Java graphics (don't get me started)17:06
laszlokCairo integrates really well with GTK, in fact most widgets in GTK are now drawn using cairo17:07
laszlokI will show you how to use it with GTK and also how to use some other cairo backends like svg, pdf, and png17:07
laszlokIn terms of creating stunning interfaces, it can be done with cairo. If you create a stunning GTK app then you are doing it with cairo anyway ;)17:08
laszlokhowever cairo is low level17:08
laszlokif you are using cairo directly you are drawing all the lines and calculating all the geometry yourself17:09
laszlokThere was a talk yesterday about goocanvas, which uses cairo and gives a much higher level view. You can deal with objects instead of geometry calculations.17:10
laszlokBut if anyone has questions about that, please ask17:10
laszlokhttp://www.cairographics.org/samples/17:10
laszlokhere is a page on the cairo website with some sample code and how it will look17:11
laszlokthe code is in C, but it is quite similar to python as you will see17:11
laszlokQUESTION: Can we build all the application interface using Cairo (except for the Window container)?17:12
laszlokyes you can, but it will involve a lot of trickiness if you want to detect mouse clicks on many different objects17:14
laszlokit will work fine for a simple drawing, but once you start using lots of objects you might find the geometry to figure out which one is clicked it too much17:14
laszlokthis is why things like goocanvas were invented; to automate those things17:14
laszlokQUESTION: can we use cairo to create the interface separate from the logic that runs the program?17:15
laszlokyes, in the same way that you would have a GTK interface separate from the program logic17:15
laszlokQUESTION: maybe for later, is there a preferred way of doing animations in cairo?17:16
laszlokcairo does not provide support for animations, so it has to be done essentially the same as animations in other drawing apis17:16
laszlokthat means having a timer to redraw the screen and have code to redraw the whole screen (or just the parts that change)17:17
laszlokso as you can see in the samples, cairo has primitives for arcs, lines, etc.17:18
laszlokThinking about an interface in these primitives is a bit low level, but it gives you the great flexibility17:18
laszlokQUESTION: Does the animation redraw method you just described use a lot of cpu power?17:19
laszlokif your drawing is complex, it probably will17:19
laszlokbut cairo is quite efficient, and allows you flexibility for caching drawings17:19
laszlokfor example if you have a background which requires a long time to draw, you can draw it to an ImageSurface in memory instead17:20
laszlokand then it is one operation to draw it on screen17:20
laszlokQUESTION: would like to add to performance that strokes are the ones that are expensive.17:21
laszlokthat's not a question ;)17:21
laszlokhttp://www.cairographics.org/documentation/pycairo/reference/index.html17:22
laszlokhere is the python documentation for cairo17:22
laszlokthat is good reference when looking at the next link17:22
laszlokhttp://laszlopandy.com/files/drawing_interface.html17:23
laszlokhere is some poorly commented python code I prepared17:23
laszlokQUESTION: waht are all the required components to start working on cairo+python?17:23
laszlokonly cairo, python and pycairo17:23
laszlokif you want to render directly on screen (as opposed to png or svg) you should have pygtk installed as well17:24
laszlokfor example, in the code i prepared I am importing both gtk and cairo17:24
laszlokcopy and paste this code into your editor17:25
laszlokif you run it with no arguments you will get a gtk window17:25
laszlokif you give it 'png', 'svg' or 'pdf' as an argument, it will generate that kind of file17:25
laszlokso lets take a look at the GTK code, in the DrawingInterface class17:25
laszlokit creates a window, and adds a gtk.DrawingArea17:26
laszlokthe DrawingArea is a widget which is like a blank canvas we can draw to17:27
laszlokthen we set the size of the window, and show it17:28
laszloknot much to see there17:28
laszlokthe expose event is the event when the X server tells the window to redraw itself17:28
laszlokso this is what we are using to trigger our drawing code17:28
laszlokalso notice that in the GTK code the cairo context is created directy from the widget. GTK is integrated with cairo and makes it easy17:29
laszlokthe context is what holds all the information about your drawing as you add lines and shapes17:29
laszlokthe draw_rounded_rentangle() method is converted from the C example on http://www.cairographics.org/samples/17:30
laszlokif you compare them you can see it is mostly identical code17:30
laszlokQUESTION: please explain the underlying functiosn used in on_expose17:31
laszlokhttp://laszlopandy.com/files/drawing_interface.html17:31
laszlokin on_expose we create the cairo context associated with the widget17:31
laszlokso when we draw using that context, it will draw on the widget17:32
laszlokwidget.get_allocation() returns a renctangle with the width and height of the window, so we know how much space we have to draw17:32
laszlokand self.drawing.draw() calls the method on the drawing class three lines below that17:32
laszlokQUESTION: will the get_allocation be called only after drawing.draw is called?17:33
laszlokthis is equivalent to:17:33
laszlokrectangle = widget.get_allocation()17:33
laszlokself.drawing.draw(ctx, rectangle)17:33
laszlokso the draw() method can know the size of the widget17:34
laszlokby default, the DrawingArea widget is the default gtk colour17:34
laszlokso in the draw() method I create a rectangle the size of the widget and fill it with white17:35
laszlokthe context remembers things like rectangles i have created, and also what colour i set it17:35
laszlokafter I call fill() the rectangle is removed from the context and put on the screen, but the colour is still set17:36
laszlokso remember to change your colour or it will be whatever you set it previously17:36
laszlokQUESTION: Is it possible to do some basic 3d transformation? (Like perspective on GIMP)17:36
laszlokcairo is a 2d canvas, but you can do transformation17:36
laszlokto fake a perspective17:36
laszloktake a look at http://www.cairographics.org/documentation/pycairo/reference/matrix.html#class-matrix17:37
laszlokIn get_gradient() http://laszlopandy.com/files/drawing_interface.html17:38
laszlokyou can see cairo makes gradients really simple17:38
laszlokyou create a gradient with a start and end point to define how long the colour change will be and in what direction17:38
laszlokand then you set stops on the gradient, just like you would do on inkscape or other graphics programs17:39
laszlokthe first argument to add_color_stop_rgb is the offset between 0 and 117:39
laszlokso i set two colour stops. One at the beginning and one at the end17:39
laszlokyou can easily add a third one in set it to offset 0.5 and your gradient will blend three colours17:40
laszloknow look at the bottom part of the code where it says if arg == 'pdf':17:41
laszloki mentioned earlier about using image surfaces to store your drawing in memory17:41
laszloksurfaces also allow you do store in files17:41
laszlokQUESTION: can you set the gradient to go through the hues in the opposite direction?17:42
laszlokyes17:42
laszlokeither reverse the offsets17:42
laszlok(set the first one to offset 1, and second to offset 0)17:42
laszlokor reverse the pairs of (x,y) parameters to the LinearGradient constructor17:43
laszlokQUESTION: does the context variable acts as a placeholder or as a memory buffer?17:44
laszlokit is the same as the drawing context created from the GTK widget except it writes to a file17:44
laszlokso it will store your drawing in memory and write it to the file when you complete a fill() or stroke()17:45
laszlokQUESTION: How to make it write to a jpg file?17:45
laszlokJPG file compression is meant for pictures where there are not perfectly smooth lines17:46
laszlokPNG compression works much better for drawings, things with smooth and sharp borders17:46
laszlokso cairo does not support JPG directly, i would write to svg or png and use imagemagick to convert it17:46
laszlokso as you can see, cairo surfaces make it really easy to export to other formats17:48
laszlokand if you were writing on windows or mac, you would use a surface specifically for the platform and the rest of the api would be the same17:49
laszlokany questions?17:50
laszlokQUESTION: does cairo do that "redraw only changed parts" automagically, or do we manually tell what changed ?17:50
laszlokyou could have to do that manually17:50
laszlokin this case i redraw the white rectangle each time, therefore blanking the entire screen17:51
laszlokthis is something that goocanvas would also automate for you17:51
laszlokQUESTION: How difficult is it to use cairo in combination with pygoocanvas?  (For example, if I wanted to draw/animate something like a progress indicator on top of my goocanvas while waiting for goocanvas to update during a slow operation.)17:52
laszlokthat seems like a strange use case, but it should work17:52
laszloktheoretically you can use cairo to draw on top of any GTK widget17:52
laszlokas long as the proper flags are set17:53
laszlokQUESTION: What are the advantages of using cairo directly instead of through goocanvas?17:55
laszlokgoocanvas is much higher level17:55
laszlokand cairo is very lightweight17:55
laszlokif you are doing something simple and want the flexibility, or don't mind doing the drawing manually then cairo is the way to go17:56
laszlokits really easy to get started with, and can work with GTK mouse clicks, etc well for simpler things17:56
laszlokif you know you have a bunch of objects you want to drag around on the screen, goocanvas will probably make your life much easier17:57
laszlokQUESTION: the png format uses the format_argb32 constant. the manual shows 3 more. can u tell the formats they specify?17:57
laszlokreferring to http://www.cairographics.org/documentation/pycairo/reference/constants.html#constants-format17:58
laszlokFORMAT_ARGB32 is colour surface with alpha support17:58
laszlokFORMAT_RGB24 is the same without alpha support so you will not be able to do transparency17:59
laszlokthe others are for alpha only masks and do not store colour values17:59
laszlokthese formats are for image surfaces. You may need to specify alpha only if you want to make a transparency mask18: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 || Event: Ubu ntu Opportunistic Developer Week - Current Session: What's new in Quickly 0.4 - Didier Roche - Instructor: didrocks || Questions in #ubuntu-classroom-chat
didrocksawesome laszlok, thanks for your session :) Just a question, when will you do a Quickly template for a cairo project? :p (kidding)18:01
didrocksso, welcome everyone on the session about Quickly 0.418:01
didrocks[SLIDE 1]18:02
didrockswho is interested on what we backed for Quickly 0.4? hands up in -chat!18:02
didrocksnice18:03
didrocksso, I'm Didier Roche, one of the Quickly developer and also desktop team member18:03
didrocks(and fresh ubuntu core dev :))18:04
didrocksfor people not seeing the slide, you can get them at http://people.canonical.com/~didrocks/Quickly-0.4.pdf18:04
didrocksit should be on the Session tab in lernid18:04
didrocksso, first, what this session is *not* about18:05
didrocksthis session isn't a presentation of Quickly. This has already been done later this week by Rick Spencer. logs availabled at https://wiki.ubuntu.com/MeetingLogs/OpWeek1003/Quickly18:05
didrocks[SLIDE 2]18:06
didrocks(at least, it works me in lernid :p)18:06
didrocks(and that's not Quickly's fault ;))18:06
didrocksso, 0.4 is unfortunately still in development18:06
=== yofel_ is now known as yofel
didrocksit still needs some stuff to be added in launchpad to make things easier18:07
didrocksand I prefer to do that the right way than a quickly screenscrapping18:07
didrocksso, warning, it's unstable, the current version is 0.3.518:07
didrocksI hope to release the stable version before lucid beta 118:07
didrocksin any case, Quickly 0.4 will be in lucid :)18:08
didrocksso, a little about stats18:08
didrockslast version which is 0.2.6 has been release approximately 6 months before18:08
didrocksand a lot happens in 6 months :)18:08
didrocksyou can see some stats for the addicts: 250 commits and 12930 changed lines18:09
didrocksto be honest, some file had been moved, so if we want to be fair, I would say 4000 code of code have been really impacted18:09
didrocksit's a lot, and I'll show you now what are in those lines :)18:09
didrocks[SLIDE 3]18:10
didrockssouces: how to be informed of what's new?18:10
didrockswell, this session is dedicated to that, so that's a good first step :)18:10
didrocks(I'll probably blog on planet ubuntu too when Quickly 0.4 will be out)18:10
didrocksa more detailed sources the NEWS file in trunk18:11
didrocksI try to keep it pretty complete18:11
didrocksand of course, if you want full details, you have to read the 250 commits :)18:11
didrockslet's first see what's the most noticeable changes18:13
didrocksthe first thing is that the ubuntu-project template (the only one which existed in 0.2.x) is no more…18:13
didrocksdon't be panic, it has just been renamed ubuntu-application18:13
didrocksof course, existing project will be transitionned appropriately so that you don't have to change anything for existing Quickly users18:13
didrocksQuickly 0.4 will welcome at least one new template, and even maybe a third one in trunk :)18:13
didrocksubuntu-cli template is to create a command line soft with all the ubuntu-application intgration18:14
didrocks(a lot of people asked for a cli template :))18:14
didrocksubuntu-game (or pygame, or whatever) will be detailed later in this week by Rick, you should be already aware of that if you read planet ubuntu18:14
didrocksalso, artfwo (thanks to the template inheritance I'll described later) is beginning to implement a gedit-plugin template18:15
didrocksso, a lot of goodness to come in a very short time :)18:15
didrocks[SLIDE 4]18:15
didrocksas there is no question, let's dive a little bit more on what's interest most of you: ubuntu-project… hum… ubuntu-application new capability ;)18:16
didrocksfirst thing (and I'll come back later on that) you have to understand is that your existing app will be converted for 0.418:17
didrocksit will be the first time you run a quickly command on it18:17
didrocks(also if you proceed some tab completion)18:17
didrocksthat's needed and it's a new Quickly core capability18:17
didrocksthat implies that projects which will be converted to Quickly 0.4 won't work anymore with a previous version of Quickly18:18
didrocks(it's still possible to convert back by hand, but complicated)18:18
didrocksas I wrote, ubuntu-application in 0.4 has a new versionning scheme18:19
didrocksthat means that project will follow by default ubuntu way of versionning thing18:19
didrocksfor instance, if I run "quickly release" just now, my release will be 10.0318:19
didrocksif I run quickly release again, it will be 10.03.118:19
didrocksand so on :)18:19
didrocksyou are still able to provide your release version yourself18:20
didrocksthe second point is the most tricky one but the one on the top priority list18:20
didrocksdid you have some troubles setting up your gpg and ssh key on LP to make your first quickly share/quickly release?18:20
didrocksthat will be (we hope) part of the past in 0.4!18:21
didrocksthis is what I'm currently working and that needs a lot of work on launchpad side… and I'm not a LP hacker18:22
didrocksso, normally, if you don't have one, Quickly will do everything for your18:22
didrocksyou*18:22
didrocksalso, selecting the right email adress through some algorithms :)18:23
didrocksmoving on…18:23
didrocksquickly license has been totally reshaped18:23
didrocksno more Copyright file which populate an AUTHOR file, you will only have to edit the AUTHOR one18:23
didrocks(this confused some people before)18:23
didrocksthe next one is more interesting18:24
didrockswhen you quickly release, your changelog will automatically be collected with all the messages you provided in "quickly save <your message>" from the last release18:24
didrocksit will create a release and milestone on launchpad18:24
didrocksupload your tarball too to be available on the first page18:24
didrocksand create an annoucement with your changelog18:25
didrocksof course, as a good upstream, it signs the tarball file too (as it's recommended as a best practice)18:25
didrocksyou can see what it gives on my test project: https://edge.launchpad.net/fooby18:26
didrocksnext point is ppa18:26
didrockswhen Quickly 0.2 was released, launchpad only enabled you to have one ppa18:27
didrockswhich was called… "ppa"18:27
didrocksthings have changed now and you can have multiple ppa18:27
didrocksalso, some people would like to upload the package to a team ppa18:27
didrocksand to be honest, that makes sense :)18:27
didrocksso, now, you can upload to any ppa you want18:27
didrockseither by providing --ppa <ppa_name>18:28
didrocksto quickly share and release18:28
didrocksor to put it as a default with quickly configure ppa <ppa_name>18:28
didrocksof course, shell completion still works there and give you the list of all ppa you have access18:28
didrocks(/!\ it's slow on LP side, can take more than 10s)18:29
didrocksppa_name can be: "myppa" or "team/ppaname"18:29
didrocksand shell completion works for everycase :)18:29
didrockson another aspect, as I wrote some commands have been rename to be more consistent18:30
didrocksquickly dialog is now quickly add dialog18:30
didrocks(that will avoid in the futur to have 50 commands in a template)18:30
didrocksquickly lp-project is quickly configure lp-project18:30
didrocksand quickly glade is now quickly design18:30
didrocksof course, as always, statement completion is here to help you to find commands name and arguments to the commands :)18:31
didrocksfor instance quickly configure [tab][tab] will show you all available options like ppa, lp-project, bzr18:31
didrocks[SLIDE 5]18:32
didrocksah, I like very much next option :)18:32
didrockswhen you "quickly release", now, you will have the about dialog automatically refreshed18:32
didrocksthat means, your logo, but also the new version number appears, the Copyright holder, the homepage, the Credit (authors) button and license one18:33
didrocksso, no need to before or to think about them, Quickly is handling that for you :)18:33
didrocksthat avoid to make a .1 release with "I forgot to…"18:34
didrocksnext item (no, not the blank one) had been asked also by a lot of persons18:34
didrocksbeing able to add manual dependencies18:34
didrocks"why care, quickly already grab all the depends for us?" you will tell me…18:35
didrocksthat's both true and false to be honest :)18:35
didrocksfor instance, if you launch a command yourself as a subprocess pythondistutils-extra won't find it and you will have a missing dependency18:35
didrocksso now, for that, you can just fire away $ quickly configure dependencies18:36
didrocksas "dependencies" is typo-prone, think about using shell completion for that too :)18:36
didrocksnext thing is bzr branch, as for ppa, you can tell where you can push and pull your code if you are interested in :)18:37
didrocksquickly configure bzr of course :)18:37
didrocksmaybe the tutorial which (I'm afraid) is still not internationalized will be thanks to fagan. But nothing sure yet, still ongoing work :)18:38
didrocksof course, this was only the most important things I can list for that session for ubuntu-application template, but there are a lot of various fixes, new licenses available, packagin tweak, internationalized application, and so on :)18:39
didrocks[SLIDE 6]18:39
didrocksoh btw, I forgot about the apport hook!18:39
didrocksall project will come (but you can still disabling that if you don't want) an apport hook by default18:40
didrocksand the menu will have the launchpad addition for translation and help in the help menu18:40
didrocksok, so, now, really slide 6 :)18:40
didrocksthis is for prospective template developers and people interested in making a GUI for Quickly18:41
didrocksfirst thing is importing commands between templates is available18:41
didrocksQUESTION: does having an apport hook mean that if the program crashes and stuff you can send a detailed report to the launchpad project?18:41
didrocksdbell: exactly :)18:41
didrocksand you get that for free :)18:42
didrocksso, back on importing commands18:42
didrocksif one day you want to look at the ubuntu-cli template18:42
didrocksyou will see that there is 0 line of code18:42
didrocksyes, no typo, I said 0!18:42
didrocksit's just a new boiler plate, and I import all commands from ubuntu-application18:43
didrocksso, basically, there is a commandsconfig with:18:43
didrocks[ubuntu-application]18:43
didrocksIMPORT=configure;create;edit;license;package;release;run;save;shar18:43
didrocks(for obvious reason for a cli template, I don't import design and add dialog :))18:44
didrocksand then, I can create a ubuntu-cli application, edit, licence, package…18:44
didrocksand get statement completion for all of those using the new boiler plate code :)18:44
didrocksso, creating a template from an existing one is really really easy18:45
didrocksQUESTION: Will apps still work if python-launchpad-integration isn't installed (eg. on other distros)18:45
didrocksRainCT: we try to include that as a patch, so that pristine tarball doesn't have that code and so other distros aren't impacted18:45
didrocks(it's basically a try: pass)18:45
didrockswell, other functions (quickly ;))18:46
didrocksyou can now pass option to template18:46
didrockswe have apport integration18:46
didrocksso ubuntu-bug quickly is your friend :)18:46
didrocksas I told you, you can now quickly configure [tab][tab] --ppa [tab][tab]18:47
didrocksthat means that the core has now option completion for you18:47
didrockswe handle template upgrade18:47
didrocks(even if you launch a command from one template into another project)18:47
didrockslike quickly --template my-awesome-template foocommand18:47
didrockswe have also now an API18:48
didrocksso, if you want to build a GUI or integrate it into an IDE, that's the way to go :)18:48
didrocksof course, in addition to thing, many fixes and refactoring18:48
didrocks[SLIDE 7]18:48
didrocksI've already talked about the ubuntu-cli template18:49
didrocksthe most important thing is that it's a new boiler plate for no code for the commands :)18:49
didrocksif you want to implement your own template with import of ubuntu-application command, that's where to look for examples18:49
didrocksQUESTION: Any examples on the API?18:50
didrocksosteenbergen47: basically, you just have to "from quickly import api" and then, look at the api file18:50
didrocksif you are interested in that, join #quickly and I can help you :)18:50
didrocksQUESTION: is there a tutorial on how to do own/custom templates ?18:50
didrocksoskude: I've written one for Quickly 0.2, let me find the link18:51
didrockshttp://blog.didrocks.fr/index.php/post/Build-your-application-quickly-with-Quickly%3A-Inside-Quickly-part-618:51
didrocks(and now, I kill my Internet connexion as I host myself my server ;))18:52
didrocksthis is quite outdated18:52
didrocksI will refresh that once 0.4 out18:52
didrocks[SLIDE 8]18:52
didrocksso, you want to try Quickly 0.4? (well, 0.3.5)18:52
didrocksas I mentionned before, we warned, you can't convert back your project to the previous format18:53
didrocksand I don't have the time to ensure that everycommand works at each commit, but I try to fix the issue within the day18:53
didrocksso, jump into #quickly, so that you can yell at me that it's broken :)18:53
didrocksand if you want to test, branch the trunk18:54
didrocksbzr branch lp:quickly18:54
didrocksexport PATH=<path_to_your_trun>/bin:$PATH18:54
didrocks(note the /bin :))18:54
didrocksquickly --version should normally answer you about the current version18:54
didrocks[SLIDE 9]18:54
didrocksof course special thanks to Rick to have the idea of this project18:55
didrocksand he will do the two next session, stay around :)18:55
didrocksalso some contributors are really awesome and help pushing the project further :)18:55
didrocks[SLIDE 10]18:55
didrocksso, taking questions now in the 5 remaining minutes18:55
didrocksQUESTION: Is there an easy way to try fresh quickly on Karmic? The straightforward setup.py build/install way results in a lot of errors.18:56
didrocksright, there is a bug logged about that18:56
didrocksI don't see anything preventing for backporting to karmic18:56
didrocksBUT18:56
didrocksyou need last distutils-extra version18:56
didrocks(else you can't add depends, nor you have the automated changelog goodness)18:57
didrocksand I probably have to fix setup.py18:57
didrocksI think I'll try to provide a package in the quickly ppa for karmic18:57
didrocksQUESTION: Is there a ppa-daily of Quickly for auto installing the last one?18:57
didrocksthere is a daily ppa, jcastro was the owner IIRC, I don't know the current state to be honest18:58
didrocksI think export PATH is more convenient :)18:58
didrocksand that's what I do everyday :)18:58
didrockswell, of course the day we can do "quickly release lucid", I think Quickly will take some thousands lines of code :)18:59
jcastroThe dailies work, if they don't work for you just poke me.18:59
didrocksbut as I still like my job, it won't happen :)18:59
didrocksI guess it's time :)18:59
didrocksand thanks jcastro18:59
didrocksthanks all for your attention19:00
didrocksnow, stage is to you rickspencer319:00
didrocksand thanks for having launched Quickly once more :)19: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 || Event: Ubuntu Opportunistic Developer Week - Current Session: Create games with PyGame - Rick Spencer - Instructor: rickspencer3 || Questions in #ubuntu-classroom-chat
rickspencer3hi all19:01
rickspencer3ready for some pygame stuff?19:01
rickspencer3great19:02
rickspencer3as usual, I got my notes ready before hand and stuck them on the wiki:19:02
rickspencer3https://wiki.ubuntu.com/UbuntuOpportunisticDeveloperWeek/PyGameClassNotes19:02
rickspencer3so I'll go through each section and take questions19:03
rickspencer3Pygame is a library for making arcade style sprite games19:03
rickspencer3It features very easy blitting and colision detection19:03
rickspencer3I have some sample code to help with understanding pygame here:19:03
rickspencer3https://code.edge.launchpad.net/~rick-rickspencer3/pygame-template/trunk19:03
rickspencer3I think you can go:19:03
rickspencer3bzr branch lp:pygame-template too19:04
rickspencer3note that some of this code is a bit old, and I need to reformat it and such19:05
rickspencer3but it19:05
rickspencer3s failry readable19:05
rickspencer3however, it will eventually be a quickly template, hopefully in time for lucid19:05
rickspencer3if you want to grab that it might help you follow the class a bit, but it is not required19:05
rickspencer3it comes with some basic game play that you can study and modify19:05
rickspencer3essentially, it is kind of like asteroids19:05
rickspencer3you control the black triangle in the middle, and there are two enemies19:05
rickspencer3Of course you will want some docs19:05
rickspencer3Pygame has good docs here:19:05
rickspencer3http://www.pygame.org/docs/19:05
rickspencer3before we discuss how to set up a game19:06
rickspencer3any questions?19:06
rickspencer3ok, then let us rock19:06
rickspencer3so, you're going to set up a game19:06
rickspencer3first thing you need to do is set up a game surface19:06
rickspencer3and do other initalizations19:07
rickspencer3so ..19:07
rickspencer3initialize pygame libraries19:07
rickspencer3pygame.font.init()19:07
rickspencer3pygame.mixer.init()19:07
rickspencer3(assuming you are using fonts and sound of course)19:07
rickspencer3then create a screen19:07
rickspencer3the screen will be the surface on which your sprites will be drawn, essentially where your game will occur19:07
rickspencer3screen = pygame.display.set_mode((800, 480))19:07
rickspencer3that's for an 800 x 400 pixel game19:08
rickspencer3also, create a couple of variable you will need later19:08
rickspencer3like a background image19:08
rickspencer3background = pygame.image.load(path_to_background)19:08
rickspencer3notice the image is a PyGame image19:08
rickspencer3and a clock19:08
rickspencer3clock = pygame.time.Clock()19:08
rickspencer3you'll see why we need the clock next19:08
rickspencer3pygame games use a good old fashioned input loop19:09
rickspencer3don't know if you all ever programmed with an event loop19:09
rickspencer3but it was very common for writing GUI apps back around when dinosaurs used computers19:09
rickspencer3essentially, you tell your app to keep looping19:09
rickspencer3and whenever it goes through the loop do a few things19:09
rickspencer31. respond to user input19:10
rickspencer32.update data for any sprites on the screen19:10
rickspencer3this includes seeing if any sprites have collided19:10
rickspencer33. redraw everything19:10
rickspencer3let's look at setting up a game loop19:10
rickspencer3 while 1:19:10
rickspencer3  clock.tick(15)19:10
rickspencer3  if ControllerTick() == 0:19:10
rickspencer3   return19:10
rickspencer3  if not game.paused:19:10
rickspencer3   ViewTick()19:10
rickspencer3   if CheckCollisions() == 0:19:10
rickspencer3    return19:10
rickspencer3you can see this code in the crashteroids file at line 16919:10
rickspencer3so first, the loop just runs and runs until etiher ControllerTick or CheckCollisions returns 019:11
rickspencer3the first line in the loop basically says to have 15 frames per second19:11
rickspencer3this is not like a sleep function where the argument says how long to sleep19:11
rickspencer3make sure that you pick a number that is low enough that a lower powered computer can keep up, if you care about that kind of thing19:11
rickspencer3The next line calls ControllerTick()19:11
rickspencer3This function checks for user input, which I will explain in a moment, and the updates all the game data19:11
rickspencer3this is a function that *you* write19:11
rickspencer3it's not built into PyGame19:12
rickspencer3then next in the loop19:12
rickspencer3assuming that the game is not paused, it will go ahead and update the view and do collision detection19:12
rickspencer3The reason that controllertick is always called is because this function controlls pausing and unpausing of the game19:12
rickspencer3if you didn't call it every time through, the user couldn't unpause19:12
rickspencer3we'll look at each of these functions in more detail19:12
rickspencer3but first, questions?19:12
ClassBotmhall119 asked: what file is that in?19:13
rickspencer3it's in crashteroids/bin/crashteroids19:13
ClassBotryzrecreel asked: What kind of image formats can you use?19:13
rickspencer3dunno for sure19:13
rickspencer3I always use png19:13
rickspencer3ok, no more questions, so moving on19:14
rickspencer3let's start by handling user input19:14
rickspencer3pygame basically queues up input events19:14
rickspencer3you can then loop through them and respond to each event19:14
rickspencer3at line 93, you can see how the loop is set up19:14
rickspencer3 for event in pygame.event.get():19:14
rickspencer3  if event.type == pygame.QUIT:19:14
rickspencer3   return 019:14
rickspencer3pygame.QUIT is called when the window closes or such19:14
rickspencer3of course you could also do something smart and save game state or such19:14
rickspencer3but this code returns 0, which causes the main event loop to quit19:15
rickspencer3now, let's say what I want to do is make the ship go forward when the user presses the j key19:15
rickspencer3(which is what crashteroids does by default)19:15
rickspencer3first I ask what kind of event it was19:15
rickspencer3  if event.type == pygame.KEYDOWN:19:15
rickspencer3yup, I want to respond to key down events19:15
rickspencer3so this I'll write some code here19:16
rickspencer3and then if it was a key event, what key was pressed19:16
rickspencer3    if event.key == pygame.K_l:19:16
rickspencer3     #do something19:16
rickspencer3oops19:16
rickspencer3that's for l key :)19:16
rickspencer3I guess l is for move, and j is to shoot19:16
rickspencer3in any case, you can probably guess that the correct event.key is pygame.k_j to respond to the j key19:17
rickspencer3;)19:17
rickspencer3you can see the whole tree of if, else statements starting at line 8919:17
rickspencer3there are also events for the mouse and joysticks even19:17
rickspencer3so it's easy to create games that aren't only using the keyboard if you want19:17
rickspencer3so that's how to handle input19:17
rickspencer3let's look at sprites, but first, any questions?19:17
ClassBotmhall119 asked: any kind of vector graphics?19:18
rickspencer3could be, but PyGame is really sprite based19:18
rickspencer3vector graphics is how games like asteroids and battlezone, and starcastle and stuff were created19:18
rickspencer3but sprites are when you use images19:18
ClassBotM49 asked: Does pygame have any dialog for key configuration?19:19
rickspencer3not that I know of19:19
rickspencer3that would be a nice thing to add to a quickly template though, wouldn't it19:19
rickspencer3I would guess that you would just use PyGtk for this19:19
rickspencer3create it yourself19:19
rickspencer3ok19:19
rickspencer3let's move on to sprites19:19
rickspencer3A sprite is basically an image in an arcade game19:20
rickspencer3pygame handles blitting for you, which is quite nice19:20
rickspencer3I'll discuss blitting in a bit19:20
rickspencer3If you wrote games long ago, you may remember rendering a sprite strip to an offscreen graphics world19:20
rickspencer3and then selecting bits of that strip and copying them to the onscreen graphics world19:20
rickspencer3pygame does not reqiure that at all19:20
rickspencer3it is much more fun and easy19:20
rickspencer3you just subclass the Sprite class19:21
rickspencer3one key thing a sprite has is an Pygame.Image member, called image19:21
rickspencer3I usually like to keep the original image around, as if you keep rotating the image and such, it will get more and more distorted over time19:21
rickspencer3so when I create a sprite object, I set up the image member like this:19:22
rickspencer3  self.masterImage = pygame.image.load(path_to_image_file)19:22
rickspencer3  self.image = self.masterImage19:22
rickspencer3this is all in the BastSprite class, btw, if you want to see the code in situ19:22
rickspencer3a sprite also has a "virtual" function, called update19:22
rickspencer3update is supposed to be called to tell a sprite to update it's data for a tick19:22
rickspencer3you set things like the sprite's x, y coordinates in this function, and such19:22
rickspencer3all your sprites should use this because you can then add a sprite to a RenderUpdates sprite group19:22
rickspencer3don't add your own custom named method to do this, or you will lose a lot of benefits of PyGame19:23
rickspencer3call update for that group, which will call update for each sprite19:23
rickspencer3you create a sprite group like this:19:23
rickspencer3enemies = pygame.sprite.RenderUpdates()19:23
rickspencer3and then you can add an sprite to that group19:24
rickspencer3enemies.add(create_enemy())19:24
rickspencer3you can also empty a sprite group19:24
rickspencer3enemies.empty()19:24
rickspencer3useful when you are resetting a level or something19:24
rickspencer3as we'll see later, sprite groups also help lots with collision detection19:24
rickspencer3back to sprites though19:24
rickspencer3so you have an image on a sprite19:24
rickspencer3you also need to define an x and y for your sprite19:24
rickspencer3I in my sprite subclass, I might set x and y randomly like this:19:25
rickspencer3   self.x = random.randint(0,300)19:25
rickspencer3   self.y = random.randint(0,140)19:25
rickspencer3(only when the sprite is created, of course)19:25
rickspencer3but then on each call to update(), just change the x and/or y if the sprite is moving19:25
rickspencer3sprites also have a "kill()" member function19:25
rickspencer3calling kill causes the sprite to be removed from the playing surface19:25
rickspencer3questions before we talk about updating the display?19:25
ClassBotmhall119 asked: can you change the image on update?19:26
rickspencer3yes19:26
rickspencer3absolutely19:26
rickspencer3you can also rotate it and other things19:26
rickspencer3my sprites usually have an "explode" method19:26
rickspencer3which causes a stage of an explosion to be displayed with each tick in update19:27
rickspencer3so if you look at crashteroids, changing images on update is how I get the explosion effect19:27
ClassBotmhall119 asked: Like, to animate your sprite19:27
rickspencer3totally19:27
rickspencer3like if you had a tank19:27
rickspencer3and it was going to shoot a missle19:27
rickspencer3you could have swap in images that make it look like a little guy loading the turret or something19:28
ClassBotmhall119 asked: can you layer images to make a single sprite image?19:28
rickspencer3hmmm19:28
rickspencer3not that I know of19:28
rickspencer3I don't think a sprite can composit images like that19:28
rickspencer3ok19:29
rickspencer3so now you have your event loop running, your game surface set up, and some sprites created19:29
rickspencer3now we need to actually draw the sprites19:29
rickspencer3for sprites that are not in a sprite group, we need to blit them19:29
rickspencer3fortunately this does not involve the crazy gworld hackery of days of hold19:29
rickspencer3pygame gives us a blit method19:29
rickspencer3blitting is essentially the act of repainting parts of the screen that have changed19:29
rickspencer3without blitting, the whole screen repaints and appears to flash19:29
rickspencer3so to blit the blackgroud, we'll use the screen to blit19:30
rickspencer3remember when we created teh screen object? now it's time to use it19:30
rickspencer3screen.blit(background, [0,0])19:30
rickspencer3I think that blitting the background like this basically repaints the whole background image over everything19:30
rickspencer3if you are tuning for a very slow platform, or a game with lots and lots of sprites, you may not want do it this way or you get flashing19:30
rickspencer3in those cases you might need to track the parts of the background exposed by moving sprites19:30
rickspencer3this is a bit of work, but probably will not be necessary for you to do19:31
rickspencer3I certainly have never run into trouble with this19:31
=== mohi1 is now known as mohi_
rickspencer3for all I know, blit() is smart enough to not cause flashing19:31
=== mohi_ is now known as mohi1
rickspencer3to blit an individual sprite, you have to tell the screen the image to use and the rect, or xy coords and dimensions, for hte sprite to blit19:31
rickspencer3So if we have a sprite object called "g", we blit it like this:19:31
rickspencer3screen.blit(g.image, g.rect)19:31
rickspencer3sprites in a sprite group are a bit easier to blit19:31
rickspencer3you can tell the sprite group to blit them all:19:32
rickspencer3 enemies.draw(screen)19:32
rickspencer3this blits all the enemies for you19:32
rickspencer3we do this each time through the loop19:32
rickspencer3in ViewTick()19:33
rickspencer3question before we discuss collision detection?19:33
ClassBotw1nGNUtz asked: will you explain anitmations? I'd like to understand how to animate an sprite using the clock19:33
rickspencer3yeah19:33
rickspencer3so let's say you want have an animation that shows a guy walking19:33
rickspencer3create enough images to show taking a step smoothly19:33
rickspencer3I'll guess it will take 8 frames to show smooth step19:34
rickspencer3in the sprites update method19:34
rickspencer3swap in the next image each time through19:34
rickspencer3for example19:34
rickspencer3when I show a guy exploding19:34
rickspencer3I have 8 frames or so showing the explosion19:34
rickspencer3named ship_explode_1.png to ship_explode_8.png19:35
rickspencer3(or named similary, I forget exactly what I named them)19:35
rickspencer3then I keep track in the update method of a counting variable19:35
rickspencer3let me get the exact code, hold on19:35
rickspencer3  if self.exploding:19:36
rickspencer3   #do an explosion image for each tick19:36
rickspencer3   self.explodestage += 119:36
rickspencer3   e = self.explodestage19:36
rickspencer3   if e < 8:#there are 7 explosion images19:36
rickspencer3    e = str(e)19:36
rickspencer3    self.masterImage = pygame.image.load(crashteroidsconfig.guy_explode_stage + e  + ".png")19:36
rickspencer3    self.updateImage()19:36
rickspencer3updateImage is a function I wrote that rotates the image and does some other stuff19:36
rickspencer3but essentially sets the sprites image member, like this:19:37
rickspencer3self.image = pygame.transform.rotate(self.masterImage,self.orientation)19:37
rickspencer3(if you weren't doing rotation and stuff, you could just assign the new image directly)19:37
ClassBotmhall119 asked: does pygame offer any kind of "damage" data to tell what parts of the screen should be repainted?19:37
rickspencer3I don't know19:38
rickspencer3I always let the sprites blit() method take care of that for me19:38
rickspencer3I don't think you'll to track this19:38
rickspencer3back in the day, you would always track the previous rect for the sprites location19:38
rickspencer3so that you could repaint it with the background19:38
rickspencer3but I don't think PyGame requires this19:39
ClassBotgooomba asked: Is pygame also suited for non-arcade games like chess for example?19:39
rickspencer3yes19:39
rickspencer3it wuold be good for board games for sure19:39
rickspencer3ok, so collision detection19:40
rickspencer3so let's say when an enemy rams our guy, we want both to be killed19:40
rickspencer3but how to tell when an ememy hits?19:40
rickspencer3detecting overlapping sprites is called "collision detection" and is handled quite well by PyGame19:40
rickspencer3this saves you tons of work19:40
rickspencer3(believe me, tracking rects and writing code to detect overlapping rects is not fun or easy!)19:40
rickspencer3you can detect if two sprites have collided using pygame.sprite.spritecollide (), collideany, or groupcollide19:41
rickspencer3so let's see if our guy, called g, has collided with an enemy19:41
rickspencer3  e = pygame.sprite.spritecollideany(g, enemies)19:41
rickspencer3call this each tick19:41
rickspencer3I always have specific function to handle collision detection19:41
rickspencer3if the guy has not collided with any enemies, e will be None19:41
rickspencer3but when e is not None, that means boom19:42
rickspencer3"boom"19:42
rickspencer3let's say your guys shoots bullets19:42
rickspencer3those bullets will most likely be managed in a sprite group19:42
rickspencer3so we should also see if any enemies were killed by bullets19:42
rickspencer3hits_dict = pygame.sprite.groupcollide(bullets, enemies, False, False)19:42
rickspencer3since we are asking for a collision between groups of sprites19:42
rickspencer3here you get back a dictionary19:42
rickspencer3the keys are sprites from the first sprite group19:42
rickspencer3and the values are keys from the second sprite group19:42
rickspencer3so then we can just go through and kill each bullet and enemy for the collision:19:42
rickspencer3   for b in hits_dict:19:43
rickspencer3    for e in hits_dict[b]:19:43
rickspencer3     e.kill()19:43
rickspencer3     b.kill()19:43
rickspencer3ok, next and last section is on playing sounds19:43
rickspencer3any questions first?19:43
ClassBotmhall119 asked: does pygame have any kind of scene-graph, to animate sprites without writing a whole bunch of python code?19:43
rickspencer3if I know what that meant, I would give you a pithy answer19:43
rickspencer3unfortunately, I have to say "I don't know"19:43
ClassBotM49 asked: Does it track only bounding boxes or does it use trasparency information from sprites?19:44
rickspencer3the bounding box one19:44
rickspencer3actually, you can set the rect for the sprite specifically19:44
rickspencer3I often set the rect for the sprite to be slightly smaller than the image itself19:44
rickspencer3this give a nice effect where two sprites can just touch19:44
rickspencer3and not explode19:44
rickspencer3it gives a nice "near miss" effect19:44
rickspencer3it also lets you tune each rect to different shaped sprites19:45
rickspencer3note that the rect is only used for collision detection so far as I know19:45
rickspencer3so the whole image will always be displayed19:45
rickspencer3ok, finally, sounds19:46
rickspencer3we use the Pygame.mixer module to manage sounds19:46
rickspencer3we need to initialize it before we use it:19:46
rickspencer3pygame.mixer.init()19:46
rickspencer3now I'll load an explosion sound to play when my guy explodes:19:46
rickspencer3self.explosionSound = pygame.mixer.Sound(path_to_sound_file)19:46
rickspencer3let's assume this sound is a bit loud, we can adjust the volume as we like:19:47
rickspencer3  self.explosionSound.set_volume(.2)19:47
rickspencer3then we can play the sound:19:47
rickspencer3   self.explosionSound.play()19:47
rickspencer3we can stop it too if it's going too long:19:47
rickspencer3   self.explosionSound.stop()19:47
rickspencer3the mixer module is quite rich19:47
rickspencer3there are channels, fades, and all kinds of stuff19:47
rickspencer3so19:48
rickspencer3that was the last "chapter" for the class19:48
rickspencer3we're a bit early19:48
rickspencer3any questions?19:48
ClassBotgooomba asked: what are the "False"-arguments in groupcollide() for?19:48
rickspencer3shucks, I forget19:48
* rickspencer3 looks at docs19:48
rickspencer3huh19:49
rickspencer3http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.groupcollide19:49
rickspencer3no longer seems part of the API19:49
rickspencer3I guess I can just remove that from the template19:49
ClassBotmhall119 asked: what audio formats does mixer support?19:50
rickspencer3I know ogg and wav19:50
rickspencer3don't know what else, sorry19:50
rickspencer3there are nine minutes left19:51
rickspencer3any last questions, requests?19:51
rickspencer3(otherwise I'll grab some soda and get ready for my next session ;) )19:51
ClassBotoskude asked: how do i use the examples on that pygame site ?19:52
rickspencer3I'm not sure what you are asking specifically19:52
rickspencer3but I don't think they are set up as runable samples, but rather like code snippets19:52
rickspencer3I used those samples heavily back when I was learning PyGame tough19:53
rickspencer3ok, looks like no more questions19:53
rickspencer3please feel free to join us in #quickly19:53
rickspencer3any feedback on the PyGame template and how to improve it, what's wrong with it, etc...19:54
rickspencer3is much appreciated19:54
rickspencer3thanks all!19:54
=== 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 || Event: Ubuntu Opportunistic Developer Week - Current Session: SHOWCASE: Photobomb - Rick Spencer - Instructor: rickspencer3 || Questions in #ubuntu-classroom-chat
=== enli is now known as enli|away
rickspencer3hi all20:02
rickspencer3soooo20:02
rickspencer3I'm here to talk about photobomb20:02
rickspencer3jono thought some folks might be interested in hearing about some of the technology that I used and such20:02
rickspencer3to make it easier to walk through, I put some screenshots and some notes:20:03
rickspencer3here:20:03
rickspencer3http://theravingrick.blogspot.com/2010/03/photobomb-featured-app-for-opp-dev-week.html20:03
rickspencer3shall I begin with photobomb?20:04
rickspencer3I wrote the first iteration of Photobomb one Saturday afternoon.20:05
rickspencer3does everyone know what it does?20:05
rickspencer3it's basically a hacked together photo editor20:05
rickspencer3that let's you mash up images from sources like your feeds, your computer, the web, your web cam, etc...20:06
rickspencer3do some fun stuff20:06
rickspencer3and then you can save the image or tweet it20:06
rickspencer3I wrote this totally just for the fun of it in my spare time20:06
rickspencer3during January, I set the goal of writing one new feature a night20:06
rickspencer3so I got pretty far with it that way20:06
rickspencer3of course, it's a bit buggy still20:06
rickspencer3but it's kinda fun to use20:07
rickspencer3anyone who wants to contribute to it, fork it, whatever20:07
rickspencer3by all means, have a go20:07
rickspencer3anyway ...20:07
rickspencer3I used Quickly to get the project started, so it was just a matter of laying out some UI in Glade, and then figuring out how to manipulate images.20:07
rickspencer3I used Python Imaging Library (PIL) to create a cropped version of that little squirrel, and to paste it onto the picture.20:07
rickspencer3PIL is a complete and power library. It was a bit tough figuring out the masking to crop the squirrel image as desired, but I eventually managed.20:08
rickspencer3I ended up moving away from PIL, but from what I saw, I was impressed20:08
rickspencer3any questions do far?20:08
ClassBotmhall119 asked: where can we get the code?20:09
rickspencer3it's in a junk branch20:09
* rickspencer3 gets20:09
rickspencer3https://code.edge.launchpad.net/~rick-rickspencer3/+junk/photobomb20:09
rickspencer3party on!20:09
rickspencer3I think it might be in my ppa too20:09
rickspencer3ok20:10
rickspencer3so following along to the next screen shot20:10
rickspencer3I added the ability to choose an image to stick in there20:10
rickspencer3and photobomb with that little squirrel20:11
rickspencer3It turned out to be tedious to write code to open an image file.20:11
rickspencer3So I added a prompt to quickly.widgets to handle opening files.20:11
rickspencer3Having your own library of reusable widgets is quite a luxury.20:11
rickspencer3if you look closely at the screenshot ...20:11
rickspencer3Note that I didn't know the gtk.FileChooser API that well, so made a couple of early mistakes, such as handling the existing file replace functionality myself.20:11
rickspencer3Didn't realize that the API could handle it20:11
rickspencer3but in any case, the shell of photobomb is PyGtk of course20:12
rickspencer3and I had to learn a bit about some areas of Gtk that I hadn't used too much20:12
rickspencer3any questions about that one?20:12
ClassBotmhall119 asked: Did you already know Glade before you started this?20:13
rickspencer3oh yes20:13
rickspencer3quite20:13
rickspencer3at first, you think Glade is your enemy20:13
rickspencer3but after a while, you learn it is our friend20:13
rickspencer3but Glade can be a bit hard to learn20:13
rickspencer3and it isn't designed to do everything20:14
rickspencer3so writing gtk.UIBuilder code is still part of hte process20:14
rickspencer3quickly makes this a bit easier, by giving each window a builder function20:14
rickspencer3I mean builder member20:14
rickspencer3so you can go:20:14
rickspencer3self.builder.get_object("hbox1").pack_start(my_widget)20:14
ClassBotmhall119 asked: does photobomb run on Karmic?  or just Lucid?20:15
rickspencer3well20:15
rickspencer3it's packaged for Lucid20:15
rickspencer3because it uses quickly-widgets20:15
rickspencer3which is in the quidgets project20:15
rickspencer3however, if you want to run it20:15
rickspencer3it shouldn't be too hard20:15
rickspencer3just branch photobomb20:15
rickspencer3then branch quidgets20:16
rickspencer3then stick quidgets/quickly dir in photobomb/photobomb, and it might work20:16
rickspencer3or just put quidgets somewhere on disk and set the python path when you run it20:17
rickspencer3!PYTHONPATH="~/quidgets/quickly" python photobomb/bin/photobomb20:17
rickspencer3for example20:17
ClassBotmhall119 asked: Any good tutorials on learning to make Glade my friend?20:17
rickspencer3mmm20:17
rickspencer3not really20:17
rickspencer3there are a bunch of tutorials20:18
rickspencer3but many are out of date, since PyGtk moved form LibGlade to UI Builder20:18
rickspencer3if you have Quickly installed, there is a bit in there to help you get started20:18
rickspencer3#ubuntu-app-devel is a good place to ask specific gladey questions20:18
rickspencer3unless it's about workign with a quickly template, in which case #quickly might be better20:19
rickspencer3ok20:19
rickspencer3so next section20:19
rickspencer3When I tried to implement some captioning and other features, I came to realize that PIL was just not designed for the kind of stuff I wanted to do with it.20:19
rickspencer3When I switched to GooCanvas, it became much easier to add features.20:19
rickspencer3I was able to add resizing, rotation, and drag to move in a matter of an hour or so.20:19
rickspencer3A couple of days later I fixed an issue with dragging rotated items that resulted from the craziness involved with items in goocanvas maintaining their own coordinate system seperate from the goocanvas they are in.20:20
rickspencer3questions about PIL, GooCanvas, or anything else so far?20:21
ClassBotmhall119 asked: it doesn't look like you did much with glade, do you find yourself doing most UI building directly in python?20:21
rickspencer3yes20:21
rickspencer3I genreally use glade to set up containers20:22
rickspencer3then I target those container from code20:22
rickspencer3especially for custom images and such'20:22
rickspencer3also, I use subclassing a lot20:22
rickspencer3and I haven't done much work to make my own widgets work within glade20:22
rickspencer3ok20:22
rickspencer3I could then go and the ability for users to use a pen tool in photobomb.20:22
rickspencer3This required managing mouse events and creating a PolyLine object from the collected mouse points.20:23
rickspencer3Later I found that a Path worked better than a PolyLine for creating the Ink. I still have not figured out how to add points to an existing Path.20:23
rickspencer3As a result, Photobomb recreates the Path with each mouse move. This gets slow if the Path is not short.20:23
rickspencer3I did a session on GooCanvas yesterday, but can take some quick questions on it today20:23
rickspencer3I used the gtk.ColorChooserDialog for color selection.20:24
rickspencer3I also added color button and ink width button.20:24
rickspencer3originally, These hosted a goocanvas, and I just added a path to each and set the properties of the Path to display the selected color and width.20:24
rickspencer3later I changed the color button to change it's background to show the correct color20:25
rickspencer3I mean, selected color20:25
rickspencer3there's a "color selection" button in Gtk, but it didn't quite suite my UI20:25
rickspencer3in terms of getting settings from users20:25
rickspencer3I had already created quickly.prompts to make it easy to collect a line width from the user. (quickly.prompts.integer()).20:25
rickspencer3I could handle this with a GooCanvas.Widget object embedded in situ, but that's a lot of work and using quickly.prompts.string() is a one-liner.20:26
rickspencer3questions so far?20:26
rickspencer3following along, the next thing I implemented was adding text to the goocanvas20:26
rickspencer3I added a gtk.STOCK_EDIT button to collect text from the user.20:26
rickspencer3well, that was just to manage the correct icon20:27
rickspencer3since i wanted buttons to be compact20:28
rickspencer3I used toolbar buttons, and just setting them to stock worked well20:28
rickspencer3later, I had to hack around some limitations to how "stock" works20:28
rickspencer3I used a quickly.prompts.string() to collect the string to display from the user.20:29
rickspencer3next I added the some feedback about the current selection20:29
rickspencer3To display selection, I simply used a GooCanvas.Rect with a bit of buffer around the selected object.20:29
rickspencer3I could have added stock selection points from gtk, but that sounded like a lot of work.20:30
rickspencer3questions so far?20:30
rickspencer3I added a bit of opacity to the selection box. This works better, as you can see what is behind the selected item20:32
rickspencer3Then I added opacity to other selectable items.20:32
rickspencer3I sniped some code from segphault's grabbersnap app to figure out how to set up rgba colors.20:32
rickspencer3It's a bit of a hack, but seems to work well.20:33
rickspencer3At this point in the project I also switched from having the user open individual images to add, to iterating through the Pictures directory and adding a button for each encountered image.20:33
rickspencer3I accomplished this asynchronously by putting this on a thread, using quickly.widgets.asynch_task_progressbox()20:33
rickspencer3This simplifies threaded coding a bit, but I am finding that threads + Python + PyGtk don't work out as well as I want, no matter how carefully I code it20:33
rickspencer3happy to take questions now if you've gottem'20:33
rickspencer3so moving on to the web cam feature20:34
rickspencer3Web Cam support is an important feature for Photobomb,20:34
rickspencer3but the available APIs looked daunting.20:34
rickspencer3That is, until I discovered that Pygame had a simplified web cam interface.20:35
rickspencer3I created a quickly.widget to handle web cam integration and added that widget to Photobomb.20:35
rickspencer3Note that this means quickly.widgets depends on PyGame.20:35
rickspencer3I think I shall move the webcam widget out of the default install and make it available in some other manner.20:35
rickspencer3Having another source of images meant that I needed to add a gtk.Notebook to handle switching between the two sources.20:35
rickspencer3I later went on to use icons for the notebook tabs, but labels worked fine when there were only 2 sources20:36
rickspencer3Questions so far?20:36
ClassBotw1nGNUtz asked: It seems some programs take too long to evolve. How could it be if you manage to do this so quickly?20:36
rickspencer3hmm20:36
rickspencer3interesting quetsion20:36
rickspencer3I guess I just did one new feature a night20:37
rickspencer3I refactored as I went20:37
rickspencer3to support adding new features20:37
rickspencer3this was a really fun project to work on20:37
rickspencer3so I don't know20:37
rickspencer3I guess PyGtk + GooCanvas are just really productive libraries20:37
ClassBottiteuf_87 asked: is there any reasons you went with pygame instead of gstreamer?20:38
rickspencer3for the simple reason that I discovered the PyGame api, and it looked like I could do it20:38
rickspencer3I would switch to gstreamer if I saw sample code that convinced me it would be easy to do20:38
rickspencer3I would love to break the PyGame dependency20:38
rickspencer3ok20:39
rickspencer3so Web image searching20:39
rickspencer3I added this next20:39
rickspencer3so you could search for a term, and then get back a list of related images20:39
rickspencer3I ended up using the Yahoo! image search api for this20:39
rickspencer3for the sole reason that the API was dead simple to use and well documented20:40
rickspencer3around this time, someone picked up another program I wrote, and added good support for extracting image urls from a web page20:40
rickspencer3so I sniped that code and made it so that if you entered a URL20:41
rickspencer3instead of doing an image search, it would scrape images from that page20:41
rickspencer3while I was at it, I also let the user type in a url directly to a photo and loaded that20:41
rickspencer3I think the web image search functionality is really fun to use20:41
rickspencer3like, "it would be funny if a picture of a cat were here"20:41
rickspencer3type "cats"20:42
rickspencer3and then you can get the cat, use the clipping tool, and drag it where you want20:42
rickspencer3I'll pause to see if there are questions now20:42
rickspencer3ok20:42
rickspencer3so the next major change I made was from toolbar buttons to normal buttons20:43
rickspencer3the motivation was this:20:43
rickspencer3Changing size, rotation, and opacity required the user to click the button once for each increment.20:43
rickspencer3So rotating something to be upside required the user to go "click click click click", etc...20:43
rickspencer3What I wanted was the user to click the button, and hold it down as the image rotated, and then to stop when it was positioned as desired.20:43
rickspencer3Sadly, there is no "key-down" event on gtk.Toolbars.20:43
rickspencer3well, gtk.ToolButtons, I mean20:43
rickspencer3So I had to switch Photobomb from using toolbars to using regular gtk.Button.20:43
rickspencer3I achieved the layout by using a gtk.Table20:44
rickspencer3I also created a new quickly.widget.PressAndHold widget to add press and hold functionality20:44
rickspencer3I accomplish the asynch behavior with gobject.timeout_add(250, self.__tick).20:44
rickspencer3At each tick the button emits a signal telling the consuming app to do something.20:44
rickspencer3Questions?20:44
ClassBotM49 asked: Does it check license metadata for pictures?20:45
rickspencer3nope20:45
rickspencer3that might be a nice feature to add though20:45
rickspencer3especially if this is something that concerns you20:45
rickspencer3but I don't think it's pertinent to the way I envisioned folks using photobomb20:46
rickspencer3basically, making funny pictures from themselves and their friends20:46
rickspencer3ok20:46
rickspencer3last section is on the Social Network Integration20:46
rickspencer3this was almost all achieved with Gwibber20:46
rickspencer3Because Gwibber uses desktopcouch to store messages in Lucid,20:46
rickspencer3 I could add the feature to grovel through the messages and extract images coming from social feeds to display.20:47
rickspencer3Of course, this will only work in Lucid ;)20:47
rickspencer3I also sniped Gwibber's fb credentials from desktopcouch, and used that and some FML to get images from Facebook.20:47
rickspencer3so your gwibber tab of the notebook loads up all the images in feeds you subscribe to, and also any images in facebook ...20:47
rickspencer3that are tagged with any of your friends so long as the image has been modified in the last 5 days20:48
rickspencer3I think this aspect of photobomb is really fun20:48
rickspencer3converging your personal feeds into an app that is designed to mash 'em all up20:48
rickspencer3I used the Gwibber API to add broadcasting Photobomb images.20:48
rickspencer3The GooCanvas renders a png that is saved to a temp location.20:49
rickspencer3Then pycurl uploads the image to imgur.com, which returns a url.20:49
rickspencer3Gwibber's GwibberPosterVBox to broadcast the URL.20:49
rickspencer3So that20:49
rickspencer3s the photobomb showcase20:49
rickspencer3I would love finish off photobomb sometime and let folks have fun with it20:49
rickspencer3but I've been a bit busy20:49
rickspencer3there are few bugs here and there, some of them quite annoying, as they involve frozen UI20:50
rickspencer3so, 10 minutes left20:50
rickspencer3happy to discuss anything now, answer any questions20:50
rickspencer3ok20:51
rickspencer3I'm going to call that a wrap, then20:51
rickspencer3thanks all for coming!20:51
rickspencer3and if anyone wants to contribute to photobomb in any way20:51
rickspencer3I am totally open to that'20:51
rickspencer3it's more fun working on these things together ;)20:51
=== 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

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