Closed probonopd closed 5 years ago
Here is a nice font chooser. But how do I get the font filename from this?
from gi.repository import Gtk, Pango
import sys
class MyWindow(Gtk.ApplicationWindow):
def __init__(self, app):
Gtk.Window.__init__(self, title="FontChooserWidget", application=app)
self.font_chooser = Gtk.FontChooserWidget()
self.font_chooser.set_font("FreeSans")
self.font_chooser.set_preview_text("This is an example of preview text!")
self.font_chooser.connect("notify::font", self.font_cb)
self.add(self.font_chooser)
def font_cb(self, event, user_data):
print("You chose the font " + self.font_chooser.get_font())
desc = Pango.FontDescription(self.font_chooser.get_font()).to_filename()
print(desc)
class MyApplication(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self)
def do_activate(self):
win = MyWindow(self)
win.show_all()
def do_startup(self):
Gtk.Application.do_startup(self)
app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
Font selection dropdown not functional