Why is the source not changed in Raspberry Pi?

Asked

Viewed 73 times

1

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

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

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

Or this way, to modify only 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 in linux Mint and installed them all on Raspberry, modified the font with several different names but none works, copied the sources of linux Mint and put in Raspberry and also did not work. I also checked the sources installed at Raspberry, and they’re all the ones I tried installed. It doesn’t seem logical this error, the most interesting is that if you modify only the font size, leaving the default font, the size is also not changed. Is there any possible explanation and solution for this case?

1 answer

4


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!

  • I can not believe, I managed to do here on the computer, but also does not generate changes in Raspberry!

  • Hmmm... I did on the computer here - compare with yours. Hitting the selectors took some work, since they are different from the example there.

  • 1

    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?

  • 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.