=== 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 || Current Session: NBS and how to keep the archive fresh - Instructor: persia || Questions in #ubuntu-classroom-chat === 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 === mohi_away is now known as mohi1 [16:58] dpm about set? [16:58] jono, ready to roll [16:58] you rock :) [16:59] #community rocks! [16:59] :) === 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 Opportunis tic Developer Week - Current Session: Hot rodding your app for translations support - David Planella - Instructor: dpm || Questions in #ubuntu-classroom-chat [17:00] hello everybody! [17:01] Welcome to today's first session of Ubuntu Opportunistic Developer Week [17:02] let's just wait a couple of minutes, to see that everyone gets here... [17:03] I should also remind you that today is a snippets day [17:03] of which you'll find all details here: https://wiki.ubuntu.com/PythonSnippets [17:04] There'll also be a snippets party in #ubuntu-app-devel later, so be sure to join the fun! [17:04] Anyway, without further ado... [17:04] [SLIDE 1] [17:05] Welcome to this session on Hot rodding your application for translations support [17:06] In the next hour we'll talk on how to get your app ready to speak a multitude of languages [17:06] and set up so that our awesome translation teams can do their work [17:06] For those who are not using Lernid, here's a direct link to the slides in this session: http://people.ubuntu.com/~dpm/Quickly-i18n.pdf [17:07] This talk will be based on quickly as the framework to opportunistically create your application in no time [17:08] parts of the talk were contributed by didrocks, Didier Roche, who's the main quickly developer [17:08] Let's start having a quick look at the main players involved in the internationalization game: [17:09] [SLIDE 2] [17:09] == GNU Gettext == [17:09] Gettext is the underlying and most widely used technology to enable translations of Open Source projects. [17:09] It defines a standard format of translation files translators can do their work with (PO files) [17:09] and lets applications load those translations compiled in a binary format (MO files) at runtime. [17:10] It has implementations for many programming languages, and amongst them, of course, Python. [17:10] You'll find that the comprehensive gettext manual at http://www.gnu.org/software/gettext/manual/gettext.html can be a very useful reference, [17:10] The Python implementation of the gettext API is what we'll use to internationalize our project with Quickly today. [17:11] Needless to say, it also comes with some nifty documentation at http://docs.python.org/library/gettext.html [17:11] == intltool == [17:11] Intltool is a higher level tool that adds functionality to gettext by allowing the extraction of translatable strings from a variety of file formats [17:11] It has also become a standard tool when implementing internationalization for OSS projects. Nearly all (if not all) GNOME projects, for example, use intltool. [17:12] == python-distutils-extra == [17:12] Python-distutils-extra is a python package that makes it easy to integrate themable icons, documentation and gettext based translations in your python install and build tools, and it's basically an enhancement to python-distutils. [17:12] The project's page is at http://www.glatzor.de/projects/python-distutils-extra/ [17:12] The three above technologies (gettext, intltool, python-distutils-extra) are transparently used by quickly, so we won't get into much more detail for now. [17:13] There are also more aspects involved in internationalizing applications, such as font rendering, input methods, etc., but this should get you started for now. [17:13] == Quickly == [17:14] I'll be very brief here and let you figure out more on quickly as we go along [17:14] For now, it will suffice give you a teaser and tell you that it is the tool which brings back the fun in writing applications! [17:14] == Launchpad Translations == [17:15] Launchpad Translations ( https://translations.launchpad.net/ ) is the collaborative online tool which allows translation communities to be brought together and translate applications online through its web UI. [17:15] Apart from the very polished UI to provide translations, it has other nice features such as message sharing across project series (translate one message in a series and it instantly propagates to all other shared series), [17:15] global suggestions (suggestions of translations across _all_ projects in Launchpad), automatic imports of translations and automatic commits to bzr branches, several levels of permissions, and a huge translator base. [17:16] On the right hand side of the URL I gave you you can see that there are quite a lot of projects using Launchpad to make translations easy both for developers and translators. [17:16] Ok, enough theory, let's have a go at using quickly to create your first internationalized application [17:17] You can install Quickly on Karmic or Lucid simply by executing 'sudo apt-get install quickly' [17:18] or if you are brave, you can try the trunk version (bzr branch lp:quickly) [17:18] let's focus on the stable version, though [17:19] [SLIDE 3] [17:19] You should see an overview of quickly here [17:20] Quickly has two parts: the core, which basically parses your input and templates. [17:20] Templates are sets of commands and code generators that are designed to work together in an end to end fashion to help developers write a certain kind of application. [17:21] with templates, you can then create application or document set. [17:21] We'll focus there only on i18n with the first template that Quickly 0.2 provides: ubuntu-project (renamed ubuntu-application on the coming 0.4 release!) [17:21] (this template is using Glade, couchdb, has some nice trick for gedit, use bzr, and complete integration with LaunchPad and debian packaging) [17:22] For instance, Lernid that some of you may be using, was created with the ubuntu-project template. (http://www.jonobacon.org/?p=2258 for a shot of the story) [17:22] [SLIDE 4] [17:22] So, let's create first a simple ubuntu-project (assuming you are using Quickly 0.2, the stable version): [17:22] You can run this: [17:22] quickly create ubuntu-project fooby [17:23] this tells Quickly to use the ubuntu-project template, and to call what is created "fooby" [17:23] This causes a bunch of info to be dumped to the command line, but ends with the application being run [17:23] What Quickly did was to copy over basically a sample application, and do some text switcheroos to customize the app [17:23] You can see there the ui which contains some text that needs translation. [17:23] To start making change to your app, cd to it (normally, [17:24] cd fooby [17:24] You can then edit your code with $ quickly edit, change the UI with $ quickly glade, and try your changes with $ quickly run [17:24] You can save your change with $ quickly save [17:24] changes [17:25] Finally, to package, share, release your apps so that other will be, with the following commands (not all are necessary): $ quickly package / $ quickly share / $ quickly release [17:25] I won't cover in any more detail Quickly or the ubuntu-project template here (quickly help does this for you), [17:26] you can find more info at: https://wiki.ubuntu.com/MeetingLogs/devweek0909/QuicklyFun [17:26] Let's see what you can do in "quickly edit" and "quickly glade": adding internalization support to your app [17:26] As the project stands now, it has the infrastructure for internationalization in place, but we have to initialize it to enable it. [17:27] This will include: [17:27] * Initializing gettext [17:27] * Marking strings for translation [17:27] * Updating the translation template [17:28] [SLIDE 5] [17:28] First of all, we'll initialize gettext, which will basically be adding four lines of code. Here's how it goes: [17:28] quickly edit [17:28] This will open all your project files in a text editor (Gedit by default) [17:28] 1. Go to the fooby file and add the following two lines below 'import gtk', near the top of the file: [17:28] import gettext [17:28] import locale [17:29] This will import the required modules for internationalization [17:29] 2. Still on the fooby file, add the following line below the 'import logging, optparse' one, near the end of the file: [17:29] gettext.install('fooby', unicode=True) [17:29] This will install the _() function to mark (and call) translations as such in Python's builtins namespace, based on the 'fooby' domain. The domain basically tells gettext where to load translations from. [17:30] This will also save you to include 'import gettext' statements in all of your project files using gettext. This will do for your first application [17:30] Refer to the gettext documentation to find out more about translation domains. [17:30] 3. Finally, add the following line to 'fooby', before the 'builder = gtk.Builder()' line [17:30] locale.textdomain('fooby') [17:30] This will tell GtkBuilder about the translation domain as well [17:31] So that was it! Let's move on to marking strings for translation: [17:31] First of all we'll tackle the .destop file [17:31] Open the fooby.desktop.in file and prepend the Name and comment fields with an underscore (_), so they look like: [17:31] _Name=Fooby [17:31] _Comment=Fooby application [17:32] This will tell intltool that this strings contain translations [17:32] Next comes the UI. Let's see how you can mark strings in the UI for translation. Try: [17:32] quickly glade [17:32] This will open your UI files in the glade editor. [17:32] Once opened, click on the "Your application has been created! ..." label, find it in the General > Label field on the right, click on the ellipsis (the three dots) button and... [17:33] amaze at the fact that it has already been marked as "Translatable", so you won't have to do anything. [17:33] Right, so next comes something very important that you'll have to bear in mind for all strings you'd like to be translatable in your application: [17:33] * using the _() function call. [17:33] This will mark them as translatable and call gettext to load the translations, and should be used for all messages you'd like to present to users. [17:34] Let's just see how we can do this. [17:34] Go back to your fooby file and find the "parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Show debug messages")" line near the bottom. [17:34] We want the "Show debug messages" message to get shown to users in their language, so we'll enclose it with the _() function, and it will look like: [17:34] parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help=_("Show debug messages")) [17:35] Now we're done [17:35] The last part will be to update the translations template. [17:35] A translations template is a formatted text file generally named yourproject.pot [17:35] which contains your project's translatable strings in English and is what translators use as a basis for their translations. [17:36] You should do this at least before each release, so that translations are put in this template and are up-to-date for translators to work on. [17:36] It is considered good practice to announce a string freeze (that is, the period in which strings are considered to be stable) a week or two before the release, so that translators know when they can start their work. [17:36] This can be done in several ways with quickly, let's pick one: [17:36] quickly package [17:37] After running this, you'll notice that (apart from having your application packaged!) there is a 'po' folder containing the translation template, ready for translators to work on. [17:37] If you open it, you'll notice the format and will see that all the strings you marked for translation are there. [17:37] You can also do this with 'quickly share', 'quickly release' or directly using the python-distutils-extra command: './setup.py build_i18n' [17:37] == Launchpad Translations == [17:38] If this weren't awesome enough, once you've created a project in Launchpad ('quickly share', 'quickly release' or https://help.launchpad.net/ will help you on that) you can expose it for the world to translate [17:38] so that you as a developer can use the automatic bzr import/export features to basically "forget" about translations and translators can use the web UI to translate. [17:39] Let me tell you a bit more on those: [17:39] [SLIDE 6] [17:39] == Automatic imports == [17:39] Enabling this feature will allow you to automatically import the translation template for your application into Launchpad upon commit, with no further steps required. [17:39] So the basic workflow will be: hack, hack, hack, update template, commit, have translators automagically see the new strings in Launchpad. [17:40] You can find more about this at http://blog.launchpad.net/translations/import-translation-templates-from-your-projects-bazaar-branches and http://blog.launchpad.net/general/trying-out-launchpad-translations [17:40] or at http://blog.launchpad.net/translations/screencast-importing-translation-templates-from-a-bazaar-branch [17:40] == Automatic exports == [17:41] With automatic exports, you'll be able to complete the whole circle for automation: getting translations committed automatically (daily) to a bzr branch of your choice, so that neither you nor translators have to worry to get translations into your project. [17:41] I personally find this one of the most coolest features [17:41] Here's more info: http://blog.launchpad.net/general/exporting-translations-to-a-bazaar-branch [17:41] And here's a screencast on how to enable it http://blog.launchpad.net/translations/screencast-exporting-translations-to-a-bazaar-branch [17:42] == Permissions == [17:42] One very important aspect is how you want translations permissions for your project to be. This basically means choosing who will be responsible for submitting and reviewing those [17:42] translations for each language. [17:42] Launchpad is flexible in allowing different levels of openness for translating your project. [17:43] This generally means that you as a maintainer will have to make a decision to balance openness (open translations for everyone) with quality control (a more closed process with reviewers and a QA workflow). [17:43] The Launchpad help page on permissions at https://help.launchpad.net/Translations/YourProject/PermissionPolicies explains very well the different permissions you can use (Open, Structured, Restricted and Closed). [17:43] If you decide for quality, you'll next have to choose to whom you assign the translation of your project. [17:43] Here is where translation groups come to the rescue. [17:44] Translation groups are confederations of translation teams, one for each language you can assign as a pack to translate your project. [17:44] The teams in those groups are considered to be trusted to have experience with translations and generally have a review process in place. [17:44] Here's a list of all current translation groups: https://translations.launchpad.net/+groups [17:44] You can see that the two biggest ones are Launchpad Translators and Ubuntu Translators. [17:45] While you can create a translation group specific to your project, we generally encourage maintainers to choose one of the existing ones, [17:45] in order to reuse the pool of translators and not to further fragment translations communities. [17:45] I personally recommend choosing Restricted (or Structured), assigned to the trusted Launchpad Translators or Ubuntu Translators (if your project is Ubuntu-specific) translations groups [17:45] [SLIDE 7] [17:46] I'll rapidly go through quickly's incoming features and then we can do some Q&A [17:46] Quickly 0.4 will bring a lot of new experiences and commodities to the users (more than 200 commits, 6 months of hard work!) and will be delivered in Lucid. [17:47] Regarding internationalization, all the tedious job of importing/initalizing gettext and adding _() will be done for you in all newly created apps. [17:47] "$ quickly add pythonfile" will also add one boiler plate file containing that for you. [17:47] Quickly 0.6 later on will try to achieve the automatic imports and exports previously described on each $ quickly share / $ quickly release command. [17:48] So, normally, you won't have to bother anymore about localization and being in sync with the awesome work of your contributors [17:48] just mark strings with _() [17:48] So that was it! [17:48] Questions? [17:51] QUESTION: How does one get the translation files for each language from the .pot file? [17:51] That's usually the work of translators [17:51] when you've committed the .pot file to your bzr branch, and it is exposed in Launchpad with automatic imports [17:52] translators will see the translatable strings in Launchpad and start doing their work [17:53] if you've got automatic exports activated, the PO files will be created for you whenever there is a new translation, and committed to your branch of choice [17:53] So, in short, as a maintainer this will happen automagically for you :) [17:54] keep them coming :) [17:55] O I see, gnunerz is asking: [17:55] QUESTION: I get that... I'm just curious as to how does the manual process goes :) [17:56] if you were not using Launchpad, you'd announce that there is a new POT file available, and translators would fetch it, create a PO file containing the translation for their language, and would send it back to you [17:56] The same process: translators always take care of translations, but with a bit more manual work for all people involved [17:57] So, in shourt, I'd recommend using Launchpad and automatic import/export [17:57] QUESTION: It is possible to define which languages I want my app be translated to? [17:58] No, in general you want your application to be available in as many languages as possible, and Launchpad allows translating in almost any language [17:58] You might be able to limit which translations are build in your project's build infrastructure [17:59] But you'll have to explicitly set it up to use just some of the translations [17:59] QUESTION: Does this process also take care of locale stuff, like how is the date presented to the users? [17:59] in general, yes [18:00] but we'd need another session to go into the details :) [18:00] basically, the app must set up the locale settings right on initialization === 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: Learning through examples with Acire and Python-Snippets - Jono Bac - Instructor: jono || Questions in #ubuntu-classroom-chat [18:01] :) [18:01] alrighty [18:01] thanks dpm [18:01] isn't that man such a freaking rock star?! [18:01] everyone needs to give him a hug in #ubuntu-classroom-chat :) [18:01] * jono hugs dpm [18:01] hi everyone and welcome to the python snippets session at Ubuntu Opportunistic Developer Week! [18:02] how are we all doing today? [18:02] the focus of this session is some work I have been doing recently around building a library of python snippets and (a) how this library can be useful for you as an opportunistic developer, but also (b) how you contribute to it to make it an even better resource! [18:03] so, let's get started [18:03] I have always been the kind of person who learns via examples [18:03] when I started learning the guitar, I learned by watching other guitarists play, and when I started learning Python and how to build apps on Ubuntu, I have always learned by hunting out little source code examples that do what I need to do and then learning from them and merging them into my programs [18:04] the problem is that these snippets were scattered all over the Internet and sometimes pretty hard to find [18:04] my dream was to have a program that would bring these snippets together into a library so that I could select them, run them and learn from them [18:05] well, on a flight home from England at Christmas, armed with those small bags of peanuts and a few gin and tonics, I decided to write this little program and it is called Acire, named after my wife's name backwards (Erica) [18:05] Acire is a really simple program that provides an interface to this library of snippets [18:06] let's look at how it works [18:06] check out http://farm5.static.flickr.com/4045/4406908674_2934c4d5c0_o.jpg [18:06] this is a screenshot of the main Acire interface [18:06] in the top-left part of the window there is a drop-down combo box that lists a series of categories of different snippets [18:07] when you select a category, the list of snippets that are in that category are listed below [18:07] in the screenshot you can see the list of snippets that are in the Python Core category: that is, snippets that demonstrate features in the main Python language [18:07] to see a snippet you just click on it and it appears in the code view to the right, all nicely syntax highlighted so you can read it easily :-) [18:08] running the snippet is simple, just click on the Execute button [18:08] how come i don't have python core in my acire ? [18:09] we had a few out of date python-snippets packages - you might have an old package [18:09] embedded in the window is a little terminal view: this is important for snippets that don't have a GUI (such as the Python Core snippets) - if you select a GUI snippet the window will appear when you click the Execute button [18:09] running the snippet gives you a good chance to play with it and see how it works and then take a look at the snippet code in the window [18:10] another feature is that you can edit the snippet code and when you hit Execute it will run your modified program too: this makes it really easy to play with the snippet inside Acire itself - you can then click the Save As button and save the code somewhere else if you like [18:10] we already have a bunch of snippets in Acire: 104 right now (as you can see in the status bar) [18:11] here is the current list of categories [18:11] http://farm5.static.flickr.com/4050/4406908744_d75cbac80f_o.jpg [18:11] if you are curious what my wallpaper is, it is the most awesome duck ever - http://www.flickr.com/photos/w9ned/3563985252/sizes/l/in/pool-1058695 :-) [18:12] anyway, back to the screenshot: http://farm5.static.flickr.com/4050/4406908744_d75cbac80f_o.jpg [18:12] as you can see, it is pretty cool: it provides a really nice resource for looking at a bunch of python examples and it helps you to learn quickly and easily and solve problems right away [18:13] let me now explain how to get it [18:13] I have deliberately split the actual python snippets from the graphical interface - this was because many people may want to produce viewers for the snippets (e.g. a KDE version, a web interface etc) so I did not want to depend on the GUI [18:13] as such, we have two projects: [18:14] acire - the graphical interface to the snippets available at http://www.launchpad.net/acire [18:14] python-snippets - the library of snippets available at http://www.launchpad.net/python-snippets [18:14] the first thing we want to grab are the snippets [18:15] part of my goal here is to make sure that the library of snippets is regularly updated as more snippets are made available [18:15] how can i get the latest version of acire? [18:15] I will explain in just a moment :) [18:15] fortunately, we have an awesome technology for doing this - Personal Package Archives (PPA) - a place in which you can subscribe to a package and you get regular updates [18:16] is acire going to be available in Lucid? [18:16] it runs on Lucid now :) [18:16] so, we have a PPA that generates a daily package of the latest python-snippets library [18:17] ryanprior, nope, what was it? [18:17] QUESTION: can we add snippets in languages other than Python? === yofel_ is now known as yofell [18:17] no, Acire and python-snippets is focused on Python [18:18] although I would love to see other languages have a similar project :) [18:18] so, we have a PPA that generates a daily package of the latest python-snippets library [18:18] adding the PPA is simple, just click Applications -> Accessories -> Terminal and add these commands: [18:18] sudo add-apt-repository ppa:python-snippets-drivers/python-snippets-daily [18:18] sudo apt-get update [18:18] sudo apt-get install python-snippets [18:19] this will add the snippets to /usr/share/python-snippets [18:19] you now need to install Acire to view them [18:19] we also have a PPA for this too [18:20] I recently kicked out a new release, but I haven't had a chance to provide a Karmic package yet, so the new release is just in Lucid right now - the PPA still has the older release though, so this still works [18:20] just follow these steps: [18:20] click Applications -> Accessories -> Terminal (or use the Terminal in Lernid!) and add these commands: [18:20] sudo add-apt-repository ppa:acire-team/acire-releases [18:20] sudo apt-get update [18:20] sudo apt-get install acire [18:21] all of the instructions for doing this are on https://wiki.ubuntu.com/PythonSnippets [18:21] ok, so let's now get to the question about running the latest bleeding edge Acire [18:21] some of you may want to grab the latest code for Acire and run it - this is also really simple, just follow these commands: [18:22] click Applications -> Accessories -> Terminal (or use the Terminal in Lernid!) and add these commands: [18:22] first install all the packages requires to run it: [18:22] sudo apt-get install bzr python-desktopcouch-records python-gconf python-gtk2 python-gtksourceview2 python-vte quickly [18:22] this will grab everything you need [18:22] it may take a little while to grab everything, but not too long :) [18:23] :'( no amd64 [18:23] yeah, but the 32-bit version should run I imagine [18:23] or you can follow these instructions [18:23] ok [18:23] first install all the packages requires to run it: [18:23] sudo apt-get install bzr python-desktopcouch-records python-gconf python-gtk2 python-gtksourceview2 python-vte quickly [18:23] next, let's grab the code [18:23] again, this is really simple thanks our pal, bzr: [18:23] just type in: [18:23] bzr branch lp:acire [18:24] this will grab the latest acire code from Launchpad [18:24] when it has got the code, now enter the directory: [18:24] cd acire [18:24] and then run it: [18:24] quickly run [18:25] A few broken dependencies in Karmic :( [18:25] yeah we had a few issues with dependencies, but you can solve them by making sure you run this line: [18:25] sudo apt-get install bzr python-desktopcouch-records python-gconf python-gtk2 python-gtksourceview2 python-vte quickly [18:25] that will get everything you need [18:25] and you obviously need to ensure the python-snippets PPA is installed, as I described above [18:25] :) [18:26] this will then get you up and running :) [18:26] awesome to see you folks getting it up and running :) [18:26] now, today is an exciting day as we are really keen to encourage you folks to join us in making a bunch of python snippets today to add to the library [18:27] this resource is only as useful as the snippets inside it, so I am really keen to crowdsource this and have any many people as possible join in and contribute snippets [18:27] right now we have 104 snippets [18:27] my dream for today is that we hit the 150 mark :) [18:27] you folks interested in helping? [18:27] interesting in helping to make this rock? [18:27] :) [18:27] we welcome snippets on *any* python module [18:28] so if you can do *something* in python, you could write a snippet [18:28] whether it is as simple as doing something to a list or using a module such as feedparser [18:28] QUESTION: should snippets for a given package (like PyGTK for example) live in python-snippets, or in pythin-gtk2-doc, or where? [18:29] great question ryanprior [18:29] let me explain how the snippets are organized [18:30] ok [18:30] take a look at http://bazaar.launchpad.net/~jonobacon/python-snippets/trunk/files [18:30] this is a list of the content in the main python-snippets archive right now [18:30] as you can see, there are a bunch of directories [18:31] each directory refers to a particular python module [18:31] as an example, the gstreamer dir has snippets that use the GStreamer multimedia framework [18:32] This seems like a great opportunity for upstream involvement. We can help people with their documentation. [18:32] exactly! :) [18:32] inside each dir lives the snippets [18:32] so if we click on the gwibber dir: [18:32] http://bazaar.launchpad.net/~jonobacon/python-snippets/trunk/files/head:/gwibber/ [18:32] there is one snippet [18:33] gwibber is a python module that ships in Lucid that allows you to microblog right from your app [18:33] so the snippet we have is sendmessage.py [18:33] you can see it at http://bazaar.launchpad.net/~jonobacon/python-snippets/trunk/annotate/head:/gwibber/sendmessage.py [18:33] and that explains how in just a few lines of Python you can tweet, dent, Facebook etc [18:34] so in a nutshell the library of snippets is in /usr/share/python-snippets and in there are subdirs, each of which refers to a python module, and the snippets about that module live in there [18:34] so let me explain how a snippet is mad [18:34] made [18:35] a snippet is just a piece of code that demonstrates something [18:35] but what allows us to categorize and show it in Acire are some comments at the top [18:35] let's use http://bazaar.launchpad.net/~jonobacon/python-snippets/trunk/annotate/head:/gwibber/sendmessage.py as an examoke [18:35] example [18:35] the comments with 'SNIPPET' in them are what Acire uses for index and show them [18:35] here are the different lines: [18:35] [SNIPPET_NAME: Send a message] [18:36] this is the text that appears in the sidebar when you have select a snippet category [18:36] a short, sharp description of the snippet [18:36] [SNIPPET_CATEGORIES: Gwibber] [18:36] this is a tag for the snippet [18:36] this is the category that appears in the drop-down box [18:37] snippets can have multiple categories separated by commas if needed [18:37] we have a main list of categories in the CATEGORIES file in the main /usr/share/python-snippets dir [18:37] [SNIPPET_DESCRIPTION: Send a message using the Gwibber API] [18:37] this is the description that appears under the code - a longer description of what the snippet does [18:38] [SNIPPET_AUTHOR: Jono Bacon ] [18:38] this is who wrote it with their email address [18:38] [SNIPPET_LICENSE: GPL] [18:38] and this is the license [18:38] again, a standard set of licenses are in the LICENSES file in /usr/share/python-snippets [18:38] I am happy to accept snippets into the library so long as they use a recognized free software license [18:39] so created a snippet is simple: [18:39] 1. pick which dir it should be in (or create a new one if your snippet is the first for a given python module) [18:39] 2. write the snippet [18:39] 3. include these comments at the top [18:39] 4. submit it :) [18:40] submitting a snippet is explained on https://wiki.ubuntu.com/PythonSnippets [18:40] so today we are having a snippets part [18:40] party [18:41] this is a session in #ubuntu-app-devel where I am encouraging folks to submit snippets for inclusion :) [18:41] so this is a great opportunity to join and get involved and share your knowledge [18:41] the snippets party takes place at 9pm UTC [18:42] and will go on for a few hours, so do come along and join us - it is really cool seeing a snippet that you made show up in the library for everyone to learn from [18:42] do you folks want me to explain how you contribute a snippet? [18:43] ok cool :) [18:43] so first run: [18:43] bzr branch lp:python-snippets [18:43] this will grab the python-snippets library [18:43] now go in and add your snippet [18:43] you can add it to an existing directory in there if the snippet is about one of those topics [18:44] or feel free to create a new dir for a python module that is not covered in the library yet [18:44] when you create your snippet make sure you have the comments at the top of the file [18:44] e.g: [18:44] # [SNIPPET_NAME: Playing a Pipeline] [18:44] # [SNIPPET_CATEGORIES: GStreamer] [18:44] # [SNIPPET_DESCRIPTION: Construct and play a pipeline] [18:44] # [SNIPPET_AUTHOR: Jono Bacon ] [18:44] # [SNIPPET_LICENSE: GPL] [18:44] i'm seriously learning a lot this week. contributing as a developer actually seems possible now. [18:44] that is awesome! :D [18:45] when you have added your snippet, add it to the local library with: [18:45] bzr add your-snippet.py [18:45] obviously replace your-snippet.py with the filename for your snippet [18:45] now commit your changes: [18:45] bzr commit [18:46] when you run the above command you can enter a short message about what your snippet does [18:46] now you need to upload the snippet to Launchpad: [18:46] bzr push lp:~/python-snippets/ [18:46] so an example if I was to upload this I might use the following command: [18:46] bzr push lp:~jonobacon/python-snippets/new-gstreamer-snippet [18:47] finally, go to https://code.launchpad.net/python-snippets and you should see your branch listed there. Click on it and when the branch page information page loads click on the Propose for merging link. Add a short description of what you examples do in the Initial Comment box and then click the Propose Merge button. [18:48] QUESTION: is it possible to run acire and make it look in that directory for snippets instead of the default one? [18:48] right now, no, but I am adding a feature to do that [18:49] what you can do is set up a symbolic link from /usr/share/python-snippets to wherever you checked out the python-snippets code [18:49] QUESTION: Can we use Ground Control to submit a new snippet? [18:49] absolutely! [18:50] so what I recommend you folks do is check out the python-snippets library, add a snippet and submit it and I can test if it works in Acire [18:50] meanwhile I will get as feature into Acire to point it at another directory so it is easier to test it [18:51] so we have our snippets party at 9pm UTC, that is two hours away - I recommend you all come along to #ubuntu-app-devel and join us and I can help you get started writing snippets :) [18:51] any more questions? [18:52] How about adding snippets as design patterns or algorithms? [18:52] absolutely! we have a Patterns dir for design patterns [18:52] I would love an algorithms dir too [18:52] I am keen to ensure that *all* python snippets are welcome [18:52] if they run and they explain how to do something, I will make sure we add it :) [18:53] any more questions? [18:53] QUESTION: if I run a snippet in Acire and it crashes, does that bring Acire down too? [18:53] usually no [18:54] if it does crash Acire, that is a bug and we need to fix it :) [18:54] QUESTION: As Acire grows, how about adding some Search/Sort functions? [18:55] I am really keen to add that too [18:55] if someone wants to write a patch for this, do go ahead [18:55] I think Acire needs a search facility and a find facility for search snippets [18:55] QUESTION: how do contributors handle python versioning idiosyncacies (e.g., 2.5 functions versus 3.x)? [18:56] snippets that need to care about Python versions typically do a test in the code [18:56] there are a few snippets that have examples of this [18:56] awesome [18:56] I think we are done [18:56] thanks everyone for joining me here! [18:57] and I hope to see you all in #ubuntu-app-devel in two hours for the snippets party! [19:00] rockstar, all good? === 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: Write Beautiful Code (and Maintain it Beautifully) - rockstar - Instructor: rockstar || Questions in #ubuntu-classroom-chat === Goomba is now known as Guest41661 [19:01] jono, starting now? [19:01] jono, starting now? [19:01] yep :) [19:02] Hi folks. Apologies in advance for the Lernid users, but I'm not really a slide guy, so you'll just have to follow along. [19:03] So, dholbach asked me if I'd be willing to talk about writing beautiful code. [19:03] That puts me in a hard spot, since sometimes I write code that fell out of the ugly tree and hit every branch on the way dawn. [19:04] As I thought about it though, beautiful code is a process. It's iterative, and the things you find beautiful now will (probably) be ugly to you in a year. === yofell is now known as yofel [19:05] So I began thinking about that process - this is what I'd like to chat about today. [19:06] Since this is opportunistic developer week, I want to make this a story about opportunities. [19:08] The scenario I'd like to start with is this: [19:08] "You've been using Ubuntu and you're feeling very comfortable. You're in an IRC channel when someone says 'It would be nice if I had an app that would...'" [19:08] Uh oh. There's not an app for that. [19:09] But guess what? You're an opportunistic developer! This is an opportunity! [19:09] QUESTION: will you be going over some tips for making ugly code better? :) [19:10] ANSWER: Yes, as I said, making ugly code better is a process. The process is the core of this talk. [19:10] So, we're going to start a new project. In this scenario, staying away from ugly code is easy, since there's no ugly code to begin with. [19:11] When you start a new project, you should get a few things together. First, you need some version control system (Renaming files to .bak doesn't count) [19:12] You also should have an issue tracker, even if you haven't even released your code. This may be as simple as a TODO file. [19:12] Luckily, we have Launchpad. Those Launchpad developers are awesome. They do awesome things. [19:13] You'll also want a style guide. [19:14] Programmers have stolen the idea of a style guide from writers and journalists. A style guide allows you to set some social contracts in how your code is structured. [19:15] This is a must. If you don't have this right now in your project, your homework is to go out and establish one. [19:15] Everyone has different tendencies in their code, so code can get messy as soon as more than one person touches it. [19:15] QUESTION: I assume when you say style guide you mean the same thing as "coding standards"? [19:16] Yes, same idea. You should have common idioms. [19:16] Document this well. It makes life much better when contributors come aboard. [19:16] QUESTION: QUESTION: are there any good sample style guides to start with? [19:17] Python (my favoritest most bestedest language) has a language-wide style guide. [19:17] It's called PEP 8. [19:17] http://www.python.org/dev/peps/pep-0008/ [19:18] Basically, it addresses where to put comments, how to name variables/classes/"constants"/functions/etc [19:18] \sh kindly points out https://dev.launchpad.net/StyleGuides [19:19] So, on the Launchpad team, there is a style guide that supplements PEP 8, and then we have a style guide for our javascript, etc. [19:20] I don't personally like some of the standard styles in the Launchpad team. If I wanted, I could violate those styles, but then no one would approve the code review, and I'd never get anything done. [19:20] The "social contract" basically allows us all to come to the table with the same expectations for the quality of code. That's what the style guide gives us. [19:21] QUESTION: Kinda offtopic but is there a reason why space indentation is preferred to tab indentation in PEP 8? [19:21] somename, the BDFL of Python has spoken. [19:22] That question is actually quite on-topic. Sometimes there's no other reason to have the rule than to just have a standard rule. You can't have both, so there as a choice made. [19:22] So put together your style guides. They won't be set in stone. In fact, they'll be quite fluid. [19:23] The Launchpad team meets once a week to evaluate if style changes are needed. [19:23] Just yesterday I proposed a change in style and everyone agreed. [19:23] QUESTION: When there is a small bug that needs to be fixed real quick, I violate all the style guides and fix it as fast as I can. Does anybody have the same problem as me? [19:24] I guess I don't know the specific situation, and sometimes you need to do some hacky things to get bugs fixed. Your style guide shouldn't get in the way of your work. [19:25] However, when you violate the guide, you're automatically making your code harder to read for others. [19:25] This actually brings me to my next point (thanks for the easy segway). [19:25] In whatever language you're working with, the code you write is not for the computer. [19:26] The computer is going to take that code, translate it into something it understands, and then run it. [19:26] The code you write is for humans like you and me. [19:27] Remember that when you're writing the code. Keep it in mind. Read your code out loud. [19:27] C-code, for me, is especially difficult to read aloud, but it helps me to see where something doesn't make sense. [19:28] Since most documentation standards target US or UK English, your code should kinda make sense that way as well. [19:29] Sometimes (as in the case of asychronous code) you won't be able to write your code left-to-right/top-to-bottom [19:30] Use comments in those cases. [19:31] Alright. We have about 20 minutes left. In about 10, I'd like to take and review some "ugly code" that some of you would like to submit. Please pastebin your examples of "ugly code" and then post them in the chat [19:32] Okay. So let's look at another situation, one that is more common, and will probably help you to be better when you actually start projects. [19:32] You're in IRC, and someone says " is really cool, but it has a problem with " [19:33] Opportunity awaits! [19:33] Often, this is where I see "ugly" code, because it's not my code, and it's not in a style I understand immediately. [19:34] If the project has a style guide, read it before sleuthing to fix the problem. [19:34] If it doesn't, Thor help you. :) [19:35] After you're comfortable with reading the app's code (whether by style guide or fumbling around), find the code you want to work in. [19:35] As you write your feature, explore the idea of writing a test for that feature. [19:36] Many languages have great test frameworks that you can use. [19:37] Testing helps you to avoid embarrassment when (not if) your feature breaks. [19:37] Make sure, as you write your patch, that you're sticking with common coding conventions. [19:38] When I say "common" I mean "common the surrounding source code" - Make the code consistent. [19:38] Once you have your patch (and hopefully test), you're ready to show someone your code. [19:39] This step is the most important. [19:39] You're more likely to write ugly code when no one has to see it, and when you don't have to justify why it's ugly. [19:40] I had a friend who worked as an intern on a proprietary mobile phone platform that said "You would hate this source. It's terrible, because no one has to see it." [19:41] Okay, so we submit our code for review. [19:41] Does anyone want to pastebin their ugly code? [19:42] QUESTION: Question first: Are there any Python style (say PEP 8) checkers? [19:42] Yes. On Launchpad, we use pylint (slow, annoying) and pyflakes (doesn't handle exceptions to the rule well) [19:43] For javascript (my second favoritest language) jslint is what I use. [19:44] Let's look at the "ugly code" here: http://pastebin.com/1jWRpKCG [19:44] Thanks to theDtTvB2`MB for putting himself out there. That's good. [19:45] Okay, so this javascript code. [19:45] Javascript is notorious for being a wild west "every man for himself" language. It's easy to write messy code, it's easy to write code that leaks memory. [19:46] So as a reviewer, I'm first going to ask what "r" on line 4 is. [19:46] "r" doesn't tell me anything about the variable, what it contains, or what it's used for. [19:46] Neither does "c" or "is_DM" [19:47] That makes this code hard to follow. [19:49] I also don't have very many comments. [19:49] Line 53 is actually succinct and rather helpful. [19:50] Basically, are we starting with the first item in the index? [19:52] I also am not entirely clear on what the function returns. It returns a few different things, depending on specific conditions. A comment at the top of the function would go miles in helping understand what's going on. [19:52] I rather like jsdoc, and having been using it in my javascript gaming engine I've been working on. [19:53] By documenting, you help other young developers to start off knowing what the function is doing, and then they can use that context as they read the code. [19:53] And now I starting to forget what some of these line do. [19:53] theDtTvB2`MB, this is why we strive to write beautiful code. [19:54] :) [19:54] Any other questions? [19:54] Let me point out a potential opportunity here: Does Lernid have a search feature in the Session window? That would help to jump to code. [19:55] QUESTION: Does it need a rewrite? [19:55] So, rewrites can be scary, especially when you don't have tests (and sometimes even when you do). [19:56] Usually, when I get into code I wrote that I have forgotten about, I will take some time to sleuth the code, remind myself, and then document the code, and sometimes make slight changes (variable names, etc.) [19:56] Sometimes code is unsalvagable, and you'll have to re-write it, but just be careful there. You don't want to be KDE 4.0, do you? :) [19:57] QUESTION: when does it makes sense to make code more generic (useful in many places). Or to make an abstraction to it? [19:57] I would say that you should NEVER repeat code. Never, ever, ever, never, ever. [19:57] Sometimes, abstractions are harder to understand, so you'll have to "glue" that with good comments. [19:58] QUESTION: So can I find good examples of python coding style by doing: grep python /usr/bin/* ? [19:58] So, I'm not sure what that would give you. [19:59] Bazaar's source code is awesome for seeing good coding standards as well as ways to make python perform better. [19:59] They have some potentially difficult and crazy code that is commented with things like "we have to do this now, or the function won't return fast enough" and things like that. [20:00] Any more questions? === 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: Speed your development with quickly.widgets - Rick Spencer - Instructor: rickspencer3 || Questions in #ubuntu-classroom-chat [20:00] Thanks folks! [20:01] hi all [20:01] shall we dive into quickly-widgets? [20:01] or maybe you need some time to recover from that stellar class by rockstar [20:03] ok, I guess I'll get started [20:03] ok [20:03] my code is ugly [20:03] but functional ;) [20:03] as usual I put my class notes on the wiki [20:03] https://wiki.ubuntu.com/UbuntuOpportunisticDeveloperWeek/Quidgets [20:04] so, quickly-widgets started as a personal side project of mine [20:04] and it got totally out of control [20:04] at some point I discovered it was writing itself at night [20:04] the goal of quickly widgets is to make PyGtk programming more easy and fun [20:04] PyGtk is a fantastic UI tool kit [20:04] It is very powerful, functional, and flexible [20:05] However, at the moment, it lacks some higher order abstractions that developers have come to expect [20:05] The result being that developers have to write reams of code using multiple classes and such for things that are more simple in other frameworks [20:05] for example, popping dialogs, putting data into a grid and such [20:05] so I'm hoping quickly-widgets can fill in some of these use cases [20:05] please note that quickly-widgets is very early in development and experimental [20:05] this means that it is to be buggy and incomplete [20:06] or at least I strongly suspect that it is [20:06] but it also means that if you want to, you can have a lot of influence on how it develops [20:06] so bug reports and branches, more than welcome [20:06] btw [20:06] so what is Quidgets? [20:06] "Quidgets" is the original name of quickly-widgets [20:06] it was a silly name [20:06] I made it up without really thinking [20:06] the project is still called Quidgets [20:06] so you can get the code: [20:06] $bzr branch lp:quidgets [20:06] quickly-widgets is currently in universe for Lucid [20:07] (this scares me a bit, but what the heck ;) ) [20:07] it is not packaged for Karmic [20:07] though if someone wanted to do that, I would not complain too much ;) [20:07] currently, quickly widgets has two modules [20:07] quickly.prompts [20:07] and quickly.widgets [20:07] quickly.widgets has some general widgets [20:07] but also some widgets for displaying data, basically extending TreeView and making it simpler to use [20:07] I'll discuss each of these three areas in a bit more depth [20:08] But first, Questions? [20:08] oskude asked: does quickly-widgets work with or without glade (the editor) ? [20:08] currently there is no glade integration [20:08] I don't think it would be too hard to add this, but it hasn't been tackled yet [20:08] I think to do this would require crafting a library file in XML [20:09] but then also making sure the properties were properly setable in the glade propery editor [20:09] Before we look at the modules, a word on the mental model of using quickly-widgets [20:09] There are 3 "levels" to consuming quickly-widgets [20:09] Most of the time, you should be fine with the first level, which is the "Use" level [20:09] At this level, you just make a one-liner that uses the API and does something useful [20:10] like, get as string from the user: [20:10] quickly.prompts.string("My Title","Give me a string","default val") [20:10] or maybe you want do display the data in a dictionary: [20:10] dg = DictionaryGrid(my_list_of_dicts) [20:10] dg.show() [20:10] see, you just go ahead and "use" the classes [20:10] sometimes you want to tweak something a bit. In these cases you go to the configure level. [20:10] When you are doing "configure" you might end up a using the underlying PyGtk API a bit [20:10] For example, a dictionary grid is really just a Treeview [20:10] So if you want to configure the title for a column, you might go [20:11] dg.get_columns()[0].set_title("New Title") [20:11] some of the configuration might be done in the quickly.widgets library though [20:11] like if you want to display certain keys from your dictionary, you can use a list of keys to display [20:11] keys = ["key1","key2'] [20:11] dg = DictionaryGrid(my_dict,keys=keys) [20:11] I'll talk about the specifics here a bit later [20:11] but the point is, you can go beyond the one liner if you need to [20:12] so if you start with the one liner, but then need to expand out a bit [20:12] you don't throw away your code, just add some "configure" code [20:12] let's say you get back a feature request from a user or customer, and you need to do something that is not suppported by quickly-widgets through using or configuring [20:12] well, quickly-widgets strives to consume PyGtk in such a way that you can extend classes as needed to accomplish your goals [20:12] for example, if you want a grid that displays data from a certain SQL database somewhere, you can inherit from DictionaryGrid and add the SQL functionality. [20:12] This is exactly what CouchGrid does, but for generally desktopcouchy things [20:12] So, before I discuss using the prompts a bit, any questions? [20:13] \sh asked: which audience did you have in mind when you started Quickly? === AndChat is now known as Guest68634 [20:13] well, fundamentally I was scratching my own itch [20:13] I was working on bughugger and thought ... [20:13] "I cannot believe I am writing this same TreeView code *again*" [20:14] I vowed at that moment to never craft a TreeView again [20:14] though I don't mind writing code that writes TreeViews ;) [20:14] beyond me, I am thinking about application writers on Ubuntu [20:14] so I don't mind making some distro specific assumptions [20:15] ultimately, I am thinking about folks who, like me, often can visualize and app, and want to get straight to the fun part [20:15] without bothering with all the boiler plate of a powerful library like Gtk [20:15] more questions? [20:16] ok [20:16] prompts [20:16] Prompts are basically dialogs that you can use to interact with the user without writing too much code [20:16] rather than creating a PyGtk dialog or similar yourself, and then populating it, for certain scenarios a prompt in quickly-widgets can take care of it for you [20:16] the prompts module is right under quickly, so you can get it like this: [20:16] from quickly import prompts [20:16] or just quickly.prompts.string() if you want [20:16] there are three kinds of prompts [20:16] the first kind just displays info the the user [20:16] these take a couple of strings from you and display a message box to the user with the appropriate icon [20:17] so, you can go [20:17] prompts.error("Title for the Error Dialog","Error text") [20:17] this will pop up a little dialog that says "Error text" [20:17] with a dialog error icon next to it [20:17] there is also prompts.warning and prompts.info [20:17] they works the same as error [20:17] The next kind of prompt collects some info from the user [20:18] the kind of prompts built in of this kind are: [20:18] string, date, integer, decimal, and price [20:18] they all take care of displaying an appropriate widget for the user input for you [20:18] like a textbox for a string, a calendar for a date, and a spinner appropriately formatted if appropriate [20:18] they let you set a title, a message, a default value, and in the case of the numeric ones some other defaults if you want [20:18] the functions all return a gtk.RESPONSE and a value [20:18] make sure you check the response because if the user cancelled, you want to do the right thing [20:19] so to get a string, go: [20:19] response, val = quickly.prompts.string() [20:19] if response == gtk.RESPONSE_OK: [20:19] #do something with val [20:19] where val is a string [20:19] you can get a date in the same way [20:19] when dealing with date values are tuples in the form of integers for (year,month,day) [20:19] where month is zero indexed (Jaunary is 0, December is 11) [20:20] and you use tuples for the default value in teh same way [20:20] so: [20:20] response, date = quickly.widgets.date("Title String","Enter your birthday",(1968,03,22)) [20:20] so that's *April* because the months are zero indexed [20:20] if you want to get an integer, you can set min_value, and max_value as well [20:20] if you look at the doc string, you can see other options as well [20:20] decimal and price are also rich in options [20:20] price is just decimal, but with 2 decimal places set [20:20] however, they all work basically the same way, response, val = function() [20:21] if you need to configure the prompt a bit more, for each function, there is a symetrical class that you can use [20:21] so for string(), if you want to own the dialog for some reason, you can use StringPrompt [20:21] sp = StringPrompt(title, text, default_string) [20:21] then you can party on sp if you want [20:21] there is a similar dialog for date, integer, decimal, and price [20:21] each has a "get_value()" function to extract the value [20:21] The last set of prompts are FileChooserDialogs [20:21] they work the same way [20:22] response, path = quickly.prompts.choose_directory(title) [20:22] there is choose_directory, save_image_file, and open_image_file [20:22] there are classes for these as well [20:22] DirectoryChooserDialog, OpenImageDialog, and SaveImageDialog [20:22] these lack get_value, because they are just subclasses of FileChooserDialog [20:22] which already has a get_filename() function [20:22] before I talk about the gtk.Widgets, any questions? [20:23] tgalati4 asked: I noticed that quidgets is only packaged for Lucid, no Karmic. Any plans? [20:23] I'm not planning this myself [20:23] but I would be happy to work with anyone who wanted to do this [20:24] btw, I should have mentioned that the package name is quickly-widgets in universe [20:24] alright [20:24] moving on to quickly.widgets [20:24] for widgets, there are a few miscelaneous ones, and then the grid related ones [20:24] I'll start with the miscelaneous ones [20:24] the most miscelaneous one is [20:24] from quickly.widgets.camera_button import CameraButton [20:25] CameraButton wraps up the PyGame web cam API and serves up pixbufs [20:25] I don't like how this is implemented at the moment, and am planning to pull it into it's own package for a while, until I can make it work well [20:25] however, it's kinda fun when it works [20:25] there's also a subclass of button called PressAndHold button [20:25] this one is quite useful and functional [20:25] this guy fires a signal every 250ms, so long as the user is holding the button down [20:26] so this allows you to do something while the user is holding down a button [20:26] I use this in photobomb to manage rotation of times for example [20:26] first, create the button, then connect to the signal [20:26] button = PressAndHoldButton() [20:26] button.connect("tick",action) [20:26] then write a function that does something every time the signal fires [20:26] def action(self, widget=None, data=None): [20:26] #do something every 250ms [20:27] for photobomb "something" is selected_item.rotate() or such [20:27] the last misc. quickly.widget is [20:27] from quickly.widgets.asynch_task_progressbox import AsynchTaskProgressBox [20:27] in general, you should avoid threads in your python app [20:27] you should use things like gobject.timeout_add() or gobject.idle_add() [20:27] and the gio library [20:27] however, for times when you absolutely must use a thread AsynchTaskProgressBox can make it easier for you [20:27] this derives from gtk.ProgressBox, so it supplies some throbbing UI for you if you need it [20:28] the basic idea is to write a function that you want to run on a thread [20:28] I usually call this a task [20:28] create a dictionary of parameters if you want to pass some params to the function [20:28] create the AsynchTaskProgressBox [20:28] if you want to know when the task is done, connect to the complete event [20:28] here's some photobomb code for example [20:28] params = {"directory":directory} [20:28] pb = AsynchTaskProgressBox(self.__load_task, params, False) [20:28] pb.connect("complete",self.__load_task_complete) [20:28] for your task, you can simulate a killable thread (in python you can't really kill a thread, just wait for it to end) [20:29] if every [20:29] if *ever* even [20:29] you do this by checking a special key that is added to params called "kill" [20:29] if it's set to True, you can stop working [20:29] here's a bit of code from photobomb to demonstrate [20:29] def __load_task(self, params): [20:29] pictures_dir = params["directory"] [20:29] images = [] [20:29] files = os.listdir(pictures_dir) [20:29] for f in files: [20:29] try: [20:29] if params["kill"]: [20:29] return None [20:29] #etc.... [20:29] So the last bit about quickly-widgets is about Grids and Filters and stuff [20:29] before I do that, any questions so far? [20:30] stevec33 asked: Why is it best to avoid threads? [20:31] because the implentation in Python leaves a lot to be desired [20:31] like there is a global lock and scuh [20:31] they are not true threads that get deployed and run seperately on CPUs and such [20:31] but mostly, it's really hard to write code that does not have bad bugs in it [20:32] this is especially true with PyGtk [20:32] you have to call threads_enter() and threads_leave() and all this when updating the UI [20:32] or it goes quite haywire [20:33] ok [20:33] on to grids [20:33] lots of the code in quickly-widgets is about presenting data to users in a TreeView [20:33] in PyGtk, gtk.TreeView handles both displaying grid data and data in trees [20:33] quickly-widgets focuses on the Grid [20:33] and totally ignores the tree case [20:34] trees are UI elements where there are nested nodes with those little disclosure triangles and such [20:34] so, grids [20:34] the essentially scenario is that you have some tabular data to display [20:34] gtk.TreeView can let you display this in any manner you like [20:34] so long as you: [20:34] 1. Create a TreeView [20:34] 2. Cerate a treeview model store of some kind [20:34] 3. create columns [20:34] 4. create cellrenders for each column [20:34] 5. popluate the treeview model [20:35] each of these steps taking multiple lines of code *per column* [20:35] and this does not include letting users change the values in the grid [20:35] filtering [20:35] adding data after it is created, etc... [20:35] from quickly.widgets.dictionary_grid import DictionaryGrid tries to handle this for you in essentially, one line of code [20:35] the basic interaction is that you create a DictionaryGrid by handing it a list of dictionary, and it makes a TreeView for you [20:36] you just show it and add it to your form [20:36] Here's a bit from the dictionary grid test program [20:36] first, a list of dictionaries [20:36] dicts = [{"key?": True, "price":0.00,"tags" : "aaa bbb ccc","_foo":"bar","bing count":20}, [20:36] {"ID": 11, "key?": False, "price":2.00,"tags" : "bbb ccc ddd","_foo":"bar"}, [20:36] {"key?": True, "price":33.00,"tags" : "ccc ddd eee","_foo":"bar","bing count":15}, [20:36] {"ID": 3, "tags" : "ddd eee fff","_foo":"bar"}, [20:36] {"ID": 4, "price":5.00,"_foo":"bar"}] [20:36] then, create the DictionaryGrid: [20:36] grid = DictionaryGrid(dicts) [20:36] seriously, that;s all it takes to show the data in the dictionaries to a user [20:36] if you want the user to be able to edit the grid, set it to editable: [20:37] grid.editable = True [20:37] note that setting some of the properties, including editable will cause the grid to reset itself [20:37] if it's editable, the user can change the data in the dictionary [20:37] there are some properties that you can use to extract the data [20:37] like [20:37] grid.rows [20:38] this gives you all the rows [20:38] where as [20:38] grid.selected_rows gives you the currently selected row [20:38] some handy functions you get for free, like [20:38] grid.remove_selected_rows() [20:39] remove_selected_rows [20:39] oops [20:39] you can add to your grid by appending rows [20:39] grid.append_row(my_dict) [20:39] if you want to add an empty row [20:39] append_row({}) [20:39] then if the grid is editable, the user can fill itin [20:40] by default, the grid will display a column for every key it encounters UNLESS that key starts with "__" (two underscores), in which case it will be ignored [20:40] if you want to control the keys displayed, you can do this when you create it: [20:40] grid = DictionaryGrid(dicts,list_of_keys) [20:40] or you can set the keys later [20:40] grid.keys = list_of_keys [20:40] this causes the grid to reset, btw [20:40] Columns will sort properly most of the time [20:40] this is accomplished by having each column be a certain type [20:40] there is the default StingColumn, but there is also IntegerColumn, CurrencyColumn, TagsColumn, and CheckColumn [20:41] by "extending" GridColumn you can create your own column types if you need to [20:41] DictionaryGrid tries to guess the right column type to use based on the name of the key [20:41] So if you choose your key names correctly, you can get a lot of good functionality for free [20:41] for example, and key that ends with "?" DictionaryGrid will assume it is a boolean, and use CheckBoxes to show the values [20:41] and provide the appropriate sortign for you [20:41] the key "price" is assumed to be currency [20:41] anything ending in count will be an IntegerColumn, same with a key called "id" [20:41] a key called "tags" will be a tags column [20:41] tags columns are mostly important for filtering, which I will discuss in a moment [20:42] you can control the columntypes manually if you want, by passing in "Type Hints" [20:42] here's some code from the tests: [20:42] keys = ["id","price","bool?","foo"] [20:42] hints = {"id":StringColumn, "price":IntegerColumn, [20:42] "bool?":CurrencyColumn,"foo":CheckColumn} [20:42] dicts = [{"price":100,"id":"asdfas","bool?":10.01,"foo":True}] [20:42] grid = DictionaryGrid(dicts, keys, hints) [20:42] in this case hints are overriding the defaults [20:42] so I should talk about filtering next, but first, questions? [20:43] I hope there are no question be my content is so riveting, and the clarity is so profound [20:43] :) [20:43] moving on ... [20:43] so one cool thing about gtk.TreeView is the filtering capabilities [20:44] Filtering even pretty long lists works really fast [20:44] but this is a TON of work in PyGtk [20:44] from quickly.widgets.grid_filter import GridFilter makes a filter UI for you [20:44] this will let the user add filters to filter columns [20:44] if you've seen the bughugger UI, then you have seen GridFilter and DictionaryGrid in action [20:44] you just need to hand it a Grid to filter [20:44] it will pick up filter types from the GridColumns in the Grid [20:44] So for example columns with strings will get a filter with "contains substring" while a column with numbers will get ">,<.=", etc... [20:45] a tags column gets "contains one of these tags", "contains all of these tags", etc... [20:45] all this just by creating it: [20:45] filt = GridFilter(grid) [20:45] filt.show() [20:45] if you want to override the default filter types, you can pass in hints [20:45] this works pretty much like in the grid [20:45] you pass in a dictionary that matches up keys to filter types [20:45] well, actually to filter combos, but that's a bit more detail than necessary [20:45] there are StringFitlerCombo, TagsFilterCombo, CheckFilterCombo etc... [20:46] there is also blank filter combo that you can use to easily make your own filters [20:46] for example, in bughugger I created a custom filter to filter status and importance like this: [20:46] sw_filter2 = BlankFilterCombo() [20:46] sw_filter2.append("=",lambda x,y: convert_to_num(x) == float(y) ) [20:46] sw_filter2.append("<",lambda x,y: convert_to_num(x) < float(y) ) [20:46] sw_filter2.append(">",lambda x,y: convert_to_num(x) > float(y) ) [20:46] sw_filter2.append("<=",lambda x,y: convert_to_num(x) <= float(y) ) [20:46] sw_filter2.append(">=",lambda x,y: convert_to_num(x) >= float(y) ) [20:46] filter_hints = {"status":sw_filter,"importance":sw_filter2} [20:46] each call to append adds a string and a function call [20:46] the function gets called when the users changes the filter in some way [20:47] the function should return True to show the row [20:47] or False to hide the row [20:47] lastly I'll discuss CouchGrid [20:47] but first, Questions? [20:47] * rickspencer3 tap tap [20:47] is this thing on? [20:48] tgalati4 asked: Besides bughugger and photobomb, any other apps using quidgets that we can use for reference? [20:48] I don't know [20:48] I get a lot of questions about using the widgets [20:48] but I haven't tracked what folks are doing with it [20:48] sorry :/ [20:48] ok [20:49] before we break, I'll touch on CouchGrid [20:49] the flagship of the quickly-widgets package [20:49] I feel this has been talked about a lot [20:49] In Lucid, a CouchGrid is a DictionaryGrid [20:49] this is different than the CouchGrid that was desktopcouch.records.couch_grid import CouchGrid [20:50] in Lucid you get all the sorting and filtering of DictionaryGrid, plus persistance in desktopcouch [20:50] you need to define a database and a record type [20:50] if you want, you can pass in a dictionary with some starter data as well [20:50] here is some code from the GridFilter test app [20:50] database_name = "couch_widget_test" [20:50] record_type = "couch_grid_filter_test" [20:50] hints = {} [20:50] grid = CouchGrid(database_name, record_type=record_type, dictionaries=dicts) [20:50] grid.show() [20:50] filt = GridFilter(grid,hints) [20:50] filt.show() [20:50] this sets up a database for you [20:50] if the databaes is there and there are records already [20:50] it displays those for you! [20:51] if there are new records it persists them for you [20:51] so, that [20:51] s the last bit of content I had planned [20:51] Questions? [20:53] okay [20:53] so, if you're hacking and have questions, want to contribute [20:53] etc... [20:54] join #quickly any time and ask away [20:54] again, the project is early, so feedback and contributions can have a big impact at this point [20:54] this is community developed software, so it's there to be molded by the community :) [20:54] tgalati4 asked: What's on the roadmap on quidgets? What's the burning next todo item? [20:55] thanks for the question tgalati4 [20:55] next step is to get some feedback on the Grid related stuff [20:55] and fix bugs [20:55] I think that saves the most work there [20:55] also, I'd like to make the web cam button good [20:56] someone yesterday suggest gstreamer, I should give that a try [20:56] also, there may be more file chooser dialogs for the prompts [20:56] I'd like to add any widgets that folks like that they would like to find an upstream home for [20:56] but one of the most immediate burning things for me is to write documentation [20:58] please note that there is a fair amount of documentation already in the code itself [20:58] and you can access this with pydocs [20:59] thanks everyone! [20:59] I'm looking forward to working with folks to make quickly-widgets more functional and more easy and more fun [20:59] :) === 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 [21:03] hey, where does the talks logs are stored? [21:03] where are store the chat logos? (better this way) [21:04] malev there linked from the wiki paage with the schedule [21:05] ausimage: thanks! [21:05] no [21:05] np [21:05] :/ [21:05] fingers :S === enli is now known as enli|away === jw is now known as Guest61922