Skip to content

Commit

Permalink
修复第一次启动的显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Nov 19, 2023
1 parent 2714ca6 commit 1995011
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 50 deletions.
26 changes: 14 additions & 12 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
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
12 changes: 9 additions & 3 deletions app/ui_pc/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@
<rect>
<x>0</x>
<y>230</y>
<width>80</width>
<width>120</width>
<height>331</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<width>120</width>
<height>16777215</height>
</size>
</property>
Expand Down Expand Up @@ -205,10 +205,16 @@
</property>
<addaction name="action_desc"/>
</widget>
<widget class="QMenu" name="menu_3">
<property name="title">
<string>不显示或者显示异常请重启应用</string>
</property>
</widget>
<addaction name="menu_F"/>
<addaction name="menu"/>
<addaction name="menu_2"/>
<addaction name="menu_about"/>
<addaction name="menu_3"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="action_3">
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

大家有任何想法、建议或bug可以群里反馈给我

<img src="doc/images/qq.jpg" height=480/>
[//]: # (<img src="doc/images/qq.jpg" height=480/>)

## 效果

Expand Down

0 comments on commit 1995011

Please sign in to comment.