2023-01-11 13:04:19 +08:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""
|
|
|
|
|
@File : mainview.py
|
|
|
|
|
@Author : Shuaikang Zhou
|
|
|
|
|
@Time : 2022/12/13 15:07
|
|
|
|
|
@IDE : Pycharm
|
|
|
|
|
@Version : Python3.10
|
2023-02-02 00:26:44 +08:00
|
|
|
|
@comment : 主窗口
|
2023-01-11 13:04:19 +08:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from PyQt5.QtCore import *
|
|
|
|
|
from PyQt5.QtGui import *
|
2023-03-31 11:15:44 +08:00
|
|
|
|
from PyQt5.QtWidgets import *
|
|
|
|
|
|
2023-11-12 13:15:47 +08:00
|
|
|
|
from app import person, config
|
2023-11-08 00:13:12 +08:00
|
|
|
|
from app.DataBase import *
|
|
|
|
|
from app.Ui import mainwindow
|
|
|
|
|
from app.Ui.Icon import Icon
|
2023-11-12 13:15:47 +08:00
|
|
|
|
from app.Ui.MyComponents.prompt_bar import PromptBar
|
2023-11-08 00:13:12 +08:00
|
|
|
|
from app.Ui.chat import chat
|
|
|
|
|
from app.Ui.contact import contact
|
2023-01-11 13:04:19 +08:00
|
|
|
|
|
|
|
|
|
|
2023-04-02 21:23:20 +08:00
|
|
|
|
class MainWinController(QMainWindow, mainwindow.Ui_MainWindow):
|
2023-01-11 13:04:19 +08:00
|
|
|
|
exitSignal = pyqtSignal()
|
|
|
|
|
|
|
|
|
|
# username = ''
|
|
|
|
|
def __init__(self, username, parent=None):
|
|
|
|
|
super(MainWinController, self).__init__(parent)
|
|
|
|
|
self.setupUi(self)
|
2023-11-08 00:13:12 +08:00
|
|
|
|
self.setWindowIcon(Icon.MainWindow_Icon)
|
|
|
|
|
self.Me = person.Me(data.get_myinfo())
|
2023-04-02 21:23:20 +08:00
|
|
|
|
self.setAttribute(Qt.WA_AttributeCount)
|
|
|
|
|
|
|
|
|
|
self.chatView = chat.ChatController(self.Me, parent=None)
|
|
|
|
|
self.lay = QHBoxLayout()
|
2023-11-01 22:54:56 +08:00
|
|
|
|
self.page_chat.setLayout(self.lay)
|
2023-04-02 21:23:20 +08:00
|
|
|
|
self.lay.addWidget(self.chatView)
|
2023-11-01 22:54:56 +08:00
|
|
|
|
|
2023-04-02 21:23:20 +08:00
|
|
|
|
self.contactView = contact.ContactController(self.Me, parent=None)
|
|
|
|
|
self.lay0 = QHBoxLayout()
|
2023-11-01 22:54:56 +08:00
|
|
|
|
self.page_contact.setLayout(self.lay0)
|
|
|
|
|
self.lay0.addWidget(self.contactView)
|
2023-04-02 21:23:20 +08:00
|
|
|
|
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.btn_chat.clicked.connect(self.chat_view) # 聊天按钮
|
|
|
|
|
self.btn_contact.clicked.connect(self.contact_view)
|
2023-03-31 11:15:44 +08:00
|
|
|
|
# self.btn_myinfo.clicked.connect(self.myInfo)
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.btn_about.clicked.connect(self.about)
|
|
|
|
|
self.now_btn = self.btn_chat
|
2023-11-11 19:35:25 +08:00
|
|
|
|
self.btn_chat.setIcon(Icon.Chat_Icon)
|
|
|
|
|
self.btn_contact.setIcon(Icon.Contact_Icon)
|
|
|
|
|
self.btn_myinfo.setIcon(Icon.MyInfo_Icon)
|
2023-11-11 18:58:40 +08:00
|
|
|
|
self.btn_about.setIcon(Icon.MainWindow_Icon)
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.btn_about.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
|
|
|
self.btn_about.customContextMenuRequested.connect(self.create_rightmenu) # 连接到菜单显示函数
|
|
|
|
|
self.last_btn = None
|
2023-01-21 13:59:37 +08:00
|
|
|
|
self.lastView = None
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.show_avatar()
|
2023-11-06 21:00:42 +08:00
|
|
|
|
self.init_ui()
|
2023-11-11 18:58:40 +08:00
|
|
|
|
self.menubar.setVisible(False)
|
|
|
|
|
self.statusbar.setVisible(False)
|
2023-11-12 13:15:47 +08:00
|
|
|
|
self.prompt_bar = PromptBar(self)
|
|
|
|
|
self.chat_view()
|
2023-11-09 20:11:01 +08:00
|
|
|
|
# self.state_lable = QLabel(self)
|
|
|
|
|
# self.state_lable.raise_()
|
|
|
|
|
# pixmap = QPixmap('./app/data/icons/default_avatar.svg').scaled(32, 32) # 按指定路径找到图片
|
|
|
|
|
# self.state_lable.setPixmap(pixmap)
|
|
|
|
|
# self.state_lable.setText("T")
|
2023-01-11 13:04:19 +08:00
|
|
|
|
# 创建右键菜单函数
|
2023-01-21 13:59:37 +08:00
|
|
|
|
|
2023-11-06 21:00:42 +08:00
|
|
|
|
def init_ui(self):
|
|
|
|
|
self.menubar.setStyleSheet("background-color: rgb(240, 240, 240);")
|
|
|
|
|
|
2023-01-11 13:04:19 +08:00
|
|
|
|
def create_rightmenu(self):
|
|
|
|
|
# 菜单对象
|
|
|
|
|
self.groupBox_menu = QMenu(self)
|
|
|
|
|
|
|
|
|
|
self.actionA = QAction(QIcon('image/保存.png'), u'保存数据',
|
|
|
|
|
self) # self.actionA = self.contextMenu.addAction(QIcon("images/0.png"),u'| 动作A')
|
|
|
|
|
self.actionA.setShortcut('Ctrl+S') # 设置快捷键
|
|
|
|
|
self.groupBox_menu.addAction(self.actionA) # 把动作A选项添加到菜单
|
|
|
|
|
|
|
|
|
|
self.actionB = QAction(QIcon('image/删除.png'), u'删除数据', self)
|
|
|
|
|
self.groupBox_menu.addAction(self.actionB)
|
|
|
|
|
|
|
|
|
|
# self.actionA.triggered.connect(self.button) # 将动作A触发时连接到槽函数 button
|
|
|
|
|
# self.actionB.triggered.connect(self.button_2)
|
|
|
|
|
|
|
|
|
|
self.groupBox_menu.popup(QCursor.pos()) # 声明当鼠标在groupBox控件上右击时,在鼠标位置显示右键菜单 ,exec_,popup两个都可以,
|
2023-01-21 13:59:37 +08:00
|
|
|
|
|
2023-01-11 13:04:19 +08:00
|
|
|
|
def show_avatar(self):
|
2023-11-02 23:50:04 +08:00
|
|
|
|
avatar = self.Me.avatar
|
2023-11-01 22:54:56 +08:00
|
|
|
|
pixmap = QPixmap(avatar).scaled(60, 60) # 按指定路径找到图片
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.myavatar.setPixmap(pixmap) # 在label上显示图片
|
|
|
|
|
|
|
|
|
|
def chat_view(self):
|
2023-02-02 00:26:44 +08:00
|
|
|
|
"""
|
|
|
|
|
聊天窗口
|
|
|
|
|
"""
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.now_btn = self.btn_chat
|
|
|
|
|
self.now_btn.setStyleSheet(
|
2023-11-12 13:15:47 +08:00
|
|
|
|
"QPushButton {background-color: rgb(198,198,198);border:none;}")
|
2023-01-11 13:04:19 +08:00
|
|
|
|
if self.last_btn and self.last_btn != self.now_btn:
|
2023-11-12 13:15:47 +08:00
|
|
|
|
self.last_btn.setStyleSheet(
|
|
|
|
|
"QPushButton {"
|
|
|
|
|
"background-color: rgb(240,240,240);"
|
|
|
|
|
"border:none;"
|
|
|
|
|
"}"
|
|
|
|
|
"QPushButton:hover{background-color: rgb(209,209,209);}\n"
|
|
|
|
|
)
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.last_btn = self.btn_chat
|
2023-11-09 20:11:01 +08:00
|
|
|
|
# self.state_lable.setGeometry(20, 300, 32, 32)
|
2023-11-01 22:54:56 +08:00
|
|
|
|
self.stackedWidget.setCurrentIndex(0)
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.chatView.showChat()
|
|
|
|
|
|
|
|
|
|
def contact_view(self):
|
2023-02-02 00:26:44 +08:00
|
|
|
|
"""
|
|
|
|
|
联系人窗口
|
|
|
|
|
"""
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.now_btn = self.btn_contact
|
|
|
|
|
self.now_btn.setStyleSheet(
|
2023-11-12 13:15:47 +08:00
|
|
|
|
"QPushButton {background-color: rgb(198,198,198);border:none;}")
|
2023-01-11 13:04:19 +08:00
|
|
|
|
if self.last_btn and self.last_btn != self.now_btn:
|
2023-11-12 13:15:47 +08:00
|
|
|
|
self.last_btn.setStyleSheet("QPushButton {background-color: rgb(240,240,240);border:none;}"
|
2023-01-11 13:04:19 +08:00
|
|
|
|
"QPushButton:hover{background-color: rgb(209,209,209);}\n")
|
|
|
|
|
self.last_btn = self.btn_contact
|
2023-11-09 20:11:01 +08:00
|
|
|
|
# geometry = self.btn_chat.geometry()
|
|
|
|
|
# self.state_lable.setGeometry(geometry)
|
2023-11-01 22:54:56 +08:00
|
|
|
|
self.stackedWidget.setCurrentIndex(1)
|
2023-01-11 13:04:19 +08:00
|
|
|
|
|
|
|
|
|
def myInfo(self):
|
2023-02-02 00:26:44 +08:00
|
|
|
|
"""
|
|
|
|
|
显示我的个人信息
|
|
|
|
|
"""
|
2023-01-11 13:04:19 +08:00
|
|
|
|
self.now_btn = self.btn_myinfo
|
|
|
|
|
self.now_btn.setStyleSheet(
|
|
|
|
|
"QPushButton {background-color: rgb(198,198,198);}")
|
|
|
|
|
if self.last_btn and self.last_btn != self.now_btn:
|
|
|
|
|
self.last_btn.setStyleSheet("QPushButton {background-color: rgb(240,240,240);}"
|
|
|
|
|
"QPushButton:hover{background-color: rgb(209,209,209);}\n")
|
|
|
|
|
self.last_btn = self.now_btn
|
|
|
|
|
|
|
|
|
|
def about(self):
|
2023-02-02 00:26:44 +08:00
|
|
|
|
"""
|
|
|
|
|
关于
|
|
|
|
|
"""
|
2023-01-11 13:04:19 +08:00
|
|
|
|
QMessageBox.about(self, "关于",
|
2023-11-12 13:15:47 +08:00
|
|
|
|
f"版本:{config.version}\n"
|
|
|
|
|
f"QQ交流群:{config.contact}\n"
|
|
|
|
|
"地址:https://github.com/LC044/WeChatMsg"
|
2023-01-11 13:04:19 +08:00
|
|
|
|
)
|