From 0c590b01d79dcb1d1f88f83c9dfc7203f2e60aa2 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Wed, 2 Mar 2016 00:17:22 +0300 Subject: [PATCH] message item and contact item moved to single file. tests fix --- src/list_items.py | 108 ++++++++++++++++++++++++++++++++++++++++++++ src/mainscreen.py | 111 +--------------------------------------------- src/profile.py | 6 +-- 3 files changed, 112 insertions(+), 113 deletions(-) create mode 100644 src/list_items.py diff --git a/src/list_items.py b/src/list_items.py new file mode 100644 index 0000000..a5ee49e --- /dev/null +++ b/src/list_items.py @@ -0,0 +1,108 @@ +from toxcore_enums_and_consts import * +from PySide import QtGui, QtCore + + +class MessageItem(QtGui.QListWidget): + """ + Message in messages list + """ + 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, 50, 25)) + self.name.setTextFormat(QtCore.Qt.PlainText) + font = QtGui.QFont() + font.setFamily("Times New Roman") + font.setPointSize(12) + font.setBold(True) + self.name.setFont(font) + self.name.setObjectName("name") + self.name.setText(user) + + self.time = QtGui.QLabel(self) + self.time.setGeometry(QtCore.QRect(450, 0, 50, 50)) + font = QtGui.QFont() + font.setFamily("Times New Roman") + font.setPointSize(10) + font.setBold(False) + self.time.setFont(font) + self.time.setObjectName("time") + self.time.setText(time) + + self.message = QtGui.QPlainTextEdit(self) + self.message.setGeometry(QtCore.QRect(50, 0, 400, 50)) + self.message.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse) + self.message.setPlainText(text) + + if message_type == TOX_MESSAGE_TYPE['ACTION']: + self.name.setStyleSheet("QLabel { color: blue; }") + self.message.setStyleSheet("QPlainTextEdit { color: blue; }") + + +class ContactItem(QtGui.QListWidget): + """ + Contact in friends list + """ + def __init__(self, parent=None): + QtGui.QListWidget.__init__(self, parent) + # self.setMinimumSize(QtCore.QSize(250, 50)) + # self.setMaximumSize(QtCore.QSize(250, 50)) + self.setBaseSize(QtCore.QSize(250, 50)) + self.name = QtGui.QLabel(self) + self.name.setGeometry(QtCore.QRect(80, 10, 191, 25)) + font = QtGui.QFont() + font.setFamily("Times New Roman") + font.setPointSize(12) + font.setBold(True) + self.name.setFont(font) + self.name.setObjectName("name") + self.status_message = QtGui.QLabel(self) + self.status_message.setGeometry(QtCore.QRect(80, 30, 191, 17)) + font = QtGui.QFont() + font.setFamily("Times New Roman") + font.setPointSize(10) + font.setBold(False) + self.status_message.setFont(font) + self.status_message.setObjectName("status_message") + self.connection_status = StatusCircle(self) + self.connection_status.setGeometry(QtCore.QRect(200, 5, 16, 16)) + self.connection_status.setMinimumSize(QtCore.QSize(32, 32)) + self.connection_status.setMaximumSize(QtCore.QSize(32, 32)) + self.connection_status.setBaseSize(QtCore.QSize(32, 32)) + self.connection_status.setObjectName("connection_status") + + +class StatusCircle(QtGui.QWidget): + """ + Connection status + """ + + def __init__(self, parent): + QtGui.QWidget.__init__(self, parent) + self.setGeometry(0, 0, 32, 32) + self.data = None + + def mouseReleaseEvent(self, event): + pass + + def paintEvent(self, event): + paint = QtGui.QPainter() + paint.begin(self) + paint.setRenderHint(QtGui.QPainter.Antialiasing) + k = 16 + rad_x = rad_y = 5 + if self.data is None: + color = QtCore.Qt.transparent + else: + if self.data == TOX_USER_STATUS['NONE']: + color = QtCore.Qt.darkGreen + elif self.data == TOX_USER_STATUS['AWAY']: + color = QtCore.Qt.yellow + else: # self.data == TOX_USER_STATUS['BUSY']: + color = QtCore.Qt.darkRed + + paint.setPen(color) + center = QtCore.QPoint(k, k) + paint.setBrush(color) + paint.drawEllipse(center, rad_x, rad_y) + paint.end() \ No newline at end of file diff --git a/src/mainscreen.py b/src/mainscreen.py index 4175e6c..9e782e9 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -1,117 +1,8 @@ # -*- coding: utf-8 -*- -import sys -from PySide import QtGui, QtCore from menu import * from profile import * -from toxcore_enums_and_consts import * - - -# TODO: move list items to new file -class MessageItem(QtGui.QListWidget): - """ - Message in messages list - """ - 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, 50, 25)) - self.name.setTextFormat(QtCore.Qt.PlainText) - font = QtGui.QFont() - font.setFamily("Times New Roman") - font.setPointSize(12) - font.setBold(True) - self.name.setFont(font) - self.name.setObjectName("name") - self.name.setText(user) - - self.time = QtGui.QLabel(self) - self.time.setGeometry(QtCore.QRect(450, 0, 50, 50)) - font = QtGui.QFont() - font.setFamily("Times New Roman") - font.setPointSize(10) - font.setBold(False) - self.time.setFont(font) - self.time.setObjectName("time") - self.time.setText(time) - - self.message = QtGui.QPlainTextEdit(self) - self.message.setGeometry(QtCore.QRect(50, 0, 400, 50)) - self.message.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse | QtCore.Qt.LinksAccessibleByMouse) - self.message.setPlainText(text) - - if message_type == TOX_MESSAGE_TYPE['ACTION']: - self.name.setStyleSheet("QLabel { color: blue; }") - self.message.setStyleSheet("QPlainTextEdit { color: blue; }") - - -class ContactItem(QtGui.QListWidget): - """ - Contact in friends list - """ - def __init__(self, parent=None): - QtGui.QListWidget.__init__(self, parent) - # self.setMinimumSize(QtCore.QSize(250, 50)) - # self.setMaximumSize(QtCore.QSize(250, 50)) - self.setBaseSize(QtCore.QSize(250, 50)) - self.name = QtGui.QLabel(self) - self.name.setGeometry(QtCore.QRect(80, 10, 191, 25)) - font = QtGui.QFont() - font.setFamily("Times New Roman") - font.setPointSize(12) - font.setBold(True) - self.name.setFont(font) - self.name.setObjectName("name") - self.status_message = QtGui.QLabel(self) - self.status_message.setGeometry(QtCore.QRect(80, 30, 191, 17)) - font = QtGui.QFont() - font.setFamily("Times New Roman") - font.setPointSize(10) - font.setBold(False) - self.status_message.setFont(font) - self.status_message.setObjectName("status_message") - self.connection_status = StatusCircle(self) - self.connection_status.setGeometry(QtCore.QRect(200, 5, 16, 16)) - self.connection_status.setMinimumSize(QtCore.QSize(32, 32)) - self.connection_status.setMaximumSize(QtCore.QSize(32, 32)) - self.connection_status.setBaseSize(QtCore.QSize(32, 32)) - self.connection_status.setObjectName("connection_status") - - -class StatusCircle(QtGui.QWidget): - """ - Connection status - """ - - def __init__(self, parent): - QtGui.QWidget.__init__(self, parent) - self.setGeometry(0, 0, 32, 32) - self.data = None - - def mouseReleaseEvent(self, event): - pass - - def paintEvent(self, event): - paint = QtGui.QPainter() - paint.begin(self) - paint.setRenderHint(QtGui.QPainter.Antialiasing) - k = 16 - rad_x = rad_y = 5 - if self.data is None: - color = QtCore.Qt.transparent - else: - if self.data == TOX_USER_STATUS['NONE']: - color = QtCore.Qt.darkGreen - elif self.data == TOX_USER_STATUS['AWAY']: - color = QtCore.Qt.yellow - else: # self.data == TOX_USER_STATUS['BUSY']: - color = QtCore.Qt.darkRed - - paint.setPen(color) - center = QtCore.QPoint(k, k) - paint.setBrush(color) - paint.drawEllipse(center, rad_x, rad_y) - paint.end() +from list_items import * class MainWindow(QtGui.QMainWindow): diff --git a/src/profile.py b/src/profile.py index e2643bd..c737e8a 100644 --- a/src/profile.py +++ b/src/profile.py @@ -1,4 +1,4 @@ -import mainscreen +from list_items import MessageItem from settings import Settings from PySide import QtCore, QtGui import os @@ -220,7 +220,7 @@ class Profile(Contact): def new_message(self, id, message_type, message): if id == self._active_friend: # add message to list user_name = Profile.get_instance().get_active_name() - item = mainscreen.MessageItem(message.decode('utf-8'), curr_time(), user_name, message_type) + item = MessageItem(message.decode('utf-8'), curr_time(), user_name, message_type) elem = QtGui.QListWidgetItem(self._messages) elem.setSizeHint(QtCore.QSize(500, 100)) self._messages.addItem(elem) @@ -239,7 +239,7 @@ class Profile(Contact): else: message_type = TOX_MESSAGE_TYPE['NORMAL'] self.tox.friend_send_message(self._active_friend, message_type, text.encode('utf-8')) - item = mainscreen.MessageItem(text, curr_time(), self._name, message_type) + item = MessageItem(text, curr_time(), self._name, message_type) elem = QtGui.QListWidgetItem(self._messages) elem.setSizeHint(QtCore.QSize(500, 100)) self._messages.addItem(elem)