From 44e5e7d0a6e8c9850167489bb93927ac11662127 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 15 Mar 2016 23:35:15 +0300 Subject: [PATCH] bug fixes and history export --- src/history.py | 9 +++++++++ src/list_items.py | 4 ++-- src/main.py | 2 ++ src/menu.py | 2 ++ src/profile.py | 5 +++++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/history.py b/src/history.py index 46802eb..5c87f88 100644 --- a/src/history.py +++ b/src/history.py @@ -21,6 +21,15 @@ class History(object): ')') db.close() + def export(self, directory): + path = Settings.get_default_path() + self._name + '.hstr' + new_path = directory + self._name + '.hstr' + with open(path, 'rb') as fin: + data = fin.read() + with open(new_path, 'wb') as fout: + fout.write(data) + print 'History exported to: {}'.format(new_path) + def add_friend_to_db(self, tox_id): chdir(Settings.get_default_path()) db = connect(self._name + '.hstr') diff --git a/src/list_items.py b/src/list_items.py index a932769..1fc566a 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -41,11 +41,11 @@ class MessageItem(QtGui.QListWidget): def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None): QtGui.QListWidget.__init__(self, parent) self.name = QtGui.QLabel(self) - self.name.setGeometry(QtCore.QRect(0, 0, 95, 40)) + self.name.setGeometry(QtCore.QRect(0, 0, 95, 20)) self.name.setTextFormat(QtCore.Qt.PlainText) font = QtGui.QFont() font.setFamily("Times New Roman") - font.setPointSize(12) + font.setPointSize(11) font.setBold(True) self.name.setFont(font) self.name.setObjectName("name") diff --git a/src/main.py b/src/main.py index fc2dbc3..717099f 100644 --- a/src/main.py +++ b/src/main.py @@ -73,8 +73,10 @@ class Toxygen(object): self.mainloop.start() app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) app.exec_() + self.init.stop = True self.mainloop.stop = True self.mainloop.wait() + self.init.wait() data = self.tox.get_savedata() ProfileHelper.save_profile(data) del self.tox diff --git a/src/menu.py b/src/menu.py index 1cebf47..41533d6 100644 --- a/src/menu.py +++ b/src/menu.py @@ -178,6 +178,8 @@ class ProfileSettings(CenteredWidget): ProfileHelper.export_profile(directory) settings = Settings.get_instance() settings.export(directory) + profile = Profile.get_instance() + profile.export_history(directory) def closeEvent(self, event): profile = Profile.get_instance() diff --git a/src/profile.py b/src/profile.py index 67fdd42..3fa1533 100644 --- a/src/profile.py +++ b/src/profile.py @@ -186,6 +186,7 @@ class Friend(Contact): def __del__(self): self.set_visibility(False) del self._widget + del self._message_getter # ----------------------------------------------------------------------------------------------------------------- # History support @@ -210,6 +211,7 @@ class Friend(Contact): Get data to save in db :return: list of unsaved messages or [] """ + del self._message_getter return self._corr[-self._unsaved_messages:] if self._unsaved_messages else [] def get_corr(self): @@ -513,6 +515,9 @@ class Profile(Contact, Singleton): if num is None or num == self.get_active_number(): self._messages.clear() + def export_history(self, directory): + self.history.export(directory) + # ----------------------------------------------------------------------------------------------------------------- # Factories for friend and message items # -----------------------------------------------------------------------------------------------------------------