0

I can't seem to find any documentation on changing the color of a button in Gtk+ on Julia. I couldn't get the @ GtkStyleContext in the Gtk+ package to work. So I tried the following example here:

     obj = GtkButtonLeaf("test")
     context = ccall((:gtk_widget_get_style_context,libgtk),Ptr{GObject},(Ptr{GObject},),obj)

     provider = ccall((:gtk_css_provider_get_default,libgtk),Ptr{GObject},())
     filename = "C:/Users/Administrator/Documents/CMPT276_a5_copy/theme.css"

     GError() do error_check
     ccall((:gtk_css_provider_load_from_path,libgtk), Bool,
       (Ptr{GObject}, Ptr{UInt8}, Ptr{Ptr{GError}}),
       provider, bytestring(filename), error_check)
     end

     ccall((:gtk_style_context_add_provider,libgtk),Void,(Ptr{GObject},Ptr{GObject},Cuint),
            context,provider,priority)

The code compiles without any errors, but nothing happens to the button. Is the css_provider_load_From_path() not loading the .css file? This is the only reason I can think of. Any help would be much appreciated!

Edit:

priority = 1.

theme.css:

    GtkButton{
        color: red;
    }
JJTO
  • 847
  • 2
  • 8
  • 13
  • Show your CSS, please. If the provider is not loading the file, you should get an error in the GError. Also what priority are you using? – andlabs Dec 02 '16 at 14:47
  • priority = 1. theme.css: GtkButton{ color: red; } – JJTO Dec 04 '16 at 09:05

1 Answers1

0

this works:

using GTK3_jll 
const libgtk = libgtk3
using Gtk, Gtk.ShortNames
function set_gtk_style!(widget::Gtk.GtkWidget, style::String, value::Int=600)       # thank to MeteorBizone
    sc = Gtk.GAccessor.style_context(widget)
    pr = Gtk.CssProviderLeaf(data=style)
    push!(sc, Gtk.StyleProvider(pr), value)
end
g = GtkGrid()
fg_win = GtkWindow( "Try Button")
btn = GtkButton("\u22EF Push \u22EF")
set_gtk_style!(btn,".text-button {font: 20px \"sans\";color:red}",600)
g[1,1] = btn
push!(fg_win,g)
showall(fg_win)

I populate the class text_button.

Rossati
  • 79
  • 1
  • 5