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

« back to all changes in this revision

Viewing changes to pykde4/kcolordialog.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 (Color Selection)]
 
4
# [SNIPPET_CATEGORIES: PyKDE4]
 
5
# [SNIPPET_DESCRIPTION: A color selection dialog]
 
6
# [SNIPPET_AUTHOR: Jim Bublitz <jbublitz@nwinternet.com>]
 
7
# [SNIPPET_LICENSE: GPL]
 
8
# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KColorDialog.html]
 
9
 
 
10
from PyQt4.QtCore import SIGNAL, Qt
 
11
from PyQt4.QtGui import QLabel
 
12
from PyQt4.QtGui import QColor
 
13
 
 
14
from PyKDE4.kdecore import i18n
 
15
from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KColorDialog, KColorPatch
 
16
 
 
17
helpText = """This example uses KColorDialog.getColor (color, parent) to
 
18
popup a dialog that allows the user to set the color of the KColorPatch
 
19
next to the button.
 
20
 
 
21
Click the button to run the dialog and select a color.
 
22
"""
 
23
 
 
24
dialogName = "KColorDialog" 
 
25
 
 
26
class MainFrame(KVBox):       
 
27
    def __init__(self, parent):
 
28
        KVBox.__init__(self, parent)
 
29
        self.help = QLabel (helpText, self)
 
30
        self.layout ().setAlignment (self.help, Qt.AlignHCenter)
 
31
        
 
32
        hBox = KHBox (self)
 
33
        self.button = KPushButton(i18n("Show %s" % dialogName), hBox)
 
34
        self.button.setMaximumSize (250, 30)
 
35
        
 
36
        self.connect(self.button, SIGNAL('clicked()'), self.showDialog)
 
37
 
 
38
        self.colorPatch = KColorPatch (hBox)
 
39
        self.colorPatch.setColor (Qt.red)
 
40
        self.colorPatch.setMaximumSize (40, 40)
 
41
 
 
42
 
 
43
    def showDialog(self):
 
44
        color = QColor ()
 
45
        result = KColorDialog.getColor (color, self)
 
46
        self.colorPatch.setColor (color)
 
47
 
 
48
 
 
49
 
 
50
# This example can be run standalone
 
51
 
 
52
if __name__ == '__main__':
 
53
 
 
54
    import sys
 
55
 
 
56
    from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
 
57
    from PyKDE4.kdeui import KApplication, KMainWindow
 
58
    
 
59
            
 
60
    class MainWin (KMainWindow):
 
61
        def __init__ (self, *args):
 
62
            KMainWindow.__init__ (self)
 
63
 
 
64
            self.resize(640, 480)
 
65
            self.setCentralWidget (MainFrame (self))    
 
66
    
 
67
    #-------------------- main ------------------------------------------------
 
68
    
 
69
    appName     = "default.py"
 
70
    catalog     = ""
 
71
    programName = ki18n ("default")                 #ki18n required here
 
72
    version     = "1.0"
 
73
    description = ki18n ("Default Example")         #ki18n required here
 
74
    license     = KAboutData.License_GPL
 
75
    copyright   = ki18n ("(c) 2007 Jim Bublitz")    #ki18n required here
 
76
    text        = ki18n ("none")                    #ki18n required here
 
77
    homePage    = "www.riverbankcomputing.com"
 
78
    bugEmail    = "jbublitz@nwinternet.com"
 
79
 
 
80
    aboutData   = KAboutData (appName, catalog, programName, version, description,
 
81
                              license, copyright, text, homePage, bugEmail)
 
82
 
 
83
    # ki18n required for first two addAuthor () arguments
 
84
    aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
 
85
    aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
 
86
    
 
87
    KCmdLineArgs.init (sys.argv, aboutData)
 
88
    
 
89
    app = KApplication ()
 
90
    mainWindow = MainWin (None, "main window")
 
91
    mainWindow.show()
 
92
    app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
 
93
    app.exec_ ()