menu update - avatars, bug fixes
This commit is contained in:
parent
716abd7b3b
commit
2125636b41
@ -107,10 +107,12 @@ def friend_message(window):
|
|||||||
def wrapped(tox, friend_number, message_type, message, size, user_data):
|
def wrapped(tox, friend_number, message_type, message, size, user_data):
|
||||||
print 'Message: ', message.decode('utf8')
|
print 'Message: ', message.decode('utf8')
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
if not window.isActiveWindow() and Settings()['notifications']:
|
settings = Settings.get_instance()
|
||||||
friend = profile.get_friend_by_number(friend_number)
|
|
||||||
tray_notification(friend.name, message.decode('utf8'))
|
|
||||||
invoke_in_main_thread(profile.new_message, friend_number, message_type, message)
|
invoke_in_main_thread(profile.new_message, friend_number, message_type, message)
|
||||||
|
if not window.isActiveWindow():
|
||||||
|
friend = profile.get_friend_by_number(friend_number)
|
||||||
|
if settings['notifications']:
|
||||||
|
invoke_in_main_thread(tray_notification, friend.name, message.decode('utf8'))
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ class MessageEdit(QtGui.QPlainTextEdit):
|
|||||||
self.document().setTextWidth(parent.width() - 100)
|
self.document().setTextWidth(parent.width() - 100)
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setFamily("Times New Roman")
|
font.setFamily("Times New Roman")
|
||||||
font.setPixelSize(12)
|
font.setPixelSize(14)
|
||||||
font.setBold(False)
|
font.setBold(False)
|
||||||
self.setFont(font)
|
self.setFont(font)
|
||||||
lines = 0
|
lines = 0
|
||||||
@ -19,7 +19,6 @@ class MessageEdit(QtGui.QPlainTextEdit):
|
|||||||
try:
|
try:
|
||||||
for elem in xrange(self.document().blockCount()):
|
for elem in xrange(self.document().blockCount()):
|
||||||
block = self.document().findBlockByLineNumber(elem)
|
block = self.document().findBlockByLineNumber(elem)
|
||||||
l = block.length()
|
|
||||||
line_width = fm.width(block.text())
|
line_width = fm.width(block.text())
|
||||||
print 'Width: ', line_width
|
print 'Width: ', line_width
|
||||||
print 'Parent width', parent.width()
|
print 'Parent width', parent.width()
|
||||||
@ -29,7 +28,7 @@ class MessageEdit(QtGui.QPlainTextEdit):
|
|||||||
print 'lines ', lines
|
print 'lines ', lines
|
||||||
if self.document().blockCount() == 1:
|
if self.document().blockCount() == 1:
|
||||||
lines += 1
|
lines += 1
|
||||||
size = (lines - 1) * 18 + 12
|
size = lines * 21
|
||||||
self.setFixedHeight(max(size, 30))
|
self.setFixedHeight(max(size, 30))
|
||||||
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
|
self.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse)
|
||||||
|
|
||||||
@ -41,11 +40,11 @@ class MessageItem(QtGui.QListWidget):
|
|||||||
def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
|
def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
|
||||||
QtGui.QListWidget.__init__(self, parent)
|
QtGui.QListWidget.__init__(self, parent)
|
||||||
self.name = QtGui.QLabel(self)
|
self.name = QtGui.QLabel(self)
|
||||||
self.name.setGeometry(QtCore.QRect(5, 0, 95, 30))
|
self.name.setGeometry(QtCore.QRect(0, 0, 95, 40))
|
||||||
self.name.setTextFormat(QtCore.Qt.PlainText)
|
self.name.setTextFormat(QtCore.Qt.PlainText)
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setFamily("Times New Roman")
|
font.setFamily("Times New Roman")
|
||||||
font.setPointSize(10)
|
font.setPointSize(12)
|
||||||
font.setBold(True)
|
font.setBold(True)
|
||||||
self.name.setFont(font)
|
self.name.setFont(font)
|
||||||
self.name.setObjectName("name")
|
self.name.setObjectName("name")
|
||||||
|
@ -124,6 +124,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
def setup_left_top(self, Form):
|
def setup_left_top(self, Form):
|
||||||
Form.setObjectName("left_top")
|
Form.setObjectName("left_top")
|
||||||
Form.resize(500, 300)
|
Form.resize(500, 300)
|
||||||
|
Form.setCursor(QtCore.Qt.PointingHandCursor)
|
||||||
Form.setMinimumSize(QtCore.QSize(250, 100))
|
Form.setMinimumSize(QtCore.QSize(250, 100))
|
||||||
Form.setMaximumSize(QtCore.QSize(250, 100))
|
Form.setMaximumSize(QtCore.QSize(250, 100))
|
||||||
Form.setBaseSize(QtCore.QSize(250, 100))
|
Form.setBaseSize(QtCore.QSize(250, 100))
|
||||||
@ -131,7 +132,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
self.avatar_label.setGeometry(QtCore.QRect(10, 20, 64, 64))
|
self.avatar_label.setGeometry(QtCore.QRect(10, 20, 64, 64))
|
||||||
self.avatar_label.setScaledContents(True)
|
self.avatar_label.setScaledContents(True)
|
||||||
self.name = Form.name = QtGui.QLabel(Form)
|
self.name = Form.name = QtGui.QLabel(Form)
|
||||||
Form.name.setGeometry(QtCore.QRect(80, 30, 200, 25))
|
Form.name.setGeometry(QtCore.QRect(80, 30, 120, 25))
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setFamily("Times New Roman")
|
font.setFamily("Times New Roman")
|
||||||
font.setPointSize(14)
|
font.setPointSize(14)
|
||||||
@ -149,6 +150,10 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
Form.connection_status.setMinimumSize(QtCore.QSize(32, 32))
|
Form.connection_status.setMinimumSize(QtCore.QSize(32, 32))
|
||||||
Form.connection_status.setMaximumSize(QtCore.QSize(32, 32))
|
Form.connection_status.setMaximumSize(QtCore.QSize(32, 32))
|
||||||
Form.connection_status.setBaseSize(QtCore.QSize(32, 32))
|
Form.connection_status.setBaseSize(QtCore.QSize(32, 32))
|
||||||
|
self.avatar_label.mouseReleaseEvent = self.profile_settings
|
||||||
|
self.status_message.mouseReleaseEvent = self.profile_settings
|
||||||
|
self.name.mouseReleaseEvent = self.profile_settings
|
||||||
|
self.connection_status.raise_()
|
||||||
Form.connection_status.setObjectName("connection_status")
|
Form.connection_status.setObjectName("connection_status")
|
||||||
|
|
||||||
def setup_right_top(self, Form):
|
def setup_right_top(self, Form):
|
||||||
@ -243,7 +248,7 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
self.a_c = AddContact()
|
self.a_c = AddContact()
|
||||||
self.a_c.show()
|
self.a_c.show()
|
||||||
|
|
||||||
def profile_settings(self):
|
def profile_settings(self, *args):
|
||||||
self.p_s = ProfileSettings()
|
self.p_s = ProfileSettings()
|
||||||
self.p_s.show()
|
self.p_s.show()
|
||||||
|
|
||||||
|
49
src/menu.py
49
src/menu.py
@ -4,7 +4,19 @@ from profile import Profile
|
|||||||
from util import get_style
|
from util import get_style
|
||||||
|
|
||||||
|
|
||||||
class AddContact(QtGui.QWidget):
|
class CenteredWidget(QtGui.QWidget):
|
||||||
|
def __init__(self):
|
||||||
|
super(CenteredWidget, self).__init__()
|
||||||
|
self.center()
|
||||||
|
|
||||||
|
def center(self):
|
||||||
|
qr = self.frameGeometry()
|
||||||
|
cp = QtGui.QDesktopWidget().availableGeometry().center()
|
||||||
|
qr.moveCenter(cp)
|
||||||
|
self.move(qr.topLeft())
|
||||||
|
|
||||||
|
|
||||||
|
class AddContact(CenteredWidget):
|
||||||
"""Add contact form"""
|
"""Add contact form"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -64,7 +76,7 @@ class AddContact(QtGui.QWidget):
|
|||||||
self.label_2.setText(QtGui.QApplication.translate('AddContact', "Message:", None, QtGui.QApplication.UnicodeUTF8))
|
self.label_2.setText(QtGui.QApplication.translate('AddContact', "Message:", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
|
|
||||||
class ProfileSettings(QtGui.QWidget):
|
class ProfileSettings(CenteredWidget):
|
||||||
"""Form with profile settings such as name, status, TOX ID"""
|
"""Form with profile settings such as name, status, TOX ID"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ProfileSettings, self).__init__()
|
super(ProfileSettings, self).__init__()
|
||||||
@ -72,10 +84,8 @@ class ProfileSettings(QtGui.QWidget):
|
|||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
self.setObjectName("ProfileSettingsForm")
|
self.setObjectName("ProfileSettingsForm")
|
||||||
self.resize(600, 400)
|
self.setMinimumSize(QtCore.QSize(650, 400))
|
||||||
self.setMinimumSize(QtCore.QSize(700, 400))
|
self.setMaximumSize(QtCore.QSize(650, 400))
|
||||||
self.setMaximumSize(QtCore.QSize(700, 400))
|
|
||||||
self.setBaseSize(QtCore.QSize(700, 400))
|
|
||||||
self.nick = QtGui.QLineEdit(self)
|
self.nick = QtGui.QLineEdit(self)
|
||||||
self.nick.setGeometry(QtCore.QRect(30, 60, 351, 27))
|
self.nick.setGeometry(QtCore.QRect(30, 60, 351, 27))
|
||||||
self.nick.setObjectName("nick")
|
self.nick.setObjectName("nick")
|
||||||
@ -120,6 +130,12 @@ class ProfileSettings(QtGui.QWidget):
|
|||||||
font.setPointSize(18)
|
font.setPointSize(18)
|
||||||
self.tox_id_2.setFont(font)
|
self.tox_id_2.setFont(font)
|
||||||
self.tox_id_2.setObjectName("tox_id_2")
|
self.tox_id_2.setObjectName("tox_id_2")
|
||||||
|
self.new_avatar = QtGui.QPushButton(self)
|
||||||
|
self.new_avatar.setGeometry(QtCore.QRect(400, 50, 200, 50))
|
||||||
|
self.delete_avatar = QtGui.QPushButton(self)
|
||||||
|
self.delete_avatar.setGeometry(QtCore.QRect(400, 100, 200, 50))
|
||||||
|
self.delete_avatar.clicked.connect(self.reset_avatar)
|
||||||
|
self.new_avatar.clicked.connect(self.set_avatar)
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
QtCore.QMetaObject.connectSlotsByName(self)
|
QtCore.QMetaObject.connectSlotsByName(self)
|
||||||
|
|
||||||
@ -130,19 +146,32 @@ class ProfileSettings(QtGui.QWidget):
|
|||||||
self.label_3.setText(QtGui.QApplication.translate("ProfileSettingsForm", "TOX ID:", None, QtGui.QApplication.UnicodeUTF8))
|
self.label_3.setText(QtGui.QApplication.translate("ProfileSettingsForm", "TOX ID:", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.copyId.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Copy TOX ID", None, QtGui.QApplication.UnicodeUTF8))
|
self.copyId.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Copy TOX ID", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.tox_id_2.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Language:", None, QtGui.QApplication.UnicodeUTF8))
|
self.tox_id_2.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Language:", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.new_avatar.setText(QtGui.QApplication.translate("ProfileSettingsForm", "New avatar", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.delete_avatar.setText(QtGui.QApplication.translate("ProfileSettingsForm", "Reset avatar", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
clipboard = QtGui.QApplication.clipboard()
|
clipboard = QtGui.QApplication.clipboard()
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
clipboard.setText(profile.tox_id)
|
clipboard.setText(profile.tox_id)
|
||||||
|
|
||||||
|
def reset_avatar(self):
|
||||||
|
Profile.get_instance().reset_avatar()
|
||||||
|
|
||||||
|
def set_avatar(self):
|
||||||
|
name = QtGui.QFileDialog.getOpenFileName(self, 'Open file')
|
||||||
|
print name
|
||||||
|
if name[0]:
|
||||||
|
with open(name[0], 'rb') as f:
|
||||||
|
data = f.read()
|
||||||
|
Profile.get_instance().set_avatar(data)
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
profile = Profile.get_instance()
|
profile = Profile.get_instance()
|
||||||
profile.set_name(self.nick.text().encode('utf-8'))
|
profile.set_name(self.nick.text().encode('utf-8'))
|
||||||
profile.set_status_message(self.status.text().encode('utf-8'))
|
profile.set_status_message(self.status.text().encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
class NetworkSettings(QtGui.QWidget):
|
class NetworkSettings(CenteredWidget):
|
||||||
"""Network settings form: UDP, Ipv6 and proxy"""
|
"""Network settings form: UDP, Ipv6 and proxy"""
|
||||||
# TODO: add possibility to change network settings
|
# TODO: add possibility to change network settings
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -189,7 +218,7 @@ class NetworkSettings(QtGui.QWidget):
|
|||||||
self.label_2.setText(QtGui.QApplication.translate("Form", "Port:", None, QtGui.QApplication.UnicodeUTF8))
|
self.label_2.setText(QtGui.QApplication.translate("Form", "Port:", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
|
|
||||||
class PrivacySettings(QtGui.QWidget):
|
class PrivacySettings(CenteredWidget):
|
||||||
"""Privacy settings form: history, typing notifications"""
|
"""Privacy settings form: history, typing notifications"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -234,7 +263,7 @@ class PrivacySettings(QtGui.QWidget):
|
|||||||
settings.save()
|
settings.save()
|
||||||
|
|
||||||
|
|
||||||
class NotificationsSettings(QtGui.QWidget):
|
class NotificationsSettings(CenteredWidget):
|
||||||
"""Notifications settings form"""
|
"""Notifications settings form"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -277,7 +306,7 @@ class NotificationsSettings(QtGui.QWidget):
|
|||||||
settings.save()
|
settings.save()
|
||||||
|
|
||||||
|
|
||||||
class InterfaceSettings(QtGui.QWidget):
|
class InterfaceSettings(CenteredWidget):
|
||||||
"""Interface settings form"""
|
"""Interface settings form"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -138,6 +138,18 @@ class Contact(object):
|
|||||||
self._widget.avatar_label.setPixmap(avatar_path)
|
self._widget.avatar_label.setPixmap(avatar_path)
|
||||||
self._widget.avatar_label.repaint()
|
self._widget.avatar_label.repaint()
|
||||||
|
|
||||||
|
def reset_avatar(self):
|
||||||
|
avatar_path = (Settings.get_default_path() + 'avatars/{}.png').format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])
|
||||||
|
if os.path.isfile(avatar_path):
|
||||||
|
os.remove(avatar_path)
|
||||||
|
self.load_avatar()
|
||||||
|
|
||||||
|
def set_avatar(self, avatar):
|
||||||
|
avatar_path = (Settings.get_default_path() + 'avatars/{}.png').format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])
|
||||||
|
with open(avatar_path, 'wb') as f:
|
||||||
|
f.write(avatar)
|
||||||
|
self.load_avatar()
|
||||||
|
|
||||||
|
|
||||||
class Friend(Contact):
|
class Friend(Contact):
|
||||||
"""
|
"""
|
||||||
@ -398,8 +410,9 @@ class Profile(Contact, Singleton):
|
|||||||
self.screen.messageEdit.clear()
|
self.screen.messageEdit.clear()
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Work with friends (add, remove, set alias, clear history)
|
# Work with friends (remove, set alias, clear history)
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def set_alias(self, num):
|
def set_alias(self, num):
|
||||||
friend = self._friends[num]
|
friend = self._friends[num]
|
||||||
name = friend.name.encode('utf-8')
|
name = friend.name.encode('utf-8')
|
||||||
@ -442,6 +455,25 @@ class Profile(Contact, Singleton):
|
|||||||
self.screen.friends_list.setItemWidget(elem, item)
|
self.screen.friends_list.setItemWidget(elem, item)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
def delete_friend(self, num):
|
||||||
|
"""
|
||||||
|
Removes friend from contact list
|
||||||
|
:param num: number of friend in list
|
||||||
|
"""
|
||||||
|
friend = self._friends[num]
|
||||||
|
self.tox.friend_delete(friend.number)
|
||||||
|
del self._friends[num]
|
||||||
|
self.screen.friends_list.takeItem(num)
|
||||||
|
if num == self._active_friend: # active friend was deleted
|
||||||
|
if not len(self._friends): # last friend was deleted
|
||||||
|
self.set_active(-1)
|
||||||
|
else:
|
||||||
|
self.set_active(0)
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
# Friend requests
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def send_friend_request(self, tox_id, message):
|
def send_friend_request(self, tox_id, message):
|
||||||
"""
|
"""
|
||||||
Function tries to send request to contact with specified id
|
Function tries to send request to contact with specified id
|
||||||
@ -478,21 +510,6 @@ class Profile(Contact, Singleton):
|
|||||||
except Exception as ex: # something is wrong
|
except Exception as ex: # something is wrong
|
||||||
log('Accept friend request failed! ' + str(ex))
|
log('Accept friend request failed! ' + str(ex))
|
||||||
|
|
||||||
def delete_friend(self, num):
|
|
||||||
"""
|
|
||||||
Removes friend from contact list
|
|
||||||
:param num: number of friend in list
|
|
||||||
"""
|
|
||||||
friend = self._friends[num]
|
|
||||||
self.tox.friend_delete(friend.number)
|
|
||||||
del self._friends[num]
|
|
||||||
self.screen.friends_list.takeItem(num)
|
|
||||||
if num == self._active_friend: # active friend was deleted
|
|
||||||
if not len(self._friends): # last friend was deleted
|
|
||||||
self.set_active(-1)
|
|
||||||
else:
|
|
||||||
self.set_active(0)
|
|
||||||
|
|
||||||
|
|
||||||
def tox_factory(data=None, settings=None):
|
def tox_factory(data=None, settings=None):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user