Why does not font change in Raspberry Pi?

1

I have a graphical application using Gtk in Python, the program has font definitions and font sizes. When running the program in linux works correctly, but when running on Raspberry the font is not changed. Does anyone know why this happens?

The part of the code that modifies the font is as follows:

self.tp_encerrar_btn.modify_font(Pango.FontDescription('Dejavu Sans 10'))

Or this way, to only modify the size and leave the default font:

fonte = Pango.FontDescription()
fonte.set_absolute_size(15000)
self.tp_tabela.modify_font(fonte)

I checked the packages installed on linux mint and installed them all on Raspberry, I modified the font with a lot of different names but none worked, I copied the linux mint fonts and I put it on Raspberry and it did not work either. I also checked the fonts installed on Raspberry, and all the ones I tried installed. It does not seem logical to this error, the most interesting is that if you modify only the font size, leaving the default font, the size also does not change. Is there any possible explanation and solution for this case?

    
asked by anonymous 06.02.2018 / 19:28

1 answer

4

The problem seems more complicated than it should be.

Apparently one of Raspberry's UI developers decided that it's not for people to be switching sources - see this post here: link

And it is referenced by people who have had the same problem you are having (although programming in C).

They have managed to get around the problem - but the code to force another source is much more complicated, it is necessary to use the internal mechanisms of Gtk3 CSS - take the thread below and see the post of November 29, 2016 of PeterO: / p>

link

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()
    
07.02.2018 / 13:21