Archive for the ‘Desktop’ Category
Posted on March 15, 2010 - by jono
Download Files Async With Gio And Python
Recently I asked for some help on how to download a file without blocking the GUI. Thanks to everyone who contributed their expertise in the post comments: I now have my program working great.
I wanted to now share my conclusions so that others can benefit from them too. To do this I am going to first explain how this works, and secondly I have created a Python Snippet and added it to the Python Snippets library so there is a great working example you folks can play with. You can use Acire to load the snippet and play with it. This is the first gio snippet, and I hope there will be many more.
The goal I set out with was to download a file without freezing the GUI. This was somewhat inspired from a recent Shot Of Jaq shot that we did on async programming, and I used this app as a good example to play with. Typically I had downloaded files the manual way and this had blocked my GUI hard, but I was aware that this is exactly what gio, part of the GNOME platform is here to solve.
The way async basically works is that you kick off an operation and then you wait for confirmation of the result before you proceed. It is the opposite of procedural programming: you don’t kick off an operation and in the next line process it. When you do things the async way, you start an operation and then tell it what callback should be called when it is complete. It feels very event-driven: kind of how you connect a handler to a signal in a widget so that when that signal is generated, the handler is called.
When I started playing with this the docs insinuated that read_async() and read_finish() were what I needed to use. I started off with code that looked a little like this:
def download_latest_shot(self):
audiourl = "http://....the url to the Ogg file...."
self.shot_stream = gio.File(audiourl)
self.shot_stream.read_async(self.download_latest_shot_complete)
It then calls this callback:
def download_latest_shot_complete(self, gdaemonfile, result):
f = self.shot_stream.read_finish(result).read()
outputfile = open("/home/jono/Desktop/shot.ogg","w")
outputfile.writelines(f)
After some helpful notes from the GNOME community, it turned out that what I really needed to use was load_contents_async() to download the full content of the file (read_async() merely kicks off a read operation) and load_contents_finish() as the callback that is called when it is complete. This worked great for me.
As such, here is the snippet which I have added to the Python Snippets library which downloads the Ubuntu HTML index page, shows it in a GUI without blocking it and writes it to the disk:
#!/usr/bin/env python
#
# [SNIPPET_NAME: Download a file asynchronously]
# [SNIPPET_CATEGORIES: GIO]
# [SNIPPET_DESCRIPTION: Download a file async (useful for not blocking the GUI)]
# [SNIPPET_AUTHOR: Jono Bacon <jono@ubuntu.com>]
# [SNIPPET_LICENSE: GPL]
import gio, gtk, os
# Downloading a file in an async way is a great way of not blocking a GUI. This snippet will show a simple GUI and
# download the main HTML file from ubuntu.com without blocking the GUI. You will see the dialog appear with no content
# and when the content has downloaded, the GUI will be refreshed. This snippet also writes the content to the home
# directory as pythonsnippetexample-ubuntuwebsite.html.
# To download in an async way you kick off the download and when it is complete, another callback is called to process
# it (namely, display it in the window and write it to the disk). This separation means you can download large files and
# not block the GUI if needed.
class Example(object):
def download_file(self, data, url):
"""Download the file using gio"""
# create a gio stream and download the URL passed to the method
self.stream = gio.File(url)
# there are two methods of downloading content: load_contents_async and read_async. Here we use load_contents_async as it
# downloads the full contents of the file, which is what we want. We pass it a method to be called when the download has
# complete: in this case, self.download_file_complete
self.stream.load_contents_async(self.download_file_complete)
def download_file_complete(self, gdaemonfile, result):
"""Method called after the file has downloaded"""
# the result from the download is actually a tuple with three elements. The first element is the actual content
# so let's grab that
content = self.stream.load_contents_finish(result)[0]
# update the label with the content
label.set_text(content)
# let's now save the content to the user's home directory
outputfile = open(os.path.expanduser('~') + "/pythonsnippetexample-ubuntuwebsite.html","w")
outputfile.write(content)
ex = Example()
dial = gtk.Dialog()
label = gtk.Label()
dial.action_area.pack_start(label)
label.show_all()
label.connect('realize', ex.download_file, "http://www.ubuntu.com")
dial.run()
I am still pretty new to this, and I am sure there is plenty that can be improved in the snippet, so feel free submit a merge request if you would like to improve it. Hope this helps!
Posted on March 15, 2010 - by jono
Downloading Large Files Async With GIO
Slightly technical question for my friends on Planet GNOME. I have been hunting around for some help online with no luck, so I figured I would post here and hopefully this blog entry can be a solution for those who have similar questions.
I am in the process of porting App Of Jaq to to async. To do this I am using gio and have the code that downloads XML feeds up and running pretty well, and the app feels much more responsive. Now I need to have the application download an Ogg asynchronously without freezing the GUI.
My code currently looks like this:
def download_latest_shot(self):
audiourl = "http://....the url to the Ogg file...."
self.shot_stream = gio.File(audiourl)
self.shot_stream.read_async(self.download_latest_shot_complete)
It then calls this callback:
def download_latest_shot_complete(self, gdaemonfile, result):
f = self.shot_stream.read_finish(result).read()
outputfile = open("/home/jono/Desktop/shot.ogg","w")
outputfile.writelines(f)
Now, I am still pretty new to this, and while this code does work, it freezes the GUI pretty hard. Can anyone recommend some next steps for how I can download the file without it freezing? Some example code would be great.
Thanks in advance for anyone who can help.
Posted on March 4, 2010 - by jono
Ubuntu Opportunistic Developer Week and Python Snippets Day
Ubuntu Opportunistic Developer Week day 4 kicks off and we have some incredible events today:
- 5pm UTC – Hot rodding your app for translations support – David Planella
- 6pm UTC – Learning through examples with Acire and Python-Snippets – Jono Bacon
- 7pm UTC – Write Beautiful Code (and Maintain it Beautifully) – rockstar
- 8pm UTC – Speed your development with quickly.widgets – Rick Spencer
- 9pm UTC onwards – Snippets Party – Join us in
#ubuntu-app-develand create Python snippets to share with other people – see this page for details of how to get involved!
It is recommended that you enjoy the week in Lernid. You can find out more details of how to install Lernid right here. Don’t want to use Lernid? No worries, just pop over to #ubuntu-classroom and #ubuntu-classroom-chat to join in the fun. Don’t forget that #ubuntu-app-devel is the place to ask questions about general development on Ubuntu.
Join the snippets party!
Today is a special day this week: in addition to providing some great content to help people get started writing apps on Ubuntu, we are also keen to continue growing our wonderful library of python-snippets which is viewed with a program I wrote called Acire. This library of snippets provides a range of examples that you can run, play with, modify and merge into your programs. So many of us learn by doing, and the more snippets we have the easier it is the learn from a diverse range of topics!
We have two events today I am keen to encourage you to join. First I will be delivering a session on the python snippets project:
- 6pm UTC – Learning through examples with Acire and Python-Snippets – Jono Bacon
In the session I will explain how the project came about, it’s current progress and where we are going. We will then have a fun snippets party a little later:
- 9pm UTC onwards – Snippets Party – Join us in
#ubuntu-app-develand create Python snippets to share with other people – see this page for details of how to get involved!
The snippets party is simple: just join #ubuntu-app-devel on freenode and join us to write a bunch of snippets and contribute them to python-snippets. Today we have 104 snippets already in the library: I would love to see us get that to over 150 today. Come and join us!
Contributing snippets is simple: just click here to find out more!
Posted on March 3, 2010 - by jono
Refreshing The Ubuntu Brand

The new style of Ubuntu is driven by the theme “Light”. We’ve developed a comprehensive set of visual guidelines and treatments that reflect that style, and are updating key assets like the logo accordingly. The new theme takes effect in 10.04 LTS and will define our look and feel for several years.
Ubuntu has seen a tremendous amount of growth and change since it was conceived in 2004. Back then it was a small project with strong ambitions and a handful of developers passionate about delivering a world class Linux Operating System that can compete on every level with Microsoft and Apple. We adopted a style based on the tagline “Linux for Human Beings”, and called it “Human”. Six years on we have made incredible progress. Ubuntu is a global phenomenon: we have carved out a pervasive culture of quality and design, thoughtful usability and great technology all fused together in a project that maintains the same commitment to community and collaborative development that we embraced back in 2004.
In 2009, a small team lead by Mark Shuttleworth, conducted a review of our key brand values and identity. Based on that work, a set of visual treatments were produced, and shared with key members of the Ubuntu Art community, spanning the core distributions, derivatives, and aligned efforts like the Forums. Representatives from Ubuntu, Kubuntu, Edubuntu, Xubuntu, Mythbuntu, SpreadUbuntu and more came to London and worked with the Canonical design team to refine the designs and work together. The results of that work are presented here.
This collection of community representatives worked with the design team and created some great work. Some examples:

In addition to this we also worked with our key governance boards: the Community Council, Technical Board, Forums Council, LoCo Council and others around this work to ensure that our community can use it to it’s best advantage.
Brand Values
The key values we believe are reflected in the Ubuntu project are:
Precision. We ship high quality software, and we ship it exactly on schedule. Our Debian heritage means that the individual components of our platform are tightly defined and neatly arranged. There is no excess, no fat, and no waste in Ubuntu. We are a community that thrives on delivery.
Reliability. We are building Ubuntu for serious use. Whether it is being deployed on the desktop or in the cloud, we care that Ubuntu is secure, reliable and predictable. We deliver updates to Ubuntu that are rigorously tested. When we make a mistake, we learn from it and put in place good processes to ensure that it does not happen again.
Collaboration. Ubuntu is the result of collaborative work between thousands of people, and it is both the beneficiary and the public face of the collaborative work of tens of thousands of free software developers who build individual upstream components, or aggregate them in Debian. We go to great lengths to ensure that anybody, anywhere, who is passionate about Ubuntu and competent to participate, can do so. We enable virtual participation in our physical Ubuntu Developer Summits, we use mailing lists and IRC in preference to over-the-cubicle-wall communications, and we welcome contributions from both companies and individuals. Our governance bodies reflect the diversity of that participation, and leadership or permissions are based on proven merit, not corporate employment.
Freedom. We strive to deliver the very best free software platform. Our highest mission is to accelerate the adoption and spread of free software, to make it the de facto standard way that people build and consume software. We celebrate the work of other groups committed to collaborative content development, and open content licensing. While we are pragmatic about this (we ship proprietary drivers when we believe they are a requirement to get free software working well on PC’s) we expressly do not include any proprietary applications in the default installation of Ubuntu. We want people to love and appreciate free software, and even though we work to make sure that Ubuntu is compatible with, certified with and iteroperable with popular proprietary software, we do so to facilitate the adoption of free alternatives to proprietary solutions.
While the branding has changed, the freedoms and rights have not: our global community will still maintain access to the resources needed to construct logos that use the branding. We will be providing the new font, images, colour specs, and a set of recommendations for creating branding for websites, t-shirts and the other needs of our community. As before we will protect the integrity of the Ubuntu brand with the Ubuntu Trademark Policy.
Light: Ubuntu is Lightware


The new style in Ubuntu is inspired by the idea of “Light”.
We’re drawn to Light because it denotes both warmth and clarity, and intrigued by the idea that “light” is a good value in software. Good software is “light” in the sense that it uses your resources efficiently, runs quickly, and can easily be reshaped as needed. Ubuntu represents a break with the bloatware of proprietary operating systems and an opportunity to delight to those who use computers for work and play. More and more of our communications are powered by light, and in future, our processing power will depend on our ability to work with light, too.
Visually, light is beautiful, light is ethereal, light brings clarity and comfort.
Historical perspective: From 2004-2010, the theme in Ubuntu was “Human”. Our tagline was “Linux for Human Beings” and we used a palette reflective of the full range of humanity. Our focus as a project was bringing Linux from the data center into the lives of our friends and global family.
Go and see the full details of the brand refresh here, with more images.
Posted on March 3, 2010 - by jono
Ubuntu Opportunistic Developer Week Day 3 Kicks Off In An hour
Just a quick note to let you all know that Ubuntu Opportunistic Developer Week day 3 kicks off in an hour!
Here is the order of events for today:
- 5pm UTC – Creating stunning interfaces with Cairo – Laszlo Pandy
- 6pm UTC – What’s new in Quickly 0.4 – Didier Roche
- 7pm UTC – Create games with PyGame – Rick Spencer
- 8pm UTC – SHOWCASE: Photobomb – Rick Spencer
- 9pm UTC onwards – Hacking party in
#ubuntu-app-develon freenode! Come and join us, work on your apps, ask questions and have fun in our community.
It is recommended that you enjoy the week in Lernid. You can find out more details of how to install Lernid right here. Don’t want to use Lernid? No worries, just pop over to #ubuntu-classroom and #ubuntu-classroom-chat to join in the fun. Don’t forget that #ubuntu-app-devel is the place to ask questions about general development on Ubuntu.
Posted on March 2, 2010 - by jono
Ubuntu Opportunistic Developer Week Day 2 Kicks Off In An Hour
Just a quick note to let you all know that Ubuntu Opportunistic Developer Week day 2 kicks off in an hour!
Here is the order of events for today:
- 4pm UTC – Gooey Graphics with GooCanvas – Rick Spencer
- 5pm UTC – Writing a Rhythmbox plug-in – Stuart Langridge
- 6pm UTC – Microblog from your app with the Gwibber API – Ken VanDine
- 7pm UTC – SHOWCASE: Gwibber – Ken Vandine
- 8pm UTC – Building multimedia into your app with GStreamer – Laszlo Pandy
- 9pm UTC onwards – Hacking parts in
#ubuntu-app-develon freenode! Come and join us, work on your apps, ask questions and have fun in our community.
It is recommended that you enjoy the week in Lernid. You can find out more details of how to install Lernid right here. Don’t want to use Lernid? No worries, just pop over to #ubuntu-classroom and #ubuntu-classroom-chat to join in the fun. Don’t forget that #ubuntu-app-devel is the place to ask questions about general development on Ubuntu.
Posted on March 1, 2010 - by jono
Ubuntu Opportunistic Developer Week Kicks Off In An Hour
Just a quick note to let you all know that Ubuntu Opportunistic Developer Week kicks off in an hour!
Here is the order of events for today:
- 4pm UTC – Welcome! Ubuntu For Opportunistic Developers – Jono Bacon
- 5pm UTC – CouchDB support in your app with DesktopCouch – Stuart Langridge
- 6pm UTC – Creating an application from scratch with Quickly – Rick Spencer
- 7pm UTC – Building in Application Indicator support – Sense Hofstede
- 8pm UTC – Integrated development workflow with Ground Control – Martin Owens
- 9pm UTC onwards – Hacking parts in
#ubuntu-app-develon freenode! Come and join us, work on your apps, ask questions and have fun in our community.
It is recommended that you enjoy the week in Lernid. You can find out more details of how to install Lernid right here. Don’t want to use Lernid? No worries, just pop over to #ubuntu-classroom and #ubuntu-classroom-chat to join in the fun.
Posted on March 1, 2010 - by jono
Ubuntu Opportunistic Developer Week This Week

Well, folks, this week Ubuntu Opportunistic Developer Week kicks off with a fantastic week jammed with great sessions helping to bridge the gap for opportunistic developers who want to write fun, useful applications using Ubuntu as a platform. We have a wonderful week of sessions ahead and as ever, it is recommended that you enjoy the week in Lernid. You can find out more details of how to install Lernid right here. Don’t want to use Lernid? No worries, just pop over to #ubuntu-classroom and #ubuntu-classroom-chat to join in the fun.
I will be kicking off the week at 4pm UTC and talking through the goals for the week and talking through some of the work we are doing to help opportunistic developers enjoy Ubuntu as a platform and write some fun apps.
Friends, also don’t forget about the fun challenge I set last week:
Think of a fun program to write, and see how much you can get completed by the end of the week, Fri 5th March 2010. On Friday I will write a blog entry that showcases screenshots of your progress and (if possible) a PPA where people can download a package to try.
When you have something you would like me to blog, send an email no later than the end of the day Pacific time on Thu 4th March 2010 to me at jono AT ubuntu DOT com and include:
- The name of your program and a brief description of what it does.
- A link to a screenshot online that shows your new app running.
- If available, tell me the name of the Launchpad project where it is hosted and the PPA with the package. This is a great way for people to try your program and possibly join the project and contribute to it!
I will send a t-shirt out to the three app authors who made the most interesting apps with the most progress.
Start your engines folks, let’s see what we can do! I can’t wait to see how you folks get on!
Posted on February 27, 2010 - by jono
Fun Little Acire Story
With the new release of Acire just out I wanted to tell you folks a fun little story of an added benefit to Acire that I never envisaged when I came up with the idea for the app.
Yesterday I got an email from someone (I will keep the identify private) saying:
I’m trying to create an application but I can’t seem to find any way to embed a gnome-terminal into my app. I know you’re not offering support
but if you have some spare time is there any chance you can point me to the documentation for that?
This happens a lot: someone wants to do something, so they ask for help over email or on another medium such as IRC. Unfortunately, I am usually pretty busy and typically don’t have the time to answer support questions. Before Acire existed I would have at most hunted out some links or possibly just the person to to go and ask on a particular forum or mailing list.
Now Acire exists, I just fired it up, selected Python VTE from the cateogries combo box, clicked on the snippet, and then cut and pasted the code into the email:
#!/usr/bin/env python
# [SNIPPET_NAME: Embed a VTE terminal]
# [SNIPPET_CATEGORIES: Python VTE]
# [SNIPPET_DESCRIPTION: Embed a VTE terminal in your application]
try:
import gtk
except:
print >> sys.stderr, "You need to install the python gtk bindings"
sys.exit(1)
# import vte
try:
import vte
except:
error = gtk.MessageDialog (None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
'You need to install python bindings for libvte')
error.run()
sys.exit (1)
if __name__ == '__main__':
# create the terminal
v = vte.Terminal()
v.connect ("child-exited", lambda term: gtk.main_quit())
# fork_command() will run a command, in this case it shows a prompt
v.fork_command()
# create a window and add the VTE
window = gtk.Window()
window.add(v)
window.connect('delete-event', lambda window, event: gtk.main_quit())
# you need to show the VTE
window.show_all()
# Finally, run the application
gtk.main()
Job done. What made me smile about this was that Acire not only helps me, but it helped me help someone else too. Rocking.
Posted on February 26, 2010 - by jono
Acire 0.3 Released

Everyone’s favorite tool to browse Python snippets, run them, learn from them and incorporate them into your programs has been released! This new release has the following new features:
- Translated – Acire has now got support for multiple languages, but this is very new so it needs your translations! Want to help make Acire rocking in your language? Easy. Go and contribute here!
- Edit Snippets – Acire now allows you to edit the code inside a snippet and execute it within Acire itself.
- Save Snippets – You can now save the snippets, even if they have been edited, into a specific file on your system.
- Look and Feel Polish – a little bit of spit and shine has been applied to respect your chosen monospace font, use a scalable icon for docky and a few other little changes.
As I have mentioned before, I the snippets that Acire shows and the Acire itself are in two separate packages (this means that others can write viewers to view the snippets on other environments).
Installing Acire and it’s snippets is simple. First install the daily snippets PPA (this will deliver new snippets to your system on a daily bases):
sudo add-apt-repository ppa:python-snippets-drivers/python-snippets-daily
sudo apt-get update
sudo apt-get install python-snippets
Now install the Acire PPA:
sudo add-apt-repository ppa:acire-team/acire-releases
sudo apt-get update
sudo apt-get install acire
Right now packages are available for Ubuntu 10.04 Lucid Lynx and Ubuntu 9.10 Karmic Koala packages should be available soon.
We need your snippets!
The fuel that makes Acire rock is the library of snippets. To really get the most out of Acire and it’s library of snippets, we need you to contribute snippets that demonstrate something in Python. These snippets are really helpful in showing us all how a given Python modules works, and really helpful in lowering the bar to development. Here is how you can contribute a snippet!
Step 1: Grab the library
Just run:
bzr branch lp:python-snippets
Step 2: Create your snippet
A snippet should demonstrate a specific feature in a given module or in the Python language. This could include showing how to use a specific widget, a feature of that widget, or another function.
python-snippets is divided into sub-directories which outlines the theme of the snippets. You should pick the most appropriate directory to put your snippet it, and add it there. If a suitable directory does not exist already, create it and add it there.
Step 3: Add metadata
The way Acire pulls out the snippets is by detecting some specific metadata additions to comments at the top of the file You should now add the following meta data as comments to the top of the file:
# [SNIPPET_NAME: A Short Name For The Snippet]
# [SNIPPET_CATEGORIES: Category] <-- see CATEGORIES file for existing categories
# [SNIPPET_DESCRIPTION: A single line description of the snippet]
# [SNIPPET_AUTHOR: Your Name <your@emailaddress.com>]
# [SNIPPET_LICENSE: An Open Source license (from the LICENSES file)]
Here is an example:
# [SNIPPET_NAME: Playing a Pipeline]
# [SNIPPET_CATEGORIES: GStreamer]
# [SNIPPET_DESCRIPTION: Construct and play a pipeline]
# [SNIPPET_AUTHOR: Jono Bacon <jono@ubuntu.com>]
# [SNIPPET_LICENSE: GPL]
You now need to add your file to your branch with:
bzr add your-snippet.py
Step 4: Propose it for merging
With your new snippet ready, it is time to propose it for inclusion in the main python-snippets library.
First, commit your changes to your local branch with:
bzr commit
Now push it to your own branch on Launchpad:
bzr push lp:~<your launchpad username>/python-snippets/<name of your branch>
As an example:
bzr push lp:~jonobacon/python-snippets/gstreamer-snippets
Now 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.
We will then review the merge and if it looks good, add it to python-snippets and it will be delivered to Acire users in the next daily package upload.







