Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use the system monospace font in gtk textview

Tags:

python

gtk

I would like to have a GtkTextView in my (Python) program which shows text with the system monospace font. I found many ways which use an expicit font family name and size. However, I would like to use the system specified monospace font (e.g. from the ubuntu font preferences panel).

My program should be able to run on Windows as well as Linux without modifications, chosing automatically the right font.

to clarify, this is not what I want:

fontdesc = pango.FontDescription("Courier 18")
textview.modify_font(fontdesc)
like image 922
user450766 Avatar asked Sep 17 '10 16:09

user450766


2 Answers

You can just use "monospace 18" as your font and it will use the system monospaced font.

like image 64
supakeen Avatar answered Sep 19 '22 15:09

supakeen


[available since 3.16]

set_monospace()

GTK3+ Doc https://developer.gnome.org/gtk3/stable/GtkTextView.html#gtk-text-view-set-monospace

gtk_text_view_set_monospace ()

void

gtk_text_view_set_monospace (GtkTextView *text_view, gboolean monospace);

Sets the “monospace” property, which indicates that the text view should use monospace fonts.

Parameters

text_view a GtkTextView

monospace TRUE to request monospace styling

like image 23
user3439968 Avatar answered Sep 18 '22 15:09

user3439968