[OBORONA-SPAM] [pygtk] Installing and switching themes in pygtk
Popov Oleg
opopov at yandex.ru
Mon Feb 20 16:59:49 WST 2006
David Hirschfield пишет:
> I'm a newbie to pygtk and gtk programming in general...so forgive
> these very basic questions:
>
> 1. Where does a person find gtk themes? Is there a good clearing house
> website?
-www.gnome-look.org
> 2. Do all gtk themes work with pygtk? I would assume so...as long as
> the theme is for the version of gtk and pygtk you're using.
> 3. How does one install new gtk themes? Do they have to be installed
> in a specific directory? If so, where?
> 4. How can a pygtk program change the gtk theme used to draw itself?
> Can it be done programmatically from within the pygtk program that
> wants to set its theme?
This is short example :
1) You can make your own rc file and place it into directory for your
application
for example:
------------------<custom rc file mygtkrc>----------------------
gtk-theme-name = "Sugarshack"
style "user-font"
{
font_name="verdana 10"
}
widget_class "*" style "user-font"
--------------------------------------------------
2) Then You can reparse this file before main window will be visible :
mygtkrc=os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),'mygtkrc'))
gtk.rc_set_default_files([mygtkrc])
self.current_setting=gtk.settings_get_default()
gtk.rc_reparse_all_for_settings(self.current_setting,True)
--------------------------example.py-----------------------------------------
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import pygtk
pygtk.require('2.0')
import gtk
import os
import sys
class HelloGtkApp:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Custom gtkrc demo ")
self.window.set_border_width(24)
self.window.set_default_size(210, 80)
self.window.connect("delete_event", lambda widget,event: False)
self.window.connect("destroy", lambda widget: gtk.main_quit())
self.button1 = gtk.Button("Hello")
self.button1.connect("clicked", self.button_clicked)
self.window.add(self.button1)
self.set_custom_rc_file()
self.window.show_all()
def set_custom_rc_file(self):
mygtkrc=os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),'mygtkrc'))
gtk.rc_set_default_files([mygtkrc])
self.current_setting=gtk.settings_get_default()
gtk.rc_reparse_all_for_settings(self.current_setting,True)
def button_clicked(self, widget,data=None):
message="Button pressed "
self.dialog=gtk.MessageDialog(self.window,gtk.DIALOG_MODAL,
gtk.MESSAGE_INFO,gtk.BUTTONS_OK,
message_format=message)
self.dialog.connect("response", lambda widget,data: self.dialog.destroy())
self.dialog.show()
myapp=HelloGtkApp()
gtk.main()
-------------------------------------------------------------------
>
> I'm asking because we have a pygtk app that needs to be able to switch
> themes on the fly depending on certain user choices. But we don't want
> it to affect all pygtk apps, just the one the user makes the choice in.
>
> Any pointers appreciated,
> -Dave
>
-Popov Oleg
More information about the pygtk
mailing list