progressbar is now work
This commit is contained in:
parent
2131fa3868
commit
bfbc82a9a3
3 changed files with 20 additions and 14 deletions
|
@ -29,7 +29,7 @@ class FileTransfer(QtCore.QObject):
|
||||||
self.state = TOX_FILE_TRANSFER_STATE['RUNNING']
|
self.state = TOX_FILE_TRANSFER_STATE['RUNNING']
|
||||||
self._file_number = file_number
|
self._file_number = file_number
|
||||||
self._creation_time = time()
|
self._creation_time = time()
|
||||||
self._size = size
|
self._size = float(size)
|
||||||
self._done = 0
|
self._done = 0
|
||||||
self._state_changed = StateSignal()
|
self._state_changed = StateSignal()
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class FileTransfer(QtCore.QObject):
|
||||||
def send_control(self, control):
|
def send_control(self, control):
|
||||||
if self._tox.file_control(self._friend_number, self._file_number, control):
|
if self._tox.file_control(self._friend_number, self._file_number, control):
|
||||||
self.state = control
|
self.state = control
|
||||||
self._state_changed.signal.emit(self.state, self._done / self._size)
|
self._state_changed.signal.emit(self.state, self._done / self._size if self._size else 0)
|
||||||
|
|
||||||
def get_file_id(self):
|
def get_file_id(self):
|
||||||
return self._tox.file_get_file_id(self._friend_number, self._file_number)
|
return self._tox.file_get_file_id(self._friend_number, self._file_number)
|
||||||
|
@ -79,13 +79,16 @@ class SendTransfer(FileTransfer):
|
||||||
if size:
|
if size:
|
||||||
self._file.seek(position)
|
self._file.seek(position)
|
||||||
data = self._file.read(size)
|
data = self._file.read(size)
|
||||||
|
try:
|
||||||
self._tox.file_send_chunk(self._friend_number, self._file_number, position, data)
|
self._tox.file_send_chunk(self._friend_number, self._file_number, position, data)
|
||||||
|
except:
|
||||||
|
print self._friend_number, self._file_number, position, data
|
||||||
self._done += size
|
self._done += size
|
||||||
self._state_changed.signal.emit(self.state, self._done / self._size)
|
self._state_changed.signal.emit(self.state, self._done / self._size)
|
||||||
else:
|
else:
|
||||||
self._file.close()
|
self._file.close()
|
||||||
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
||||||
self._state_changed.signal.emit(self.state, self._done / self._size)
|
self._state_changed.signal.emit(self.state, 1)
|
||||||
|
|
||||||
|
|
||||||
class SendAvatar(SendTransfer):
|
class SendAvatar(SendTransfer):
|
||||||
|
@ -115,7 +118,7 @@ class ReceiveTransfer(FileTransfer):
|
||||||
if data is None:
|
if data is None:
|
||||||
self._file.close()
|
self._file.close()
|
||||||
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
self.state = TOX_FILE_TRANSFER_STATE['FINISHED']
|
||||||
self._state_changed.signal.emit(self.state, self._done / self._size)
|
self._state_changed.signal.emit(self.state, self._done / self._size if self._size else 0)
|
||||||
else:
|
else:
|
||||||
data = ''.join(chr(x) for x in data)
|
data = ''.join(chr(x) for x in data)
|
||||||
if self._file_size < position:
|
if self._file_size < position:
|
||||||
|
@ -124,9 +127,10 @@ class ReceiveTransfer(FileTransfer):
|
||||||
self._file.seek(position)
|
self._file.seek(position)
|
||||||
self._file.write(data)
|
self._file.write(data)
|
||||||
self._file.flush()
|
self._file.flush()
|
||||||
if position + len(data) > self._file_size:
|
l = len(data)
|
||||||
self._file_size = position + len(data)
|
if position + l > self._file_size:
|
||||||
self._done += len(data)
|
self._file_size = position + l
|
||||||
|
self._done += l
|
||||||
self._state_changed.signal.emit(self.state, self._done / self._size)
|
self._state_changed.signal.emit(self.state, self._done / self._size)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -200,7 +200,7 @@ class FileTransferItem(QtGui.QListWidget):
|
||||||
icon = QtGui.QIcon(pixmap)
|
icon = QtGui.QIcon(pixmap)
|
||||||
self.accept.setIcon(icon)
|
self.accept.setIcon(icon)
|
||||||
self.accept.setIconSize(QtCore.QSize(50, 50))
|
self.accept.setIconSize(QtCore.QSize(50, 50))
|
||||||
self.accept.clicked.connect(lambda: self.accept_transfer(friend_number, file_number))
|
self.accept.clicked.connect(lambda: self.accept_transfer(friend_number, file_number, size))
|
||||||
self.accept.setVisible(is_incoming_transfer)
|
self.accept.setVisible(is_incoming_transfer)
|
||||||
|
|
||||||
self.pb = QtGui.QProgressBar(self)
|
self.pb = QtGui.QProgressBar(self)
|
||||||
|
@ -231,16 +231,18 @@ class FileTransferItem(QtGui.QListWidget):
|
||||||
self.accept.setVisible(False)
|
self.accept.setVisible(False)
|
||||||
self.pb.setVisible(False)
|
self.pb.setVisible(False)
|
||||||
|
|
||||||
def accept_transfer(self, friend_number, file_number):
|
def accept_transfer(self, friend_number, file_number, size):
|
||||||
directory = QtGui.QFileDialog.getExistingDirectory()
|
directory = QtGui.QFileDialog.getExistingDirectory()
|
||||||
if directory:
|
if directory:
|
||||||
pr = profile.Profile.get_instance()
|
pr = profile.Profile.get_instance()
|
||||||
pr.accept_transfer(self, directory + '/' + self.saved_name, friend_number, file_number)
|
pr.accept_transfer(self, directory + '/' + self.saved_name, friend_number, file_number, size)
|
||||||
self.accept.setVisible(False)
|
self.accept.setVisible(False)
|
||||||
|
|
||||||
@QtCore.Slot(int, float)
|
@QtCore.Slot(int, float)
|
||||||
def update(self, state, progress):
|
def update(self, state, progress):
|
||||||
self.pb.setValue(int(progress * 100))
|
self.pb.setValue(int(progress * 100))
|
||||||
|
#self.pb.repaint()
|
||||||
|
print state, progress
|
||||||
if state == TOX_FILE_TRANSFER_STATE['CANCELED']:
|
if state == TOX_FILE_TRANSFER_STATE['CANCELED']:
|
||||||
self.setStyleSheet('QListWidget { background-color: red; }')
|
self.setStyleSheet('QListWidget { background-color: red; }')
|
||||||
self.cancel.setVisible(False)
|
self.cancel.setVisible(False)
|
||||||
|
|
|
@ -729,8 +729,8 @@ class Profile(Contact, Singleton):
|
||||||
tr.cancel()
|
tr.cancel()
|
||||||
del self._file_transfers[(friend_number, file_number)]
|
del self._file_transfers[(friend_number, file_number)]
|
||||||
|
|
||||||
def accept_transfer(self, item, path, friend_number, file_number):
|
def accept_transfer(self, item, path, friend_number, file_number, size):
|
||||||
rt = ReceiveTransfer(path, self._tox, friend_number, file_number)
|
rt = ReceiveTransfer(path, self._tox, friend_number, size, file_number)
|
||||||
self._file_transfers[(friend_number, file_number)] = rt
|
self._file_transfers[(friend_number, file_number)] = rt
|
||||||
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME'])
|
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME'])
|
||||||
rt.set_state_changed_handler(item.update)
|
rt.set_state_changed_handler(item.update)
|
||||||
|
@ -742,7 +742,7 @@ class Profile(Contact, Singleton):
|
||||||
:param file_number: file number
|
:param file_number: file number
|
||||||
:param size: size of avatar or 0 (default avatar)
|
:param size: size of avatar or 0 (default avatar)
|
||||||
"""
|
"""
|
||||||
ra = ReceiveAvatar(self._tox, friend_number, file_number, size)
|
ra = ReceiveAvatar(self._tox, friend_number, size, file_number)
|
||||||
if ra.state != TOX_FILE_TRANSFER_STATE['CANCELED']:
|
if ra.state != TOX_FILE_TRANSFER_STATE['CANCELED']:
|
||||||
self._file_transfers[(friend_number, file_number)] = ra
|
self._file_transfers[(friend_number, file_number)] = ra
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue