2022-08-19 07:12:58 -04:00
|
|
|
try:
|
2023-01-14 17:10:19 -05:00
|
|
|
from PyQt6 import QtCore, QtWidgets
|
2022-08-19 07:12:58 -04:00
|
|
|
except ImportError:
|
|
|
|
print("PyQt5 fallback (mood.py)")
|
2023-01-14 17:10:19 -05:00
|
|
|
from PyQt5 import QtCore, QtWidgets
|
2011-09-15 03:09:56 -04:00
|
|
|
|
|
|
|
from generic import PesterIcon
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
class Mood:
|
2022-10-07 16:51:40 -04:00
|
|
|
moods = [
|
|
|
|
"chummy",
|
|
|
|
"rancorous",
|
|
|
|
"offline",
|
|
|
|
"pleasant",
|
|
|
|
"distraught",
|
|
|
|
"pranky",
|
|
|
|
"smooth",
|
|
|
|
"ecstatic",
|
|
|
|
"relaxed",
|
|
|
|
"discontent",
|
|
|
|
"devious",
|
|
|
|
"sleek",
|
|
|
|
"detestful",
|
|
|
|
"mirthful",
|
|
|
|
"manipulative",
|
|
|
|
"vigorous",
|
|
|
|
"perky",
|
|
|
|
"acceptant",
|
|
|
|
"protective",
|
|
|
|
"mystified",
|
|
|
|
"amazed",
|
|
|
|
"insolent",
|
|
|
|
"bemused",
|
|
|
|
]
|
2011-09-15 03:09:56 -04:00
|
|
|
moodcats = ["chums", "trolls", "other"]
|
2022-10-07 16:51:40 -04:00
|
|
|
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",
|
|
|
|
}
|
2011-09-15 03:09:56 -04:00
|
|
|
|
|
|
|
def __init__(self, mood):
|
|
|
|
if type(mood) is int:
|
|
|
|
self.mood = mood
|
|
|
|
else:
|
|
|
|
self.mood = self.moods.index(mood)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
def value(self):
|
|
|
|
return self.mood
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
def name(self):
|
|
|
|
try:
|
|
|
|
name = self.moods[self.mood]
|
|
|
|
except IndexError:
|
|
|
|
name = "chummy"
|
|
|
|
return name
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
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)
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
class PesterMoodAction(QtCore.QObject):
|
|
|
|
def __init__(self, m, func):
|
|
|
|
QtCore.QObject.__init__(self)
|
|
|
|
self.mood = m
|
|
|
|
self.func = func
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def updateMood(self):
|
|
|
|
self.func(self.mood)
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
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)
|
2021-03-23 17:36:43 -04:00
|
|
|
b.clicked.connect(b.updateMood)
|
|
|
|
b.moodUpdated[int].connect(self.updateMood)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
def removeButtons(self):
|
2021-03-23 17:36:43 -04:00
|
|
|
for b in list(self.buttons.values()):
|
2011-09-15 03:09:56 -04:00
|
|
|
b.close()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
def showButtons(self):
|
2021-03-23 17:36:43 -04:00
|
|
|
for b in list(self.buttons.values()):
|
2011-09-15 03:09:56 -04:00
|
|
|
b.show()
|
|
|
|
b.raise_()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
@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)
|
2022-10-07 16:51:40 -04:00
|
|
|
self.mainwindow.currentMoodIcon.setPixmap(
|
|
|
|
moodicon.pixmap(moodicon.realsize())
|
|
|
|
)
|
2011-09-15 03:09:56 -04:00
|
|
|
if oldmood.name() != newmood.name():
|
2021-03-23 17:36:43 -04:00
|
|
|
for c in list(self.mainwindow.convos.values()):
|
2011-09-15 03:09:56 -04:00
|
|
|
c.myUpdateMood(newmood)
|
|
|
|
self.mainwindow.moodUpdated.emit()
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
class PesterMoodButton(QtWidgets.QPushButton):
|
2011-09-15 03:09:56 -04:00
|
|
|
def __init__(self, parent, **options):
|
|
|
|
icon = PesterIcon(options["icon"])
|
2021-03-23 17:36:43 -04:00
|
|
|
QtWidgets.QPushButton.__init__(self, icon, options["text"], parent)
|
2011-09-15 03:09:56 -04:00
|
|
|
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"])
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
def setSelected(self, selected):
|
|
|
|
if selected:
|
|
|
|
self.setStyleSheet(self.selectedSheet)
|
|
|
|
else:
|
|
|
|
self.setStyleSheet(self.unselectedSheet)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def updateMood(self):
|
|
|
|
# updates OUR mood
|
|
|
|
self.moodUpdated.emit(self.mood.value())
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
moodUpdated = QtCore.pyqtSignal(int)
|