2. Running the applet in its own window

A common issue when developping an applet is the debug process which means knowing what it's failing and why. As an applet is nothing but a GTK+ application we can use an additional command line argument like "run-in-window" to put it in window-mode by creating a GTK+ window and inserting the applet in it.


    if len(sys.argv) == 2 and sys.argv[1] == "run-in-window":   
        main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        main_window.set_title("Python Applet")
        main_window.connect("destroy", gtk.mainquit) 
        app = gnome.applet.Applet()
        sample_factory(app, None)
        app.reparent(main_window)
        main_window.show_all()
        gtk.main()
        sys.exit()
    

We can see how the applet object use the gtk.Widget reparent() method to change its parent to the GTK+ Window "main_window".