summaryrefslogtreecommitdiffstats
path: root/examples/uimodules/uidialogs.py
blob: 1c85fbe027bc4b0a91d328c873681ee5164522db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
from qt import TQVBox, TQLabel, TQLineEdit, TQString, TQPixmap, TQPushButton, TQColor, SIGNAL, TQButtonGroup,\
               TQRadioButton, TQt, TQWidget

from tdecore import KAccel, i18n

from tdeui import KAboutDialog, KAboutKDE, KBugReport, KColorDialog,  KDialog, KDialogBase, KFontDialog,\
                  KPasswordDialog, KMessageBox, KLineEditDlg, KKeyDialog, KWizard

# despite what the docs say, there is no enum (in 2.1.1 anyway)
# that contains these values
QuestionYesNo         = 0
WarningYesNo          = 1
WarningContinueCancel = 2
WarningYesNoCancel    = 3
Information           = 4
Sorry                 = 5
Error                 = 6

# Python 2.2.2 supplies these, but they're duplicated here
# for backward compatibility
False = 0
True  = 1

class CustomDlg (KDialog):
    def __init__ (self, parent, name = "custom dlg", modal = False):
        KDialog.__init__ (self, parent, name, modal)

        x = 20
        y = 10

        rLbl        = TQLabel ("r", self)
        gLbl        = TQLabel ("g", self)
        bLbl        = TQLabel ("b", self)
        self.rEd    = TQLineEdit ("64", self)
        self.gEd    = TQLineEdit ("64", self)
        self.bEd    = TQLineEdit ("64", self)
        self.dlgBtn = TQPushButton ("Set/Get Color", self)
        self.okBtn  = TQPushButton ("OK", self)
        self.canBtn = TQPushButton ("Cancel", self)

        rLbl.setGeometry (x, y, 25, 20)
        gLbl.setGeometry (x + 30, y, 25, 20)
        bLbl.setGeometry (x + 60, y, 25, 20)
        y = y + 20
        self.rEd.setGeometry (x, y, 25, 20)
        self.gEd.setGeometry (x + 30, y, 25, 20)
        self.bEd.setGeometry (x + 60, y, 25, 20)
        y = y + 30
        self.dlgBtn.setGeometry (x, y, 90, 22)
        y = y + 30
        self.okBtn.setGeometry (x, y, 40, 22)
        self.canBtn.setGeometry (x + 50, y, 40, 22)

        self.connect (self.dlgBtn, SIGNAL ("clicked()"), self.dlgClicked)
        self.connect (self.okBtn, SIGNAL ("clicked ()"), self.okClicked)
        self.connect (self.canBtn, SIGNAL ("clicked ()"), self.cancelClicked)

    def dlgClicked (self):
        # get some (numerical) color values from the original dialog
        red   = int (self.rEd.text ().latin1 ())
        green = int (self.gEd.text ().latin1 ())
        blue  = int (self.bEd.text ().latin1 ())

        # convert the numbers to a TQColor
        color = TQColor (red, green, blue)

        # invoke the dialog (getColor is a 'static' call)
        # initialize with the colors from above (in color)
        # color will also hold the new value chosen in the
        # KColorDialog
        result = KColorDialog.getColor (color, self)

        # get the numerical color values back
        red, green, blue = color.rgb ()

        # update the TQLineEdits in the original dialog
        self.rEd.setText (str (red))
        self.gEd.setText (str (green))
        self.bEd.setText (str (blue))

    def okClicked (self):
        self.done (1)

    def cancelClicked (self):
        self.done (0)

class MessageDlg (KDialog):
    def __init__ (self, parent, name = "message dlg", modal = False):
        KDialog.__init__ (self, parent, name, modal)

        buttons = ["QuestionYesNo", "WarningYesNo", "WarningContiueCancel", "WarningYesNoCancel",\
                   "Information", "Sorry", "Error"]

        n = len (buttons)

        grp = TQButtonGroup (n, TQt.Vertical, "MessageBoxes", self, "button grp")
        grp.setGeometry (10, 10, 200, 30*n)
        for i in range (n):
            TQRadioButton (buttons [i], grp)

        self.connect (grp, SIGNAL ("clicked (int)"), self.launch)

    def launch (self, which):
        if which == QuestionYesNo:
            KMessageBox.questionYesNo (self, "This is a questionYesNo message box\nThere is also a list version of this dialog",\
                                       "questionYesNo")

        elif which == WarningYesNo:
            KMessageBox.warningYesNo (self, "This is a warningYesNo message box", "warningYesNo")

        elif which == WarningContinueCancel:
            KMessageBox.warningContinueCancel (self, "This is a warningContinueCancel message box", "warningContinueCancel");

        elif which == WarningYesNoCancel:
            KMessageBox.warningYesNoCancel (self, "This is a warningYesNoCancel message box", "warningYesNoCancel")

        elif which == Information:
            KMessageBox.information (self, "This is an information message box", "Information")

        elif which == Sorry:
            KMessageBox.sorry (self, "This is a 'sorry' message box", "Sorry")

        elif which == Error:
            KMessageBox.error (self, "No - this isn't really an error\nIt's an error message box\n", "Error")


def dlgKAboutDialog (parent):
    dlg = KAboutDialog (parent, 'about dialog', False)
    dlg.setLogo (TQPixmap ("pytestimage.png"))
    dlg.setTitle ("UISampler for PyKDE")
    dlg.setAuthor ("Jim Bublitz", "jbublitz@nwinternet.com", "http://www.riverbankcomputing.co.uk",\
                    "\n\nPyKDE -- Python bindings\n\tfor KDE")
    dlg.addContributor ("PyKDE list", "pykde@mats.gmd.de", TQString.null, TQString.null)

    dlg.show ()


def dlgKBugReport (parent):
    dlg = KBugReport (parent)
    dlg.exec_loop ()

def dlgKAboutKDE (parent):
    dlg = KAboutKDE (parent, "about kde", False)
    dlg.show ()

def dlgKColorDialog (parent):
    dlg = KColorDialog (parent, "color dlg", False)
    dlg.show ()

def dlgKDialog (parent):
    dlg = CustomDlg (parent)
    dlg.show ()

def dlgKDialogBase (parent):
    caption = "KDialogBase sample"
    text_ = "This is a KDialogBase example"
    dlg =   KDialogBase (parent, "sample_dialog", False, caption,\
            KDialogBase.Ok | KDialogBase.Cancel, KDialogBase.Ok, True )

    page  = dlg.makeVBoxMainWidget();

    # making 'page' the parent inserts the widgets in
    # the VBox created above
    label = TQLabel( caption, page, "caption" );

    lineedit = TQLineEdit(text_, page, "lineedit" );
    lineedit.setMinimumWidth(dlg.fontMetrics().maxWidth()*20);

    # This tests some handwritten code in KDialogBase
    label0 = TQLabel ("Border widths", page)
    a, b, c, d = dlg.getBorderWidths ()
    labelA = TQLabel ("Upper Left X: " + str (a), page)
    labelB = TQLabel ("Upper Left Y: " + str (b), page)
    labelC = TQLabel ("Lower Right X: " + str (c), page)
    labelD = TQLabel ("Lower Right Y: " + str (d), page)

    dlg.show ()

def dlgKFontDialog (parent):
    dlg = KFontDialog (parent, "font dlg", False, False)
    dlg.show ()

def dlgKKeyDialog (parent):
    # This really doesn't do anything except pop up the dlg
    keys = KAccel (parent)
    keys.insertItem( i18n( "Zoom in" ), "Zoom in", "+" );
    keys.readSettings();
    KKeyDialog.configureKeys (keys)

def dlgKLineEditDlg (parent):
    result, ok = KLineEditDlg.getText ("Enter text", "<Your input here>", parent)
    print "result", result
    print "ok", ok

    # pop up another dlg to show what happened in the KLineEditDlg
    if ok:
        result = result.latin1 ()
        KMessageBox.information (parent, "OK was pressed\nText: " + result, "KLineEditDlg result")
    else:
        result = ""
        KMessageBox.information (parent, "Cancel pressed\nText: " + result, "KLineEditDlg result")

def dlgKMessageBox (parent):
    dlg = MessageDlg (parent)
    dlg.show ()

def dlgKPasswordDialog (parent):
    dlg = KPasswordDialog (KPasswordDialog.Password, "Enter password (just a test)")
    dlg.exec_loop ()

def dlgKWizard (parent):
    wiz = KWizard (parent)

    page1 = TQWidget (wiz)
    p1Lbl = TQLabel ("This is page 1", page1)
    p1Lbl.setGeometry (20, 20, 100, 20)
    page2 = TQWidget (wiz)
    p2Lbl = TQLabel ("This is page 2", page2)
    p2Lbl.setGeometry (50, 20, 100, 20)
    page3 = TQWidget (wiz)
    p3Lbl = TQLabel ("This is page 3", page3)
    p3Lbl.setGeometry (80, 20, 100, 20)

    wiz.addPage (page1, "Page 1")
    wiz.addPage (page2, "Page 2")
    wiz.addPage (page3, "Page 3")
    wiz.show ()

if __name__ == "__main__":
    print
    print "Please run uisampler.py"
    print