From ce7f6e03f5f27fc12d9072ff3c38adf6c719611a Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 29 Mar 2016 17:11:30 +0300 Subject: [PATCH] some improvements --- src/history.py | 20 +++++++++++--------- src/list_items.py | 4 ++-- src/mainscreen.py | 10 ++++++++-- src/messages.py | 1 - src/profile.py | 26 ++++++++++++++++++-------- 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/history.py b/src/history.py index c34a4fe..08c7182 100644 --- a/src/history.py +++ b/src/history.py @@ -1,9 +1,11 @@ # coding=utf-8 from sqlite3 import connect -from settings import Settings +import profile as pr from os import chdir +PAGE_SIZE = 42 + MESSAGE_OWNER = { 'ME': 0, 'FRIEND': 1 @@ -13,7 +15,7 @@ MESSAGE_OWNER = { class History(object): def __init__(self, name): self._name = name - chdir(Settings.get_default_path()) + chdir(pr.ProfileHelper.get_path()) db = connect(name + '.hstr') cursor = db.cursor() cursor.execute('CREATE TABLE IF NOT EXISTS friends(' @@ -22,7 +24,7 @@ class History(object): db.close() def export(self, directory): - path = Settings.get_default_path() + self._name + '.hstr' + path = pr.ProfileHelper.get_path() + self._name + '.hstr' new_path = directory + self._name + '.hstr' with open(path, 'rb') as fin: data = fin.read() @@ -31,7 +33,7 @@ class History(object): print 'History exported to: {}'.format(new_path) def add_friend_to_db(self, tox_id): - chdir(Settings.get_default_path()) + chdir(pr.ProfileHelper.get_path()) db = connect(self._name + '.hstr') try: cursor = db.cursor() @@ -51,7 +53,7 @@ class History(object): db.close() def delete_friend_from_db(self, tox_id): - chdir(Settings.get_default_path()) + chdir(pr.ProfileHelper.get_path()) db = connect(self._name + '.hstr') try: cursor = db.cursor() @@ -65,7 +67,7 @@ class History(object): db.close() def friend_exists_in_db(self, tox_id): - chdir(Settings.get_default_path()) + chdir(pr.ProfileHelper.get_path()) db = connect(self._name + '.hstr') cursor = db.cursor() cursor.execute('SELECT 0 FROM friends WHERE tox_id=?', (tox_id, )) @@ -74,7 +76,7 @@ class History(object): return result is not None def save_messages_to_db(self, tox_id, messages_iter): - chdir(Settings.get_default_path()) + chdir(pr.ProfileHelper.get_path()) db = connect(self._name + '.hstr') try: cursor = db.cursor() @@ -88,7 +90,7 @@ class History(object): db.close() def delete_messages(self, tox_id): - chdir(Settings.get_default_path()) + chdir(pr.ProfileHelper.get_path()) db = connect(self._name + '.hstr') try: cursor = db.cursor() @@ -105,7 +107,7 @@ class History(object): class MessageGetter(object): def __init__(self, name, tox_id): - chdir(Settings.get_default_path()) + chdir(pr.ProfileHelper.get_path()) self._db = connect(name + '.hstr') self._cursor = self._db.cursor() self._cursor.execute('SELECT message, owner, unix_time, message_type FROM id' + tox_id + diff --git a/src/list_items.py b/src/list_items.py index 8af7b13..0100307 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -60,9 +60,9 @@ class MessageItem(QtGui.QWidget): self.message.setStyleSheet("QTextEdit { color: #4169E1; }") else: if text[0] == '>': - self.message.setStyleSheet("QPlainTextEdit { color: green; }") + self.message.setStyleSheet("QTextEdit { color: green; }") if text[-1] == '<': - self.message.setStyleSheet("QPlainTextEdit { color: red; }") + self.message.setStyleSheet("QTextEdit { color: red; }") class ContactItem(QtGui.QWidget): diff --git a/src/mainscreen.py b/src/mainscreen.py index f8a1e3d..4c34874 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -13,7 +13,11 @@ class MessageArea(QtGui.QPlainTextEdit): def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Return: - self.parent.send_message() + modifiers = event.modifiers() + if modifiers & QtCore.Qt.ControlModifier or modifiers & QtCore.Qt.ShiftModifier: + self.appendPlainText('') + else: + self.parent.send_message() else: super(self.__class__, self).keyPressEvent(event) @@ -384,7 +388,7 @@ class MainWindow(QtGui.QMainWindow): class ScreenShotWindow(QtGui.QWidget): - # TODO: make window semi-transparent + # TODO: make selected area transparent def __init__(self): super(ScreenShotWindow, self).__init__() self.setMouseTracking(True) @@ -405,6 +409,7 @@ class ScreenShotWindow(QtGui.QWidget): self.rubberband.setGeometry( QtCore.QRect(self.origin, event.pos()).normalized()) QtGui.QWidget.mouseMoveEvent(self, event) + self.repaint() def mouseReleaseEvent(self, event): if self.rubberband.isVisible(): @@ -425,3 +430,4 @@ class ScreenShotWindow(QtGui.QWidget): + diff --git a/src/messages.py b/src/messages.py index 3c82738..ef5109a 100644 --- a/src/messages.py +++ b/src/messages.py @@ -1,5 +1,4 @@ -PAGE_SIZE = 42 MESSAGE_TYPE = { 'TEXT': 0, diff --git a/src/profile.py b/src/profile.py index ec3fabd..14b5ae7 100644 --- a/src/profile.py +++ b/src/profile.py @@ -227,7 +227,8 @@ class Friend(Contact): data.reverse() else: return [] - self._corr = map(lambda tupl: TextMessage(*tupl), data) + self._corr + data = map(lambda tupl: TextMessage(*tupl), data) + self._corr = data + self._corr self._history_loaded = True return data @@ -258,7 +259,7 @@ class Friend(Contact): """ if hasattr(self, '_message_getter'): del self._message_getter - self._corr = [] + self._corr = filter(lambda x: x.get_type() > 1, self._corr) self._unsaved_messages = 0 def update_transfer_data(self, file_number, status): @@ -595,12 +596,18 @@ class Profile(Contact, Singleton): return data.reverse() for message in data: - data = message.get_data() - self.create_message_item(data[0], - convert_time(data[2]), - friend.name if data[1] else self._name, - data[3], - False) + if message.get_type() <= 1: + data = message.get_data() + self.create_message_item(data[0], + convert_time(data[2]), + friend.name if data[1] else self._name, + data[3], + False) + elif message.get_type() == 2: + item = self.create_file_transfer_item(message, False) + if message.get_status() in (2, 4): + ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())] + ft.set_state_changed_handler(item.update) def export_history(self, directory): self._history.export(directory) @@ -811,6 +818,7 @@ class Profile(Contact, Singleton): file_number) if friend_number == self.get_active_number(): self.create_file_transfer_item(tm) + self._messages.scrollToBottom() else: friend.set_messages(True) friend.append_message(tm) @@ -867,6 +875,7 @@ class Profile(Contact, Singleton): item = self.create_file_transfer_item(tm) friend.append_message(tm) st.set_state_changed_handler(item.update) + self._messages.scrollToBottom() def send_file(self, path): """ @@ -886,6 +895,7 @@ class Profile(Contact, Singleton): item = self.create_file_transfer_item(tm) st.set_state_changed_handler(item.update) self._friends[self._active_friend].append_message(tm) + self._messages.scrollToBottom() def incoming_chunk(self, friend_number, file_number, position, data): if (friend_number, file_number) in self._file_transfers: