12

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)
user450766
  • 133
  • 1
  • 5

2 Answers2

7

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

supakeen
  • 2,876
  • 19
  • 19
  • what would I use, if I want the system default font size, too? – user450766 Sep 17 '10 at 16:48
  • you're right, it's working. That's something I could have thought of myself. Thanks! – user450766 Sep 18 '10 at 01:57
  • 1
    actually, (tested in Ubuntu 12.04) it is not working. Setting the font to "monospace" keeps the last set font size. – xubuntix Aug 07 '12 at 07:35
  • 1
    I'm not sure this is entirely correct. "Monospace" is the fontconfig alias for the default monospace font. GTK+ has its own settings in dconf where you can change the default monospace font through gnome-tweak-tool, without affecting fontconfig aliases in any way. – Marius Gedminas Sep 16 '15 at 10:23
  • 1
    Hm, now I see that GTK+ itself hardcodes "Monospace", so maybe I'm worrying unnecessarily: https://github.com/GNOME/gtk/blob/ee8eb91523fcca2c7d0c783a3289e9f72bb74770/gtk/theme/Adwaita/_common.scss#L3334-L3336 – Marius Gedminas Sep 16 '15 at 10:38
1

[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

user3439968
  • 3,418
  • 1
  • 18
  • 15