-
Notifications
You must be signed in to change notification settings - Fork 20
/
mood.py
176 lines (155 loc) · 4.77 KB
/
mood.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
try:
from PyQt6 import QtCore, QtWidgets
except ImportError:
print("PyQt5 fallback (mood.py)")
from PyQt5 import QtCore, QtWidgets
from generic import PesterIcon
class Mood:
moods = [
"chummy",
"rancorous",
"offline",
"pleasant",
"distraught",
"pranky",
"smooth",
"ecstatic",
"relaxed",
"discontent",
"devious",
"sleek",
"detestful",
"mirthful",
"manipulative",
"vigorous",
"perky",
"acceptant",
"protective",
"mystified",
"amazed",
"insolent",
"bemused",
]
moodcats = ["chums", "trolls", "other"]
revmoodcats = {
"discontent": "trolls",
"insolent": "chums",
"rancorous": "chums",
"sleek": "trolls",
"bemused": "chums",
"mystified": "chums",
"pranky": "chums",
"distraught": "chums",
"offline": "chums",
"chummy": "chums",
"protective": "other",
"vigorous": "trolls",
"ecstatic": "trolls",
"relaxed": "trolls",
"pleasant": "chums",
"manipulative": "trolls",
"detestful": "trolls",
"smooth": "chums",
"mirthful": "trolls",
"acceptant": "trolls",
"perky": "trolls",
"devious": "trolls",
"amazed": "chums",
}
def __init__(self, mood):
if isinstance(mood, int):
self.mood = mood
else:
self.mood = self.moods.index(mood)
def value_str(self):
"""Return mood index as str."""
return str(self.mood)
def value(self):
return self.mood
def name(self):
try:
name = self.moods[self.mood]
except IndexError:
name = "chummy"
return name
def icon(self, theme):
try:
f = theme["main/chums/moods"][self.name()]["icon"]
except KeyError:
return PesterIcon(theme["main/chums/moods/chummy/icon"])
return PesterIcon(f)
class PesterMoodAction(QtCore.QObject):
def __init__(self, m, func):
QtCore.QObject.__init__(self)
self.mood = m
self.func = func
@QtCore.pyqtSlot()
def updateMood(self):
self.func(self.mood)
class PesterMoodHandler(QtCore.QObject):
def __init__(self, parent, *buttons):
QtCore.QObject.__init__(self)
self.buttons = {}
self.mainwindow = parent
for b in buttons:
self.buttons[b.mood.value()] = b
if b.mood.value() == self.mainwindow.profile().mood.value():
b.setSelected(True)
b.clicked.connect(b.updateMood)
b.moodUpdated[int].connect(self.updateMood)
def removeButtons(self):
for b in list(self.buttons.values()):
b.close()
def showButtons(self):
for b in list(self.buttons.values()):
b.show()
b.raise_()
@QtCore.pyqtSlot(int)
def updateMood(self, m):
# update MY mood
oldmood = self.mainwindow.profile().mood
try:
oldbutton = self.buttons[oldmood.value()]
oldbutton.setSelected(False)
except KeyError:
pass
try:
newbutton = self.buttons[m]
newbutton.setSelected(True)
except KeyError:
pass
newmood = Mood(m)
self.mainwindow.userprofile.chat.mood = newmood
self.mainwindow.userprofile.setLastMood(newmood)
if self.mainwindow.currentMoodIcon:
moodicon = newmood.icon(self.mainwindow.theme)
self.mainwindow.currentMoodIcon.setPixmap(
moodicon.pixmap(moodicon.realsize())
)
if oldmood.name() != newmood.name():
for c in list(self.mainwindow.convos.values()):
c.myUpdateMood(newmood)
self.mainwindow.moodUpdated.emit()
class PesterMoodButton(QtWidgets.QPushButton):
def __init__(self, parent, **options):
icon = PesterIcon(options["icon"])
QtWidgets.QPushButton.__init__(self, icon, options["text"], parent)
self.setIconSize(icon.realsize())
self.setFlat(True)
self.resize(*options["size"])
self.move(*options["loc"])
self.unselectedSheet = options["style"]
self.selectedSheet = options["selected"]
self.setStyleSheet(self.unselectedSheet)
self.mainwindow = parent
self.mood = Mood(options["mood"])
def setSelected(self, selected):
if selected:
self.setStyleSheet(self.selectedSheet)
else:
self.setStyleSheet(self.unselectedSheet)
@QtCore.pyqtSlot()
def updateMood(self):
# updates OUR mood
self.moodUpdated.emit(self.mood.value())
moodUpdated = QtCore.pyqtSignal(int)