3
# [SNIPPET_NAME: Dialog (Font Selection)]
4
# [SNIPPET_CATEGORIES: PyKDE4]
5
# [SNIPPET_DESCRIPTION: A dialog that provides interactive font selection]
6
# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
7
# [SNIPPET_LICENSE: GPL]
8
# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KFontDialog.html]
10
from PyQt4.QtCore import SIGNAL, Qt
11
from PyQt4.QtGui import QLabel, QDialog, QFont
13
from PyKDE4.kdecore import i18n
14
from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KFontDialog
16
helpText = """A KFontDialog allows the user to select a new font.
18
Click the button to change the font of the displayed text.
21
quote = """Now is the winter of our discontent
22
made summer by this glorious sun of York.
25
dialogName = "KFontDialog"
27
class MainFrame(KVBox):
28
def __init__(self, parent):
29
KVBox.__init__(self, parent)
31
self.help = QLabel (i18n (helpText), self)
32
self.layout ().setAlignment (self.help, Qt.AlignHCenter)
34
self.button = KPushButton(i18n("Show %s" % dialogName), self)
35
self.button.setFixedSize (200, 30)
36
self.layout ().setAlignment (self.button, Qt.AlignHCenter)
37
self.fontLabel = QLabel (quote, self)
38
self.layout ().setAlignment (self.fontLabel, Qt.AlignHCenter)
40
self.connect(self.button, SIGNAL('clicked()'), self.showDialog)
44
result, checkState = KFontDialog.getFont (font)
45
if result == QDialog.Accepted:
46
self.fontLabel.setFont (font)
50
# This example can be run standalone
52
if __name__ == '__main__':
56
from PyQt4.QtCore import Qt
57
from PyQt4.QtGui import QFrame, QVBoxLayout
59
from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
60
from PyKDE4.kdeui import KApplication, KMainWindow
62
class MainWin (KMainWindow):
63
def __init__ (self, *args):
64
KMainWindow.__init__ (self)
67
self.setCentralWidget (MainFrame (self))
70
#-------------------- main ------------------------------------------------
72
appName = "default.py"
74
programName = ki18n ("default") #ki18n required here
76
description = ki18n ("Default Example") #ki18n required here
77
license = KAboutData.License_GPL
78
copyright = ki18n ("(c) 2007 Jim Bublitz") #ki18n required here
79
text = ki18n ("none") #ki18n required here
80
homePage = "www.riverbankcomputing.com"
81
bugEmail = "jbublitz@nwinternet.com"
83
aboutData = KAboutData (appName, catalog, programName, version, description,
84
license, copyright, text, homePage, bugEmail)
86
# ki18n required for first two addAuthor () arguments
87
aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
88
aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
90
KCmdLineArgs.init (sys.argv, aboutData)
93
mainWindow = MainWin (None, "main window")
95
app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)