def updstartup(self): self.udprecvcnt = 0 self.udpsendcnt = 0 self.socket = QtNetwork.QUdpSocket() self.socket.bind(QtNetwork.QHostAddress(""), 6000) self.socket.readyRead.connect(self.recvudp) log.debug("Connected to socket, waiting for udp stream", extra = log.HST)
def __init__(self): super(Server_MainWindow, self).__init__() super(Ui_MainWindow, self).__init__() self.setupUi(self) self.dbcon = sql.connect('database.db') # with self.dbcon: # self.dbcon.execute(""" # CREATE TABLE ALERTS ( # id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 0, # time TEXT, # date TEXT, # message TEXT # ); # """) self.tablemodel = TableModel() self.tableview.setModel(self.tablemodel) self.tableview.horizontalHeader().setSectionResizeMode( 2, QtWidgets.QHeaderView.Stretch) self.tableview.verticalHeader().setSectionResizeMode( QtWidgets.QHeaderView.ResizeToContents) self.socket = QtNetwork.QUdpSocket(self) self.socket.bind(QtNetwork.QHostAddress.LocalHost, 45454, QtNetwork.QAbstractSocket.ReuseAddressHint) self.send_button.pressed.connect(self.addMessage)
def forward(self, alarm): data = None if alarm.source == 'pager': data = alarm.pager.encode('utf-8') socket = QtNetwork.QUdpSocket() for host, addr, port in self.hosts: self.logger.info('Forwarding to %s (%s:%u/udp)', host, addr.toString(), port) socket.writeDatagram(data, addr, port) elif alarm.source == 'xml': data = alarm.xml # bytes socket = QtNetwork.QTcpSocket() for host, addr, port in self.hosts: self.logger.info('Forwarding to %s (%s:%u/tcp)', host, addr.toString(), port) socket.connectToHost(addr, port) if not socket.waitForConnected(5000): self.logger.error('Connection failed.') continue socket.writeData(data) if not socket.waitForBytesWritten(5000): self.logger.error('Writing to socket failed.') socket.close()
def __init__(self, username): super().__init__() self.username = username self.socket = qtn.QUdpSocket() self.socket.bind(qtn.QHostAddress.Any, self.port) self.socket.readyRead.connect(self.process_datagrams) self.socket.error.connect(self.on_error)
def __init__(self): super(Client_MainWindow, self).__init__() super(Ui_MainWindow, self).__init__() self.setupUi(self) self.model = TableModel() self.tableview.setModel(self.model) self.tableview.horizontalHeader().setSectionResizeMode(2, QtWidgets.QHeaderView.Stretch) self.tableview.verticalHeader().setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents) self.socket = QtNetwork.QUdpSocket(self) self.socket.bind(QtNetwork.QHostAddress.LocalHost, 45454, QtNetwork.QUdpSocket.ReuseAddressHint) self.socket.errorOccurred.connect(self.socketHasError) self.socket.readyRead.connect(self.processPendingDatagrams) self.minimizeAction = QtWidgets.QAction("Minimize", self) self.restoreAction = QtWidgets.QAction("Restore", self) self.quitAction = QtWidgets.QAction("Exit", self) self.trayicon = QtWidgets.QSystemTrayIcon(self) self.icon = QtGui.QIcon('alert.jpg') self.trayIconMenu = QtWidgets.QMenu(self) self.trayIconMenu.addAction(self.minimizeAction) self.trayIconMenu.addAction(self.restoreAction) self.trayIconMenu.addAction(self.quitAction) self.setTrayIconActions() self.showTrayIcon()
def init_socket(self): self.socket = QtNetwork.QUdpSocket(self) self.socket.readyRead.connect(self.read_datagrams) self.socket.bind( 3010, QtNetwork.QUdpSocket.ShareAddress | QtNetwork.QUdpSocket.ReuseAddressHint) log.info("Listening on UDP 3010")
def __init__(self): QtCore.QObject.__init__(self) self.socket = QtNetwork.QUdpSocket(self) self.timer = QtCore.QTimer() self.timer.setInterval(500) self.timer.timeout.connect(self.send_packet) self.timer.start()
def __init__(self, qtapp): super().__init__() self.qtapp = qtapp self.socket = QtNetwork.QUdpSocket() self.socket.bind(QtNetwork.QHostAddress(""), 6001) self.t1 = QtCore.QTimer(qtapp) self.t1.setInterval(10) self.t1.timeout.connect(self.sample)
def openUDPConnection(self): """Open UDP connection, configure from settings and turn the light green.""" self.udpSocket = QtNetwork.QUdpSocket() self.udpSocket.bind(QtNetwork.QHostAddress.LocalHost, int(self.portInput.text())) self.udpSocket.readyRead.connect(self.readFromCondor) self.settings.beginGroup("CONNECTION_CONFIG") self.settings.setValue("CONDOR_UDP_PORT", int(self.portInput.text())) self.settings.endGroup() self.udpLight.turnOn()
def __init__(self, port, *args, **kwargs): super().__init__(*args, **kwargs) udpSocket = QtNetwork.QUdpSocket() udpSocket.bind(QtNetwork.QHostAddress.Any, port) udpSocket.readyRead.connect(self.readPendingDatagrams) mainWindow = MainWindow() mainWindow.show() self._udpSocket = udpSocket self._mainWindow = mainWindow
def __init__( self, parent, identifier_string, listener_address, port, timeout_ms=5000 ): super().__init__( parent ) #self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.timeout_ms = timeout_ms self.port_for_ping = int(port) self.active_connections = {} self.tcp_server = QtNetwork.QTcpServer() self.udp_socket = QtNetwork.QUdpSocket() self.identifier_string = identifier_string if not listener_address or listener_address == '': listener_address = QtNetwork.QHostAddress.AnyIPv4 if( not self.Listen_For_Replies( listener_address ) ): raise Exception( "Failed to find local network " + listener_address.toString() )
def __init__(self, logger): super(SocketListener, self).__init__() self.logger = logger self.udpSocket = QtNetwork.QUdpSocket(self) self.udpSocket.bind(QtNetwork.QHostAddress.Any, 11211) self.udpSocket.readyRead.connect(self.readUdpSocket) self.tcpServer = QtNetwork.QTcpServer(self) self.tcpServer.listen(QtNetwork.QHostAddress.Any, 11211) self.tcpServer.newConnection.connect(self.tcpConnection) self.tcpConnection = None self.tcpData = b''
def __init__( self, parent, identifier_string, listener_address, port, timeout_ms=20000 ): super().__init__( parent ) #self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.timeout_ms = timeout_ms self.port_for_ping = int(port) self.active_connections = {} self.tcp_server = QtNetwork.QTcpServer() self.udp_socket = QtNetwork.QUdpSocket() self.identifier_string = identifier_string if( not self.Listen_For_Replies( listener_address ) ): if listener_address is None: raise Exception( "Failed to listen on default ip" ) else: raise Exception( "Failed to listen on ip " + listener_address.toString() )
def get_broadcast_ips(self): localhost = QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost) for _if in QtNetwork.QNetworkInterface.allInterfaces(): for addr in _if.addressEntries(): if addr.ip().protocol() == QtNetwork.QAbstractSocket.IPv4Protocol and not addr.netmask().isNull() and \ addr.ip() != localhost: bcast = QtNetwork.QHostAddress( addr.ip().toIPv4Address() | ((1 << 32) - 1 - addr.netmask().toIPv4Address())) # bit not udp_sock = QtNetwork.QUdpSocket(self) udp_sock.bind(addr.ip()) self.bcast_sockets[bcast.toString()] = udp_sock udp_sock.readyRead.connect(self.read_ip_from_socket)
def __init__(self): # Create the main window super(MainWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) # Timer to update UDP subscription self.timer = QtCore.QTimer(self) self.timer.setInterval(60000) self.timer.timeout.connect(self.subscribe) # Timer to update display self.displayTimer = QtCore.QTimer(self) self.displayTimer.setInterval(2000) self.displayTimer.timeout.connect(self.display) # Timer to update web server self.webdisplayTimer = QtCore.QTimer(self) self.webdisplayTimer.setInterval(10000) self.webdisplayTimer.timeout.connect(self.webdisplay) # Timer to reset thermometers self.resetMMR3Timer = QtCore.QTimer(self) self.resetMMR3Timer.setInterval(150000) self.resetMMR3Timer.timeout.connect(self.resetMMR3) # UDP socket self.udp = QtNetwork.QUdpSocket(self) self.udp.bind(12000) self.udp.readyRead.connect(self.process) # Last values self.lastvalues = [] for m in modules: self.lastvalues.extend([(c, { 'value': None, 'time': None, 'status': None }) for c in m['channels'] if c]) self.lastvalues = OrderedDict(self.lastvalues) l = [len(k) for k in self.lastvalues.keys()] self.fmtstring = '{{0:{0}s}} {{1}} {{2}} {{3}}'.format(max(l)) self.newvalues = dict() self.postdata = [] self.logger = WebLogger(self.postdata) # Start self.start() self.displayTimer.start() self.webdisplayTimer.start() #ZMQ server self.zmqserver = ZMQserver(self.__call__) self.zmqserver.start()
def open_receiver(self): # create a UDP socket to send and receive messages from the client if self.port is not None: self.port.close() self.port = QtNetwork.QUdpSocket() success = self.port.bind(QtNetwork.QHostAddress(self.listener_address), self.listener_portnum) if not success: self.window.show_status("Failed to bind listener socket.") self.port.close() self.port = None else: self.port.readyRead.connect(self.message_received) self.window.show_status( "Ready to go, listening for OSC UDP packets on %s:%d..." % (self.listener_address, self.listener_portnum)) return
def __init__(self, server, parent=None): super(VOIP, self).__init__(parent) self.udpSocket = QN.QUdpSocket(self) self.udpSocket.bind(QN.QHostAddress("0.0.0.0"), VOIP.MYPORT) self.udpSocket.readyRead.connect(self.processPendingDatagrams) self.p = pyaudio.PyAudio() self.serverIP = server self.history = Sequence(True) self.resendTimer = QC.QTimer() self.resendTimer.setInterval(VOIP.RINTERVAL) self.resendTimer.timeout.connect(self.resendDatagram) self.resendTimer.start()
def buttonclick(self, who, ident, tid, snr, dtime, dfreq, mode, msg, conf, mods, theudpport): #print ("Responding to "+who) a = wsjtxudp.encode_reply(who, ident, tid, snr, dtime, dfreq, mode, msg, conf, mods) print(who) print(ident) print(tid) # ms since midnight print(snr) print(dtime) print(dfreq) print(mode) print(msg) print(conf) print(mods) s = QtNetwork.QUdpSocket() s.writeDatagram(a, QtNetwork.QHostAddress.LocalHost, theudpport)
def __init__(self, parent=None): super(VOIP, self).__init__(parent) self.udpSocket = QN.QUdpSocket(self) self.udpSocket.bind(QN.QHostAddress("0.0.0.0"), VOIP.MYPORT) self.udpSocket.readyRead.connect(self.processPendingDatagrams) self.players = {} self.connectionAddress = [] self.history = (Sequence(), Sequence(), Sequence(), Sequence(), Sequence(), Sequence()) self.resendTimer = QC.QTimer() self.resendTimer.setInterval(VOIP.RINTERVAL) self.resendTimer.timeout.connect(self.resend) self.resendTimer.start()
def Run_Server(): app = QtCore.QCoreApplication(sys.argv) SOCKET = QtNetwork.QUdpSocket() def Bind_Server(HOST="127.0.0.1", PORT=33002): SOCKET.bind(QtNetwork.QHostAddress(HOST), PORT) def Send_Message(message, client, port): SOCKET.writeDatagram(message.encode(), QtNetwork.QHostAddress(client), port) def Receive_Message(): while SOCKET.hasPendingDatagrams(): received_message, received_client, received_port = SOCKET.readDatagram( SOCKET.pendingDatagramSize()) received_message = received_message.decode() received_client = received_client.toString() if received_message.startswith("{CONNECT}"): print(f"{received_client}:{str(received_port)} has connected.") if received_message.startswith("{DISCONNECT}"): SOCKET.close() break if received_message.startswith("{REGISTER}"): new_message = f"{{MSG}}Welcome {received_client}!" Send_Message(new_message, received_client, received_port) if received_message.startswith("{UNREGISTER}"): new_message = f"{{MSG}}Bye {received_client}!" Send_Message(new_message, received_client, received_port) if received_message.startswith("{ALL}"): new_message = f"{{MSG}} {received_message}" Send_Message(new_message, received_client, received_port) Bind_Server() SOCKET.readyRead.connect(Receive_Message) sys.exit(app.exec_())
def __init__(self, scene): super(Server, self).__init__() self.scene = scene self.personages = { 0: self.scene.my_tank } if hasattr(scene, 'my_tank') else {} self.personage_index = 1 self.commands_map = { 'create_personage': self.create_personage, 'delete_personage': self.delete_personage, 'increase_speed': self.increase_speed, 'reduce_speed': self.reduce_speed, 'reduce_angle': self.reduce_angle, 'increase_angle': self.increase_angle, 'reduce_rotation_speed': self.reduce_rotation_speed, 'increase_rotation_speed': self.increase_rotation_speed, 'create_bullet': self.create_bullet } print("create server: interface:0.0.0.0 port:%s" % (self.port, )) self.udp_socket = QtNetwork.QUdpSocket() self.udp_socket.bind(QtNetwork.QHostAddress.AnyIPv4, self.port) self.udp_socket.readyRead.connect(self.read_pending_datagrams)
def open_receiver(self): """Create a UDP socket, bind it to the desired port, and set up callbacks to process messages upon receipt. This may be called again after the port address has changed and will create a new socket. """ # create a UDP socket to send and receive messages from the client if self.port is not None: self.port.close() self.port = QtNetwork.QUdpSocket() success = self.port.bind(QtNetwork.QHostAddress(self.listener_address), self.listener_portnum) if not success: log.warning("Failed to bind listener socket.") self.port.close() self.port = None else: self.port.readyRead.connect(self.message_received) log.info( "OSC receiver ready to go, listening for OSC UDP packets on %s:%d" % (self.listener_address, self.listener_portnum)) return
def tes(self): QtNetwork.QUdpSocket(self)
def __init__(self, parent=None): self.RPMlimit = 100 self.cmd = 100 QtWidgets.QMainWindow.__init__(self, parent) self.setGeometry(200, 100, 650, 300) self.h_f = QtGui.QPixmap( 'NewAntTest_res/h_f.png') #GROUP_FAST_BACKWARD self.h_b = QtGui.QPixmap('NewAntTest_res/h_bb.png') #GROUP_BACKWARD self.d_u = QtGui.QPixmap('NewAntTest_res/d_u.png') #GROUP_UP self.d_d = QtGui.QPixmap('NewAntTest_res/d_d.png') #GROUP_DOWN self.hd_stop = QtGui.QPixmap( 'NewAntTest_res/hd_stop.png') #GROUP_STOP_X self.redBox = QtGui.QPixmap('NewAntTest_res/redBox.png') self.grayBox = QtGui.QPixmap('NewAntTest_res/grayBox.png') self.greenBox = QtGui.QPixmap('NewAntTest_res/greenBox.png') self.Timer = QtCore.QTimer(self) self.Timer.timeout.connect(self.onTimer) self.Timer.start(1000) self.curTime = QtWidgets.QTextEdit(self) self.curTime.setText('00:00:00') self.curTime.setGeometry(100, 260, 70, 30) self.curDate = QtWidgets.QTextEdit(self) self.curDate.setText('00:00:00') self.curDate.setGeometry(20, 260, 70, 30) self.NTPSync = QtWidgets.QLabel(self) self.NTPSync.setPixmap(self.redBox) self.NTPSync.setGeometry(180, 268, 12, 12) self.NTPSynced = False self.NTPState = False self.Network = QtWidgets.QLabel(self) self.Network.setGeometry(560, 10, 30, 30) self.NetworkSynced = False self.NetworkState = False self.Latitude = QtWidgets.QTextEdit(self) self.Latitude.setText('') self.Latitude.setGeometry(200, 170, 80, 25) self.LatitudeLabel = QtWidgets.QLabel('Latitude', self) self.LatitudeLabel.setGeometry(220, 150, 60, 20) self.Longitude = QtWidgets.QTextEdit(self) self.Longitude.setText('') self.Longitude.setGeometry(285, 170, 80, 25) self.LongitudeLabel = QtWidgets.QLabel('Longitude', self) self.LongitudeLabel.setGeometry(300, 150, 60, 20) self.Altitude = QtWidgets.QTextEdit(self) self.Altitude.setText('') self.Altitude.setGeometry(370, 170, 80, 25) self.AltitudeLabel = QtWidgets.QLabel('Altitude', self) self.AltitudeLabel.setGeometry(380, 150, 60, 20) self.AzActualSpeed = QtWidgets.QTextEdit(self) self.AzActualSpeed.setText(' ') self.AzActualSpeed.setGeometry(150, 43, 80, 23) self.AzActualSpeedLabel = QtWidgets.QLabel('Actual', self) self.AzActualSpeedLabel.setGeometry(165, 25, 60, 20) self.AzDesiredSpeed = QtWidgets.QDoubleSpinBox(self) self.AzDesiredSpeed.setSingleStep(0.01) self.AzDesiredSpeed.setRange(0, self.RPMlimit) self.AzDesiredSpeed.setGeometry(235, 43, 80, 23) self.AzDesiredSpeedLabel = QtWidgets.QLabel('Desired', self) self.AzDesiredSpeedLabel.setGeometry(245, 25, 60, 20) self.ElActualSpeed = QtWidgets.QTextEdit(self) self.ElActualSpeed.setText(' ') self.ElActualSpeed.setGeometry(350, 43, 80, 23) self.ElActualSpeedLabel = QtWidgets.QLabel('Actual', self) self.ElActualSpeedLabel.setGeometry(370, 25, 60, 20) self.ElDesiredSpeed = QtWidgets.QDoubleSpinBox(self) self.ElDesiredSpeed.setSingleStep(0.1) self.ElDesiredSpeed.setRange(0, self.RPMlimit) self.ElDesiredSpeed.setGeometry(435, 43, 80, 23) self.ElDesiredSpeedLabel = QtWidgets.QLabel('Desired', self) self.ElDesiredSpeedLabel.setGeometry(440, 25, 60, 20) self.Azimuth = QtWidgets.QLabel('AZIMUTH', self) self.Azimuth.setGeometry(200, 5, 60, 20) self.Elevation = QtWidgets.QLabel('ELEVATION', self) self.Elevation.setGeometry(400, 5, 60, 20) # self.ClientSocket=QtNetwork.QUdpSocket() # self.ClientSocket.bind(QtNetwork.QHostAddress.Any,0) # self.ClientSocket.readyRead.connect(self.onClientSocketReady) self.powerLabel = QtWidgets.QLabel(self) self.powerLabel.setGeometry(80, 115, 20, 30) self.powerState = QtWidgets.QLabel(self) self.powerState.setGeometry(80, 112, 20, 20) self.powerButton = QtWidgets.QPushButton('ON/OFF', self) self.powerButton.setGeometry(580, 10, 60, 25) self.powerButton.setCheckable(True) self.powerButton.clicked.connect(self.onPowerButton) pal = self.powerButton.palette() pal.setColor(QtGui.QPalette.Button, QtGui.QColor('red')) self.powerButton.setAutoFillBackground(True) self.powerButton.setStyleSheet('QPushButton {color: green}') self.powerButton.setPalette(pal) self.powerButton.update() self.AntButton1 = QtWidgets.QPushButton('ANT1', self) self.AntButton1.setCheckable(True) self.AntButton1.setGeometry(20, 10, 40, 30) self.AntButton1.toggled.connect(self.onAntButton1) self.AntButton2 = QtWidgets.QPushButton('ANT2', self) self.AntButton2.setCheckable(True) self.AntButton2.setGeometry(60, 10, 40, 30) self.AntButton2.toggled.connect(self.onAntButton2) self.AntButton3 = QtWidgets.QPushButton('ANT3', self) self.AntButton3.setCheckable(True) self.AntButton3.setGeometry(100, 10, 40, 30) self.AntButton3.toggled.connect(self.onAntButton3) self.Forw = QtWidgets.QPushButton(self) self.Forw.setCheckable(True) self.Forw.setIcon(QtGui.QIcon(self.h_f)) self.Forw.setIconSize(QtCore.QSize(20, 20)) self.Forw.setGeometry(245, 100, 40, 30) self.Forw.toggled.connect(self.onForw) self.Back = QtWidgets.QPushButton(self) self.Back.setCheckable(True) self.Back.setIcon(QtGui.QIcon(self.h_b)) self.Back.setIconSize(QtCore.QSize(20, 20)) self.Back.setGeometry(155, 100, 40, 30) self.Back.toggled.connect(self.onBack) self.Up = QtWidgets.QPushButton(self) self.Up.setCheckable(True) self.Up.setIcon(QtGui.QIcon(self.d_u)) self.Up.setIconSize(QtCore.QSize(20, 20)) self.Up.setGeometry(350, 100, 40, 30) self.Up.toggled.connect(self.onUp) self.Down = QtWidgets.QPushButton(self) self.Down.setCheckable(True) self.Down.setIcon(QtGui.QIcon(self.d_d)) self.Down.setIconSize(QtCore.QSize(20, 50)) self.Down.setGeometry(440, 100, 40, 30) self.Down.toggled.connect(self.onDown) self.StopAz = QtWidgets.QPushButton(self) self.StopAz.setIcon(QtGui.QIcon(self.hd_stop)) self.StopAz.setIconSize(QtCore.QSize(18, 18)) self.StopAz.setGeometry(200, 100, 40, 30) self.StopAz.clicked.connect(self.onStopAz) self.StopElev = QtWidgets.QPushButton(self) self.StopElev.setIcon(QtGui.QIcon(self.hd_stop)) self.StopElev.setIconSize(QtCore.QSize(18, 18)) self.StopElev.setGeometry(395, 100, 40, 30) self.StopElev.clicked.connect(self.onStopElev) self.VLTStateAz = QtWidgets.QLabel(self) self.VLTStateAz.setPixmap(self.redBox) self.VLTStateAz.setGeometry(20, 70, 12, 12) self.VLTStateAzLabel = QtWidgets.QLabel("VLT ready", self) self.VLTStateAzLabel.setGeometry(35, 60, 120, 30) self.VLTStateEl = QtWidgets.QLabel(self) self.VLTStateEl.setPixmap(self.redBox) self.VLTStateEl.setGeometry(618, 70, 12, 12) self.VLTStateElLabel = QtWidgets.QLabel("VLT ready", self) self.VLTStateElLabel.setGeometry(495, 60, 120, 30) self.VLTStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.FCStateAz = QtWidgets.QLabel(self) self.FCStateAz.setPixmap(self.redBox) self.FCStateAz.setGeometry(20, 85, 12, 12) self.FCTStateAzLabel = QtWidgets.QLabel("FC ready", self) self.FCTStateAzLabel.setGeometry(35, 75, 120, 30) self.FCStateEl = QtWidgets.QLabel(self) self.FCStateEl.setPixmap(self.redBox) self.FCStateEl.setGeometry(618, 85, 12, 12) self.FCStateElLabel = QtWidgets.QLabel("FC ready", self) self.FCStateElLabel.setGeometry(495, 75, 120, 30) self.FCStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.CoastStateAz = QtWidgets.QLabel(self) self.CoastStateAz.setPixmap(self.redBox) self.CoastStateAz.setGeometry(20, 100, 12, 12) self.CoastStateAzLabel = QtWidgets.QLabel("Coasting stop", self) self.CoastStateAzLabel.setGeometry(35, 90, 120, 30) self.CoastStateEl = QtWidgets.QLabel(self) self.CoastStateEl.setPixmap(self.redBox) self.CoastStateEl.setGeometry(618, 100, 12, 12) self.CoastStateElLabel = QtWidgets.QLabel("Coasting stop", self) self.CoastStateElLabel.setGeometry(495, 90, 120, 30) self.CoastStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.AlarmStateAz = QtWidgets.QLabel(self) self.AlarmStateAz.setPixmap(self.redBox) self.AlarmStateAz.setGeometry(20, 115, 12, 12) self.AlarmStateAzLabel = QtWidgets.QLabel("Alarm", self) self.AlarmStateAzLabel.setGeometry(35, 105, 120, 30) self.AlarmStateEl = QtWidgets.QLabel(self) self.AlarmStateEl.setPixmap(self.redBox) self.AlarmStateEl.setGeometry(618, 115, 12, 12) self.AlarmStateElLabel = QtWidgets.QLabel("Alarm", self) self.AlarmStateElLabel.setGeometry(495, 105, 120, 30) self.AlarmStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.RunStateAz = QtWidgets.QLabel(self) self.RunStateAz.setPixmap(self.redBox) self.RunStateAz.setGeometry(20, 130, 12, 12) self.RunStateAzLabel = QtWidgets.QLabel("Running", self) self.RunStateAzLabel.setGeometry(35, 120, 120, 30) self.RunStateEl = QtWidgets.QLabel(self) self.RunStateEl.setPixmap(self.redBox) self.RunStateEl.setGeometry(618, 130, 12, 12) self.RunStateElLabel = QtWidgets.QLabel("Running", self) self.RunStateElLabel.setGeometry(495, 120, 120, 30) self.RunStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.WarningStateAz = QtWidgets.QLabel(self) self.WarningStateAz.setPixmap(self.redBox) self.WarningStateAz.setGeometry(20, 145, 12, 12) self.WarningStateAzLabel = QtWidgets.QLabel("Warning", self) self.WarningStateAzLabel.setGeometry(35, 135, 120, 30) self.WarningStateEl = QtWidgets.QLabel(self) self.WarningStateEl.setPixmap(self.redBox) self.WarningStateEl.setGeometry(618, 145, 12, 12) self.WarningStateElLabel = QtWidgets.QLabel("Warning", self) self.WarningStateElLabel.setGeometry(495, 135, 120, 30) self.WarningStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.ReferenceStateAz = QtWidgets.QLabel(self) self.ReferenceStateAz.setPixmap(self.redBox) self.ReferenceStateAz.setGeometry(20, 160, 12, 12) self.ReferenceStateAzLabel = QtWidgets.QLabel("Reference", self) self.ReferenceStateAzLabel.setGeometry(35, 150, 120, 30) self.ReferenceStateEl = QtWidgets.QLabel(self) self.ReferenceStateEl.setPixmap(self.redBox) self.ReferenceStateEl.setGeometry(618, 160, 12, 12) self.ReferenceStateElLabel = QtWidgets.QLabel("Reference", self) self.ReferenceStateElLabel.setGeometry(495, 150, 120, 30) self.ReferenceStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.AutoModeStateAz = QtWidgets.QLabel(self) self.AutoModeStateAz.setPixmap(self.redBox) self.AutoModeStateAz.setGeometry(20, 175, 12, 12) self.AutoModeStateAzLabel = QtWidgets.QLabel("Auto mode", self) self.AutoModeStateAzLabel.setGeometry(35, 165, 120, 30) self.AutoModeStateEl = QtWidgets.QLabel(self) self.AutoModeStateEl.setPixmap(self.redBox) self.AutoModeStateEl.setGeometry(618, 175, 12, 12) self.AutoModeStateElLabel = QtWidgets.QLabel("Auto mode", self) self.AutoModeStateElLabel.setGeometry(495, 165, 120, 30) self.AutoModeStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.InFrequencyRangeStateAz = QtWidgets.QLabel(self) self.InFrequencyRangeStateAz.setPixmap(self.redBox) self.InFrequencyRangeStateAz.setGeometry(20, 190, 12, 12) self.InFrequencyRangeStateAzLabel = QtWidgets.QLabel( "In frequency range", self) self.InFrequencyRangeStateAzLabel.setGeometry(35, 180, 120, 30) self.InFrequencyRangeStateEl = QtWidgets.QLabel(self) self.InFrequencyRangeStateEl.setPixmap(self.redBox) self.InFrequencyRangeStateEl.setGeometry(618, 190, 12, 12) self.InFrequencyRangeStateElLabel = QtWidgets.QLabel( "In frequency range", self) self.InFrequencyRangeStateElLabel.setGeometry(495, 180, 120, 30) self.InFrequencyRangeStateElLabel.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) # self.InFrequencyRangeStateElLabel.setFrameShape(QtGui.QFrame.Panel) self.VoltageWarningStateAz = QtWidgets.QLabel(self) self.VoltageWarningStateAz.setPixmap(self.redBox) self.VoltageWarningStateAz.setGeometry(20, 205, 12, 12) self.VoltageWarningStateAzLabel = QtWidgets.QLabel( "Voltage warning", self) self.VoltageWarningStateAzLabel.setGeometry(35, 195, 120, 30) self.VoltageWarningStateEl = QtWidgets.QLabel(self) self.VoltageWarningStateEl.setPixmap(self.redBox) self.VoltageWarningStateEl.setGeometry(618, 205, 12, 12) self.VoltageWarningStateElLabel = QtWidgets.QLabel( "Voltage warning", self) self.VoltageWarningStateElLabel.setGeometry(495, 195, 120, 30) self.VoltageWarningStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.CurLimitStateAz = QtWidgets.QLabel(self) self.CurLimitStateAz.setPixmap(self.redBox) self.CurLimitStateAz.setGeometry(20, 220, 12, 12) self.CurLimitStateAzLabel = QtWidgets.QLabel("Current limit", self) self.CurLimitStateAzLabel.setGeometry(35, 210, 120, 30) self.CurLimitStateEl = QtWidgets.QLabel(self) self.CurLimitStateEl.setPixmap(self.redBox) self.CurLimitStateEl.setGeometry(618, 220, 12, 12) self.CurLimitStateElLabel = QtWidgets.QLabel("Current limit", self) self.CurLimitStateElLabel.setGeometry(495, 210, 120, 30) self.CurLimitStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.ThermalWarningStateAz = QtWidgets.QLabel(self) self.ThermalWarningStateAz.setPixmap(self.redBox) self.ThermalWarningStateAz.setGeometry(20, 235, 12, 12) self.ThermalWarningStateAzLabel = QtWidgets.QLabel( "Thermal warning", self) self.ThermalWarningStateAzLabel.setGeometry(35, 225, 120, 30) self.ThermalWarningStateEl = QtWidgets.QLabel(self) self.ThermalWarningStateEl.setPixmap(self.redBox) self.ThermalWarningStateEl.setGeometry(618, 235, 12, 12) self.ThermalWarningStateElLabel = QtWidgets.QLabel( "Thermal warning", self) self.ThermalWarningStateElLabel.setGeometry(495, 225, 120, 30) self.ThermalWarningStateElLabel.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.Log = QtWidgets.QTextEdit(self) self.Log.setGeometry(200, 200, 250, 90) self.SrhAntSocket = QtNetwork.QUdpSocket() self.SrhAntSocket.bind(QtNetwork.QHostAddress.Any, 9998) self.SrhAntSocket.readyRead.connect(self.onSrhAntSocketReady) # self.NTPSocket=QtNetwork.QUdpSocket() # self.NTPSocket.bind(QtNetwork.QHostAddress.Any,1234) # self.NTPSocket.readyRead.connect(self.onNTPSocketReady) # self.AlarmAz = (False) self.AlarmEl = (False) self.WarningAz = (False) self.WarningEl = (False)
def Run_Client(): # Intialize the udp socket and the chat window: SOCKET = QtNetwork.QUdpSocket() app = QtWidgets.QApplication(sys.argv) # Custom High DPI Scalling as the builtin Qt HDPi is not working well: Screen_Size = app.primaryScreen().availableGeometry() Scaled_App_Width = int(Screen_Size.width() / 3) Scaled_App_Height = int(Screen_Size.height() / 2) Scaled_Border_Radius = str(int(Screen_Size.height() / 86.4)) Scaled_Font_Size = str(int(Screen_Size.height() / 100)) Scaled_Underline_Size = str(int(Screen_Size.height() / 720)) Chat_Window = QtWidgets.QDialog() Chat_Window.setObjectName("Chat_Window") Chat_Window.setGeometry( int(Screen_Size.width() / 2) - int(Scaled_App_Width / 2), int(Screen_Size.height() / 2) - int(Scaled_App_Height / 2), Scaled_App_Width, Scaled_App_Height) Chat_Window.setWindowTitle(" texte") # Chosen Brand Name for the Client Chat_Window.setWindowIcon( QtGui.QIcon(f"{os.getcwd()}/icons/texte_icon.svg")) # Creates the left menu bar: Chat_Settings_Menu = QtWidgets.QFrame(Chat_Window) Chat_Settings_Menu.setObjectName("Chat_Settings_Menu") Chat_Settings_Menu.setGeometry(-int(Scaled_App_Width / 30), int(2 * Scaled_App_Height / 3), int(Scaled_App_Width / 3.62), int(Scaled_App_Height / 2.9)) Chat_Settings_Menu.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 25), blurRadius=60, xOffset=int(Scaled_App_Width / 128), yOffset=int(Scaled_App_Height / 103.5))) Chat_Settings_Menu_Animation = QtCore.QPropertyAnimation( Chat_Settings_Menu, b'pos') Chat_Settings_Menu_Animation.setStartValue(Chat_Settings_Menu.pos()) Chat_Settings_Menu_Animation.setEndValue( QtCore.QPoint(0, int(2 * Scaled_App_Height / 3))) Chat_Settings_Menu_Animation.setDuration(150) Sign_In_Menu = QtWidgets.QFrame(Chat_Window) Sign_In_Menu.setObjectName("Sign_In_Menu") Sign_In_Menu.setGeometry(-int(Scaled_App_Width / 20), int(Scaled_App_Height / 3), int(Scaled_App_Width / 3.62), int(Scaled_App_Height / 3)) Sign_In_Menu.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 25), blurRadius=60, xOffset=int(Scaled_App_Width / 128), yOffset=int(Scaled_App_Height / 103.5))) Sign_In_Menu_Animation = QtCore.QPropertyAnimation(Sign_In_Menu, b'pos') Sign_In_Menu_Animation.setStartValue(Sign_In_Menu.pos()) Sign_In_Menu_Animation.setEndValue( QtCore.QPoint(0, int(Scaled_App_Height / 3))) Sign_In_Menu_Animation.setDuration(150) Server_Settings_Menu = QtWidgets.QFrame(Chat_Window) Server_Settings_Menu.setObjectName("Server_Settings_Menu") Server_Settings_Menu.setGeometry(-int(Scaled_App_Width / 10), 0, int(Scaled_App_Width / 3.62), int(Scaled_App_Height / 3)) Server_Settings_Menu.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 25), blurRadius=60, xOffset=int(Scaled_App_Width / 128), yOffset=int(Scaled_App_Height / 103.5))) Server_Settings_Menu_Animation = QtCore.QPropertyAnimation( Server_Settings_Menu, b'pos') Server_Settings_Menu_Animation.setStartValue(Server_Settings_Menu.pos()) Server_Settings_Menu_Animation.setEndValue(QtCore.QPoint(0, 0)) Server_Settings_Menu_Animation.setDuration(150) # Creates the 'server settings' submenu: Server_Settings_Icon = QtWidgets.QPushButton(Server_Settings_Menu) Server_Settings_Icon.setObjectName("Server_Settings_Icon") Server_Settings_Icon.setGeometry(int(Scaled_App_Width / 60), int(Scaled_App_Height / 45), int(Scaled_App_Width / 28), int(Scaled_App_Height / 22)) Server_Settings_Icon.setStyleSheet( "background: transparent; border: none;") Server_Settings_Icon.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/server_icon.svg")) Server_Settings_Icon.setIconSize( QtCore.QSize(int(Scaled_App_Width / 28), int(Scaled_App_Height / 24))) Server_Settings_Icon.setCheckable( True) # Turns the pushbutton into a toggle switch Server_Settings_Icon.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 100), blurRadius=30, xOffset=int(Scaled_App_Width / 350), yOffset=int(Scaled_App_Height / 350))) Server_Settings_Icon.raise_() Server_Settings_Title = QtWidgets.QLabel(Server_Settings_Menu) Server_Settings_Title.setObjectName("Server_Settings_Title") Server_Settings_Title.setGeometry(int(Scaled_App_Width / 13.2), int(Scaled_App_Height / 33), int(Scaled_App_Width / 5), int(Scaled_App_Height / 34)) Server_Settings_Title.setText("Server Settings") Host_Title = QtWidgets.QLabel(Server_Settings_Menu) Host_Title.setObjectName("Host_Title") Host_Title.setGeometry(int(Scaled_App_Width / 12.8), int(Scaled_App_Height / 11.2), int(Scaled_App_Width / 5), int(Scaled_App_Height / 34)) Host_Title.setText("Hostname") Host_Address = QtWidgets.QLineEdit(Server_Settings_Menu) Host_Address.setObjectName("Host_Address") Host_Address.setGeometry(int(Scaled_App_Width / 13.2), int(Scaled_App_Height / 7.7), int(Scaled_App_Width / 11.6), int(Scaled_App_Height / 33)) Host_Address.setText( "127.0.0.1") # Prefilled default as also provided in server.py Port_Title = QtWidgets.QLabel(Server_Settings_Menu) Port_Title.setObjectName("Port_Title") Port_Title.setGeometry(int(Scaled_App_Width / 12.8), int(Scaled_App_Height / 5.6), int(Scaled_App_Width / 5), int(Scaled_App_Height / 34)) Port_Title.setText("Port #") Port_Number = QtWidgets.QLineEdit(Server_Settings_Menu) Port_Number.setObjectName("Port_Number") Port_Number.setGeometry(int(Scaled_App_Width / 13.2), int(Scaled_App_Height / 4.56), int(Scaled_App_Width / 11.6), int(Scaled_App_Height / 33)) Port_Number.setText( "33002") # Prefilled default as also provided in server.py Server_Button = QtWidgets.QPushButton(Server_Settings_Menu) Server_Button.setObjectName("Server_Button") Server_Button.setGeometry(int(Scaled_App_Width / 4.7), int(Scaled_App_Height / 5.1), int(Scaled_App_Width / 25), int(Scaled_App_Height / 20)) Server_Button.setStyleSheet("background: transparent; border: none;") Server_Button.setIcon(QtGui.QIcon(f"{os.getcwd()}/icons/enter_icon.svg")) Server_Button.setIconSize( QtCore.QSize(int(Scaled_App_Width / 20), int(Scaled_App_Height / 17))) Server_Button.setCheckable( True) # Turns the pushbutton into a toggle switch Server_Button.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 100), blurRadius=30, xOffset=int(Scaled_App_Width / 300), yOffset=int(Scaled_App_Height / 350))) Server_Connection_Status = QtWidgets.QLabel(Server_Settings_Menu) Server_Connection_Status.setObjectName("Server_Connection_Status") Server_Connection_Status.setGeometry(0, int(Scaled_App_Height / 3.5), int(Scaled_App_Width / 3.62), int(Scaled_App_Height / 20)) Server_Connection_Status.setText( "<html><head/><body><center>NOT CONNECTED</center></body></html>") # Creates the 'sign-in' submenu with FAKE password (NO AUTH): User_Avatar = QtWidgets.QPushButton(Sign_In_Menu) User_Avatar.setObjectName("user1") User_Avatar.setGeometry(int(Scaled_App_Width / 65), int(Scaled_App_Height / 48), int(Scaled_App_Width / 20), int(Scaled_App_Height / 15)) User_Avatar.setStyleSheet("background: transparent; border: none;") User_Avatar.setIcon(QtGui.QIcon(f"{os.getcwd()}/avatars/user1.svg")) User_Avatar.setIconSize( QtCore.QSize(int(Scaled_App_Width / 20), int(Scaled_App_Height / 17))) User_Avatar.setCheckable(True) # Turns the pushbutton into a toggle switch User_Avatar.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 100), blurRadius=30, xOffset=int(Scaled_App_Width / 350), yOffset=int(Scaled_App_Height / 350))) User_Avatar.setVisible(False) User_Avatar.raise_() Temporary_Avatar = QtWidgets.QPushButton(Sign_In_Menu) Temporary_Avatar.setObjectName("Temporary_Avatar") Temporary_Avatar.setGeometry(int(Scaled_App_Width / 65), int(Scaled_App_Height / 48), int(Scaled_App_Width / 20), int(Scaled_App_Height / 15)) Temporary_Avatar.setStyleSheet("background: transparent; border: none;") Temporary_Avatar.setIcon(QtGui.QIcon(f"{os.getcwd()}/avatars/user1.svg")) Temporary_Avatar.setIconSize( QtCore.QSize(int(Scaled_App_Width / 20), int(Scaled_App_Height / 17))) Temporary_Avatar.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 100), blurRadius=30, xOffset=int(Scaled_App_Width / 350), yOffset=int(Scaled_App_Height / 350))) Sign_In_Title = QtWidgets.QLabel(Sign_In_Menu) Sign_In_Title.setObjectName("Sign_In_Title") Sign_In_Title.setGeometry(int(Scaled_App_Width / 13.2), int(Scaled_App_Height / 33), int(Scaled_App_Width / 5), int(Scaled_App_Height / 34)) Sign_In_Title.setText("Sign-in") Username_Title = QtWidgets.QLabel(Sign_In_Menu) Username_Title.setObjectName("Username_Title") Username_Title.setGeometry(int(Scaled_App_Width / 12.8), int(Scaled_App_Height / 11.2), int(Scaled_App_Width / 5), int(Scaled_App_Height / 34)) Username_Title.setText("Username") Username = QtWidgets.QLineEdit(Sign_In_Menu) Username.setObjectName("Username") Username.setGeometry(int(Scaled_App_Width / 13.2), int(Scaled_App_Height / 7.7), int(Scaled_App_Width / 11.6), int(Scaled_App_Height / 33)) Username.setText("Hugo") # Prefilled for convenience Username.setEnabled(False) Password_Title = QtWidgets.QLabel(Sign_In_Menu) Password_Title.setObjectName("Password_Title") Password_Title.setGeometry(int(Scaled_App_Width / 12.8), int(Scaled_App_Height / 5.6), int(Scaled_App_Width / 5), int(Scaled_App_Height / 34)) Password_Title.setText("Password") Password = QtWidgets.QLineEdit(Sign_In_Menu) Password.setObjectName("Password") Password.setGeometry(int(Scaled_App_Width / 13.2), int(Scaled_App_Height / 4.56), int(Scaled_App_Width / 11.6), int(Scaled_App_Height / 33)) Password.setText( "********") # FAKE: Does nothing, just for UI/UX conformity! Password.setEnabled(False) Sign_In_Button = QtWidgets.QPushButton(Sign_In_Menu) Sign_In_Button.setObjectName("Sign_In_Button") Sign_In_Button.setGeometry(int(Scaled_App_Width / 4.7), int(Scaled_App_Height / 5.1), int(Scaled_App_Width / 25), int(Scaled_App_Height / 20)) Sign_In_Button.setStyleSheet("background: transparent; border: none;") Sign_In_Button.setIcon(QtGui.QIcon(f"{os.getcwd()}/icons/enter_icon.svg")) Sign_In_Button.setIconSize( QtCore.QSize(int(Scaled_App_Width / 20), int(Scaled_App_Height / 17))) Sign_In_Button.setEnabled(False) Sign_In_Button.setCheckable(True) Sign_In_Button.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 100), blurRadius=30, xOffset=int(Scaled_App_Width / 300), yOffset=int(Scaled_App_Height / 350))) User_Connection_Status = QtWidgets.QLabel(Sign_In_Menu) User_Connection_Status.setObjectName("User_Connection_Status") User_Connection_Status.setGeometry(0, int(Scaled_App_Height / 3.5), int(Scaled_App_Width / 3.62), int(Scaled_App_Height / 20)) User_Connection_Status.setText( "<html><head/><body><center>SIGNED-OUT </center></body></html>") # Extended Avatar Selection GUI Avatar_Selector_Widget = QtWidgets.QStackedWidget(Chat_Window) Avatar_Selector_Widget.setGeometry(int(Scaled_App_Width / 25), int(Scaled_App_Height / 2.78), int(Scaled_App_Width / 5.12), int(Scaled_App_Height / 3.4)) Avatar_Selector_Widget.setObjectName("Avatar_Selector_Widget") Avatar_Selector_Widget.setVisible(False) Avatar_Selector_Widget.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 50), blurRadius=20, xOffset=int(Scaled_App_Width / 300), yOffset=int(Scaled_App_Height / 300))) Avatar_Selector_Widget_Opening_Animation = QtCore.QPropertyAnimation( Avatar_Selector_Widget, b'pos') Avatar_Selector_Widget_Opening_Animation.setStartValue( Avatar_Selector_Widget.pos()) Avatar_Selector_Widget_Opening_Animation.setEndValue( QtCore.QPoint(int(Scaled_App_Width / 14.7), int(Scaled_App_Height / 2.78))) Avatar_Selector_Widget_Opening_Animation.setDuration(20) Avatar_Selector_Widget_Closing_Animation = QtCore.QPropertyAnimation( Avatar_Selector_Widget, b'pos') Avatar_Selector_Widget_Closing_Animation.setStartValue( Avatar_Selector_Widget.pos()) Avatar_Selector_Widget_Closing_Animation.setEndValue( QtCore.QPoint(int(Scaled_App_Width / 25), int(Scaled_App_Height / 2.78))) Avatar_Selector_Widget_Closing_Animation.setDuration(25) Avatar_Selector_Page_1 = QtWidgets.QWidget() Avatar_Selector_Page_1.setObjectName("Avatar_Selector_Page_1") Avatar_Selector_Page_2 = QtWidgets.QWidget() Avatar_Selector_Page_2.setObjectName("Avatar_Selector_Page_2") Avatar_Selector_Page_3 = QtWidgets.QWidget() Avatar_Selector_Page_3.setObjectName("Avatar_Selector_Page_3") Avatar_Selector_Widget.addWidget(Avatar_Selector_Page_1) Avatar_Selector_Widget.addWidget(Avatar_Selector_Page_2) Avatar_Selector_Widget.addWidget(Avatar_Selector_Page_3) Avatar_Selector_Widget.setCurrentIndex(0) def Select_Avatar(): """Allows selection of an avatar thorugh the avatar selection window.""" Selected_Avatar = User.sender() User_Avatar.setIcon( QtGui.QIcon( f"{os.getcwd()}/avatars/{Selected_Avatar.objectName()}.svg")) Temporary_Avatar.setIcon( QtGui.QIcon( f"{os.getcwd()}/avatars/{Selected_Avatar.objectName()}.svg")) User_Avatar.setObjectName(Selected_Avatar.objectName()) User_Avatar.toggle() Avatar_Selector_Widget_Closing_Animation.start() if Avatar_Selector_Widget.x() == int(Scaled_App_Width / 25): Avatar_Selector_Widget.setVisible(False) def Open_Avatar_Selector(): """Opens the avatar selection window.""" if User_Avatar.isChecked(): Avatar_Selector_Widget.setVisible(True) Avatar_Selector_Widget_Opening_Animation.start() else: Avatar_Selector_Widget_Closing_Animation.start() if Avatar_Selector_Widget.x() == int(Scaled_App_Width / 25): Avatar_Selector_Widget.setVisible(False) def Scroll_Avatar_Selector(): """Allows flipping of pages in the avatar selection window.""" Current_Index = Avatar_Selector_Widget.currentIndex() Avatar_Selector_Widget.setCurrentIndex(Current_Index + 1) if Current_Index == 2: Avatar_Selector_Widget.setCurrentIndex(0) for i in range(36): # Dynamic Avatar Creation j = [ 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 ] if i < 4: Page = Avatar_Selector_Page_1 x = int(Avatar_Selector_Widget.width() / 25) + (j[i] * int(Avatar_Selector_Widget.width() / 4.166)) y = int(Avatar_Selector_Widget.height() / 14.5) if i >= 4: Page = Avatar_Selector_Page_1 x = int(Avatar_Selector_Widget.width() / 25) + (j[i] * int(Avatar_Selector_Widget.width() / 4.166)) y = int(Avatar_Selector_Widget.height() / 2.9) if i >= 8: Page = Avatar_Selector_Page_1 x = int(Avatar_Selector_Widget.width() / 25) + (j[i] * int(Avatar_Selector_Widget.width() / 4.166)) y = int(Avatar_Selector_Widget.height() / 1.611) if i >= 12: Page = Avatar_Selector_Page_2 x = int(Avatar_Selector_Widget.width() / 25) + (j[i] * int(Avatar_Selector_Widget.width() / 4.166)) y = int(Avatar_Selector_Widget.height() / 14.5) if i >= 16: Page = Avatar_Selector_Page_2 x = int(Avatar_Selector_Widget.width() / 25) + (j[i] * int(Avatar_Selector_Widget.width() / 4.166)) y = int(Avatar_Selector_Widget.height() / 2.9) if i >= 20: Page = Avatar_Selector_Page_2 x = int(Avatar_Selector_Widget.width() / 25) + (j[i] * int(Avatar_Selector_Widget.width() / 4.166)) y = int(Avatar_Selector_Widget.height() / 1.611) if i >= 24: Page = Avatar_Selector_Page_3 x = int(Avatar_Selector_Widget.width() / 25) + (j[i] * int(Avatar_Selector_Widget.width() / 4.166)) y = int(Avatar_Selector_Widget.height() / 14.5) if i >= 28: Page = Avatar_Selector_Page_3 x = int(Avatar_Selector_Widget.width() / 25) + (j[i] * int(Avatar_Selector_Widget.width() / 4.166)) y = int(Avatar_Selector_Widget.height() / 2.9) if i >= 32: Page = Avatar_Selector_Page_3 x = int(Avatar_Selector_Widget.width() / 25) + (j[i] * int(Avatar_Selector_Widget.width() / 4.166)) y = int(Avatar_Selector_Widget.height() / 1.611) User = QtWidgets.QPushButton(Page) User.setObjectName(f"User{str(i + 1)}") User.setGeometry(x, y, int(Avatar_Selector_Widget.width() / 5), int(Avatar_Selector_Widget.height() / 5.9)) User.setStyleSheet("background: transparent; border: none;") User.setIcon( QtGui.QIcon(f"{os.getcwd()}/avatars/User{str(i + 1)}.svg")) User.setIconSize( QtCore.QSize(int(Avatar_Selector_Widget.width() / 5), int(Avatar_Selector_Widget.height() / 5.9))) User.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 100), blurRadius=30, xOffset=int(Scaled_App_Width / 350), yOffset=int(Scaled_App_Height / 350))) User.clicked.connect(Select_Avatar) if i == 8 or i == 20 or i == 32: Avatar_Selector_Next_Button = QtWidgets.QPushButton(Page) Avatar_Selector_Next_Button.setObjectName( "Avatar_Selector_Next_Button") Avatar_Selector_Next_Button.setGeometry( int(Avatar_Selector_Widget.width() / 1.29), int(Avatar_Selector_Widget.height() / 1.23), int(Avatar_Selector_Widget.width() / 5), int(Avatar_Selector_Widget.height() / 5.9)) Avatar_Selector_Next_Button.setStyleSheet( "background: transparent; border: none;") Avatar_Selector_Next_Button.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/next_icon.svg")) Avatar_Selector_Next_Button.setIconSize( QtCore.QSize(int(Avatar_Selector_Widget.width() / 6.25), int(Avatar_Selector_Widget.height() / 14.75))) Avatar_Selector_Next_Button.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 100), blurRadius=10, xOffset=int(Scaled_App_Width / 300), yOffset=int(Scaled_App_Height / 350))) Avatar_Selector_Next_Button.clicked.connect(Scroll_Avatar_Selector) # Creates the 'chat settings' submenu: Chat_Settings_Icon = QtWidgets.QPushButton(Chat_Settings_Menu) Chat_Settings_Icon.setObjectName("Chat_Settings_Icon") Chat_Settings_Icon.setGeometry(int(Scaled_App_Width / 65), int(Scaled_App_Height / 60), int(Scaled_App_Width / 23), int(Scaled_App_Height / 17)) Chat_Settings_Icon.setStyleSheet("background: transparent; border: none;") Chat_Settings_Icon.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/chat_icon.svg")) Chat_Settings_Icon.setIconSize( QtCore.QSize(int(Scaled_App_Width / 23), int(Scaled_App_Height / 19))) Chat_Settings_Icon.setCheckable( True) # Turns the pushbutton into a toggle switch Chat_Settings_Icon.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 100), blurRadius=30, xOffset=int(Scaled_App_Width / 350), yOffset=int(Scaled_App_Height / 350))) Chat_Settings_Icon.raise_() Chat_Settings_Title = QtWidgets.QLabel(Chat_Settings_Menu) Chat_Settings_Title.setObjectName("Chat_Settings_Title") Chat_Settings_Title.setGeometry(int(Scaled_App_Width / 13.2), int(Scaled_App_Height / 33), int(Scaled_App_Width / 5), int(Scaled_App_Height / 34)) Chat_Settings_Title.setText("Chat Settings") Chat_Theme_Title = QtWidgets.QLabel(Chat_Settings_Menu) Chat_Theme_Title.setObjectName("Chat_Theme_Title") Chat_Theme_Title.setGeometry(int(Scaled_App_Width / 12.8), int(Scaled_App_Height / 11.2), int(Scaled_App_Width / 5), int(Scaled_App_Height / 34)) Chat_Theme_Title.setText("Theme") Chat_Theme = QtWidgets.QComboBox(Chat_Settings_Menu) Chat_Theme.setObjectName("Chat_Theme") Chat_Theme.setGeometry(int(Scaled_App_Width / 13.2), int(Scaled_App_Height / 7.7), int(Scaled_App_Width / 11.6), int(Scaled_App_Height / 33)) Chat_Theme.addItems(["Default", "Blue", "Dark", "Light"]) Chat_Theme.setEnabled(False) Chat_Theme.currentIndexChanged.connect( lambda: Theme(Chat_Theme.currentText())) Chat_Selector_Title = QtWidgets.QLabel(Chat_Settings_Menu) Chat_Selector_Title.setObjectName("Chat_Selector_Title") Chat_Selector_Title.setGeometry(int(Scaled_App_Width / 12.8), int(Scaled_App_Height / 5), int(Scaled_App_Width / 5), int(Scaled_App_Height / 34)) Chat_Selector_Title.setText("Recipient") Chat_Selector = QtWidgets.QComboBox(Chat_Settings_Menu) Chat_Selector.setObjectName("Chat_Selector") Chat_Selector.setGeometry(int(Scaled_App_Width / 13), int(Scaled_App_Height / 4.15), int(Scaled_App_Width / 11.6), int(Scaled_App_Height / 33)) Chat_Selector.addItem("ALL") Chat_Selector.setEnabled(False) Chat_Confirm_Button = QtWidgets.QPushButton(Chat_Settings_Menu) Chat_Confirm_Button.setObjectName("Chat_Confirm_Button") Chat_Confirm_Button.setGeometry(int(Scaled_App_Width / 4.7), int(Scaled_App_Height / 4.4), int(Scaled_App_Width / 25), int(Scaled_App_Height / 20)) Chat_Confirm_Button.setStyleSheet("background: transparent; border: none;") Chat_Confirm_Button.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/check_icon.svg")) Chat_Confirm_Button.setIconSize( QtCore.QSize(int(Scaled_App_Width / 21), int(Scaled_App_Height / 18))) Chat_Confirm_Button.setEnabled(False) Chat_Confirm_Button.setCheckable( True) # Turns the pushbutton into a toggle switch Chat_Confirm_Button.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 100), blurRadius=30, xOffset=int(Scaled_App_Width / 300), yOffset=int(Scaled_App_Height / 350))) # Overlays the OS provided drop down with a custom icon: # NOTE: Please keep this code below the 'chat settings' code in order for it to be drawn above the OS drop down menu! Chat_Theme_Drop_Down_Background = QtWidgets.QLabel(Chat_Theme) Chat_Theme_Drop_Down_Background.setObjectName( "Chat_Theme_Drop_Down_Background") Chat_Theme_Drop_Down_Background.setGeometry(int(Chat_Theme.x() / 1.26), 0, int(Chat_Theme.width() / 3), int(Chat_Theme.height() / 1)) Chat_Theme_Drop_Down = QtWidgets.QPushButton(Chat_Theme) Chat_Theme_Drop_Down.setObjectName("Chat_Theme_Drop_Down") Chat_Theme_Drop_Down.setGeometry(int(Chat_Theme.x() / 1.26), 0, int(Chat_Theme.width() / 3), int(Chat_Theme.height() / 1.1)) Chat_Theme_Drop_Down.setStyleSheet( "background: transparent; border: none;") Chat_Theme_Drop_Down.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/drop_down_icon.svg")) Chat_Theme_Drop_Down.setIconSize( QtCore.QSize(int(Scaled_App_Width / 25.6), int(Scaled_App_Height / 20.7))) Chat_Theme_Drop_Down.setVisible(False) Chat_Selector_Drop_Down_Background = QtWidgets.QLabel(Chat_Selector) Chat_Selector_Drop_Down_Background.setObjectName( "Chat_Selector_Drop_Down_Background") Chat_Selector_Drop_Down_Background.setGeometry( int(Chat_Selector.x() / 1.3), 0, int(Chat_Selector.width() / 3), int(Chat_Selector.height() / 1)) Chat_Selector_Drop_Down = QtWidgets.QPushButton(Chat_Selector) Chat_Selector_Drop_Down.setObjectName("Chat_Selector_Drop_Down") Chat_Selector_Drop_Down.setGeometry(int(Chat_Selector.x() / 1.3), 0, int(Chat_Selector.width() / 3), int(Chat_Selector.height() / 1.1)) Chat_Selector_Drop_Down.setStyleSheet( "background: transparent; border: none;") Chat_Selector_Drop_Down.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/drop_down_icon.svg")) Chat_Selector_Drop_Down.setIconSize( QtCore.QSize(int(Scaled_App_Width / 25.6), int(Scaled_App_Height / 20.7))) Chat_Selector_Drop_Down.setVisible(False) # Creates the chat log area: Chat_Log = QtWidgets.QListWidget(Chat_Window) Chat_Log.setGeometry(int(Scaled_App_Width / 3.2), int(Scaled_App_Height / 25.8), int(Scaled_App_Width / 1.52), int(Scaled_App_Height / 1.2)) Chat_Log.setObjectName("Chat_Log") Chat_Log.setEnabled( False) # Keeps the area disabled from interactions before sign-in # Creates the message field with attach button: Message_Field = QtWidgets.QLineEdit(Chat_Window) Message_Field.setObjectName("Message_Field") Message_Field.setGeometry(int(Scaled_App_Width / 3.2), int(Scaled_App_Height), int(Scaled_App_Width / 1.68), int(Scaled_App_Height / 20.7)) Message_Field.setText("Waiting for connection...") Message_Field.setGraphicsEffect( QtWidgets.QGraphicsDropShadowEffect( color=QtGui.QColor(0, 0, 0, 25), blurRadius=60, xOffset=int(Scaled_App_Width / 128), yOffset=int(Scaled_App_Height / 103.5))) Message_Field.setEnabled( False) # Keeps the field disabled from interactions before sign-in Message_Field_Animation = QtCore.QPropertyAnimation(Message_Field, b'pos') Message_Field_Animation.setStartValue(Message_Field.pos()) Message_Field_Animation.setEndValue( QtCore.QPoint(int(Scaled_App_Width / 3.2), int(Scaled_App_Height / 1.1))) Message_Field_Animation.setDuration(150) Attach_Button = QtWidgets.QPushButton(Chat_Window) Attach_Button.setObjectName("Attach_Button") Attach_Button.setGeometry(int(Scaled_App_Width / 1.075), int(Scaled_App_Height), int(Scaled_App_Width / 25.09), int(Scaled_App_Height / 20.29)) Attach_Button.setStyleSheet("background: transparent; border: none;") Attach_Button.setIcon(QtGui.QIcon(f"{os.getcwd()}/icons/attach_icon.svg")) Attach_Button.setIconSize( QtCore.QSize(int(Scaled_App_Width / 25.6), int(Scaled_App_Height / 20.7))) Attach_Button.setEnabled( False) # Keeps the button disabled from interactions before sign-in Attach_Button_Animation = QtCore.QPropertyAnimation(Attach_Button, b'pos') Attach_Button_Animation.setStartValue(Attach_Button.pos()) Attach_Button_Animation.setEndValue( QtCore.QPoint(int(Scaled_App_Width / 1.075), int(Scaled_App_Height / 1.1))) Attach_Button_Animation.setDuration(150) def Theme(theme_name): """Assigns the theme based on User selection.""" # Default Theme if theme_name == "Default": Main_Background_Color = "#28284E" Main_Title_Color = "#A599E9" Main_Text_Color = "#FFFFFF" Main_Text_Alternate_Color = "#FAD000" Main_Underline_Color = "#544F83" Main_Status_Banner_Disconnected_Color = "#DE486F" Main_Status_Banner_Connected_Color = "#8FE47F" Main_Status_Banner_Shadow_Color = "#202044" Main_Chat_Log_Background_Color = "#F0F0F0" Main_Chat_Log_Text_Color = "#000000" Main_Message_Field_Background_Color = "#FFFFFF" Main_Message_Field_Text_Color = "#000000" # Blue Theme if theme_name == "Blue": Main_Background_Color = "#073642" Main_Title_Color = "#94A1A1" Main_Text_Color = "#EEE8D5" Main_Text_Alternate_Color = "#268BD2" Main_Underline_Color = "#576A71" Main_Status_Banner_Disconnected_Color = "#CD3080" Main_Status_Banner_Connected_Color = "#8FE47F" Main_Status_Banner_Shadow_Color = "#002B36" Main_Chat_Log_Background_Color = "#00212B" Main_Chat_Log_Text_Color = "#EEE8D5" Main_Message_Field_Background_Color = "#125252" Main_Message_Field_Text_Color = "#EEE8D5" # Dark Theme if theme_name == "Dark": Main_Background_Color = "#272822" Main_Title_Color = "#FCFAF2" Main_Text_Color = "#E1E676" Main_Text_Alternate_Color = "#D33682" Main_Underline_Color = "#544F83" Main_Status_Banner_Disconnected_Color = "#FD275A" Main_Status_Banner_Connected_Color = "#8FE47F" Main_Status_Banner_Shadow_Color = "#1E1F1C" Main_Chat_Log_Background_Color = "#1E1F1C" Main_Chat_Log_Text_Color = "#65D9EF" Main_Message_Field_Background_Color = "#414339" Main_Message_Field_Text_Color = "#65D9EF" # Light Theme if theme_name == "Light": Main_Background_Color = "#E3E3E9" Main_Title_Color = "#073642" Main_Text_Color = "#657B83" Main_Text_Alternate_Color = "#2A8FDA" Main_Underline_Color = "#93A1A1" Main_Status_Banner_Disconnected_Color = "#CD3080" Main_Status_Banner_Connected_Color = "#5AE150" Main_Status_Banner_Shadow_Color = "#E6E6E6" Main_Chat_Log_Background_Color = "#F0F0F0" Main_Chat_Log_Text_Color = "#073642" Main_Message_Field_Background_Color = "#C0C0D8" Main_Message_Field_Text_Color = "#6A5878" Server_Settings_Menu.setStyleSheet( f"background: {Main_Background_Color}") Server_Settings_Title.setStyleSheet( f"color: {Main_Title_Color}; font: {Scaled_Font_Size}px;") Host_Title.setStyleSheet( f"color: {Main_Title_Color}; font: {Scaled_Font_Size}px;") Host_Address.setStyleSheet( f"background: transparent; border: transparent; border-bottom: {Scaled_Underline_Size} solid {Main_Underline_Color}; padding: 0 5px; color: {Main_Text_Color}; font: {Scaled_Font_Size}px;" ) Port_Title.setStyleSheet( f"color: {Main_Title_Color}; font: {Scaled_Font_Size}px;") Port_Number.setStyleSheet( f"background: transparent; border: transparent; border-bottom: {Scaled_Underline_Size} solid {Main_Underline_Color}; padding: 0 5px; color: {Main_Text_Alternate_Color}; font: {Scaled_Font_Size}px;" ) if Server_Connection_Status.text( ) == "<html><head/><body><center>NOT CONNECTED</center></body></html>": Server_Connection_Status.setStyleSheet( f"color: {Main_Status_Banner_Disconnected_Color}; background: transparent; border-bottom: 2px solid {Main_Status_Banner_Shadow_Color}; font: {Scaled_Font_Size}px;" ) else: Server_Connection_Status.setStyleSheet( f"color: {Main_Status_Banner_Connected_Color}; background: transparent; border-bottom: 2px solid {Main_Status_Banner_Shadow_Color}; font: {Scaled_Font_Size}px;" ) Sign_In_Menu.setStyleSheet(f"background: {Main_Background_Color}") Sign_In_Title.setStyleSheet( f"color: {Main_Title_Color}; font: {Scaled_Font_Size}px;") Username_Title.setStyleSheet( f"color: {Main_Title_Color}; font: {Scaled_Font_Size}px;") Username.setStyleSheet( f"background: transparent; border: transparent; border-bottom: {Scaled_Underline_Size} solid {Main_Underline_Color}; padding: 0 5px; color: {Main_Text_Color}; font: {Scaled_Font_Size}px;" ) Password_Title.setStyleSheet( f"color: {Main_Title_Color}; font: {Scaled_Font_Size}px;") Password.setStyleSheet( f"background: transparent; border: transparent; border-bottom: {Scaled_Underline_Size} solid {Main_Underline_Color}; padding: 0 5px; color: {Main_Text_Alternate_Color}; font: {Scaled_Font_Size}px;" ) if User_Connection_Status.text( ) == "<html><head/><body><center>SIGNED-OUT </center></body></html>": User_Connection_Status.setStyleSheet( f"color: {Main_Status_Banner_Disconnected_Color}; background: transparent; border-bottom: 2px solid {Main_Status_Banner_Shadow_Color}; font: {Scaled_Font_Size}px;" ) else: User_Connection_Status.setStyleSheet( f"color: {Main_Status_Banner_Connected_Color}; background: transparent; border-bottom: 2px solid {Main_Status_Banner_Shadow_Color}; font: {Scaled_Font_Size}px;" ) # Avatar_Selector_Widget.setStyleSheet(f"background: {Main_Background_Color}") Avatar_Selector_Widget.setStyleSheet( f"background: #31315B; border-radius: {Scaled_Border_Radius}px") Chat_Settings_Menu.setStyleSheet( f"background: {Main_Background_Color}") Chat_Settings_Title.setStyleSheet( f"color: {Main_Title_Color}; font: {Scaled_Font_Size}px;") Chat_Theme_Title.setStyleSheet( f"color: {Main_Title_Color}; font: {Scaled_Font_Size}px;") Chat_Theme.setStyleSheet( f"background: {Main_Background_Color}; border: none; border-bottom: {Scaled_Underline_Size} solid {Main_Underline_Color}; padding: 0 5px; color: {Main_Text_Color}; font: {Scaled_Font_Size}px;" ) Chat_Selector_Title.setStyleSheet( f"color: {Main_Title_Color}; font: {Scaled_Font_Size}px;") Chat_Selector.setStyleSheet( f"background: {Main_Background_Color}; border: none; border-bottom: {Scaled_Underline_Size} solid {Main_Underline_Color}; padding: 0 5px; color: {Main_Text_Alternate_Color}; font: {Scaled_Font_Size}px;" ) Chat_Theme_Drop_Down_Background.setStyleSheet( f"background: {Main_Background_Color}") Chat_Selector_Drop_Down_Background.setStyleSheet( f"background: {Main_Background_Color}") Chat_Window.setStyleSheet( f"background-color: {Main_Chat_Log_Background_Color}") Chat_Log.setStyleSheet( f"border: none; color: {Main_Chat_Log_Text_Color}; background-color: {Main_Chat_Log_Background_Color}; padding: 10px 20px; font: {Scaled_Font_Size}px;" ) Message_Field.setStyleSheet( f"border: 0px solid #000000; color: {Main_Message_Field_Text_Color}; background-color: {Main_Message_Field_Background_Color}; border-radius: {Scaled_Border_Radius}px; padding: 0 15px; font: {Scaled_Font_Size}px;" ) Theme("Default") # Starts the app in default theme def Connect_Client(): """Connects to the server with provided hostname and port.""" if Server_Button.isChecked(): HOST = Host_Address.text() PORT = int(Port_Number.text()) SOCKET.connectToHost(QtNetwork.QHostAddress(HOST), PORT) Send_Message("{CONNECT}") Server_Button.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/exit_icon.svg")) Server_Connection_Status.setText( "<html><head/><body><center>CONNECTED </center></body></html>" ) Theme(Chat_Theme.currentText()) Host_Address.setEnabled(False) Port_Number.setEnabled(False) Temporary_Avatar.setVisible(False) User_Avatar.setVisible(True) Username.setEnabled(True) Sign_In_Button.setEnabled(True) Message_Field.setText("Waiting for sign-in...") else: Send_Message("{DISCONNECT}") Server_Button.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/enter_icon.svg")) Server_Connection_Status.setText( "<html><head/><body><center>NOT CONNECTED</center></body></html>" ) Theme(Chat_Theme.currentText()) Host_Address.setEnabled(True) Port_Number.setEnabled(True) Temporary_Avatar.setVisible(True) User_Avatar.setVisible(False) Username.setEnabled(False) Sign_In_Button.setEnabled(False) Message_Field.setText("Dissconnected! Good Bye...") def Sign_In(): """Registers the provided username with the server.""" if Sign_In_Button.isChecked(): Send_Message("{REGISTER}") Server_Button.setEnabled(False) Sign_In_Button.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/exit_icon.svg")) User_Connection_Status.setText( "<html><head/><body><center>SIGNED-IN </center></body></html>" ) Theme(Chat_Theme.currentText()) Username.setEnabled(False) Temporary_Avatar.setVisible(True) User_Avatar.setVisible(False) Chat_Theme.setEnabled(True) Chat_Theme_Drop_Down.setVisible(True) Chat_Selector.setEnabled(True) Chat_Selector.setItemText(0, "ALL") Chat_Selector_Drop_Down.setVisible(True) Chat_Confirm_Button.setEnabled(True) Message_Field.setText("Select a user to start chatting...") Chat_Log.setEnabled(True) else: Send_Message("{UNREGISTER}") Server_Button.setEnabled(True) Sign_In_Button.setIcon( QtGui.QIcon(f"{os.getcwd()}/icons/enter_icon.svg")) User_Connection_Status.setText( "<html><head/><body><center>SIGNED-OUT </center></body></html>" ) Theme(Chat_Theme.currentText()) Username.setEnabled(True) Temporary_Avatar.setVisible(False) User_Avatar.setVisible(True) Chat_Theme.setEnabled(False) Chat_Theme_Drop_Down.setVisible(False) Chat_Selector.setEnabled(False) Chat_Selector_Drop_Down.setVisible(False) Chat_Confirm_Button.setEnabled(False) Message_Field.setText("Signed Out!...") Chat_Log.setEnabled(False) def Send_Message(message, HOST="127.0.0.1", PORT=33002): if message.startswith("{FIELD}"): message = message.replace("{FIELD}", "") SOCKET.writeDatagram(message.encode(), QtNetwork.QHostAddress(HOST), PORT) Message_Field.setText("") Message_Field.setFocus() else: SOCKET.writeDatagram(message.encode(), QtNetwork.QHostAddress(HOST), PORT) def Receive_Message(): while SOCKET.hasPendingDatagrams(): received_message, received_client, received_port = SOCKET.readDatagram( SOCKET.pendingDatagramSize()) received_message = received_message.decode() if received_message.startswith("{MSG}"): received_message = received_message.replace("{MSG}", "") Chat_Log.addItem(received_message) # timer = QtCore.QTimer(interval=1000, timeout=Sign_In) # timer.start() # Allows the custom drop down menu to mimic the one provided by the OS: def Better_Drop_Down(whom): """Provides a cleaner drop down experience""" if whom == 0: Chat_Theme_Drop_Down.parent().showPopup() if whom == 1: Chat_Selector_Drop_Down.parent().showPopup() # Defines the logic for chat recipient confirmation and revocation after 'Chat_Confirm_Button' press: def Chat_Target(): """Provides the option to select the recipient of one's messages.""" if Chat_Confirm_Button.isChecked(): Chat_Confirm_Button.setIcon( QtGui.QIcon( QtGui.QPixmap(f"{os.getcwd()}/icons/cancel_icon.svg"))) Chat_Theme.setEnabled(False) Chat_Theme_Drop_Down.setVisible(False) Chat_Selector.setEnabled(False) Chat_Selector_Drop_Down.setVisible(False) Sign_In_Button.setEnabled(False) Message_Field.setEnabled(True) Message_Field.setText("") Message_Field.setFocus() Chat_Log.setEnabled(True) Attach_Button.setEnabled(True) else: Chat_Confirm_Button.setIcon( QtGui.QIcon( QtGui.QPixmap(f"{os.getcwd()}/icons/check_icon.svg"))) Chat_Theme.setEnabled(True) Chat_Theme_Drop_Down.setVisible(True) Chat_Selector.setEnabled(True) Chat_Selector_Drop_Down.setVisible(True) Sign_In_Button.setEnabled(True) Message_Field.setEnabled(False) Message_Field.setText("Select a User to start chatting...") Chat_Log.setEnabled(False) Attach_Button.setEnabled(False) def Attach_Picture(): Image = QtWidgets.QFileDialog.getOpenFileName( Chat_Window, 'Attach an Image', os.getcwd(), "Image files (*.jpg *.png *.gif *.svg)") Attached_Image = QtWidgets.QListWidgetItem("\n\n\n\n") Attached_Image.setIcon(QtGui.QIcon(Image[0])) Chat_Log.setIconSize( QtCore.QSize(int(Scaled_App_Width / 20), int(Scaled_App_Height / 17))) Chat_Log.addItem(Attached_Image) # Assigns each pushbutton their respective function: SOCKET.readyRead.connect(Receive_Message) Server_Button.clicked.connect(Connect_Client) User_Avatar.clicked.connect(Open_Avatar_Selector) Sign_In_Button.clicked.connect(Sign_In) Chat_Theme_Drop_Down.clicked.connect(lambda: Better_Drop_Down(0)) Chat_Selector_Drop_Down.clicked.connect(lambda: Better_Drop_Down(1)) Chat_Confirm_Button.clicked.connect(Chat_Target) Message_Field.returnPressed.connect(lambda: Send_Message( f"{{FIELD}}{{{Chat_Selector.currentText()}}}Message_Field.text()")) Attach_Button.clicked.connect(Attach_Picture) # Draws the entire GUI: Chat_Window.show() Server_Settings_Menu_Animation.start() Sign_In_Menu_Animation.start() Chat_Settings_Menu_Animation.start() Message_Field_Animation.start() Attach_Button_Animation.start() sys.exit(app.exec_())
print('From:') print(host.toString()) print(port) # Sending back addr = QtNetwork.QHostAddress.LocalHost status = socket.writeDatagram(b'Hello there', host, port) print('Sending back', status) #status = socket.writeDatagram(b'Hello', addr, 7755) #print('Sending to 7755', status) if __name__ == '__main__': # Create the GUI application app = QApplication(sys.argv) # Instantiate the main window dmw = MainWindow() app.aboutToQuit.connect(dmw.on_quit) # Show it dmw.show() # Defile and start timer task timer = QTimer() timer.timeout.connect(dmw.timer_handler) timer.start(1000) # Start UDP server socket = QtNetwork.QUdpSocket() socket.bind(7755) socket.readyRead.connect(dmw.data_arrived) # Start the Qt main loop execution, exiting from this script # with the same return code of Qt application sys.exit(app.exec_())
def __init__(self, mgui, parent=None): super(myudp, self).__init__(parent) self.socket = QtNetwork.QUdpSocket(self) self.socket.bind(2237) self.socket.readyRead.connect(self.handle) self.gui = mgui