2023-11-05 21:14:14 +08:00
|
|
|
import os.path
|
2023-11-15 21:57:29 +08:00
|
|
|
from typing import Dict
|
2023-11-05 21:14:14 +08:00
|
|
|
|
2023-11-15 22:59:25 +08:00
|
|
|
from PyQt5.QtCore import Qt
|
2023-10-31 23:25:58 +08:00
|
|
|
from PyQt5.QtGui import QPixmap
|
|
|
|
|
2023-11-08 00:13:12 +08:00
|
|
|
from app.DataBase import data
|
2023-11-15 23:53:39 +08:00
|
|
|
from app.Ui.Icon import Icon
|
2023-11-08 00:13:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
# from app.Ui.Icon import Icon
|
2023-10-30 23:55:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Person:
|
|
|
|
def __init__(self, wxid: str):
|
2023-11-17 22:44:55 +08:00
|
|
|
|
2023-10-30 23:55:26 +08:00
|
|
|
self.wxid = wxid
|
2023-10-31 23:25:58 +08:00
|
|
|
self.conRemark = data.get_conRemark(wxid)
|
|
|
|
self.nickname, self.alias = data.get_nickname(wxid)
|
2023-10-30 23:55:26 +08:00
|
|
|
self.avatar_path = data.get_avator(wxid)
|
2023-11-05 21:14:14 +08:00
|
|
|
if os.path.exists(self.avatar_path):
|
|
|
|
self.avatar = QPixmap(self.avatar_path).scaled(60, 60)
|
|
|
|
else:
|
2023-11-08 00:13:12 +08:00
|
|
|
self.avatar_path = './app/data/icons/default_avatar.svg'
|
|
|
|
# self.avatar_path = Icon.Default_avatar_path
|
2023-11-05 21:14:14 +08:00
|
|
|
self.avatar = QPixmap(self.avatar_path).scaled(60, 60)
|
2023-10-31 23:25:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Me(Person):
|
|
|
|
def __init__(self, wxid: str):
|
|
|
|
super(Me, self).__init__(wxid)
|
|
|
|
self.city = None
|
|
|
|
self.province = None
|
|
|
|
|
|
|
|
|
|
|
|
class Contact(Person):
|
|
|
|
def __init__(self, wxid: str):
|
|
|
|
super(Contact, self).__init__(wxid)
|
2023-11-15 21:57:29 +08:00
|
|
|
self.smallHeadImgUrl = ''
|
|
|
|
self.bigHeadImgUrl = ''
|
|
|
|
|
|
|
|
|
2023-11-17 21:34:22 +08:00
|
|
|
def singleton(cls):
|
|
|
|
_instance = {}
|
|
|
|
|
|
|
|
def inner():
|
|
|
|
if cls not in _instance:
|
|
|
|
_instance[cls] = cls()
|
|
|
|
return _instance[cls]
|
|
|
|
|
|
|
|
return inner
|
|
|
|
|
|
|
|
|
|
|
|
@singleton
|
|
|
|
class MePC:
|
2023-11-17 22:44:55 +08:00
|
|
|
def __init__(self):
|
2023-11-17 23:02:40 +08:00
|
|
|
self.avatar = QPixmap(Icon.Default_avatar_path)
|
2023-11-21 22:23:23 +08:00
|
|
|
self.avatar_path = 'D:\Project\Python\WeChatMsg\\app\data\icons\default_avatar.svg'
|
2023-11-20 22:30:31 +08:00
|
|
|
self.wxid = ''
|
|
|
|
self.wx_dir = ''
|
|
|
|
self.name = ''
|
|
|
|
self.mobile = ''
|
2023-11-17 21:34:22 +08:00
|
|
|
|
|
|
|
def set_avatar(self, img_bytes):
|
|
|
|
if not img_bytes:
|
|
|
|
self.avatar.load(Icon.Default_avatar_path)
|
|
|
|
return
|
|
|
|
if img_bytes[:4] == b'\x89PNG':
|
|
|
|
self.avatar.loadFromData(img_bytes, format='PNG')
|
|
|
|
else:
|
|
|
|
self.avatar.loadFromData(img_bytes, format='jfif')
|
|
|
|
|
|
|
|
|
2023-11-15 21:57:29 +08:00
|
|
|
class ContactPC:
|
|
|
|
def __init__(self, contact_info: Dict):
|
|
|
|
self.wxid = contact_info.get('UserName')
|
|
|
|
self.remark = contact_info.get('Remark')
|
|
|
|
# Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl,bigHeadImgUrl
|
|
|
|
self.alias = contact_info.get('Alias')
|
|
|
|
self.nickName = contact_info.get('NickName')
|
2023-11-16 23:56:36 +08:00
|
|
|
if not self.remark:
|
|
|
|
self.remark = self.nickName
|
2023-11-15 21:57:29 +08:00
|
|
|
self.smallHeadImgUrl = contact_info.get('smallHeadImgUrl')
|
2023-11-15 22:32:11 +08:00
|
|
|
self.smallHeadImgBLOG = b''
|
2023-11-15 22:59:25 +08:00
|
|
|
self.avatar = QPixmap()
|
2023-11-21 22:23:23 +08:00
|
|
|
self.avatar_path = 'D:\Project\Python\WeChatMsg\\app\data\icons\default_avatar.svg'
|
2023-11-15 22:59:25 +08:00
|
|
|
|
|
|
|
def set_avatar(self, img_bytes):
|
|
|
|
if not img_bytes:
|
|
|
|
self.avatar.load(Icon.Default_avatar_path)
|
|
|
|
return
|
|
|
|
if img_bytes[:4] == b'\x89PNG':
|
|
|
|
self.avatar.loadFromData(img_bytes, format='PNG')
|
|
|
|
else:
|
|
|
|
self.avatar.loadFromData(img_bytes, format='jfif')
|
2023-11-21 22:23:23 +08:00
|
|
|
|
2023-11-15 22:59:25 +08:00
|
|
|
self.avatar.scaled(60, 60, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
|
2023-10-31 23:25:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Group(Person):
|
|
|
|
def __init__(self, wxid: str):
|
|
|
|
super(Group, self).__init__(wxid)
|
2023-11-17 21:34:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-11-17 22:44:55 +08:00
|
|
|
p1 = MePC()
|
|
|
|
p2 = MePC()
|
|
|
|
print(p1 == p2)
|