~stefano-palazzo/python-snippets/python-snippets-stefano0

« back to all changes in this revision

Viewing changes to pykde4/kfontdialog.py

  • Committer: Jono Bacon
  • Date: 2010-03-24 06:59:55 UTC
  • mfrom: (49.1.1 python-snippets)
  • Revision ID: jono@ubuntu.com-20100324065955-g6nbs0zaxhxek62m
A bunch of fantastic KDE snippets thanks to nixternal!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
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]
 
9
 
 
10
from PyQt4.QtCore import SIGNAL, Qt
 
11
from PyQt4.QtGui import QLabel, QDialog, QFont
 
12
 
 
13
from PyKDE4.kdecore import i18n
 
14
from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KFontDialog
 
15
 
 
16
helpText = """A KFontDialog allows the user to select a new font.
 
17
 
 
18
Click the button to change the font of the displayed text.
 
19
"""
 
20
 
 
21
quote = """Now is the winter of our discontent
 
22
made summer by this glorious sun of York.
 
23
"""
 
24
 
 
25
dialogName = "KFontDialog" 
 
26
 
 
27
class MainFrame(KVBox):       
 
28
    def __init__(self, parent):
 
29
        KVBox.__init__(self, parent)
 
30
        self.setSpacing (40)
 
31
        self.help = QLabel (i18n (helpText), self)
 
32
        self.layout ().setAlignment (self.help, Qt.AlignHCenter)
 
33
 
 
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)
 
39
        
 
40
        self.connect(self.button, SIGNAL('clicked()'), self.showDialog)
 
41
 
 
42
    def showDialog(self):
 
43
        font = QFont ()
 
44
        result, checkState = KFontDialog.getFont (font)
 
45
        if result == QDialog.Accepted:
 
46
            self.fontLabel.setFont (font)
 
47
 
 
48
 
 
49
 
 
50
# This example can be run standalone
 
51
 
 
52
if __name__ == '__main__':
 
53
 
 
54
    import sys
 
55
 
 
56
    from PyQt4.QtCore import Qt
 
57
    from PyQt4.QtGui import QFrame, QVBoxLayout
 
58
    
 
59
    from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
 
60
    from PyKDE4.kdeui import KApplication, KMainWindow
 
61
                    
 
62
    class MainWin (KMainWindow):
 
63
        def __init__ (self, *args):
 
64
            KMainWindow.__init__ (self)
 
65
 
 
66
            self.resize(640, 480)
 
67
            self.setCentralWidget (MainFrame (self))
 
68
    
 
69
    
 
70
    #-------------------- main ------------------------------------------------
 
71
    
 
72
    appName     = "default.py"
 
73
    catalog     = ""
 
74
    programName = ki18n ("default")                 #ki18n required here
 
75
    version     = "1.0"
 
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"
 
82
 
 
83
    aboutData   = KAboutData (appName, catalog, programName, version, description,
 
84
                              license, copyright, text, homePage, bugEmail)
 
85
 
 
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"))
 
89
    
 
90
    KCmdLineArgs.init (sys.argv, aboutData)
 
91
    
 
92
    app = KApplication ()
 
93
    mainWindow = MainWin (None, "main window")
 
94
    mainWindow.show()
 
95
    app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
 
96
    app.exec_ ()