probonopd / ptouch-770

Brother P-touch P700 label printer for Linux
GNU General Public License v2.0
38 stars 5 forks source link

Font selection dropdown not functional #4

Closed probonopd closed 5 years ago

probonopd commented 6 years ago

Font selection dropdown not functional

probonopd commented 6 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)