Applets:Example (Python)

From AWN Wiki

Jump to: navigation, search

The following code is the example python applet (compatible with Awn 0.4). It should be used as a quick reference for developing your own applets.

#!/usr/bin/python
#
#       AWN Test Python Applet
#
#       Copyright (c) 2007 Neil Jagdish Patel
#                     2010 Michal Hruby
#
#       This library is free software; you can redistribute it and/or
#       modify it under the terms of the GNU Lesser General Public
#       License as published by the Free Software Foundation; either
#       version 2 of the License, or (at your option) any later version.
#
#       This library is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#       Lesser General Public License for more details.
#
#       You should have received a copy of the GNU Lesser General Public
#       License along with this library; if not, write to the
#       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#       Boston, MA 02111-1307, USA.

import sys, os
import gobject
import gtk
import awn

class App(awn.AppletSimple):
    def __init__(self, uid, panel_id):
        # Initiate Applet
        awn.AppletSimple.__init__(self, "applet-name", uid, panel_id)

        # set icon
        self.set_icon_name("gtk-apply")

        # we could also set our icon from pixbuf
        #icon = gdk.pixbuf_new_from_file("/home/njp/Projects/test.png")
        #self.set_icon_pixbuf(icon)

        # Get out tooltip ready
        self.set_tooltip_text("Tooltip")

        # Draw our dialog
        self.dialog = awn.Dialog(self)
        button = gtk.Button(stock="gtk-apply")
        self.dialog.add(button)
        button.show_all()

        # Connect our events
        self.connect("clicked", self.on_clicked)

    def on_clicked(self, widget):
        if (self.dialog.flags() & gtk.VISIBLE) != 0:
            self.dialog.hide()
        else:
            self.dialog.show_all()


if __name__ == "__main__":
    awn.init(sys.argv[1:])
    applet = App(awn.uid, awn.panel_id)
    awn.embed_applet(applet)
    applet.show_all()
    gtk.main()

Personal tools