-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontainer_demo.py
82 lines (63 loc) · 2.83 KB
/
container_demo.py
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
# -*- coding: utf-8 -*-
import sys
from ..gui.container import ComboBoxGroup
from PySide2.QtWidgets import QWidget, QPushButton, QLabel, QCheckBox, QApplication, QFrame, QComboBox, \
QVBoxLayout, QGridLayout
class ComboBoxGroupTest(QWidget):
def __init__(self, parent=None):
super(ComboBoxGroupTest, self).__init__(parent)
frameStyle = QFrame.Sunken | QFrame.Panel
country = QComboBox()
country.addItem("China")
country.addItem("Japan")
country.addItem("Korea")
country.addItem("England")
country.addItem("American")
self.reverse = QPushButton("Reverse sequence")
self.reverse.clicked.connect(self.__slotSetReverse)
self.editable = QCheckBox("Editable")
self.editable.setCheckable(True)
self.editable.setChecked(True)
self.editable.toggled.connect(self.__slotSetEditable)
self.getSequence = QPushButton("Get sequence")
self.sequenceLabel = QLabel()
self.sequenceLabel.setFrameStyle(frameStyle)
self.getSequence.clicked.connect(self.__slotGetSequence)
self.getSequenceText = QPushButton("Get sequence text")
self.textLabel = QLabel()
self.textLabel.setFrameStyle(frameStyle)
self.getSequenceText.clicked.connect(self.__slotGetSequenceText)
self.countrySequence = ComboBoxGroup(country, autoCreate=True, ordered=True)
self.countrySequence.sequenceChanged.connect(self.__slotGetSequence)
self.countrySequence.sequenceChanged.connect(self.__slotGetSequenceText)
layout = QVBoxLayout()
for item in list(self.countrySequence.items()):
layout.addWidget(item)
layout1 = QGridLayout()
layout1.addWidget(self.editable, 0, 0)
layout1.addWidget(self.reverse, 0, 1)
layout1.addWidget(self.getSequence, 1, 0)
layout1.addWidget(self.sequenceLabel, 1, 1)
layout1.addWidget(self.getSequenceText, 2, 0)
layout1.addWidget(self.textLabel, 2, 1)
layout.addLayout(layout1)
self.setLayout(layout)
self.setWindowTitle("ComboBoxGroup Test")
self.__slotGetSequence()
self.__slotGetSequenceText()
self.setFixedSize(self.sizeHint())
def __slotSetReverse(self):
sequence = self.countrySequence.getSequence()
sequence.reverse()
self.countrySequence.setSequence(sequence)
def __slotSetEditable(self, editable):
self.countrySequence.setEditable(editable)
def __slotGetSequence(self):
self.sequenceLabel.setText("{}".format(self.countrySequence.getSequence()))
def __slotGetSequenceText(self):
self.textLabel.setText("{}".format(self.countrySequence.getSequenceText()))
if __name__ == "__main__":
app = QApplication(sys.argv)
window = ComboBoxGroupTest()
window.show()
sys.exit(app.exec_())