Blame platform-demos/C/samples/fontchooserwidget.py
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="FontChooserWidget", application=app)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a font chooser
|
|
Packit |
1470ea |
self.font_chooser = Gtk.FontChooserWidget()
|
|
Packit |
1470ea |
# a default font
|
|
Packit |
1470ea |
self.font_chooser.set_font("Sans")
|
|
Packit |
1470ea |
# a text to preview the font
|
|
Packit |
1470ea |
self.font_chooser.set_preview_text(
|
|
Packit |
1470ea |
"This is an example of preview text!")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# connect signal from the font chooser to the callback function
|
|
Packit |
1470ea |
self.font_chooser.connect("notify::font", self.font_cb)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# add the font chooser to the window
|
|
Packit |
1470ea |
self.add(self.font_chooser)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback function:
|
|
Packit |
1470ea |
def font_cb(self, event, user_data):
|
|
Packit |
1470ea |
# print in the terminal
|
|
Packit |
1470ea |
print("You chose the font " + self.font_chooser.get_font())
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication(Gtk.Application):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
Gtk.Application.__init__(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_activate(self):
|
|
Packit |
1470ea |
win = MyWindow(self)
|
|
Packit |
1470ea |
win.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = MyApplication()
|
|
Packit |
1470ea |
exit_status = app.run(sys.argv)
|
|
Packit |
1470ea |
sys.exit(exit_status)
|