Skip to content

Commit

Permalink
将自己的wxid设置为配置文件
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Nov 17, 2023
1 parent 19e485c commit a38550c
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 31 deletions.
34 changes: 18 additions & 16 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/DataBase/micro_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def get_contact():
from Contact inner join ContactHeadImgUrl on Contact.UserName = ContactHeadImgUrl.usrName
where Type=3 and Alias is not null
order by PYInitial
limit 30
'''
cursor.execute(sql)
result = cursor.fetchall()
Expand Down
2 changes: 1 addition & 1 deletion app/DataBase/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_message_by_num(username_, n):
from MSG
where StrTalker=?
order by CreateTime
limit 10
limit 100
'''
result = []
try:
Expand Down
1 change: 0 additions & 1 deletion app/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def set_avatar(self, img_bytes):
self.avatar.loadFromData(img_bytes, format='PNG')
else:
self.avatar.loadFromData(img_bytes, format='jfif')
self.avatar = QPixmap()


class ContactPC:
Expand Down
10 changes: 10 additions & 0 deletions app/ui_pc/chat/chat_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@


class ChatWindow(QWidget, Ui_Form):
load_finish_signal = pyqtSignal(bool)

def __init__(self, parent=None):
super().__init__(parent)
self.show_thread = None
Expand All @@ -56,6 +58,7 @@ def __init__(self, parent=None):
self.show_chats()

def init_ui(self):

search_action = QAction(self.lineEdit)
search_action.setIcon(Icon.Search_Icon)
self.lineEdit.addAction(search_action, QLineEdit.LeadingPosition)
Expand All @@ -74,6 +77,7 @@ def show_chats(self):
return
self.show_thread = ShowContactThread()
self.show_thread.showSingal.connect(self.show_chat)
self.show_thread.load_finish_signal.connect(self.stop_loading)
self.show_thread.start()
self.ok_flag = True

Expand All @@ -88,9 +92,14 @@ def setCurrentIndex(self, row):
print(row)
self.stackedWidget.setCurrentIndex(row)

def stop_loading(self, a0):
# self.label.setVisible(False)
self.load_finish_signal.emit(True)


class ShowContactThread(QThread):
showSingal = pyqtSignal(ContactPC)
load_finish_signal = pyqtSignal(bool)

# heightSingal = pyqtSignal(int)
def __init__(self):
Expand All @@ -113,3 +122,4 @@ def run(self) -> None:
contact.set_avatar(contact.smallHeadImgBLOG)
self.showSingal.emit(contact)
# pprint(contact.__dict__)
self.load_finish_signal.emit(True)
5 changes: 5 additions & 0 deletions app/ui_pc/contact/contact_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@


class ContactWindow(QWidget, Ui_Form):
load_finish_signal = pyqtSignal(bool)

def __init__(self, parent=None):
super().__init__(parent)
self.show_thread = None
Expand Down Expand Up @@ -73,6 +75,7 @@ def show_contacts(self):
return
self.show_thread = ShowContactThread()
self.show_thread.showSingal.connect(self.show_contact)
self.show_thread.load_finish_signal.connect(self.load_finish_signal)
self.show_thread.start()
self.ok_flag = True

Expand All @@ -90,6 +93,7 @@ def setCurrentIndex(self, row):

class ShowContactThread(QThread):
showSingal = pyqtSignal(ContactPC)
load_finish_signal = pyqtSignal(bool)

# heightSingal = pyqtSignal(int)
def __init__(self):
Expand All @@ -112,3 +116,4 @@ def run(self) -> None:
contact.set_avatar(contact.smallHeadImgBLOG)
self.showSingal.emit(contact)
# pprint(contact.__dict__)
self.load_finish_signal.emit(True)
91 changes: 79 additions & 12 deletions app/ui_pc/mainview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@Version : Python3.10
@comment : 主窗口
"""
import json
from random import randint

from PyQt5.QtCore import *
Expand Down Expand Up @@ -73,37 +74,65 @@ def __init__(self, username, parent=None):
self.resize(QSize(800, 600))
# self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget)
self.action_desc.triggered.connect(self.about)
self.load_data()
self.init_ui()
self.load_num = 0

def load_data(self):
with open('./app/data/info.json', 'r', encoding='utf-8') as f:
dic = json.loads(f.read())
wxid = dic.get('wxid')
if wxid:
me = MePC()
self.set_my_info(wxid)

def init_ui(self):
# self.movie = QMovie("./app/data/loading.gif")
self.label = QLabel(self)
self.label.setGeometry(0, 0, self.width(), self.height())
# self.label.setMovie(self.movie)
# self.movie.start()
self.listWidget.currentRowChanged.connect(self.setCurrentIndex)
tool_item = QListWidgetItem(Icon.MyInfo_Icon, '工具', self.listWidget)
chat_item = QListWidgetItem(Icon.Chat_Icon, '聊天', self.listWidget)
contact_item = QListWidgetItem(Icon.Contact_Icon, '好友', self.listWidget)
myinfo_item = QListWidgetItem(Icon.MyInfo_Icon, '我的', self.listWidget)
tool_item = QListWidgetItem(Icon.MyInfo_Icon, '工具', self.listWidget)

tool_window = ToolWindow()
tool_window.get_info_signal.connect(self.set_my_info)
self.chat_window = ChatWindow()
self.stackedWidget.addWidget(self.chat_window)
self.contact_window = ContactWindow()
# self.contact_window = QWidget()
self.stackedWidget.addWidget(self.contact_window)
label = QLabel('我是页面', self)
tool_window.load_finish_signal.connect(self.loading)
self.stackedWidget.addWidget(tool_window)
self.listWidget.setCurrentRow(0)
self.stackedWidget.setCurrentIndex(0)
chat_window = ChatWindow()
self.stackedWidget.addWidget(chat_window)
contact_window = ContactWindow()
self.stackedWidget.addWidget(contact_window)
label = QLabel('我是页面')
label.setAlignment(Qt.AlignCenter)
# 设置label的背景颜色(这里随机)
# 这里加了一个margin边距(方便区分QStackedWidget和QLabel的颜色)
label.setStyleSheet('background: rgb(%d, %d, %d);margin: 50px;' % (
randint(0, 255), randint(0, 255), randint(0, 255)))
self.stackedWidget.addWidget(label)
self.stackedWidget.addWidget(tool_window)
self.listWidget.setCurrentRow(3)
self.stackedWidget.setCurrentIndex(3)
tool_window.load_finish_signal.connect(self.loading)
contact_window.load_finish_signal.connect(self.loading)
chat_window.load_finish_signal.connect(self.loading)
# self.load_window_thread = LoadWindowThread(self.stackedWidget)
# self.load_window_thread.okSignal.connect(self.stop_loading)
# self.load_window_thread.start()

def setCurrentIndex(self, row):
if row == 1:
self.contact_window.show_contacts()
self.stackedWidget.setCurrentIndex(row)
if row == 2:
self.stackedWidget.currentWidget().show_contacts()

def setWindow(self, window):
try:
window.load_finish_signal.connect(self.loading)
except:
pass
self.stackedWidget.addWidget(window)

def set_my_info(self, wxid):
self.avatar = QPixmap()
Expand All @@ -115,9 +144,24 @@ def set_my_info(self, wxid):
self.avatar.scaled(60, 60)
me = MePC()
me.set_avatar(img_bytes)
dic = {
'wxid': wxid
}
with open('./app/data/info.json', 'w', encoding='utf-8') as f:
f.write(json.dumps(dic))
self.myavatar.setScaledContents(True)
self.myavatar.setPixmap(self.avatar)

def stop_loading(self, a0):
self.label.setVisible(False)

def loading(self, a0):
self.load_num += 1
print('加载一个了')
if self.load_num == 2:
print('ok了')
self.label.setVisible(False)

def about(self):
"""
关于
Expand All @@ -133,3 +177,26 @@ def close(self) -> bool:
del self.stackedWidget
msg.close()
self.contact_window.close()


class LoadWindowThread(QThread):
windowSignal = pyqtSignal(QWidget)
okSignal = pyqtSignal(bool)

def __init__(self, stackedWidget):
super().__init__()
self.stackedWidget = stackedWidget

def run(self):
chat_window = ChatWindow()
self.stackedWidget.addWidget(chat_window)
contact_window = ContactWindow()
self.stackedWidget.addWidget(contact_window)
label = QLabel('我是页面')
label.setAlignment(Qt.AlignCenter)
# 设置label的背景颜色(这里随机)
# 这里加了一个margin边距(方便区分QStackedWidget和QLabel的颜色)
label.setStyleSheet('background: rgb(%d, %d, %d);margin: 50px;' % (
randint(0, 255), randint(0, 255), randint(0, 255)))
self.stackedWidget.addWidget(label)
self.okSignal.emit(True)
2 changes: 2 additions & 0 deletions app/ui_pc/tool/tool_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@

class ToolWindow(QWidget, Ui_Dialog):
get_info_signal = pyqtSignal(str)
load_finish_signal = pyqtSignal(bool)

def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.setStyleSheet(Stylesheet)
self.init_ui()
self.load_finish_signal.emit(True)

def init_ui(self):
self.listWidget.clear()
Expand Down

0 comments on commit a38550c

Please sign in to comment.