summaryrefslogtreecommitdiffstats
path: root/examples/pykde-sampler/basic_widgets/historycombo.py
blob: aa35b53f7bf808a8b4cf3ee253a3c32578ae5808 (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
from qt import Qt, QFrame, QHBoxLayout, QVBoxLayout, QStringList, QLabel, \
     SIGNAL, SLOT
from kdeui import KHistoryCombo, KTextEdit


iconName = 'history'
labelText = 'KHistoryCombo'
docParts = ('kdeui', 'KHistoryCombo')
helpText = ('An example of the KHistoryCombo widget.'
            '\n\n'
            'Completion is enabled via the setHistoryItems call; when the second '
            'parameter is True, matching items from the list appear as you type.'
            '\n\n'
            'The activated signal is connected to the addToHistory '
            'slot to automatically add new items.')


historyText = 'a quick brown fox jumps over the lazy dog'


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

        self.historySelectionLabel = QLabel('Selected value: ', self)
        self.historySelection = QLabel('(none)', self)

        items = QStringList()
        for item in historyText.split():
            items.append(item)
        self.historyCombo.setHistoryItems(items, True)

        layout = QVBoxLayout(self, 4)
        layout.addWidget(self.help, 3)
        layout.addStretch(1)
        selectionLayout = QHBoxLayout(layout, 4)
        selectionLayout.addWidget(self.historySelectionLabel, 1)
        selectionLayout.addWidget(self.historySelection, 10, Qt.AlignLeft)
        layout.addWidget(self.historyCombo, 0)
        layout.addStretch(10)

        self.connect(self.historyCombo, SIGNAL('activated(const QString& )'),
                     self.historyCombo, SLOT('addToHistory(const QString&)'))
        self.connect(self.historyCombo, SIGNAL('cleared()'),
                     self.historyCleared)
        self.connect(self.historyCombo, SIGNAL('activated(const QString &)'),
                     self.historySelection.setText)

    def historyCleared(self):
        print 'History combo cleared.'