Hi,
I have been trying to offer a theme selection in an application,
but I can't get the chosen theme to update the screen. I'm not sure if
I'd like it to update only the application it runs from or the whole
desktop theme, but if I could get at least get one of both working I'd 
be happy. Ideally, I'd like to have a desktop-theme switcher too.

I have made a little example-app to test it. If someone could look at it 
and tell me what I am missing it would be really appreciated.

Thanks a lot.
--
Philippe Gendreau
#!/usr/bin/env python

# theme.py

import gtk
import isys, os
from _gtk import gtk_set_locale, gtk_rc_init, gtk_rc_reparse_all
from _gtk import _gtk_nuke_rc_files, _gtk_nuke_rc_mtimes

class ThemeWindow:

    def get_themes(self,clist):
        for dir in os.listdir('/usr/share/themes'):
            row = clist.append (((dir),))
            clist.set_row_data (row, dir)

    # If we come here, then the user has selected a row in the list.
    def selection_made(self, clist, row, event, data=None):
        # Get the text that is stored in the selected row
        # which was clicked in. We will receive it as a pointer in the
        # argument text.
        text = clist.get_text(row, 0)

        # Just prints some information about the selected row
        #print ("You selected row %d.\n" % row)
        print ("You selected row %d.\n"
               "The text in this cell is %s\n" % (row, text))

        rcfile = '/usr/share/themes/' + text + '/gtk/gtkrc'
        gtk.rc_parse(rcfile)

        _gtk_nuke_rc_mtimes ()
        _gtk_nuke_rc_files ()
        gtk_rc_reparse_all ()
        gtk_rc_init ()

        return

    def __init__(self):
        window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
        window.set_usize(300, 150)

        window.set_title("Gtk+ Theme Chooser")
        window.connect("destroy", gtk.mainquit)

        vbox = gtk.GtkVBox(gtk.FALSE, 5)
        vbox.set_border_width(5)
        window.add(vbox)
        vbox.show()

        # Create a scrolled window to pack the CList widget into
        scrolled_window = gtk.GtkScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)

        vbox.pack_start(scrolled_window, gtk.TRUE, gtk.TRUE, 0)
        scrolled_window.show()

        # Create the CList.
        clist = gtk.GtkCList()

        # When a selection is made, we want to know about it. The callback
        # used is selection_made, and its code can be found further down
        clist.connect("select_row", self.selection_made)

        # It isn't necessary to shadow the border, but it looks nice :)
        clist.set_shadow_type(gtk.SHADOW_OUT)

        # What however is important, is that we set the column widths as
        # they will never be right otherwise. Note that the columns are
        # numbered from 0 and up (to 1 in this case).
        clist.set_column_width(0, 150)

        # Add the CList widget to the vertical box and show it.
        scrolled_window.add(clist)
        clist.show()
        
        self.get_themes(clist)

        # The interface is completely set up so we show the window and
        # enter the gtk_main loop.
        window.show()

def main():
    gtk.mainloop()
    return 0

if __name__ == "__main__":
    ThemeWindow()
    main()

Reply via email to