The problem seems more complicated than it should be.
Apparently one of the developers of the Raspberry UI decided that it’s not for people to exchange fonts - see this post here:
https://www.raspberrypi.org/forums/viewtopic.php?p=1070816#p1070816
And it’s referenced by people who had the same problem that you’re having (although programming in C).
They managed to get around the problem - but the code to force another source is much more complicated, so you need to use Gtk3’s internal CSS mechanisms - track the thread below and see Petero’s post of November 29, 2016:
https://www.raspberrypi.org/forums/viewtopic.php?t=166690
A variation of the program using gtk + CSS that works in Python on the computer is:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk as gtk, Gdk as gdk
import tempfile, os
def setup():
window = gtk.Window()
# Aqui onde perdi mais tempo: nos exemplos usando glade, os
# seletores parecem ser "GtkTextView" e "GtkButton" -
# mas sem o glade são "textview" e "button" em minúsculas.
# (Também pode ser diferença na versão do GTK)
css = "textview {font-size: 24pt; color: #d0d0ff;}\n button {font-size: 40pt; color: #ff0000} "
# (a cor do textview não funcionou )
provider = gtk.CssProvider()
css_filename = tempfile.NamedTemporaryFile().name
with open(css_filename, "wt") as css_file:
css_file.write(css)
provider.load_from_path(css_filename)
# Existe o método "load_from_data", que no exemplo em C
# carrega uma string direto - mas em Python esse método
# não está funcionando, por isso o arquivo temporário
print(css_filename, provider.to_string())
# esse print certifica que o CSS foi lido e parseado:
# o GTK muda a formatação do whitespace
os.remove(css_filename)
frame = gtk.VBox()
window.add(frame)
text = gtk.TextView()
text.set_name("texto")
frame.pack_start(text, True, True, 6)
button = gtk.Button("Text test")
button.set_name("botao")
frame.pack_start(button, False, True, 6)
# aplica-se a styleshhet a toda a aplicação,
# em vez de um único widget.
screen = gdk.Screen.get_default()
context = gtk.StyleContext()
context.add_provider_for_screen(screen, provider, gtk.STYLE_PROVIDER_PRIORITY_USER)
window.connect("destroy", gtk.main_quit)
window.show_all()
def main():
gtk.init([])
window = setup()
gtk.main()
Now it’s explained, it didn’t make any sense. Thank you very much for the answer! How could I make that code in Python? If I can increase the fountain is already great!
– HelloWorld
I can not believe, I managed to do here on the computer, but also does not generate changes in Raspberry!
– HelloWorld
Hmmm... I did on the computer here - compare with yours. Hitting the selectors took some work, since they are different from the example there.
– jsbueno
In the computer the changes occur but in Raspberry not! I’m already tired, 2 days on top of it and do not leave the place. Thank you very much for trying. Is there any other possibility?
– HelloWorld
from here: think to ask questions on a forum in English, about raspbery even, without worrying about the language - focus on GTK and want to change the sources. E .. trying to change CSS selectors. It may be that they change from one gtk version to another and it may be different in what runs on the rasp.
– jsbueno