salome: signal_primer.py

File signal_primer.py, 757 bytes (added by Leon Kos, 7 years ago)

Primer povezovanja signalov v PyQt5

Line 
1from PyQt5.QtWidgets import QApplication, QMainWindow, QComboBox, QWidget
2from PyQt5.QtCore import pyqtSlot, pyqtSignal
3
4def int_slot(arg):
5    print('int_slot', arg, type(arg))
6
7def str_slot(arg):
8    print('str_slot', arg, type(arg))
9
10import sys
11app = QApplication(sys.argv)
12main = QMainWindow()
13combobox = QComboBox()
14
15main.setCentralWidget(combobox)
16
17combobox.addItems(['1', '2', '3'])
18
19# Da poslje signal integer:
20combobox.currentIndexChanged.connect(int_slot)
21# Ali istovredno
22combobox.currentIndexChanged[int].connect(int_slot)
23# Zaradi tega bo int_slot funkcija dvakrat poveyana, saj ima signal dvakrat
24# povezan
25
26
27# Ce zelimo niz ali string naredimo naslednje:
28combobox.currentIndexChanged[str].connect(str_slot)
29
30main.show()
31sys.exit(app.exec_())