Skip to content

Commit 033e68d

Browse files
ComputerTech312James Trotter
authored andcommitted
Add files via upload
1 parent 8f337f8 commit 033e68d

File tree

11 files changed

+241
-0
lines changed

11 files changed

+241
-0
lines changed
162 Bytes
Binary file not shown.

src/gui/__init__.py

Whitespace-only changes.
166 Bytes
Binary file not shown.
4.34 KB
Binary file not shown.
4.37 KB
Binary file not shown.

src/gui/connect_dialog.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLineEdit, QDialogButtonBox, QLabel
2+
3+
class ConnectDialog(QDialog):
4+
def __init__(self, parent=None):
5+
super().__init__(parent)
6+
7+
self.setWindowTitle("Connect to IRC Server")
8+
9+
self.layout = QVBoxLayout(self)
10+
11+
self.host_label = QLabel("Host:", self)
12+
self.layout.addWidget(self.host_label)
13+
self.host_input = QLineEdit(self)
14+
self.host_input.setText("irc.rizon.net")
15+
self.layout.addWidget(self.host_input)
16+
17+
self.port_label = QLabel("Port:", self)
18+
self.layout.addWidget(self.port_label)
19+
self.port_input = QLineEdit(self)
20+
self.port_input.setText("6667")
21+
self.layout.addWidget(self.port_input)
22+
23+
self.nick_label = QLabel("Nickname:", self)
24+
self.layout.addWidget(self.nick_label)
25+
self.nick_input = QLineEdit(self)
26+
self.nick_input.setText("pyechat")
27+
self.layout.addWidget(self.nick_input)
28+
29+
self.realname_label = QLabel("Real name:", self)
30+
self.layout.addWidget(self.realname_label)
31+
self.realname_input = QLineEdit(self)
32+
self.realname_input.setText("Pyechat: https://pyechat.github.io")
33+
self.layout.addWidget(self.realname_input)
34+
35+
self.channel_label = QLabel("Channel:", self)
36+
self.layout.addWidget(self.channel_label)
37+
self.channel_input = QLineEdit(self)
38+
self.channel_input.setText("#elitechat")
39+
self.layout.addWidget(self.channel_input)
40+
41+
self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)
42+
self.buttons.accepted.connect(self.accept)
43+
self.buttons.rejected.connect(self.reject)
44+
self.layout.addWidget(self.buttons)
45+
46+
def get_values(self):
47+
return self.host_input.text(), int(self.port_input.text()), self.nick_input.text(), self.realname_input.text(), self.channel_input.text()
48+
49+
def closeEvent(self, event):
50+
QApplication.quit()

src/gui/main_window.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from PyQt5.QtCore import pyqtSlot
2+
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QTextEdit, QLineEdit, QTabWidget
3+
4+
class MainWindow(QWidget):
5+
def __init__(self, client):
6+
super().__init__()
7+
8+
self.client = client
9+
self.client.received_message.connect(self.on_received_message)
10+
11+
self.layout = QVBoxLayout(self)
12+
13+
self.tab_widget = QTabWidget(self)
14+
self.layout.addWidget(self.tab_widget)
15+
16+
self.text_areas = {}
17+
18+
self.input_line = QLineEdit(self)
19+
self.input_line.returnPressed.connect(self.on_return_pressed)
20+
self.layout.addWidget(self.input_line)
21+
22+
@pyqtSlot(str)
23+
def on_received_message(self, message):
24+
parts = message.split(' ', 3)
25+
if len(parts) < 4:
26+
return
27+
user, _, channel, text = parts
28+
user = user[1:].split('!', 1)[0]
29+
channel = channel if channel.startswith('#') else user
30+
text = text[1:]
31+
32+
self.add_channel_tab(channel)
33+
self.text_areas[channel].append(f'<{user}> {text}')
34+
35+
@pyqtSlot()
36+
def on_return_pressed(self):
37+
message = self.input_line.text()
38+
self.input_line.clear()
39+
40+
channel = self.tab_widget.tabText(self.tab_widget.currentIndex())
41+
if message.startswith('/'):
42+
if ' ' in message:
43+
command, args = message[1:].split(' ', 1)
44+
if command in ['join', 'part']:
45+
channel = args.split(' ', 1)[0]
46+
self.client.send_command(f'{command.upper()} {channel}')
47+
if command == 'join':
48+
self.add_channel_tab(channel)
49+
else:
50+
self.client.send_command(f'PRIVMSG {channel} :{message}')
51+
self.text_areas[channel].append(f'<{self.client.nickname}> {message}')
52+
53+
def add_channel_tab(self, channel):
54+
if channel not in self.text_areas:
55+
text_area = QTextEdit(self)
56+
text_area.setReadOnly(True)
57+
self.text_areas[channel] = text_area
58+
self.tab_widget.addTab(text_area, channel)

src/irc/__init__.py

Whitespace-only changes.
166 Bytes
Binary file not shown.
10.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)