dropdown menu, smileys window

This commit is contained in:
ingvar1995 2016-06-14 21:47:03 +03:00
parent 7e63d9634a
commit 53a381222f
6 changed files with 200 additions and 34 deletions

View File

@ -24,6 +24,7 @@ class Friend(contact.Contact):
self._unsaved_messages = 0 self._unsaved_messages = 0
self._history_loaded = False self._history_loaded = False
self._receipts = 0 self._receipts = 0
self._curr_text = ''
def __del__(self): def __del__(self):
self.set_visibility(False) self.set_visibility(False)
@ -130,6 +131,14 @@ class Friend(contact.Contact):
except: except:
pass pass
def get_curr_text(self):
return self._curr_text
def set_curr_text(self, value):
self._curr_text = value
curr_text = property(get_curr_text, set_curr_text)
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Alias support # Alias support
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------

View File

@ -54,6 +54,9 @@ class History(object):
new_path = directory + self._name + '.hstr' new_path = directory + self._name + '.hstr'
with open(path, 'rb') as fin: with open(path, 'rb') as fin:
data = fin.read() data = fin.read()
encr = LibToxEncryptSave.get_instance()
if encr.has_password():
data = encr.pass_encrypt(data)
with open(new_path, 'wb') as fout: with open(new_path, 'wb') as fout:
fout.write(data) fout.write(data)

View File

@ -101,8 +101,6 @@ class MainWindow(QtGui.QMainWindow):
self.actionSettings.setText(QtGui.QApplication.translate("MainWindow", "Settings", None, QtGui.QApplication.UnicodeUTF8)) self.actionSettings.setText(QtGui.QApplication.translate("MainWindow", "Settings", None, QtGui.QApplication.UnicodeUTF8))
self.audioSettings.setText(QtGui.QApplication.translate("MainWindow", "Audio", None, QtGui.QApplication.UnicodeUTF8)) self.audioSettings.setText(QtGui.QApplication.translate("MainWindow", "Audio", None, QtGui.QApplication.UnicodeUTF8))
self.contact_name.setPlaceholderText(QtGui.QApplication.translate("MainWindow", "Search", None, QtGui.QApplication.UnicodeUTF8)) self.contact_name.setPlaceholderText(QtGui.QApplication.translate("MainWindow", "Search", None, QtGui.QApplication.UnicodeUTF8))
self.screenshotButton.setToolTip(QtGui.QApplication.translate("MainWindow", "Send screenshot", None, QtGui.QApplication.UnicodeUTF8))
self.fileTransferButton.setToolTip(QtGui.QApplication.translate("MainWindow", "Send file", None, QtGui.QApplication.UnicodeUTF8))
self.sendMessageButton.setToolTip(QtGui.QApplication.translate("MainWindow", "Send message", None, QtGui.QApplication.UnicodeUTF8)) self.sendMessageButton.setToolTip(QtGui.QApplication.translate("MainWindow", "Send message", None, QtGui.QApplication.UnicodeUTF8))
self.callButton.setToolTip(QtGui.QApplication.translate("MainWindow", "Start audio call with friend", None, QtGui.QApplication.UnicodeUTF8)) self.callButton.setToolTip(QtGui.QApplication.translate("MainWindow", "Start audio call with friend", None, QtGui.QApplication.UnicodeUTF8))
self.online_contacts.clear() self.online_contacts.clear()
@ -120,35 +118,24 @@ class MainWindow(QtGui.QMainWindow):
font.setPointSize(10) font.setPointSize(10)
self.messageEdit.setFont(font) self.messageEdit.setFont(font)
self.screenshotButton = QRightClickButton(Form)
self.screenshotButton.setGeometry(QtCore.QRect(455, 3, 55, 55))
self.screenshotButton.setObjectName("screenshotButton")
self.fileTransferButton = QtGui.QPushButton(Form)
self.fileTransferButton.setGeometry(QtCore.QRect(510, 3, 55, 55))
self.fileTransferButton.setObjectName("fileTransferButton")
self.sendMessageButton = QtGui.QPushButton(Form) self.sendMessageButton = QtGui.QPushButton(Form)
self.sendMessageButton.setGeometry(QtCore.QRect(565, 3, 60, 55)) self.sendMessageButton.setGeometry(QtCore.QRect(565, 3, 60, 55))
self.sendMessageButton.setObjectName("sendMessageButton") self.sendMessageButton.setObjectName("sendMessageButton")
self.menuButton = MenuButton(Form, self.show_menu)
self.menuButton.setGeometry(QtCore.QRect(QtCore.QRect(455, 3, 55, 55)))
pixmap = QtGui.QPixmap('send.png') pixmap = QtGui.QPixmap('send.png')
icon = QtGui.QIcon(pixmap) icon = QtGui.QIcon(pixmap)
self.sendMessageButton.setIcon(icon) self.sendMessageButton.setIcon(icon)
self.sendMessageButton.setIconSize(QtCore.QSize(45, 60)) self.sendMessageButton.setIconSize(QtCore.QSize(45, 60))
pixmap = QtGui.QPixmap('file.png')
icon = QtGui.QIcon(pixmap)
self.fileTransferButton.setIcon(icon)
self.fileTransferButton.setIconSize(QtCore.QSize(40, 40))
pixmap = QtGui.QPixmap('screenshot.png')
icon = QtGui.QIcon(pixmap)
self.screenshotButton.setIcon(icon)
self.screenshotButton.setIconSize(QtCore.QSize(40, 60))
self.fileTransferButton.clicked.connect(self.send_file) pixmap = QtGui.QPixmap('menu.png')
self.screenshotButton.clicked.connect(self.send_screenshot) icon = QtGui.QIcon(pixmap)
self.menuButton.setIcon(icon)
self.menuButton.setIconSize(QtCore.QSize(40, 40))
self.sendMessageButton.clicked.connect(self.send_message) self.sendMessageButton.clicked.connect(self.send_message)
self.connect(self.screenshotButton, QtCore.SIGNAL("rightClicked()"), lambda: self.send_screenshot(True))
QtCore.QMetaObject.connectSlotsByName(Form) QtCore.QMetaObject.connectSlotsByName(Form)
@ -239,7 +226,7 @@ class MainWindow(QtGui.QMainWindow):
self.typing = QtGui.QLabel(Form) self.typing = QtGui.QLabel(Form)
self.typing.setGeometry(QtCore.QRect(500, 40, 50, 30)) self.typing.setGeometry(QtCore.QRect(500, 40, 50, 30))
pixmap = QtGui.QPixmap(QtCore.QSize(50, 30)) pixmap = QtGui.QPixmap(QtCore.QSize(50, 30))
pixmap.load('typing.png') pixmap.load(curr_directory() + '/images/typing.png')
self.typing.setScaledContents(False) self.typing.setScaledContents(False)
self.typing.setPixmap(pixmap.scaled(50, 30, QtCore.Qt.KeepAspectRatio)) self.typing.setPixmap(pixmap.scaled(50, 30, QtCore.Qt.KeepAspectRatio))
self.typing.setVisible(False) self.typing.setVisible(False)
@ -334,16 +321,15 @@ class MainWindow(QtGui.QMainWindow):
QtGui.QApplication.closeAllWindows() QtGui.QApplication.closeAllWindows()
def resizeEvent(self, *args, **kwargs): def resizeEvent(self, *args, **kwargs):
self.messages.setGeometry(0, 0, self.width() - 300, self.height() - 172) self.messages.setGeometry(0, 0, self.width() - 294, self.height() - 172)
self.friends_list.setGeometry(0, 0, 270, self.height() - 140) self.friends_list.setGeometry(0, 0, 270, self.height() - 135)
self.videocallButton.setGeometry(QtCore.QRect(self.width() - 350, 20, 50, 50)) self.videocallButton.setGeometry(QtCore.QRect(self.width() - 350, 20, 50, 50))
self.callButton.setGeometry(QtCore.QRect(self.width() - 410, 20, 50, 50)) self.callButton.setGeometry(QtCore.QRect(self.width() - 410, 20, 50, 50))
self.typing.setGeometry(QtCore.QRect(self.width() - 470, 30, 50, 30)) self.typing.setGeometry(QtCore.QRect(self.width() - 470, 30, 50, 30))
self.messageEdit.setGeometry(QtCore.QRect(120, 2, self.width() - 490, 55)) self.messageEdit.setGeometry(QtCore.QRect(60, 2, self.width() - 430, 55))
self.screenshotButton.setGeometry(QtCore.QRect(0, 2, 55, 55)) self.menuButton.setGeometry(QtCore.QRect(0, 2, 55, 55))
self.fileTransferButton.setGeometry(QtCore.QRect(60, 2, 55, 55))
self.sendMessageButton.setGeometry(QtCore.QRect(self.width() - 360, 2, 60, 55)) self.sendMessageButton.setGeometry(QtCore.QRect(self.width() - 360, 2, 60, 55))
self.account_name.setGeometry(QtCore.QRect(100, 30, self.width() - 600, 25)) self.account_name.setGeometry(QtCore.QRect(100, 30, self.width() - 600, 25))
@ -401,6 +387,17 @@ class MainWindow(QtGui.QMainWindow):
self.audio_s = AudioSettings() self.audio_s = AudioSettings()
self.audio_s.show() self.audio_s.show()
def show_menu(self):
if hasattr(self, 'menu') and self.menu.isVisible():
self.menu.hide()
return
self.menu = DropdownMenu(self)
self.menu.setGeometry(QtCore.QRect(0 if Settings.get_instance()['mirror_mode'] else 270,
self.height() - 160,
150,
100))
self.menu.show()
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Messages, calls and file transfers # Messages, calls and file transfers
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
@ -410,6 +407,7 @@ class MainWindow(QtGui.QMainWindow):
self.profile.send_message(text) self.profile.send_message(text)
def send_file(self): def send_file(self):
self.menu.hide()
if self.profile.is_active_online(): # active friend exists and online if self.profile.is_active_online(): # active friend exists and online
choose_file = QtGui.QApplication.translate("MainWindow", 'Choose file', None, QtGui.QApplication.UnicodeUTF8) choose_file = QtGui.QApplication.translate("MainWindow", 'Choose file', None, QtGui.QApplication.UnicodeUTF8)
choose = QtGui.QApplication.translate("MainWindow", choose_file, None, QtGui.QApplication.UnicodeUTF8) choose = QtGui.QApplication.translate("MainWindow", choose_file, None, QtGui.QApplication.UnicodeUTF8)
@ -418,12 +416,22 @@ class MainWindow(QtGui.QMainWindow):
self.profile.send_file(name[0]) self.profile.send_file(name[0])
def send_screenshot(self, hide=False): def send_screenshot(self, hide=False):
self.menu.hide()
if self.profile.is_active_online(): # active friend exists and online if self.profile.is_active_online(): # active friend exists and online
self.sw = ScreenShotWindow(self) self.sw = ScreenShotWindow(self)
self.sw.show() self.sw.show()
if hide: if hide:
self.hide() self.hide()
def send_smiley(self):
self.menu.hide()
self.smiley = SmileyWindow(self)
self.smiley.setGeometry(QtCore.QRect(self.x() if Settings.get_instance()['mirror_mode'] else 270 + self.x(),
self.y() + self.height() - 200,
self.smiley.width(),
self.smiley.height()))
self.smiley.show()
def active_call(self): def active_call(self):
self.update_call_state('finish_call') self.update_call_state('finish_call')
@ -436,11 +444,11 @@ class MainWindow(QtGui.QMainWindow):
def update_call_state(self, fl): def update_call_state(self, fl):
# TODO: do smth with video call button # TODO: do smth with video call button
os.chdir(curr_directory() + '/images/') os.chdir(curr_directory() + '/images/')
pixmap = QtGui.QPixmap('{}.png'.format(fl)) pixmap = QtGui.QPixmap(curr_directory() + '/images/{}.png'.format(fl))
icon = QtGui.QIcon(pixmap) icon = QtGui.QIcon(pixmap)
self.callButton.setIcon(icon) self.callButton.setIcon(icon)
self.callButton.setIconSize(QtCore.QSize(50, 50)) self.callButton.setIconSize(QtCore.QSize(50, 50))
pixmap = QtGui.QPixmap('videocall.png') pixmap = QtGui.QPixmap(curr_directory() + '/images/videocall.png')
icon = QtGui.QIcon(pixmap) icon = QtGui.QIcon(pixmap)
self.videocallButton.setIcon(icon) self.videocallButton.setIcon(icon)
self.videocallButton.setIconSize(QtCore.QSize(35, 35)) self.videocallButton.setIconSize(QtCore.QSize(35, 35))

View File

@ -2,8 +2,10 @@ try:
from PySide import QtCore, QtGui from PySide import QtCore, QtGui
except ImportError: except ImportError:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from widgets import RubberBand, create_menu from widgets import RubberBand, create_menu, QRightClickButton
from profile import Profile from profile import Profile
import smileys
import util
class MessageArea(QtGui.QPlainTextEdit): class MessageArea(QtGui.QPlainTextEdit):
@ -117,3 +119,141 @@ class ScreenShotWindow(QtGui.QWidget):
self.close() self.close()
else: else:
super(ScreenShotWindow, self).keyPressEvent(event) super(ScreenShotWindow, self).keyPressEvent(event)
class SmileyWindow(QtGui.QWidget):
def __init__(self, parent):
super(SmileyWindow, self).__init__()
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
inst = smileys.SmileyLoader.get_instance()
self.data = inst.get_smileys()
count = len(self.data)
self.page_size = int(pow(count / 8, 0.5) + 1) * 8
if count % self.page_size == 0:
self.page_count = count / self.page_size
else:
self.page_count = int(count / float(self.page_size) + 0.5)
self.page = 0
self.radio = []
self.parent = parent
for i in range(self.page_count):
elem = QtGui.QRadioButton(self)
elem.setGeometry(QtCore.QRect(i * 20 + 5, 180, 20, 20))
elem.clicked.connect(lambda i=i: self.checked(i))
self.radio.append(elem)
width = max(self.page_count * 20 + 30, (self.page_size + 5) * 8 / 10)
self.setMaximumSize(width, 200)
self.setMinimumSize(width, 200)
self.buttons = []
for i in range(self.page_size):
b = QtGui.QPushButton(self)
b.setGeometry(QtCore.QRect((i / 8) * 20 + 5, (i % 8) * 20, 20, 20))
b.clicked.connect(lambda i=i: self.clicked(i))
self.buttons.append(b)
self.checked(0)
def checked(self, pos):
self.radio[self.page].setChecked(False)
self.radio[pos].setChecked(True)
self.page = pos
start = self.page * self.page_size
for i in range(self.page_size):
try:
self.buttons[i].setVisible(True)
pixmap = QtGui.QPixmap(self.data[start + i][1])
icon = QtGui.QIcon(pixmap)
self.buttons[i].setIcon(icon)
except:
self.buttons[i].setVisible(False)
def clicked(self, pos):
pos += self.page * self.page_size
smiley = self.data[pos][0]
self.parent.messageEdit.insertPlainText(smiley)
self.close()
class MenuButton(QtGui.QPushButton):
def __init__(self, parent, enter):
super(MenuButton, self).__init__(parent)
self.enter = enter
def enterEvent(self, event):
self.enter()
super(MenuButton, self).enterEvent(event)
class DropdownMenu(QtGui.QWidget):
def __init__(self, parent):
super(DropdownMenu, self).__init__(parent)
self.installEventFilter(self)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setMaximumSize(150, 100)
self.setMinimumSize(150, 100)
self.screenshotButton = QRightClickButton(self)
self.screenshotButton.setGeometry(QtCore.QRect(0, 50, 50, 50))
self.screenshotButton.setObjectName("screenshotButton")
self.fileTransferButton = QtGui.QPushButton(self)
self.fileTransferButton.setGeometry(QtCore.QRect(50, 50, 50, 50))
self.fileTransferButton.setObjectName("fileTransferButton")
self.audioMessageButton = QtGui.QPushButton(self)
self.audioMessageButton.setGeometry(QtCore.QRect(100, 50, 50, 50))
self.smileyButton = QtGui.QPushButton(self)
self.smileyButton.setGeometry(QtCore.QRect(0, 0, 50, 50))
self.videoMessageButton = QtGui.QPushButton(self)
self.videoMessageButton.setGeometry(QtCore.QRect(100, 0, 50, 50))
self.stickerButton = QtGui.QPushButton(self)
self.stickerButton.setGeometry(QtCore.QRect(50, 0, 50, 50))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/file.png')
icon = QtGui.QIcon(pixmap)
self.fileTransferButton.setIcon(icon)
self.fileTransferButton.setIconSize(QtCore.QSize(40, 40))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/screenshot.png')
icon = QtGui.QIcon(pixmap)
self.screenshotButton.setIcon(icon)
self.screenshotButton.setIconSize(QtCore.QSize(40, 50))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/audio_message.png')
icon = QtGui.QIcon(pixmap)
self.audioMessageButton.setIcon(icon)
self.audioMessageButton.setIconSize(QtCore.QSize(40, 40))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/smiley.png')
icon = QtGui.QIcon(pixmap)
self.smileyButton.setIcon(icon)
self.smileyButton.setIconSize(QtCore.QSize(40, 40))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/video_message.png')
icon = QtGui.QIcon(pixmap)
self.videoMessageButton.setIcon(icon)
self.videoMessageButton.setIconSize(QtCore.QSize(45, 45))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/sticker.png')
icon = QtGui.QIcon(pixmap)
self.stickerButton.setIcon(icon)
self.stickerButton.setIconSize(QtCore.QSize(45, 45))
self.screenshotButton.setToolTip(QtGui.QApplication.translate("MenuWindow", "Send screenshot", None, QtGui.QApplication.UnicodeUTF8))
self.fileTransferButton.setToolTip(QtGui.QApplication.translate("MenuWindow", "Send file", None, QtGui.QApplication.UnicodeUTF8))
self.audioMessageButton.setToolTip(QtGui.QApplication.translate("MenuWindow", "Send audio message", None, QtGui.QApplication.UnicodeUTF8))
self.videoMessageButton.setToolTip(QtGui.QApplication.translate("MenuWindow", "Send video message", None, QtGui.QApplication.UnicodeUTF8))
self.smileyButton.setToolTip(QtGui.QApplication.translate("MenuWindow", "Add smiley", None, QtGui.QApplication.UnicodeUTF8))
self.stickerButton.setToolTip(QtGui.QApplication.translate("MenuWindow", "Send sticker", None, QtGui.QApplication.UnicodeUTF8))
self.fileTransferButton.clicked.connect(parent.send_file)
self.screenshotButton.clicked.connect(parent.send_screenshot)
self.connect(self.screenshotButton, QtCore.SIGNAL("rightClicked()"), lambda: parent.send_screenshot(True))
self.smileyButton.clicked.connect(parent.send_smiley)
def leaveEvent(self, event):
self.close()
def eventFilter(self, object, event):
if event.type() == QtCore.QEvent.WindowDeactivate:
self.close()
return False

View File

@ -152,10 +152,12 @@ class Profile(contact.Contact, Singleton):
self.send_typing(False) self.send_typing(False)
self._screen.typing.setVisible(False) self._screen.typing.setVisible(False)
if value is not None: if value is not None:
if self._active_friend + 1:
self._friends[self._active_friend].curr_text = self._screen.messageEdit.toPlainText()
self._active_friend = value self._active_friend = value
friend = self._friends[value] friend = self._friends[value]
self._friends[value].reset_messages() self._friends[value].reset_messages()
self._screen.messageEdit.clear() self._screen.messageEdit.setPlainText(friend.curr_text)
self._messages.clear() self._messages.clear()
friend.load_corr() friend.load_corr()
messages = friend.get_corr()[-PAGE_SIZE:] messages = friend.get_corr()[-PAGE_SIZE:]
@ -912,7 +914,7 @@ class Profile(contact.Contact, Singleton):
self.get_friend_by_number(friend_number).update_transfer_data(file_number, self.get_friend_by_number(friend_number).update_transfer_data(file_number,
FILE_TRANSFER_MESSAGE_STATUS['FINISHED'], FILE_TRANSFER_MESSAGE_STATUS['FINISHED'],
inline) inline)
self.update() #self.update()
else: else:
self.get_friend_by_number(friend_number).update_transfer_data(file_number, self.get_friend_by_number(friend_number).update_transfer_data(file_number,
FILE_TRANSFER_MESSAGE_STATUS['FINISHED']) FILE_TRANSFER_MESSAGE_STATUS['FINISHED'])

View File

@ -33,6 +33,7 @@ class SmileyLoader(util.Singleton):
print 'Smiley pack', pack_name, 'loaded' print 'Smiley pack', pack_name, 'loaded'
self._set = {} self._set = {}
for key, value in self._smileys.items(): for key, value in self._smileys.items():
value = self.get_smileys_path() + value
if value not in self._set.values(): if value not in self._set.values():
self._set[key] = value self._set[key] = value
except: except:
@ -47,6 +48,9 @@ class SmileyLoader(util.Singleton):
d = util.curr_directory() + '/smileys/' d = util.curr_directory() + '/smileys/'
return [x[1] for x in os.walk(d)][0] return [x[1] for x in os.walk(d)][0]
def get_smileys(self):
return list(self._set.items())
def add_smileys_to_text(self, text, edit): def add_smileys_to_text(self, text, edit):
""" """
Adds smileys to text Adds smileys to text
@ -54,7 +58,7 @@ class SmileyLoader(util.Singleton):
:param edit: MessageEdit instance :param edit: MessageEdit instance
:return text with smileys :return text with smileys
""" """
if not self._settings['smileys']: if not self._settings['smileys'] or not len(self._smileys):
return text return text
arr = text.split(' ') arr = text.split(' ')
for i in range(len(arr)): for i in range(len(arr)):
@ -75,7 +79,7 @@ def sticker_loader():
keys = [x[1] for x in os.walk(d)][0] keys = [x[1] for x in os.walk(d)][0]
for key in keys: for key in keys:
path = d + key path = d + key
files = [f for f in os.listdir(path)] files = map(lambda f: f.endswith('.png'), os.listdir(path))
if files: if files:
result[key] = files result[key] = files
return result return result