写好菜单,聊天的联系人写了一半

This commit is contained in:
lsy2246 2024-04-15 01:26:00 +08:00
parent c8e0af64ac
commit 0e50aaa7da
15 changed files with 199 additions and 30 deletions

View File

@ -0,0 +1,103 @@
import wx
import wx.lib.scrolledpanel as scrolled
import threading
class ChatFrame(wx.Frame):
def __init__(self):
super().__init__(None, size=(1000, 700))
ChatMain_Panel = wx.Panel(self, style=wx.BORDER_SUNKEN)
ChatMain_box = wx.BoxSizer(wx.HORIZONTAL)
ChatMain_Panel.SetSizer(ChatMain_box)
Function_Panel = wx.Panel(ChatMain_Panel, style=wx.BORDER_RAISED)
Function_box = wx.BoxSizer(wx.VERTICAL)
Function_Panel.SetSizer(Function_box)
Function_Panel.SetBackgroundColour(wx.Colour(242, 242, 242))
image_chat = r'./Client/image/chat.png'
Chat_bitmap = wx.Bitmap(image_chat, wx.BITMAP_TYPE_PNG)
Chat_bitmap_static = wx.StaticBitmap(Function_Panel, bitmap=Chat_bitmap, style=wx.BORDER_RAISED)
Chat_bitmap_static.SetToolTip("聊天")
Function_box.Add(Chat_bitmap_static, 1, wx.EXPAND, 0)
Chat_bitmap_static.Bind(wx.EVT_LEFT_DOWN, self.click_chat_button)
Function_box.AddSpacer(30) # 调整这个数字以改变间距大小
image_connect = r'./Client/image/connect.png'
connect_bitmap = wx.Bitmap(image_connect, wx.BITMAP_TYPE_PNG)
connect_bitmap_static = wx.StaticBitmap(Function_Panel, bitmap=connect_bitmap, style=wx.BORDER_RAISED)
connect_bitmap_static.SetToolTip("通讯录")
Function_box.Add(connect_bitmap_static, 1, wx.EXPAND, 0)
connect_bitmap_static.Bind(wx.EVT_LEFT_DOWN, self.click_connect_button)
Function_box.AddSpacer(28) # 调整这个数字以改变间距大小
image_find = r'./Client/image/find.png'
find_bitmap = wx.Bitmap(image_find, wx.BITMAP_TYPE_PNG)
find_bitmap_static = wx.StaticBitmap(Function_Panel, bitmap=find_bitmap, style=wx.BORDER_RAISED)
find_bitmap_static.SetToolTip("查找")
Function_box.Add(find_bitmap_static, 1, wx.EXPAND, 0)
find_bitmap_static.Bind(wx.EVT_LEFT_DOWN, self.click_find_button)
Function_box.AddSpacer(340) # 调整这个数字以改变间距大小
image_site = r'./Client/image/site.png'
site_bitmap = wx.Bitmap(image_site, wx.BITMAP_TYPE_PNG)
site_bitmap_static = wx.StaticBitmap(Function_Panel, bitmap=site_bitmap, style=wx.BORDER_RAISED)
site_bitmap_static.SetToolTip("设置")
Function_box.Add(site_bitmap_static, 1, wx.EXPAND, 0)
site_bitmap_static.Bind(wx.EVT_LEFT_DOWN, self.click_site_button)
Function_box.Fit(Function_Panel) # 调整面板大小以适应图像
ChatMain_box.Add(Function_Panel, 0, wx.EXPAND | wx.ALL, 5)
operate_box = wx.BoxSizer(wx.VERTICAL)
chat_page = self.ChatPage(ChatMain_Panel) # 将 ChatMain_Panel 作为 ChatPage 的 parent
operate_box.Add(chat_page, 1, wx.EXPAND, 0)
ChatMain_box.Add(operate_box, 0, wx.EXPAND, 0)
ChatMain_Panel.SetSizer(ChatMain_box)
def click_chat_button(self, event):
print("点击了聊天")
def click_connect_button(self, event):
print("点击了联系人")
def click_site_button(self, event):
print("点击了设置")
def click_find_button(self, event):
print("点击了查找")
class ChatPage(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN)
ChatPage_main_box = wx.BoxSizer(wx.HORIZONTAL)
ChatPage_Contact_person_box = wx.BoxSizer(wx.VERTICAL)
self.ChatPage_Contact_person_panel = scrolled.ScrolledPanel(self, -1, style=wx.SUNKEN_BORDER)
self.ChatPage_Contact_person_panel.SetupScrolling() # 启用滚动功能
self.ChatPage_Contact_person_panel.SetSizer(wx.BoxSizer(wx.VERTICAL))
ChatPage_Contact_person_box.Add(self.ChatPage_Contact_person_panel, proportion=1, flag=wx.EXPAND | wx.ALL,
border=5)
ChatPage_main_box.Add(ChatPage_Contact_person_box, 0, wx.EXPAND, 0)
self.SetSizer(ChatPage_main_box)
def ChatPage_add_Contact_person(self,NetName,info):
#self.ChatPage_Contact_person_panel.GetSizer().Add(, 0, wx.ALL, 5)
self.ChatPage_Contact_person_panel.Layout() # 重新布局滚动面板

View File

@ -57,3 +57,4 @@ class Session_server:
except Exception as a:
print("发送错误:" + str(a))
self.server_status = False

View File

@ -31,13 +31,18 @@ class Client_main(LoginFrame, Session_server):
def login_page_receive(self, receive_content):
if receive_content["genre"] == '登录':
if receive_content["data"] == 0:
match receive_content["data"]:
case 0:
wx.MessageBox('登录成功', '登录', wx.OK | wx.ICON_INFORMATION)
elif receive_content["data"] == -1:
case -1:
wx.MessageBox('重复登录', '登录', wx.OK | wx.ICON_INFORMATION)
elif receive_content["data"] == 1:
case 1:
wx.MessageBox('密码错误', '登录', wx.OK | wx.ICON_INFORMATION)
elif receive_content["data"] == 2:
case 2:
wx.MessageBox('未找到该账号', '登录', wx.OK | wx.ICON_INFORMATION)
elif receive_content["genre"] == '注册':
wx.MessageBox(f'注册成功\n网名 : {receive_content["data"]['NetName']} \n账号 : {receive_content["data"]['Id']} \n密码 : {receive_content["data"]['Password']}', '注册', wx.OK | wx.ICON_INFORMATION)
wx.MessageBox(
f'注册成功\n网名 : {receive_content["data"]['NetName']} \n账号 : {receive_content["data"]['Id']} \n密码 : {receive_content["data"]['Password']}',
'注册', wx.OK | wx.ICON_INFORMATION)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -1,5 +1,5 @@
import wx
from Cilent import Client_main
from Client import Client_main
if __name__ == '__main__':
app = wx.App()

View File

@ -1,26 +1,34 @@
import wx
# 服务端
import socket
import cv2
import pickle
import struct
app = wx.App()
HOST = '127.0.0.1' # 服务器IP地址
PORT = 65432 # 监听端口
# 创建一个Frame
frame = wx.Frame(None, -1, '多行文本弹窗示例', size=(300, 200))
frame.Center()
# 创建Socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((HOST, PORT))
server_socket.listen(5)
# 创建一个Panel
panel = wx.Panel(frame, -1)
# 接受客户端连接
connection, address = server_socket.accept()
print('Connected by', address)
# 创建一个按钮
button = wx.Button(panel, -1, '点击弹窗', pos=(100, 50))
# 使用OpenCV捕获视频
cap = cv2.VideoCapture(0)
# 定义按钮的点击事件处理函数
def on_button_click(event):
message = "这是一个多行文本的弹窗。\n第二行文本。\n第三行文本。"
dlg = wx.MessageDialog(frame, message, '多行文本提示', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
while True:
ret, frame = cap.read()
# 将视频帧序列化
data = pickle.dumps(frame)
# 将序列化的数据封装成一个结构体
message = struct.pack("Q", len(data)) + data
# 发送数据到客户端
connection.sendall(message)
# 绑定按钮的点击事件
button.Bind(wx.EVT_BUTTON, on_button_click)
frame.Show()
app.MainLoop()
# 释放资源
connection.close()
server_socket.close()
cap.release()

43
python/test/test2.py Normal file
View File

@ -0,0 +1,43 @@
# 客户端
import socket
import cv2
import pickle
import struct
HOST = '127.0.0.1' # 服务器IP地址
PORT = 65432 # 连接端口
# 创建Socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((HOST, PORT))
# 接收数据
data = b""
payload_size = struct.calcsize("Q")
while True:
# 从服务器接收数据
while len(data) < payload_size:
packet = client_socket.recv(4*1024)
if not packet: break
data += packet
packed_msg_size = data[:payload_size]
data = data[payload_size:]
msg_size = struct.unpack("Q", packed_msg_size)[0]
# 接收视频帧
while len(data) < msg_size:
data += client_socket.recv(4*1024)
frame_data = data[:msg_size]
data = data[msg_size:]
# 反序列化视频帧
frame = pickle.loads(frame_data)
# 显示视频
cv2.imshow('frame', frame)
if cv2.waitKey(1) == 27:
break
# 释放资源
client_socket.close()
cv2.destroyAllWindows()

9
python/test/test_plan.py Normal file
View File

@ -0,0 +1,9 @@
import wx
from Client.Chat_main import ChatFrame
if __name__ == '__main__':
app = wx.App()
frame = ChatFrame()
frame.Show()
app.MainLoop()