1. Go: defining methods on struct types

    In Go it's possible to define methods on struct types. The syntax needed for it can be a bit strange for people that are used to define classes and methods in Java, C# etc... but once you learn it it's quite easy to use.

    In my case for example I needed something that could contain a Timer object, a string and a method that could start the timer and call a method at the end of the Timer execution. I implemented it in this way:

    ``` {.toolbar:2 .lang:go .decode:true} type DeviceTimer struct { DeviceID string DeviceTimer *time.Timer }

    func (timer DeviceTimer) startTimer() { <-timer.DeviceTimer.C notifyDeviceTimerExpired(timer.DeviceID) }

    The key point is **row 6** "*func (timer DeviceTimer) startTimer() { ...
    }*" where I defined a method called **startTimer** and I specify timer
    **DeviceTimer** inside the func definition. This basically "extends" the
    struct DeviceTimer adding that method to it. This means that I can call
    that method in this way:
    ``` {.toolbar:2 .lang:go .decode:true}
    timer := time.NewTimer(time.Millisecond * 300)
    device_timer := DeviceTimer{"abc123", timer}
    go device_timer.startTimer()

    This is all you need to do. If you want to read more about this subject, I can suggest to read these two articles:

    Note: I'm not a Go expert and these are just my personal notes I'm taking during my learning experience. I'm very keen to share my notes with everyone, but please don't take them as notes from an expert Go developer.

    read more


  2. Using GtkIconView in Python: a small tutorial

    In these days I was looking for a simple tutorial to understand how to use GtkIconView, but the only thing I was able to find was an example in PHP-Gtk. So I decided to translate it in Python language, thinking it would be useful for other people trying to use that Gtk control. You can find the code here:

    [sourcecode language='python']
    import gtk
    import gobject


    # Main Window setup
    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    window.set_size_request(400, 240)
    window.connect("destroy", gtk.main_quit)
    window.set_title("Python GtkIconView Test")

    # Add a VBox
    vbox = gtk.VBox()

    # Setup Scrolled Window
    scrolled_win = gtk.ScrolledWindow()
    scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

    # Setup ListStore to contain images and description
    model = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)

    # Create a tuple with image files
    immagini = ("BD786-TFR.jpg", "guido_sottozero.jpg", "IMG_0056.JPG", "movies_card.jpg")

    for im in immagini:
    pixbuf = gtk.gdk.pixbuf_new_from_file(im)
    pix_w = pixbuf.get_width()
    pix_h = pixbuf.get_height()
    new_h = (pix_h * DEFAULT_IMAGE_WIDTH) / pix_w # Calculate the scaled height before resizing image
    scaled_pix = pixbuf.scale_simple(DEFAULT_IMAGE_WIDTH, new_h, gtk.gdk.INTERP_TILES)
    model.append((scaled_pix, im))

    # Setup GtkIconView
    view = gtk.IconView(model) # Pass the model stored in a ListStore to the GtkIconView

    # Pack objects and show them all


    The important thing to notice is that you have to store all the images in a GtkListStore and pass it to the GtkIconView as "model" parameter. I hope this example is clear. If you have any question, please comment this post and I'll try to answer.

    This is a screenshot of this example:


    read more


  3. Eclipse plugins for Maemo Development

    [Maemo Team]{style="font-weight: bold;"} has just released a [plugin]{style="font-weight: bold;"} for [Maemo Eclipse integration]{style="font-weight: bold;"}. This tool allows developers to use Eclipse IDE to develop and test Maemo applications.

    This release includes:

    [ 1]{style="font-weight: bold;"}. maemo [PC Connectivity]{style="font-weight: bold;"} version [0.1]{style="font-weight: bold;"} (Beta)
    [ 2]{style="font-weight: bold;"}. maemo ESBox plugin for Eclipse IDE version [1.3.6]{style="font-weight: bold;"} (Beta)
    [ 3]{style="font-weight: bold;"}. maemo Pluthon plugin for Eclipse IDE version [0.1.7]{style="font-weight: bold;"} (Beta)

    Maemo PC connectivity packages are tools and other components developer needs to install into his Internet Tablet to enable connectivity between developer PC and Internet Tablet.

    Maemo ESBox plugin for Eclipse IDE integrates maemo SDK Scratchbox based development environment to the Eclipse development environment. ESBox plugin supports application developers using C, C++ or Python programming language.
    Developers are able to do all their development work inside Eclipse, from starting the project using template to packaging final application into maemo installation package.

    Maemo Pluthon plugin for Eclipse IDE integrates Eclipse IDE development environment to the Internet Tablet so that maemo Python developers do not need to use maemo SDK and Scratchbox as development environment. Maemo Pluthon plugin fully supports application development process with Python where developer develops and tests his Python application directly with Internet Tablet.

    You can find more informations on the official plugin websites:

    [ESbox:]{style="font-weight: bold;"} http://esbox.garage.maemo.org/
    [PluThon:]{style="font-weight: bold;"} http://pluthon.garage.maemo.org/

    read more


« Page 2 / 2