Ahojte, s pythonom len zacinam a rad by som sa poradil s nasledovnym. Vytvoril som definiciu ser_send(), ktora je sucastou triedy. Ako by vypadala tato definicia ak by nebola sucastou triedy ? Ak by bol ser_send() mimo triedy, tak neviem ako pouzit comboBox a textBrowser. Taktiez mi vobec nefunguje posielanie stringu na seriovy port.
class Ui_Form(object): def setupUi(self, Form): Form.setObjectName(_fromUtf8("Form")) Form.resize(400, 300) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth()) Form.setSizePolicy(sizePolicy) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8("../../Downloads/Twitter-icons-web-design-54.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off) Form.setWindowIcon(icon) self.label = QtGui.QLabel(Form) self.label.setGeometry(QtCore.QRect(10, 20, 111, 16)) self.label.setObjectName(_fromUtf8("label")) self.comboBox = QtGui.QComboBox(Form) self.comboBox.setGeometry(QtCore.QRect(120, 15, 211, 25)) self.comboBox.setEditable(False) self.comboBox.setObjectName(_fromUtf8("comboBox")) self.pushButtonPripoj = QtGui.QPushButton(Form) self.pushButtonPripoj.setGeometry(QtCore.QRect(140, 230, 87, 27)) self.pushButtonPripoj.setObjectName(_fromUtf8("pushButtonPripoj")) self.textBrowser = QtGui.QTextBrowser(Form) self.textBrowser.setGeometry(QtCore.QRect(100, 80, 191, 111)) self.textBrowser.setObjectName(_fromUtf8("textBrowser")) app.connect(self.pushButtonPripoj, QtCore.SIGNAL("clicked()"),self.ser_send) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) a = deque(serial_ports()) a.rotate(1) self.comboBox.addItems(a) def retranslateUi(self, Form): Form.setWindowTitle(_translate("Form", "Form", None)) self.label.setText(_translate("Form", "Nastavenie Portu", None)) self.pushButtonPripoj.setText(_translate("Form", "Pripoj", None)) def ser_send(self): ser = self.comboBox.currentIndex() try: srl = serial.Serial(ser) srl.write("Ahoj") srl.close() except: self.textBrowser.setText("Port je nedostupny") #self.textBrowser.setText(ser)
okay. Myslim si, ze ti rozumiem, ale co ak by tato definicia nebola sucastou triedy a namiesto print bz som pouzil ten testBrowser ? Ako to zapisem ?
Ahoj, tak to ma nenapadlo. Ja som tam furt daval Ui_Form. Predsa mam este jednu otazku. Dajme tomu, ze namiesto metody ser_send by bol kod nizsie = zatlacim tlacitko a budem prijimat data. Lenze ako zabezpecim aby to prijimanie dat bezalo na pozadi a ja dalej budem moct manipulovat s Widgetami ? Pretoze ak zatlacim tlacitkom, tak comboboxom nepohnem.
Takže som našiel niečo o Thread, ale moc tomu nerozumiem. Zatiaľ som použil prerušenie časovača. Použil som toto
Aby sa GUI neblokovalo musí sa buď použiť buď QThread, alebo QtConcurrent (prípadne aspoň vynútiť spracovanie eventov loopu).