Happy 2013!

Receiving my award at ISEF in May. Credit: James Knox

WOW, what a year!!

Looking back to 2012 is kind of hard, it was the year when I first got to a plate (a life-long dream), meet Europe, including Lyon, that became my favorite city ever, and fulfilled another two life-long at the same time:  traveled to the US, attended ISEF and even got an special award!

Midellwhile I was a normal guy attending my first year of Computer Engieneering at the University of Buenos Aires, and that actually help me to came up with an idea that I hopefully think will became my very first production site early this year. And even managed to have time to give my first talk at an open conference as Python Conference Argentina. oup, I almost forget, I was interviewed in national TV!

And of course I could not make any of those things without the help of my life-long friends and all the people all met along the way!

I have no idea how I’ll make this 2013 as awesome (or even more!) as 2012. But that is another history, I know I’ll have fun and have a supper exiting year.

Have a nice 2013 everyone!!

 

 

Music Relaxing power

I’m an overthinker. I use to have a hard every time I want to just relax. I like being busy.

But there is one think that always work for me: be in a concert of a band I don’t know. I get loose in the mood, all the mess I have in my head start having sense and after a while I don’t know longer what I was worry about a minutes before.

A super crappy picture I took the last time I went to a concert I didn’t know any of the songs they performed

This post also explains why I always agree to go to concerts from bands I don’t know (nor they are a big promise). A good sound and order is almost a must in order to have this effect on me, but in spite of that I’ve been to concerts of bands that were as bad as you can not imagine and I felt relaxed anyway.

Give it a try. It might work for you to.

 

Why Donnees sucks

It sucks for many reasons. In this post I’ll explain the most terrifying issues, why it was implemented the way it was and explain how I think should be improved in future versions.

Donnees was designed for a since fair, to motorize fish crops (yes, fish crops!), and with a deadline. I’ve been the only user since it started to been developed. That lead me to do some intolerable mistakes: all filepaths are relative instead of absolute, the database and the configuration file is in the same directory the code lives. At first this things looked like a great idea, because I wanted to be able to execute the program from a USB drive without any changes, and didn’t know the “right” way to do that.

A lot of configuration variables are missing, since I was the only user and developer the best way to configure something was editing the code!, I always knew this was wrong, but remember that I mentioned I had a deadline? All the (few) configuration options are in a lots of configuration files (one file per variable!) (!), again, remember the deadline.

These, and the other problems the software has wasn’t much important when I was developing this, because the data I was collecting with it was way more important than the software itself.

 

Donnees code released as open source project

What is Donnees?, Is a Python Powered Data Acquisition Software, find out more here.

So here I am releasing the project I’ve been working on for more than a year, Donnees (it means “data” in french). It has a couple of interesting features, or could be at least used as example code for many libraries.

This program was originally designed to be shipped with a science fair project (it ended up 4th in the category of electrical and mechanical engineering at ISEF). Currently it supports the following features:

  • Live data plotting
  • Extensible data sources, serial port is natively supported
  • Allow to record data as data logger
  • Exportable charts
  • E-mail reports
  • Built-in web interface
  • Linux and Windows support
  • Built-in SCADA sofware

What is the status, today?

The truth is that is sucks, as code quality and personalization capabilities. It may not be useful to someone else yet, but I ‘m working on it to come out with great piece of code someday. The rest of the problems (and their possible solution) can be found here.

Feel free to fork it, submit code (even though you don’t have it tested, we’ll work it through) or use it for whatever you think it may be suitable, as long as you follow the statments of the GPL license. It will also be cool if you let me know If you do something with Donnees’ code.

 

Twisted + PyGTK

A few weeks ago I starded interresting about Twisted and asynchronous programming. I realy liked the way that Twisted handles events and callbacks.

I’ve been working in a program with a graphical interface built in PyGTK that uses threads for every single taks and I wondered if I can had this program running in just one thread asynchronously. It’s realy simple implement twisted code in a PyGTK applicacion since both are event-based and Twisted has a native API to do so.

Let’s build a simple PyGTK example:

import gtk
 
class Gui:
    def __init__(self):
        self.window = gtk.Window()
        self.window.set_default_size(200,200)
        self.window.set_title("Simple PyGTK program")
 
        self.vbox = gtk.VBox()
 
        self.button = gtk.Button("I'm a button!")
        self.label = gtk.Label("Nothing here")
 
        self.vbox.pack_start(self.button)
        self.vbox.pack_start(self.label)
 
        self.window.add(self.vbox)
 
        self.button.connect("clicked", self.on_clicked)
        self.window.connect("destroy", lambda x: gtk.main_quit())
        self.window.show_all()
        self.window.show()
 
    def on_clicked(self, widget):
       self.label.set_text("You clicked the button!") 
 
if __name__ == "__main__":
    app = Gui()
    #starts the GTK loop
    gtk.main()

So, this example is using the Gtk loop. Twisted applications use the Twisted reactor, and we need the Twisted reactor to “understend” Gtk signals.
This is what you have to do:

from twisted.internet import gtk2reactor # for gtk-2.0
gtk2reactor.install()
 
#Your code
#...
 
from twisted.internet import reactor
#this starts the reactor
reactor.run()

Now we can re-implement our first example and it would look like this:

import gtk
from twisted.internet import gtk2reactor # for gtk-2.0
gtk2reactor.install() #this installs the gtk reactor
#NOTE: This have to be at top always, before importing the reactor
 
class Gui:
    def __init__(self):
        self.window = gtk.Window()
        self.window.set_default_size(200,200)
        self.window.set_title("Simple PyGTK program")
 
        self.vbox = gtk.VBox()
 
        self.button = gtk.Button("I'm a button!")
        self.label = gtk.Label("Nothing here")
 
        self.vbox.pack_start(self.button)
        self.vbox.pack_start(self.label)
 
        self.window.add(self.vbox)
 
        self.button.connect("clicked", self.on_clicked)
        self.window.connect("destroy", lambda x: gtk.main_quit())
        self.window.show_all()
        self.window.show()
 
    def on_clicked(self, widget):
       self.label.set_text("You clicked the button!") 
 
if __name__ == "__main__":
    app = Gui()
    #No Gtk anymore!
    #gtk.main()
    from twisted.internet import reactor
    #let's start the loop
    reactor.run()

Now you can enjoy the Twisted power in your graphical apps, here is a (very)simple example using Twisted-way callbacks.

import gtk
import time
from twisted.internet import gtk2reactor # for gtk-2.0
gtk2reactor.install() #this installs the gtk reactor
#NOTE: This have to be at top always, before starting the reactor
 
class Gui:
    def __init__(self):
        self.window = gtk.Window()
        self.window.set_default_size(200,200)
        self.window.set_title("Simple PyGTK program")
 
        self.vbox = gtk.VBox()
 
        self.button = gtk.Button("I'm a button!")
 
        self.time = time.time()
 
        self.label = gtk.Label("0")
 
        self.vbox.pack_start(self.button)
        self.vbox.pack_start(self.label)
 
        self.window.add(self.vbox)
 
        self.button.connect("clicked", self.on_clicked)
        self.window.connect("destroy", lambda x: gtk.main_quit())
        self.window.show_all()
        self.window.show()
        self.time = time.time()
 
    def on_clicked(self, widget=None):
        self.label_text = time.time() - self.time
        self.label.set_text("%.2fs" % self.label_text)
        #Twisted will call the sefl.on_clicked function every 100ms
        reactor.callLater(.1, self.on_clicked)
 
 
if __name__ == "__main__":
    app = Gui()
    #No Gtk anymore!
    #gtk.main()
    from twisted.internet import reactor
    #let's start the loop
    reactor.run()

Twisted also has APIS for others toolkits such as Tkinter, wxPython, Win32(Windows) and PyUI.
For more information you can visit the official documentation.