mirror of
https://github.com/Xevion/tcp-chat.git
synced 2025-12-06 05:16:45 -06:00
Move shared constants, exceptions & helpers.py into /shared/
This commit is contained in:
@@ -4,10 +4,9 @@ from typing import Tuple
|
||||
from PyQt5.QtCore import QEvent
|
||||
from PyQt5.QtWidgets import QDialog, QStatusBar
|
||||
|
||||
import constants
|
||||
from shared.constants import ConnectionOptions, DEFAULT_IP, DEFAULT_PORT
|
||||
from client.ui.ConnectionDialog import Ui_ConnectionDialog
|
||||
from client.nickname import Ui_NicknameDialog
|
||||
from constants import ConnectionOptions
|
||||
|
||||
|
||||
class NicknameDialog(QDialog, Ui_NicknameDialog):
|
||||
@@ -26,7 +25,7 @@ class NicknameDialog(QDialog, Ui_NicknameDialog):
|
||||
self.show()
|
||||
|
||||
def controlSubmit(self):
|
||||
"""Updates whether or not the dialog box is allowed to proceed"""
|
||||
"""Updates whether the dialog box is allowed to proceed"""
|
||||
if len(self.lineEdit.text()) > 2:
|
||||
if self.disabled:
|
||||
self.disabled = False
|
||||
@@ -43,7 +42,7 @@ class NicknameDialog(QDialog, Ui_NicknameDialog):
|
||||
|
||||
|
||||
class ConnectionDialog(QDialog, Ui_ConnectionDialog):
|
||||
def __init__(self, nickname: str = None, *args, **kwargs):
|
||||
def __init__(self, nickname: str = None, *args, **kwargs):
|
||||
super(ConnectionDialog, self).__init__(*args, **kwargs)
|
||||
self.setupUi(self)
|
||||
|
||||
@@ -77,8 +76,8 @@ class ConnectionDialog(QDialog, Ui_ConnectionDialog):
|
||||
|
||||
@property
|
||||
def settings(self) -> ConnectionOptions:
|
||||
return ConnectionOptions(ip=self.server_address_input.text() or constants.DEFAULT_IP,
|
||||
port=int(self.port_input.text() or constants.DEFAULT_PORT),
|
||||
return ConnectionOptions(ip=self.server_address_input.text() or DEFAULT_IP,
|
||||
port=int(self.port_input.text() or DEFAULT_PORT),
|
||||
nickname=self.nickname_input.text(),
|
||||
password=self.password_input.text(),
|
||||
remember=self.remember_checkbox.checkState())
|
||||
@@ -105,8 +104,8 @@ class ConnectionDialog(QDialog, Ui_ConnectionDialog):
|
||||
|
||||
def validate_address(self) -> Tuple[bool, bool]:
|
||||
"""Returns True if the server address and port combination is valid"""
|
||||
address = self.server_address_input.text() or constants.DEFAULT_IP
|
||||
port = self.port_input.text() or str(constants.DEFAULT_PORT)
|
||||
address = self.server_address_input.text() or DEFAULT_IP
|
||||
port = self.port_input.text() or str(DEFAULT_PORT)
|
||||
|
||||
valid_address = len(address) > 0 and re.match(r'^\d{1,4}\.\d{1,4}\.\d{1,4}\.\d{1,4}|localhost$',
|
||||
address) is not None
|
||||
|
||||
@@ -6,8 +6,8 @@ from PyQt5.QtCore import Qt, QEvent
|
||||
from PyQt5.QtWidgets import QMainWindow, QLabel
|
||||
from sortedcontainers import SortedList
|
||||
|
||||
import constants
|
||||
import helpers
|
||||
from shared import constants
|
||||
from shared import helpers
|
||||
from client.ui.MainWindow import Ui_MainWindow
|
||||
from client.worker import ReceiveWorker
|
||||
|
||||
@@ -65,7 +65,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
else:
|
||||
self.received += change
|
||||
self.data_stats.setText(f'{helpers.sizeof_fmt(self.sent)} Sent, '
|
||||
f'{helpers.sizeof_fmt(self. received)} Received')
|
||||
f'{helpers.sizeof_fmt(self.received)} Received')
|
||||
|
||||
@staticmethod
|
||||
def log(log_data: dict) -> None:
|
||||
@@ -96,7 +96,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
at_maximum = last_position == scrollbar.maximum()
|
||||
|
||||
self.messageHistory.setText('<br>'.join(
|
||||
msg['compiled'] for msg in self.messages
|
||||
msg['compiled'] for msg in self.messages
|
||||
))
|
||||
|
||||
scrollbar.setValue(scrollbar.maximum() if at_maximum else last_position)
|
||||
@@ -126,10 +126,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
message = message.strip()
|
||||
if len(message) > 0:
|
||||
self.send(helpers.prepare_json(
|
||||
{
|
||||
'type': constants.Types.MESSAGE,
|
||||
'content': message
|
||||
}
|
||||
{
|
||||
'type': constants.Types.MESSAGE,
|
||||
'content': message
|
||||
}
|
||||
))
|
||||
|
||||
def update_connections(self, users: List[dict]):
|
||||
|
||||
@@ -4,8 +4,8 @@ import socket
|
||||
|
||||
from PyQt5.QtCore import QThread, pyqtSignal
|
||||
|
||||
import constants
|
||||
import helpers
|
||||
from shared import constants
|
||||
from shared import helpers
|
||||
|
||||
|
||||
class ReceiveWorker(QThread):
|
||||
|
||||
Reference in New Issue
Block a user