Kullanıcıların yazı tipi (veya sistem varsayılanı) seçimiyle stil vermelerine izin vermek istediğim bir GtkEntry var. Yazı tipini tanımlamak için "Monospace 10" gibi bir Pango açıklama dizesiyle bitiriyorum.Pango.FontDescription öğesinden GtkEntry yazı tipini ayarlama
Şu anda override_font
kullanıyorum, CSS styling lehine önerilmemektedir.
En azından "doğru" yapmayı denemek isterim, ancak şimdi CSS'yi Pango dizesinden almak için oldukça kıvrımlı ve kırılgan bir iş akışı gibi görünüyor. İşte bir example from Github var: CSS bir dizede olduğu
def _get_editor_font_css():
"""Return CSS for custom editor font."""
font_desc = Pango.FontDescription("monospace")
if (gaupol.conf.editor.custom_font and
gaupol.conf.editor.use_custom_font):
font_desc = Pango.FontDescription(gaupol.conf.editor.custom_font)
# They fucking broke theming again with GTK+ 3.22.
unit = "pt" if Gtk.check_version(3, 22, 0) is None else "px"
css = """
.gaupol-custom-font {{
font-family: {family},monospace;
font-size: {size}{unit};
font-weight: {weight};
}}""".format(
family=font_desc.get_family().split(",")[0],
size=int(round(font_desc.get_size()/Pango.SCALE)),
unit=unit,
weight=int(font_desc.get_weight()))
css = css.replace("font-size: 0{unit};".format(unit=unit), "")
css = css.replace("font-weight: 0;", "")
css = "\n".join(filter(lambda x: x.strip(), css.splitlines()))
return css
sonra sonra bir CSSProvider
oluşturabilir ve stil bağlam en add_provider()
o geçmesine (bu arada, bu uca biriken mu CSS sağlayıcıları?).
Bu, fontun tekrar Pango'ya geri döndüğü sisteme geri getirilmesi için çok iş gibi görünüyor!
Bu gerçekten bunun için doğru yol mu?