forked from LC044/WeChatMsg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
person.py
108 lines (82 loc) · 3.05 KB
/
person.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os.path
from typing import Dict
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from app.DataBase import data
from app.ui_pc.Icon import Icon
# from app.Ui.Icon import Icon
class Person:
def __init__(self, wxid: str):
self.wxid = wxid
self.conRemark = data.get_conRemark(wxid)
self.nickname, self.alias = data.get_nickname(wxid)
self.avatar_path = data.get_avator(wxid)
if os.path.exists(self.avatar_path):
self.avatar = QPixmap(self.avatar_path).scaled(60, 60)
else:
self.avatar_path = './app/data/icons/default_avatar.svg'
# self.avatar_path = Icon.Default_avatar_path
self.avatar = QPixmap(self.avatar_path).scaled(60, 60)
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)
self.smallHeadImgUrl = ''
self.bigHeadImgUrl = ''
def singleton(cls):
_instance = {}
def inner():
if cls not in _instance:
_instance[cls] = cls()
return _instance[cls]
return inner
@singleton
class MePC:
def __init__(self):
self.avatar = QPixmap(Icon.Default_avatar_path)
self.avatar_path = 'D:\Project\Python\WeChatMsg\\app\data\icons\default_avatar.svg'
self.wxid = ''
self.wx_dir = ''
self.name = ''
self.mobile = ''
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')
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')
if not self.remark:
self.remark = self.nickName
self.smallHeadImgUrl = contact_info.get('smallHeadImgUrl')
self.smallHeadImgBLOG = b''
self.avatar = QPixmap()
self.avatar_path = 'D:\Project\Python\WeChatMsg\\app\data\icons\default_avatar.svg'
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')
self.avatar.scaled(60, 60, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
class Group(Person):
def __init__(self, wxid: str):
super(Group, self).__init__(wxid)
if __name__ == '__main__':
p1 = MePC()
p2 = MePC()
print(p1 == p2)