context menu added. alias full support, friend removing support
This commit is contained in:
parent
d641d295ca
commit
4706ef9b44
24
src/main.py
24
src/main.py
@ -74,11 +74,11 @@ def main():
|
|||||||
ms = MainWindow(tox)
|
ms = MainWindow(tox)
|
||||||
ms.show()
|
ms.show()
|
||||||
QtGui.QApplication.setStyle(get_style(settings['theme'])) # set application style
|
QtGui.QApplication.setStyle(get_style(settings['theme'])) # set application style
|
||||||
# bootstrap
|
|
||||||
for data in node_generator():
|
# init thread
|
||||||
tox.bootstrap(*data)
|
init = InitThread(tox, ms)
|
||||||
# initializing callbacks
|
init.start()
|
||||||
init_callbacks(tox, ms)
|
|
||||||
# starting thread for tox iterate
|
# starting thread for tox iterate
|
||||||
mainloop = ToxIterateThread(tox)
|
mainloop = ToxIterateThread(tox)
|
||||||
mainloop.start()
|
mainloop.start()
|
||||||
@ -92,6 +92,20 @@ def main():
|
|||||||
del tox
|
del tox
|
||||||
|
|
||||||
|
|
||||||
|
class InitThread(QtCore.QThread):
|
||||||
|
|
||||||
|
def __init__(self, tox, ms):
|
||||||
|
QtCore.QThread.__init__(self)
|
||||||
|
self.tox, self.ms = tox, ms
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# initializing callbacks
|
||||||
|
init_callbacks(self.tox, self.ms)
|
||||||
|
# bootstrap
|
||||||
|
for data in node_generator():
|
||||||
|
self.tox.bootstrap(*data)
|
||||||
|
|
||||||
|
|
||||||
class ToxIterateThread(QtCore.QThread):
|
class ToxIterateThread(QtCore.QThread):
|
||||||
|
|
||||||
def __init__(self, tox):
|
def __init__(self, tox):
|
||||||
|
@ -181,6 +181,9 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
self.friends_list = QtGui.QListWidget(widget)
|
self.friends_list = QtGui.QListWidget(widget)
|
||||||
self.friends_list.setGeometry(0, 0, 250, 250)
|
self.friends_list.setGeometry(0, 0, 250, 250)
|
||||||
self.friends_list.clicked.connect(self.friend_click)
|
self.friends_list.clicked.connect(self.friend_click)
|
||||||
|
self.friends_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
||||||
|
self.friends_list.connect(self.friends_list, QtCore.SIGNAL("customContextMenuRequested(QPoint)"),
|
||||||
|
self.friend_right_click)
|
||||||
|
|
||||||
def setup_right_center(self, widget):
|
def setup_right_center(self, widget):
|
||||||
self.messages = QtGui.QListWidget(widget)
|
self.messages = QtGui.QListWidget(widget)
|
||||||
@ -264,6 +267,43 @@ class MainWindow(QtGui.QMainWindow):
|
|||||||
text = self.messageEdit.toPlainText()
|
text = self.messageEdit.toPlainText()
|
||||||
self.profile.send_message(text)
|
self.profile.send_message(text)
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
# Functions which called when user open context menu in friends list
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def friend_right_click(self, pos):
|
||||||
|
item = self.friends_list.itemAt(pos)
|
||||||
|
if item is not None:
|
||||||
|
self.listMenu = QtGui.QMenu()
|
||||||
|
set_alias_item = self.listMenu.addAction('Set alias')
|
||||||
|
clear_history_item = self.listMenu.addAction('Clear history')
|
||||||
|
copy_key_item = self.listMenu.addAction('Copy public key')
|
||||||
|
remove_item = self.listMenu.addAction('Remove friend')
|
||||||
|
self.connect(set_alias_item, QtCore.SIGNAL("triggered()"), lambda: self.set_alias(item))
|
||||||
|
self.connect(remove_item, QtCore.SIGNAL("triggered()"), lambda: self.remove_friend(item))
|
||||||
|
self.connect(copy_key_item, QtCore.SIGNAL("triggered()"), lambda: self.copy_friend_key(item))
|
||||||
|
self.connect(clear_history_item, QtCore.SIGNAL("triggered()"), lambda: self.clear_history(item))
|
||||||
|
parent_position = self.friends_list.mapToGlobal(QtCore.QPoint(0, 0))
|
||||||
|
self.listMenu.move(parent_position + pos)
|
||||||
|
self.listMenu.show()
|
||||||
|
|
||||||
|
def set_alias(self, item):
|
||||||
|
num = self.friends_list.indexFromItem(item).row()
|
||||||
|
self.profile.set_alias(num)
|
||||||
|
|
||||||
|
def remove_friend(self, item):
|
||||||
|
num = self.friends_list.indexFromItem(item).row()
|
||||||
|
self.profile.delete_friend(num)
|
||||||
|
|
||||||
|
def copy_friend_key(self, item):
|
||||||
|
num = self.friends_list.indexFromItem(item).row()
|
||||||
|
tox_id = self.profile.friend_public_key(num)
|
||||||
|
clipboard = QtGui.QApplication.clipboard()
|
||||||
|
clipboard.setText(tox_id)
|
||||||
|
|
||||||
|
def clear_history(self, item):
|
||||||
|
num = self.friends_list.indexFromItem(item).row()
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Functions which called when user click somewhere else
|
# Functions which called when user click somewhere else
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -310,6 +310,14 @@ class Profile(Contact, Singleton):
|
|||||||
"""
|
"""
|
||||||
if value is None and self._active_friend == -1: # nothing to update
|
if value is None and self._active_friend == -1: # nothing to update
|
||||||
return
|
return
|
||||||
|
if value == -1: # all friends were deleted
|
||||||
|
self.screen.account_name.setText('')
|
||||||
|
self.screen.account_status.setText('')
|
||||||
|
self._active_friend = -1
|
||||||
|
self.screen.account_avatar.setHidden(True)
|
||||||
|
self.screen.messages.clear()
|
||||||
|
self.screen.messageEdit.clear()
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
if value is not None:
|
if value is not None:
|
||||||
self._active_friend = value
|
self._active_friend = value
|
||||||
@ -388,8 +396,37 @@ class Profile(Contact, Singleton):
|
|||||||
self.screen.messageEdit.clear()
|
self.screen.messageEdit.clear()
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Work with friends (add, remove)
|
# Work with friends (add, remove, set alias, clear history)
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
def set_alias(self, num):
|
||||||
|
friend = self._friends[num]
|
||||||
|
name = friend.name.encode('utf-8')
|
||||||
|
dialog = "Enter new alias for friend {} or leave empty to use friend's name:".format(name)
|
||||||
|
text, ok = QtGui.QInputDialog.getText(None, 'Set alias', dialog)
|
||||||
|
if ok:
|
||||||
|
settings = Settings.get_instance()
|
||||||
|
aliases = settings['friends_aliases']
|
||||||
|
if text:
|
||||||
|
friend.name = text.encode('utf-8')
|
||||||
|
try:
|
||||||
|
index = map(lambda x: x[0], aliases).index(friend.tox_id)
|
||||||
|
aliases[index] = (friend.tox_id, text)
|
||||||
|
except:
|
||||||
|
aliases.append((friend.tox_id, text))
|
||||||
|
friend.set_alias(text)
|
||||||
|
else: # use default name
|
||||||
|
friend.name = self.tox.friend_get_name(friend.number)
|
||||||
|
friend.set_alias('')
|
||||||
|
try:
|
||||||
|
index = map(lambda x: x[0], aliases).index(friend.tox_id)
|
||||||
|
del aliases[index]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
settings.save()
|
||||||
|
self.set_active()
|
||||||
|
|
||||||
|
def friend_public_key(self, num):
|
||||||
|
return self._friends[num].tox_id
|
||||||
|
|
||||||
def create_friend_item(self):
|
def create_friend_item(self):
|
||||||
"""
|
"""
|
||||||
@ -442,11 +479,17 @@ class Profile(Contact, Singleton):
|
|||||||
def delete_friend(self, num):
|
def delete_friend(self, num):
|
||||||
"""
|
"""
|
||||||
Removes friend from contact list
|
Removes friend from contact list
|
||||||
:param num: number of friend
|
:param num: number of friend in list
|
||||||
"""
|
"""
|
||||||
self.tox.friend_delete(num)
|
friend = self._friends[num]
|
||||||
friend = filter(lambda x: x.number == num, self._friends)[0]
|
self.tox.friend_delete(friend.number)
|
||||||
del friend
|
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