Skip to content

Instantly share code, notes, and snippets.

@niktto
Created August 19, 2012 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niktto/3397368 to your computer and use it in GitHub Desktop.
Save niktto/3397368 to your computer and use it in GitHub Desktop.
Issue with default Unity styling
from gi.repository import Gtk
builder = Gtk.Builder()
builder.add_from_string(
"""
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkFixed" id="fixed1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="width_request">500</property>
<property name="height_request">500</property>
<child>
<object class="GtkButton" id="sample_button">
<property name="label" translatable="yes">button</property>
<property name="width_request">250</property>
<property name="height_request">166</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<style>
<class name="sample_button"/>
</style>
</object>
<packing>
<property name="x">146</property>
<property name="y">114</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
"""
) # very simple sample of glade theme
window = builder.get_object("window1")
styler = Gtk.CssProvider()
styler.load_from_data(
"""
GtkButton {
background: url('http://24.media.tumblr.com/tumblr_m8v8njYAeb1rxukhwo2_500.jpg');
border: 0; color: red;
}
GtkButton:hover { color: green;}
"""
)
button = builder.get_object("sample_button")
button_context = button.get_style_context()
button_context.add_provider(styler, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
window.connect('delete-event', Gtk.main_quit)
window.show()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment