This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavatar_prechooser.py
51 lines (41 loc) · 1.73 KB
/
avatar_prechooser.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
from PyQt4 import uic
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import util
import cyemussa
import avatar_chooser
ym = cyemussa.CyEmussa.Instance()
class AvatarPrechooser(QObject):
def __init__(self, app):
QObject.__init__(app)
super(AvatarPrechooser, self).__init__()
self.app = app
self.widget = uic.loadUi('ui/avatar_prechooser.ui')
self.widget.setWindowFlags(self.widget.windowFlags() | Qt.Popup)
self.widget.button_selectAvatar.clicked.connect(
self._openAvatarChooser
)
self.widget.label_avatar.setPixmap(QPixmap(self.app.me.avatar.image))
self.widget.accepted.connect(self._setAvatar)
self.widget.shareRadioButton.setChecked(True)
def _openAvatarChooser(self):
self.avatarchooser = avatar_chooser.AvatarChooser(self.app)
self.avatarchooser.widget.show()
self.avatarchooser.widget.accepted.connect(self._avatarChosed)
self.widget.shareRadioButton.setChecked(True)
def _avatarChosed(self):
item = self.avatarchooser.widget.avatarListWidget.currentItem()
pixmap = util.scalePixmapAspectFill(
QPixmap(item.avatarPath),
QSize(96, 96)
)
self.widget.label_avatar.setPixmap(pixmap)
def _setAvatar(self):
if self.widget.shareRadioButton.isChecked():
self.app.me.avatar.image = self.widget.label_avatar.pixmap()
# encode the pixmap to PNG and upload it
image_data = util.pixmap_to_imgformat(self.widget.label_avatar.pixmap(), 'PNG')
ym.upload_display_image(image_data)
else:
self.app.me.avatar.image = QPixmap("ui/resources/no-avatar.png")
ym.delete_display_image()