From 9e410254bf270e113daa65da76b610e49f61e822 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 29 Jul 2016 15:27:46 +0300 Subject: [PATCH] messages selection --- toxygen/mainscreen.py | 28 +++++++++++++++++++++++++--- toxygen/profile.py | 17 ++++++++--------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/toxygen/mainscreen.py b/toxygen/mainscreen.py index b65a6ad..e4d23b0 100644 --- a/toxygen/mainscreen.py +++ b/toxygen/mainscreen.py @@ -257,7 +257,7 @@ class MainWindow(QtGui.QMainWindow, Singleton): self.messages.setSpacing(1) self.messages.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.messages.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) - self.messages.setFocusPolicy(QtCore.Qt.NoFocus) + # self.messages.setFocusPolicy(QtCore.Qt.NoFocus) def load(pos): if not pos: @@ -353,6 +353,14 @@ class MainWindow(QtGui.QMainWindow, Singleton): def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Escape: self.hide() + elif event.key() == QtCore.Qt.Key_C and event.modifiers() & QtCore.Qt.ControlModifier and self.messages.selectedIndexes(): + rows = list(map(lambda x: self.messages.row(x), self.messages.selectedItems())) + indexes = (rows[0] - self.messages.count(), rows[-1] - self.messages.count()) + s = self.profile.export_history(self.profile.active_friend, True, indexes) + clipboard = QtGui.QApplication.clipboard() + clipboard.setText(s) + elif event.key() == QtCore.Qt.Key_Z and event.modifiers() & QtCore.Qt.ControlModifier and self.messages.selectedIndexes(): + self.messages.clearSelection() else: super(MainWindow, self).keyPressEvent(event) @@ -548,9 +556,9 @@ class MainWindow(QtGui.QMainWindow, Singleton): self.connect(notes_item, QtCore.SIGNAL("triggered()"), lambda: self.show_note(friend)) self.connect(copy_name_item, QtCore.SIGNAL("triggered()"), lambda: self.copy_name(friend)) self.connect(copy_status_item, QtCore.SIGNAL("triggered()"), lambda: self.copy_status(friend)) - self.connect(export_to_text_item, QtCore.SIGNAL("triggered()"), lambda: self.profile.export_history(num)) + self.connect(export_to_text_item, QtCore.SIGNAL("triggered()"), lambda: self.export_history(num)) self.connect(export_to_html_item, QtCore.SIGNAL("triggered()"), - lambda: self.profile.export_history(num, False)) + lambda: self.export_history(num, False)) parent_position = self.friends_list.mapToGlobal(QtCore.QPoint(0, 0)) self.listMenu.move(parent_position + pos) self.listMenu.show() @@ -570,6 +578,20 @@ class MainWindow(QtGui.QMainWindow, Singleton): self.note = MultilineEdit(user, note, save_note) self.note.show() + def export_history(self, num, as_text=True): + s = self.profile.export_history(num, as_text) + directory = QtGui.QFileDialog.getExistingDirectory(None, + QtGui.QApplication.translate("MainWindow", 'Choose folder', + None, + QtGui.QApplication.UnicodeUTF8), + curr_directory(), + QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontUseNativeDialog) + + if directory: + name = 'exported_history_{}.{}'.format(convert_time(time.time()), 'txt' if as_text else 'html') + with open(directory + '/' + name, 'wt') as fl: + fl.write(s) + def set_alias(self, num): self.profile.set_alias(num) diff --git a/toxygen/profile.py b/toxygen/profile.py index 87727cf..6c391c0 100644 --- a/toxygen/profile.py +++ b/toxygen/profile.py @@ -521,7 +521,12 @@ class Profile(contact.Contact, Singleton): friend = self._friends[num] if _range is None: friend.load_all_corr() - corr = friend.get_corr() if _range is None else friend.get_corr()[_range[0]:_range[1]] + if _range is None: + corr = friend.get_corr() + elif _range[1] + 1: + corr = friend.get_corr()[_range[0]:_range[1] + 1] + else: + corr = friend.get_corr()[_range[0]:] arr = [] new_line = '\n' if as_text else '
' for message in corr: @@ -535,14 +540,7 @@ class Profile(contact.Contact, Singleton): friend.name if data[1] == MESSAGE_OWNER['FRIEND'] else self.name, data[0])) s = new_line.join(arr) - directory = QtGui.QFileDialog.getExistingDirectory(None, - QtGui.QApplication.translate("MainWindow", 'Choose folder', None, QtGui.QApplication.UnicodeUTF8), - curr_directory(), - QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontUseNativeDialog) - if directory: - name = 'exported_history_{}.{}'.format(convert_time(time.time()), 'txt' if as_text else 'html') - with open(directory + '/' + name, 'wt') as fl: - fl.write(s) + return s # ----------------------------------------------------------------------------------------------------------------- # Factories for friend, message and file transfer items @@ -818,6 +816,7 @@ class Profile(contact.Contact, Singleton): self._call.stop() del self._tox self._tox = restart() + self._call = calls.AV(self._tox.AV) self.status = None for friend in self._friends: friend.status = None