summaryrefslogtreecommitdiffstats
path: root/examples/pykde-sampler/dialogs/input.py
blob: 30edc6fb2408d4aa480a41f4e9e0e9f57cbe10f0 (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
iconName = 'editclear'
labelText = 'KInputDialog'

from qt import QFrame, QGridLayout, QLabel, QStringList, SIGNAL
from kdecore import i18n
from kdeui import KPushButton, KInputDialog, KTextEdit


helpText = ("KInputDialog allows the programmer to display a simple dialog to "
            "request a bit of text, an integer value, a double value, or a "
            "list item from the user.")


class MainFrame(QFrame):
    items = ['Apples', 'Bananas', 'Mangos', 'Oranges', 'Pears', ]

    def __init__(self, parent=None):
        QFrame.__init__(self, parent)
        self.help = KTextEdit(helpText, '', self)

        layout = QGridLayout(self, 5, 2, 4) # five rows, two cols, four px spacing
        layout.setRowStretch(0, 10)
        layout.setColStretch(1, 10)
        layout.addMultiCellWidget(self.help, 0, 1, 0, 1)

        button = KPushButton(i18n('Get Text'), self)
        self.connect(button, SIGNAL('clicked()'), self.getText)
        self.getTextLabel = QLabel('text value', self)
        layout.addWidget(button, 2, 0)
        layout.addWidget(self.getTextLabel, 2, 1)
        layout.setRowStretch(2, 0)

        button = KPushButton(i18n('Get Integer'), self)
        self.connect(button, SIGNAL('clicked()'), self.getInt)
        self.getIntLabel = QLabel('0', self)
        layout.addWidget(self.getIntLabel, 3, 1)
        layout.addWidget(button, 3, 0)
        layout.setRowStretch(3, 0)

        button = KPushButton(i18n('Get Double'), self)
        self.connect(button, SIGNAL('clicked()'), self.getDouble)
        self.getDoubleLabel = QLabel('0.0', self)
        layout.addWidget(self.getDoubleLabel, 4, 1)
        layout.addWidget(button, 4, 0)
        layout.setRowStretch(4, 0)

        button = KPushButton(i18n('Get Item'), self)
        self.connect(button, SIGNAL('clicked()'), self.getItem)
        self.getItemLabel = QLabel(self.items[0], self)
        layout.addWidget(button, 5, 0)
        layout.addWidget(self.getItemLabel, 5, 1)
        layout.setRowStretch(5, 0)

    def getText(self):
        title = 'KInputDialog.getText Dialog'
        label = 'Enter some text:'
        default = self.getTextLabel.text()
        value, accepted = KInputDialog.getText(title, label, default)
        if accepted:
            self.getTextLabel.setText(value)

    def getInt(self):
        title = 'KInputDialog.getInteger Dialog'
        label = 'Enter an integer:'
        default = int('%s' % self.getIntLabel.text())
        value, accepted = KInputDialog.getInteger(title, label, default)
        if accepted:
            self.getIntLabel.setText('%s' % value)

    def getDouble(self):
        title = 'KInputDialog.getDouble Dialog'
        label = 'Enter a double:'
        default = float('%s' % self.getDoubleLabel.text())
        value, accepted = KInputDialog.getDouble(title, label, default, -10.0, 10.0)
        if accepted:
            self.getDoubleLabel.setText('%s' % value)

    def getItem(self):
        title = 'KInputDialog.getItem Dialog'
        label = 'Select an item:'
        current = self.items.index('%s' % self.getItemLabel.text())
        selections = QStringList()
        for item in self.items:
            selections.append(item)
        value, accepted = KInputDialog.getItem(title, label, selections, current)
        if accepted:
            self.getItemLabel.setText('%s' % value)