Сори за нейминг
from PyQt5 import QtWidgets
from PyQt5.uic.properties import QtCore
import socket
import time
from mydesign import Ui_Dialog
import sys
class Robot:
user_socket = None
def bind(self):
server = socket.socket(
socket.AF_INET,
socket.SOCK_STREAM,
)
server.bind(
("192.168.1.67", 1234) # localhost
)
server.listen(5)
time.sleep(1)
while True:
self.user_socket, address = server.accept()
print(f"Подключено к {address}")
break
def stop(self):
print("stop")
self.user_socket.send("stop".encode("utf-8"))
def right(self):
print("right")
self.user_socket.send("right".encode("utf-8"))
def left(self):
print("left")
self.user_socket.send("left".encode("utf-8"))
def back(self):
print("back")
self.user_socket.send("back".encode("utf-8"))
def forward(kek):
print("forward")
kek.user_socket.send("forward".encode("utf-8"))
robot_dolbayeb = Robot #кодовое название проекта
robot_dolbayeb.bind(robot_dolbayeb)
print(robot_dolbayeb.user_socket) # вот тут выводит <socket.socket fd=348, family=AddressFamily.AF_INET,
# type=SocketKind.SOCK_STREAM, proto=0, laddr=('192.168.1.67', 1234), raddr=('192.168.1.67', 52389)>
class mywindow(QtWidgets.QMainWindow):
def __init__(self):
super(mywindow, self).__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)
print(robot_dolbayeb, robot_dolbayeb.user_socket)
self.ui.pushButton_2.clicked.connect(robot_dolbayeb.right(robot_dolbayeb)) # тут уже стао None :P
self.ui.pushButton_3.clicked.connect(robot_dolbayeb.left(robot_dolbayeb))
self.ui.pushButton_4.clicked.connect(robot_dolbayeb.back(robot_dolbayeb))
self.ui.pushButton_5.clicked.connect(robot_dolbayeb.forward(robot_dolbayeb))
app = QtWidgets.QApplication([])
application = mywindow()
application.show()
sys.exit(app.exec())
Когда делаю print() выводит информацию о сокете, а потом почему-то None