~ben-uberelvis/python-snippets/python-snippets

« back to all changes in this revision

Viewing changes to pykde4/kdatepicker.py

  • Committer: Richard A. Johnson
  • Date: 2010-03-22 21:24:55 UTC
  • mto: This revision was merged to the branch mainline in revision 50.
  • Revision ID: nixternal@ubuntu.com-20100322212455-3g71ntumplad9xgj
Adding PyKDE4 snippets - more to come in the future

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# [SNIPPET_NAME: Date Selection Widget]
 
4
# [SNIPPET_CATEGORIES: PyKDE4]
 
5
# [SNIPPET_DESCRIPTION: Provides a widget for calendar date input]
 
6
# [SNIPPET_AUTHOR: Troy Melhase]
 
7
# [SNIPPET_LICENSE: GPL]
 
8
# [SNIPPET_DOCS: http://api.kde.org/pykde-4.3-api/kdeui/KDatePicker.html]
 
9
 
 
10
from PyQt4.QtCore import SIGNAL, Qt
 
11
from PyQt4.QtGui import QLabel
 
12
 
 
13
from PyKDE4.kdecore import i18n
 
14
from PyKDE4.kdeui import KVBox, KHBox, KDatePicker, KDateWidget
 
15
 
 
16
 
 
17
helpText = """Date selection widgets - KDatePicker and KDateWidget - provide widgets for calendar
 
18
date input.
 
19
 
 
20
KDatePicker emits two types of signals, either dateSelected() or dateEntered().
 
21
 
 
22
A line edit allows the user to select a date directly by entering numbers like
 
23
19990101 or 990101 into KDatePicker."""
 
24
 
 
25
class MainFrame(KVBox):
 
26
    def __init__(self, parent=None):
 
27
        KVBox.__init__(self, parent)
 
28
        self.help = QLabel (i18n (helpText), self)
 
29
        self.layout ().setAlignment (self.help, Qt.AlignHCenter | Qt.AlignTop)
 
30
        self.setSpacing (40)
 
31
 
 
32
        hBox  = KHBox (self)
 
33
        vBox1 = KVBox (hBox)
 
34
        vBox2 = KVBox (hBox)
 
35
 
 
36
        hBox.layout ().setAlignment (vBox1, Qt.AlignHCenter)
 
37
        hBox.layout ().setAlignment (vBox2, Qt.AlignHCenter)
 
38
        vBox1.setMargin (20)
 
39
        vBox2.setSpacing (20)
 
40
        
 
41
        self.datePickerLabel = QLabel ("KDatePicker", vBox1)
 
42
 
 
43
        self.datePicker = KDatePicker(vBox2)
 
44
        self.datePicker.setFixedSize (400, 200)
 
45
 
 
46
        self.other = QLabel('KDateWidget', vBox1)
 
47
        vBox1.layout ().setAlignment (self.other, Qt.AlignBottom)
 
48
        
 
49
        self.dateDisplay = KDateWidget(vBox2)
 
50
 
 
51
        
 
52
        self.connect(self.datePicker, SIGNAL('dateChanged(QDate)'),
 
53
                     self.dateDisplay.setDate)
 
54
 
 
55
 
 
56
# This example can be run standalone
 
57
 
 
58
if __name__ == '__main__':
 
59
 
 
60
    import sys
 
61
    
 
62
    from PyKDE4.kdecore import KCmdLineArgs, KAboutData, KLocalizedString, ki18n
 
63
    from PyKDE4.kdeui import KApplication, KMainWindow
 
64
    
 
65
                
 
66
    class MainWin (KMainWindow):
 
67
        def __init__ (self, *args):
 
68
            KMainWindow.__init__ (self)
 
69
 
 
70
            self.resize(640, 500)
 
71
            self.setCentralWidget (MainFrame (self))
 
72
    
 
73
    #-------------------- main ------------------------------------------------
 
74
    
 
75
    appName     = "kdatepicker"
 
76
    catalog     = ""
 
77
    programName = ki18n ("kdatepicker")
 
78
    version     = "1.0"
 
79
    description = ki18n ("KDatePicker Example")
 
80
    license     = KAboutData.License_GPL
 
81
    copyright   = ki18n ("(c) 2006 Troy Melhase")
 
82
    text        = ki18n ("none")
 
83
    homePage    = "www.riverbankcomputing.com"
 
84
    bugEmail    = "jbublitz@nwinternet.com"
 
85
 
 
86
    aboutData   = KAboutData (appName, catalog, programName, version, description,
 
87
                              license, copyright, text, homePage, bugEmail)
 
88
 
 
89
    aboutData.addAuthor (ki18n ("Troy Melhase"), ki18n ("original concept"))
 
90
    aboutData.addAuthor (ki18n ("Jim Bublitz"), ki18n ("pykdedocs"))
 
91
    
 
92
    KCmdLineArgs.init (sys.argv, aboutData)
 
93
    
 
94
    app = KApplication ()
 
95
    mainWindow = MainWin (None, "main window")
 
96
    mainWindow.show()
 
97
    app.connect (app, SIGNAL ("lastWindowClosed ()"), app.quit)
 
98
    app.exec_ ()