inlines - part 2

This commit is contained in:
ingvar1995 2016-04-14 00:46:28 +03:00
parent df02fd9c4d
commit af22d8ef23
7 changed files with 43 additions and 44 deletions

View file

@ -19,7 +19,7 @@ Toxygen is simple [Tox](https://tox.chat/) client written on pure Python 2.7
- [x] Multiprofile - [x] Multiprofile
- [x] Multilingual - [x] Multilingual
- [x] Sound notifications - [x] Sound notifications
- [ ] Inline images - [x] Inline images
- [ ] Audio - [ ] Audio
- [ ] Video - [ ] Video
- [ ] Save file encryption - [ ] Save file encryption
@ -33,6 +33,7 @@ Toxygen is simple [Tox](https://tox.chat/) client written on pure Python 2.7
###Downloads ###Downloads
[Download last stable version](https://github.com/xveduk/toxygen/archive/master.zip) [Download last stable version](https://github.com/xveduk/toxygen/archive/master.zip)
[Download develop version](https://github.com/xveduk/toxygen/archive/develop.zip) [Download develop version](https://github.com/xveduk/toxygen/archive/develop.zip)
###Screenshots ###Screenshots

View file

@ -183,7 +183,7 @@ def file_chunk_request(tox, friend_number, file_number, position, size, user_dat
""" """
Outgoing chunk Outgoing chunk
""" """
Profile.get_instance().outgoing_chunk( invoke_in_main_thread(Profile.get_instance().outgoing_chunk,
friend_number, friend_number,
file_number, file_number,
position, position,

View file

@ -112,6 +112,9 @@ class SendFromBuffer(FileTransfer):
self._data = data self._data = data
self._file_number = tox.file_send(friend_number, TOX_FILE_KIND['DATA'], len(data), None, file_name) self._file_number = tox.file_send(friend_number, TOX_FILE_KIND['DATA'], len(data), None, file_name)
def get_data(self):
return self._data
def send_chunk(self, position, size): def send_chunk(self, position, size):
if size: if size:
data = self._data[position:position + size] data = self._data[position:position + size]

View file

@ -245,36 +245,23 @@ class FileTransferItem(QtGui.QListWidget):
class InlineImageItem(QtGui.QWidget): class InlineImageItem(QtGui.QWidget):
def __init__(self, time, user, data, parent=None): def __init__(self, data, parent=None):
QtGui.QWidget.__init__(self, parent) QtGui.QWidget.__init__(self, parent)
self.resize(QtCore.QSize(620, 500)) self.resize(QtCore.QSize(620, 500))
# self.name = DataLabel(self)
# self.name.setGeometry(QtCore.QRect(1, 15, 95, 20))
# self.name.setTextFormat(QtCore.Qt.PlainText)
# font = QtGui.QFont()
# font.setFamily("Times New Roman")
# font.setPointSize(11)
# font.setBold(True)
# self.name.setFont(font)
# self.name.setText(user)
# self.name.setStyleSheet('QLabel { color: black; }')
#
# self.time = QtGui.QLabel(self)
# self.time.setGeometry(QtCore.QRect(570, 2, 50, 46))
# font.setPointSize(10)
# font.setBold(False)
# self.time.setFont(font)
# self.time.setText(convert_time(time))
# self.time.setStyleSheet('QLabel { color: black; }')
# TODO: resize widget to picture size or resize picture
self._image_label = QtGui.QLabel(self) self._image_label = QtGui.QLabel(self)
self._image_label.raise_() self._image_label.raise_()
self._image_label.setGeometry(QtCore.QRect(0, 0, 600, 600)) self._image_label.setAutoFillBackground(True)
self._image_label.setScaledContents(False) self._image_label.setScaledContents(False)
self.pixmap = QtGui.QPixmap() self.pixmap = QtGui.QPixmap()
print self.pixmap.loadFromData(QtCore.QByteArray(data), "PNG") self.pixmap.loadFromData(QtCore.QByteArray(data), "PNG")
self._image_label.setPixmap(self.pixmap) if self.pixmap.width() <= 600:
self._image_label.setPixmap(self.pixmap)
self.resize(QtCore.QSize(600, self.pixmap.height()))
else:
pixmap = self.pixmap.scaled(600, 600, QtCore.Qt.KeepAspectRatio)
self._image_label.setPixmap(pixmap)
self.resize(QtCore.QSize(600, pixmap.height()))

View file

@ -403,7 +403,7 @@ class ScreenShotWindow(QtGui.QWidget):
self.setMouseTracking(True) self.setMouseTracking(True)
self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
self.showFullScreen() self.showFullScreen()
self.setWindowOpacity(0.4) self.setWindowOpacity(0.5)
self.rubberband = QtGui.QRubberBand(QtGui.QRubberBand.Rectangle, None) self.rubberband = QtGui.QRubberBand(QtGui.QRubberBand.Rectangle, None)
def mousePressEvent(self, event): def mousePressEvent(self, event):

View file

@ -79,8 +79,8 @@ class InlineImage(Message):
Inline image Inline image
""" """
def __init__(self, owner, time, data): def __init__(self, data):
super(InlineImage, self).__init__(MESSAGE_TYPE['INLINE'], owner, time) super(InlineImage, self).__init__(MESSAGE_TYPE['INLINE'], None, None)
self._data = data self._data = data
def get_data(self): def get_data(self):

View file

@ -199,16 +199,16 @@ class Friend(Contact):
def update_transfer_data(self, file_number, status, inline=None): def update_transfer_data(self, file_number, status, inline=None):
""" """
Update status of active transfer Update status of active transfer and load inline if needed
""" """
try: try:
tr = filter(lambda x: x.get_type() >= 2 and x.is_active(file_number), self._corr)[0] tr = filter(lambda x: x.get_type() == 2 and x.is_active(file_number), self._corr)[0]
tr.set_status(status) tr.set_status(status)
if inline: # inline was loaded if inline: # inline was loaded
i = self._corr.index(tr) i = self._corr.index(tr)
self._corr.insert(i, inline) self._corr.insert(i, inline)
except: except Exception as ex:
pass log('Update transfer data failed:' + str(ex))
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Alias support # Alias support
@ -369,8 +369,6 @@ 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 == self._active_friend:
return
if value == -1: # all friends were deleted if value == -1: # all friends were deleted
self._screen.account_name.setText('') self._screen.account_name.setText('')
self._screen.account_status.setText('') self._screen.account_status.setText('')
@ -599,9 +597,9 @@ class Profile(Contact, Singleton):
return item return item
def create_inline_item(self, data, append=True): def create_inline_item(self, data, append=True):
item = InlineImageItem(0, '', data) item = InlineImageItem(data)
elem = QtGui.QListWidgetItem() elem = QtGui.QListWidgetItem()
elem.setSizeHint(QtCore.QSize(600, 600)) elem.setSizeHint(QtCore.QSize(600, item.height()))
if append: if append:
self._messages.addItem(elem) self._messages.addItem(elem)
else: else:
@ -705,11 +703,12 @@ class Profile(Contact, Singleton):
if reply == QtGui.QMessageBox.Yes: # accepted if reply == QtGui.QMessageBox.Yes: # accepted
num = self._tox.friend_add_norequest(tox_id) # num - friend number num = self._tox.friend_add_norequest(tox_id) # num - friend number
item = self.create_friend_item() item = self.create_friend_item()
if not self._history.friend_exists_in_db(tox_id): try:
self._history.add_friend_to_db(tox_id) if not self._history.friend_exists_in_db(tox_id):
if not self._history.friend_exists_in_db(tox_id): self._history.add_friend_to_db(tox_id)
self._history.add_friend_to_db(tox_id) message_getter = self._history.messages_getter(tox_id)
message_getter = self._history.messages_getter(tox_id) except Exception as ex: # something is wrong
log('Accept friend request failed! ' + str(ex))
friend = Friend(message_getter, num, tox_id, '', item, tox_id) friend = Friend(message_getter, num, tox_id, '', item, tox_id)
self._friends.append(friend) self._friends.append(friend)
except Exception as ex: # something is wrong except Exception as ex: # something is wrong
@ -818,6 +817,7 @@ class Profile(Contact, Singleton):
:param friend_number: friend number :param friend_number: friend number
:param file_number: file number :param file_number: file number
:param size: file size :param size: file size
:param inline: is inline image
""" """
if not inline: if not inline:
rt = ReceiveTransfer(path, self._tox, friend_number, size, file_number) rt = ReceiveTransfer(path, self._tox, friend_number, size, file_number)
@ -879,12 +879,12 @@ class Profile(Contact, Singleton):
self.get_friend_by_number(friend_number).load_avatar() self.get_friend_by_number(friend_number).load_avatar()
self.set_active(None) self.set_active(None)
elif type(transfer) is ReceiveToBuffer: elif type(transfer) is ReceiveToBuffer:
inline = InlineImage(0, '', transfer.get_data()) inline = InlineImage(transfer.get_data())
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.set_active(None) self.set_active(self._active_friend)
else: else:
self.get_friend_by_number(friend_number).update_transfer_data(file_number, FILE_TRANSFER_MESSAGE_STATUS['FINISHED']) self.get_friend_by_number(friend_number).update_transfer_data(file_number, FILE_TRANSFER_MESSAGE_STATUS['FINISHED'])
del self._file_transfers[(friend_number, file_number)] del self._file_transfers[(friend_number, file_number)]
@ -896,7 +896,15 @@ class Profile(Contact, Singleton):
if transfer.state: if transfer.state:
del self._file_transfers[(friend_number, file_number)] del self._file_transfers[(friend_number, file_number)]
if type(transfer) is not SendAvatar: if type(transfer) is not SendAvatar:
self.get_friend_by_number(friend_number).update_transfer_data(file_number, FILE_TRANSFER_MESSAGE_STATUS['FINISHED']) if type(transfer) is SendFromBuffer: # inline
inline = InlineImage(transfer.get_data())
self.get_friend_by_number(friend_number).update_transfer_data(file_number,
FILE_TRANSFER_MESSAGE_STATUS['FINISHED'],
inline)
self.set_active(self._active_friend)
else:
self.get_friend_by_number(friend_number).update_transfer_data(file_number,
FILE_TRANSFER_MESSAGE_STATUS['FINISHED'])
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Avatars support # Avatars support