Skip to content

Commit

Permalink
Merge pull request LC044#15 from LC044/dev_zsk
Browse files Browse the repository at this point in the history
Dev zsk
  • Loading branch information
LC044 authored Nov 19, 2023
2 parents 2621577 + 1995011 commit 2f22d03
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 74 deletions.
69 changes: 35 additions & 34 deletions .idea/workspace.xml

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

17 changes: 16 additions & 1 deletion app/DataBase/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
cursor = DB.cursor()


def init_database():
global DB
global cursor
if not DB:
if os.path.exists(misc_path):
DB = sqlite3.connect(misc_path, check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()


def get_avatar_buffer(userName):
sql = '''
select smallHeadBuf
Expand All @@ -21,7 +31,12 @@ def get_avatar_buffer(userName):
'''
try:
lock.acquire(True)
cursor.execute(sql, [userName])
try:
cursor.execute(sql, [userName])
except AttributeError:
init_database()
finally:
cursor.execute(sql, [userName])
result = cursor.fetchall()
# print(result[0][0])
if result:
Expand Down
7 changes: 5 additions & 2 deletions app/ui_pc/chat/chat_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class ChatInfo(QWidget):
def __init__(self, contact, parent=None):
super().__init__(parent)
self.last_timestamp = 0
self.last_str_time = ''
self.last_pos = 0
self.contact = contact

self.init_ui()
self.show_chats()

Expand Down Expand Up @@ -71,6 +71,7 @@ def setScrollBarPos(self):
def is_5_min(self, timestamp):
if abs(timestamp - self.last_timestamp) > 300:
self.last_timestamp = timestamp

return True
return False

Expand All @@ -85,7 +86,8 @@ def add_message(self, message):
timestamp = message[5]
if type_ == 1:
if self.is_5_min(timestamp):
time_message = Notice(str_time)
time_message = Notice(self.last_str_time)
self.last_str_time = str_time
self.chat_window.add_message_item(time_message, 0)
bubble_message = BubbleMessage(
str_content,
Expand All @@ -96,6 +98,7 @@ def add_message(self, message):
# print(str_content)
# self.scroolAreaLayout.addWidget(bubble_message)
self.chat_window.add_message_item(bubble_message, 0)

except:
print(message)

Expand Down
33 changes: 24 additions & 9 deletions app/ui_pc/mainview.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@comment : 主窗口
"""
import json
import os.path
from random import randint

from PyQt5.QtCore import *
Expand Down Expand Up @@ -72,24 +73,31 @@ def __init__(self, username, parent=None):
self.setStyleSheet(Stylesheet)
self.listWidget.clear()
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)
if os.path.exists('./app/data/info.json'):
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)
else:
QMessageBox.information(
self,
'温馨提示',
'点击 工具->获取信息 重启后可以显示本人头像哦'
)

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.setVisible(False)
# self.label.setMovie(self.movie)
# self.movie.start()
self.listWidget.currentRowChanged.connect(self.setCurrentIndex)
Expand All @@ -105,6 +113,7 @@ def init_ui(self):
self.listWidget.setCurrentRow(0)
self.stackedWidget.setCurrentIndex(0)
chat_window = ChatWindow()
# chat_window = QWidget()
self.stackedWidget.addWidget(chat_window)
contact_window = ContactWindow()
self.stackedWidget.addWidget(contact_window)
Expand All @@ -117,7 +126,7 @@ def init_ui(self):
self.stackedWidget.addWidget(label)
tool_window.load_finish_signal.connect(self.loading)
contact_window.load_finish_signal.connect(self.loading)
chat_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()
Expand All @@ -126,6 +135,8 @@ def setCurrentIndex(self, row):
self.stackedWidget.setCurrentIndex(row)
if row == 2:
self.stackedWidget.currentWidget().show_contacts()
if row == 1:
self.stackedWidget.currentWidget().show_chats()

def setWindow(self, window):
try:
Expand All @@ -136,7 +147,10 @@ def setWindow(self, window):

def set_my_info(self, wxid):
self.avatar = QPixmap()
img_bytes = misc.get_avatar_buffer(wxid)
try:
img_bytes = misc.get_avatar_buffer(wxid)
except AttributeError:
return
if img_bytes[:4] == b'\x89PNG':
self.avatar.loadFromData(img_bytes, format='PNG')
else:
Expand All @@ -157,6 +171,7 @@ def stop_loading(self, a0):

def loading(self, a0):
self.load_num += 1
self.label.setVisible(False)
# print('加载一个了')
if self.load_num == 2:
# print('ok了')
Expand Down
58 changes: 34 additions & 24 deletions app/ui_pc/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,31 @@ def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1280, 779)
MainWindow.setStyleSheet("\n"
"/*去掉item虚线边框*/\n"
"QListWidget, QListView, QTreeWidget, QTreeView {\n"
" outline: 0px;\n"
"}\n"
"/*设置左侧选项的最小最大宽度,文字颜色和背景颜色*/\n"
"QListWidget {\n"
" min-width: 120px;\n"
" max-width: 120px;\n"
" color: black;\n"
" background: white;\n"
" border:none;\n"
"}\n"
"QListWidget::item{\n"
" height:80;\n"
"}\n"
"/*被选中时的背景颜色和左边框颜色*/\n"
"QListWidget::item:selected {\n"
" background: rgb(204, 204, 204);\n"
" border-left: 4px solid rgb(9, 187, 7);\n"
"}\n"
"/*鼠标悬停颜色*/\n"
"HistoryPanel::item:hover {\n"
" background: rgb(52, 52, 52);\n"
"}")
" /*去掉item虚线边框*/\n"
" QListWidget, QListView, QTreeWidget, QTreeView {\n"
" outline: 0px;\n"
" }\n"
" /*设置左侧选项的最小最大宽度,文字颜色和背景颜色*/\n"
" QListWidget {\n"
" min-width: 120px;\n"
" max-width: 120px;\n"
" color: black;\n"
" background: white;\n"
" border:none;\n"
" }\n"
" QListWidget::item{\n"
" height:80;\n"
" }\n"
" /*被选中时的背景颜色和左边框颜色*/\n"
" QListWidget::item:selected {\n"
" background: rgb(204, 204, 204);\n"
" border-left: 4px solid rgb(9, 187, 7);\n"
" }\n"
" /*鼠标悬停颜色*/\n"
" HistoryPanel::item:hover {\n"
" background: rgb(52, 52, 52);\n"
" }\n"
" ")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget)
Expand All @@ -58,6 +59,11 @@ def setupUi(self, MainWindow):
self.myavatar.setObjectName("myavatar")
self.listWidget = QtWidgets.QListWidget(self.frame_info)
self.listWidget.setGeometry(QtCore.QRect(0, 230, 120, 331))
self.listWidget.setMinimumSize(QtCore.QSize(120, 0))
self.listWidget.setMaximumSize(QtCore.QSize(120, 16777215))
self.listWidget.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.listWidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.listWidget.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustIgnored)
self.listWidget.setObjectName("listWidget")
item = QtWidgets.QListWidgetItem()
self.listWidget.addItem(item)
Expand Down Expand Up @@ -93,6 +99,8 @@ def setupUi(self, MainWindow):
self.menu_2.setObjectName("menu_2")
self.menu_about = QtWidgets.QMenu(self.menubar)
self.menu_about.setObjectName("menu_about")
self.menu_3 = QtWidgets.QMenu(self.menubar)
self.menu_3.setObjectName("menu_3")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
Expand All @@ -118,6 +126,7 @@ def setupUi(self, MainWindow):
self.menubar.addAction(self.menu.menuAction())
self.menubar.addAction(self.menu_2.menuAction())
self.menubar.addAction(self.menu_about.menuAction())
self.menubar.addAction(self.menu_3.menuAction())

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
Expand All @@ -143,6 +152,7 @@ def retranslateUi(self, MainWindow):
self.menu.setTitle(_translate("MainWindow", "编辑"))
self.menu_2.setTitle(_translate("MainWindow", "帮助"))
self.menu_about.setTitle(_translate("MainWindow", "关于"))
self.menu_3.setTitle(_translate("MainWindow", "不显示或者显示异常请重启应用"))
self.action_3.setText(_translate("MainWindow", "保存"))
self.action_4.setText(_translate("MainWindow", "退出"))
self.action.setText(_translate("MainWindow", "关于"))
Expand Down
Loading

0 comments on commit 2f22d03

Please sign in to comment.