Re: Setting styles in Gtk 3.0






2013/10/10 Dov Grobgeld <dov grobgeld gmail com>
​Here's what I ended up doing, with the help of Denis Linvinus:

#!/usr/bin/python

from gi.repository import Gtk

mw = Gtk.Window()

prov = Gtk.CssProvider()
Gtk.StyleContext.add_provider_for_screen(mw.get_screen(),prov,Gtk.STYLE_PROVIDER_PRIORITY_USER)
prov.load_from_data("""
* {
    font: Serif 30;
    background-color: pink;

}
""")

mw.connect('delete-event',Gtk.main_quit)
mw.add(Gtk.Label('Hello Gtk %s!'%Gtk._version))
mw.show_all()
Gtk.main()

Note that it is possible to run several prov.load_from_data() calls to interactively change the properties, e.g. based on some external event.


bad idea, you should use classes and states of widget (active,prelight,focused)

also, have a look at  this video http://www.youtube.com/watch?v=gTYUn72Wjyk
it show power of css in gtk3


1) you may attach css class for special widget, for example if you will have following application style

.my_custom_css_class {
background-color: #FF0000;
}

then you can attach this class on the fly
label.get_style_context().add_class("my_custom_css_class");

or remove it
label.get_style_context().remove_class("my_custom_css_class");

more over you may remove default class if you wish
button.get_style_context().remove_class("button");


2) if you will use your own widgets  then you can use your custom widget name in css as selector
for example  i have custom class
public class VTToggleButton : Gtk.Button{
}

now i can use name VTToggleButton in css

VTToggleButton {
background-color: #FF0000;
}

so you can completely divide applications view from application sources.
i use such approach in my application https://github.com/linvinus/AltYo

custom css style stored as option in configuration file, so user can change application theme by it self

 
​Regards,
Dov


On Thu, Oct 10, 2013 at 4:16 PM, Paul Davis <paul linuxaudiosystems com> wrote:



On Thu, Oct 10, 2013 at 4:05 AM, Dov Grobgeld <dov grobgeld gmail com> wrote:
Hi,

Has something changed with the setting of styles in Gtk3, or is there some environment setting that inhibits the setting of the style? Consider the following python program:

#!/usr/bin/python

from gi.repository import Gtk

Gtk.rc_parse_string("""
style "normal" {
    font_name ="serif 30"
}
widget "*" style "normal"
""")

My impression was that GTK RC files were deprecated (and ignored) and that all themeing/styling was done with CSS now. I may be wrong about that. Note that it isn't trivial to do per-widget CSS stuff, apparently.
 


_______________________________________________
gtk-list mailing list
gtk-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]