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]
10
from PyQt4.QtCore import SIGNAL, Qt
11
from PyQt4.QtGui import QLabel
12
from PyQt4.QtGui import QColor
14
from PyKDE4.kdecore import i18n
15
from PyKDE4.kdeui import KVBox, KHBox, KPushButton, KColorDialog, KColorPatch
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
21
Click the button to run the dialog and select a color.
24
dialogName = "KColorDialog"
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)
33
self.button = KPushButton(i18n("Show %s" % dialogName), hBox)
34
self.button.setMaximumSize (250, 30)
36
self.connect(self.button, SIGNAL('clicked()'), self.showDialog)
38
self.colorPatch = KColorPatch (hBox)
39
self.colorPatch.setColor (Qt.red)
40
self.colorPatch.setMaximumSize (40, 40)
45
result = KColorDialog.getColor (color, self)
46
self.colorPatch.setColor (color)
50
# This example can be run standalone
52
if __name__ == '__main__':
56
from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
57
from PyKDE4.kdeui import KApplication, KMainWindow
60
class MainWin (KMainWindow):
61
def __init__ (self, *args):
62
KMainWindow.__init__ (self)
65
self.setCentralWidget (MainFrame (self))
67
#-------------------- main ------------------------------------------------
69
appName = "default.py"
71
programName = ki18n ("default") #ki18n required here
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"
80
aboutData = KAboutData (appName, catalog, programName, version, description,
81
license, copyright, text, homePage, bugEmail)
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"))
87
KCmdLineArgs.init (sys.argv, aboutData)
90
mainWindow = MainWin (None, "main window")
92
app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)