Ejemplo n.º 1
0
class MessageItem(QtGui.QWidget):
    """
    Message in messages list
    """
    def __init__(self, text, time, user='', sent=True, message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(2, 2, 95, 20))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(parent.width() - 50, 0, 50, 20))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self._time = time
        if not sent:
            movie = QtGui.QMovie(curr_directory() + '/images/spinner.gif')
            self.time.setMovie(movie)
            movie.start()
            self.t = True
        else:
            self.time.setText(convert_time(time))
            self.t = False

        self.message = MessageEdit(text, parent.width() - 150, message_type, self)
        if message_type != TOX_MESSAGE_TYPE['NORMAL']:
            self.name.setStyleSheet("QLabel { color: #5CB3FF; }")
            self.message.setAlignment(QtCore.Qt.AlignCenter)
            self.time.setStyleSheet("QLabel { color: #5CB3FF; }")
        self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 150, self.message.height()))
        self.setFixedHeight(self.message.height())

    def mouseReleaseEvent(self, event):
        if event.button() == QtCore.Qt.RightButton and event.x() > self.time.x():
            self.listMenu = QtGui.QMenu()
            delete_item = self.listMenu.addAction(QtGui.QApplication.translate("MainWindow", 'Delete message', None, QtGui.QApplication.UnicodeUTF8))
            self.connect(delete_item, QtCore.SIGNAL("triggered()"), self.delete)
            parent_position = self.time.mapToGlobal(QtCore.QPoint(0, 0))
            self.listMenu.move(parent_position)
            self.listMenu.show()

    def delete(self):
        pr = profile.Profile.get_instance()
        pr.delete_message(self._time)

    def mark_as_sent(self):
        if self.t:
            self.time.setText(convert_time(self._time))
            self.t = False
            return True
        return False
Ejemplo n.º 2
0
 def __init__(self, parent=None):
     QtGui.QWidget.__init__(self, parent)
     mode = settings.Settings.get_instance()["compact_mode"]
     self.setBaseSize(QtCore.QSize(250, 40 if mode else 70))
     self.avatar_label = QtGui.QLabel(self)
     size = 32 if mode else 64
     self.avatar_label.setGeometry(QtCore.QRect(3, 4, size, size))
     self.avatar_label.setScaledContents(False)
     self.avatar_label.setAlignment(QtCore.Qt.AlignCenter)
     self.name = DataLabel(self)
     self.name.setGeometry(QtCore.QRect(50 if mode else 75, 3 if mode else 10, 150, 15 if mode else 25))
     font = QtGui.QFont()
     font.setFamily(settings.Settings.get_instance()["font"])
     font.setPointSize(10 if mode else 12)
     font.setBold(True)
     self.name.setFont(font)
     self.status_message = DataLabel(self)
     self.status_message.setGeometry(QtCore.QRect(50 if mode else 75, 20 if mode else 30, 170, 15 if mode else 20))
     font.setPointSize(10)
     font.setBold(False)
     self.status_message.setFont(font)
     self.connection_status = StatusCircle(self)
     self.connection_status.setGeometry(QtCore.QRect(230, -2 if mode else 5, 32, 32))
     self.messages = UnreadMessagesCount(self)
     self.messages.setGeometry(QtCore.QRect(20 if mode else 52, 20 if mode else 50, 30, 20))
Ejemplo n.º 3
0
class ContactItem(QtGui.QWidget):
    """
    Contact in friends list
    """

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.setBaseSize(QtCore.QSize(250, 70))
        self.avatar_label = QtGui.QLabel(self)
        self.avatar_label.setGeometry(QtCore.QRect(3, 3, 64, 64))
        self.avatar_label.setScaledContents(True)
        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(75, 10, 150, 25))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(12)
        font.setBold(True)
        self.name.setFont(font)
        self.status_message = DataLabel(self)
        self.status_message.setGeometry(QtCore.QRect(75, 30, 170, 20))
        font.setPointSize(10)
        font.setBold(False)
        self.status_message.setFont(font)
        self.connection_status = StatusCircle(self)
        self.connection_status.setGeometry(QtCore.QRect(230, 5, 32, 32))
        self.messages = UnreadMessagesCount(self)
        self.messages.setGeometry(QtCore.QRect(52, 50, 30, 20))
Ejemplo n.º 4
0
    def __init__(self, text, time, user="", sent=True, message_type=TOX_MESSAGE_TYPE["NORMAL"], parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(2, 2, 95, 23))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily(settings.Settings.get_instance()["font"])
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(parent.width() - 60, 0, 50, 25))
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self._time = time
        if not sent:
            movie = QtGui.QMovie(curr_directory() + "/images/spinner.gif")
            self.time.setMovie(movie)
            movie.start()
            self.t = True
        else:
            self.time.setText(convert_time(time))
            self.t = False

        self.message = MessageEdit(text, parent.width() - 160, message_type, self)
        if message_type != TOX_MESSAGE_TYPE["NORMAL"]:
            self.name.setStyleSheet("QLabel { color: #5CB3FF; }")
            self.message.setAlignment(QtCore.Qt.AlignCenter)
            self.time.setStyleSheet("QLabel { color: #5CB3FF; }")
        self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 160, self.message.height()))
        self.setFixedHeight(self.message.height())
Ejemplo n.º 5
0
    def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(0, 2, 95, 20))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(11)
        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(parent.width() - 50, 0, 50, 25))
        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 = MessageEdit(text, parent.width() - 150, self)
        self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 150, self.message.height()))
        self.setFixedHeight(self.message.height())

        if message_type == TOX_MESSAGE_TYPE['ACTION']:
            self.name.setStyleSheet("QLabel { color: #4169E1; }")
            self.message.setStyleSheet("QTextEdit { color: #4169E1; }")
        else:
            if text[0] == '>':
                self.message.setStyleSheet("QTextEdit { color: green; }")
            if text[-1] == '<':
                self.message.setStyleSheet("QTextEdit { color: red; }")
Ejemplo n.º 6
0
 def initUI(self, tox_id):
     self.setObjectName('AddContact')
     self.resize(568, 306)
     self.sendRequestButton = QtGui.QPushButton(self)
     self.sendRequestButton.setGeometry(QtCore.QRect(50, 270, 471, 31))
     self.sendRequestButton.setMinimumSize(QtCore.QSize(0, 0))
     self.sendRequestButton.setBaseSize(QtCore.QSize(0, 0))
     self.sendRequestButton.setObjectName("sendRequestButton")
     self.sendRequestButton.clicked.connect(self.add_friend)
     self.tox_id = LineEdit(self)
     self.tox_id.setGeometry(QtCore.QRect(50, 40, 471, 27))
     self.tox_id.setObjectName("lineEdit")
     self.tox_id.setText(tox_id)
     self.label = QtGui.QLabel(self)
     self.label.setGeometry(QtCore.QRect(50, 10, 80, 20))
     self.error_label = DataLabel(self)
     self.error_label.setGeometry(QtCore.QRect(120, 10, 420, 20))
     font = QtGui.QFont()
     font.setPointSize(10)
     font.setWeight(30)
     self.error_label.setFont(font)
     self.error_label.setStyleSheet("QLabel { color: #BC1C1C; }")
     self.label.setObjectName("label")
     self.message_edit = QtGui.QTextEdit(self)
     self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
     self.message_edit.setObjectName("textEdit")
     self.message = QtGui.QLabel(self)
     self.message.setGeometry(QtCore.QRect(50, 70, 101, 31))
     self.message.setFont(font)
     self.message.setObjectName("label_2")
     self.retranslateUi()
     self.message_edit.setText('Hello! Add me to your contact list please')
     font = QtGui.QFont()
     font.setPointSize(12)
     font.setBold(True)
     self.label.setFont(font)
     self.message.setFont(font)
     QtCore.QMetaObject.connectSlotsByName(self)
Ejemplo n.º 7
0
 def __init__(self, parent=None):
     QtGui.QWidget.__init__(self, parent)
     self.setBaseSize(QtCore.QSize(250, 70))
     self.avatar_label = QtGui.QLabel(self)
     self.avatar_label.setGeometry(QtCore.QRect(3, 3, 64, 64))
     self.avatar_label.setScaledContents(True)
     self.name = DataLabel(self)
     self.name.setGeometry(QtCore.QRect(70, 10, 160, 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 = DataLabel(self)
     self.status_message.setGeometry(QtCore.QRect(70, 30, 180, 20))
     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(220, 5, 32, 32))
     self.connection_status.setObjectName("connection_status")
Ejemplo n.º 8
0
 def __init__(self, parent=None):
     QtGui.QWidget.__init__(self, parent)
     self.setBaseSize(QtCore.QSize(250, 70))
     self.avatar_label = QtGui.QLabel(self)
     self.avatar_label.setGeometry(QtCore.QRect(3, 3, 64, 64))
     self.avatar_label.setScaledContents(True)
     self.name = DataLabel(self)
     self.name.setGeometry(QtCore.QRect(70, 10, 160, 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 = DataLabel(self)
     self.status_message.setGeometry(QtCore.QRect(70, 30, 180, 20))
     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(220, 5, 32, 32))
     self.connection_status.setObjectName("connection_status")
Ejemplo n.º 9
0
    def __init__(self, text, time, user='', sent=True, message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(2, 2, 95, 20))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(parent.width() - 50, 0, 50, 20))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self._time = time
        if not sent:
            movie = QtGui.QMovie(curr_directory() + '/images/spinner.gif')
            self.time.setMovie(movie)
            movie.start()
            self.t = True
        else:
            self.time.setText(convert_time(time))
            self.t = False

        self.message = MessageEdit(text, parent.width() - 150, message_type, self)
        if message_type != TOX_MESSAGE_TYPE['NORMAL']:
            self.name.setStyleSheet("QLabel { color: #5CB3FF; }")
            self.message.setAlignment(QtCore.Qt.AlignCenter)
            self.time.setStyleSheet("QLabel { color: #5CB3FF; }")
        self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 150, self.message.height()))
        self.setFixedHeight(self.message.height())
Ejemplo n.º 10
0
 def initUI(self, tox_id):
     self.setObjectName('AddContact')
     self.resize(568, 306)
     self.sendRequestButton = QtGui.QPushButton(self)
     self.sendRequestButton.setGeometry(QtCore.QRect(50, 270, 471, 31))
     self.sendRequestButton.setMinimumSize(QtCore.QSize(0, 0))
     self.sendRequestButton.setBaseSize(QtCore.QSize(0, 0))
     self.sendRequestButton.setObjectName("sendRequestButton")
     self.sendRequestButton.clicked.connect(self.add_friend)
     self.tox_id = LineEdit(self)
     self.tox_id.setGeometry(QtCore.QRect(50, 40, 471, 27))
     self.tox_id.setObjectName("lineEdit")
     self.tox_id.setText(tox_id)
     self.label = QtGui.QLabel(self)
     self.label.setGeometry(QtCore.QRect(50, 10, 80, 20))
     self.error_label = DataLabel(self)
     self.error_label.setGeometry(QtCore.QRect(120, 10, 420, 20))
     font = QtGui.QFont()
     font.setPointSize(10)
     font.setWeight(30)
     self.error_label.setFont(font)
     self.error_label.setStyleSheet("QLabel { color: #BC1C1C; }")
     self.label.setObjectName("label")
     self.message_edit = QtGui.QTextEdit(self)
     self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
     self.message_edit.setObjectName("textEdit")
     self.message = QtGui.QLabel(self)
     self.message.setGeometry(QtCore.QRect(50, 70, 101, 31))
     self.message.setFont(font)
     self.message.setObjectName("label_2")
     self.retranslateUi()
     self.message_edit.setText('Hello! Add me to your contact list please')
     font = QtGui.QFont()
     font.setPointSize(12)
     font.setBold(True)
     self.label.setFont(font)
     self.message.setFont(font)
     QtCore.QMetaObject.connectSlotsByName(self)
Ejemplo n.º 11
0
class MessageItem(QtGui.QWidget):
    """
    Message in messages list
    """
    def __init__(self, text, time, user='', sent=True, message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(2, 2, 95, 23))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily(settings.Settings.get_instance()['font'])
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(parent.width() - 60, 0, 50, 25))
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self._time = time
        if not sent:
            movie = QtGui.QMovie(curr_directory() + '/images/spinner.gif')
            self.time.setMovie(movie)
            movie.start()
            self.t = True
        else:
            self.time.setText(convert_time(time))
            self.t = False

        self.message = MessageEdit(text, parent.width() - 160, message_type, self)
        if message_type != TOX_MESSAGE_TYPE['NORMAL']:
            self.name.setStyleSheet("QLabel { color: #5CB3FF; }")
            self.message.setAlignment(QtCore.Qt.AlignCenter)
            self.time.setStyleSheet("QLabel { color: #5CB3FF; }")
        self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 160, self.message.height()))
        self.setFixedHeight(self.message.height())

    def mouseReleaseEvent(self, event):
        if event.button() == QtCore.Qt.RightButton and event.x() > self.time.x():
            self.listMenu = QtGui.QMenu()
            delete_item = self.listMenu.addAction(QtGui.QApplication.translate("MainWindow", 'Delete message', None, QtGui.QApplication.UnicodeUTF8))
            self.connect(delete_item, QtCore.SIGNAL("triggered()"), self.delete)
            parent_position = self.time.mapToGlobal(QtCore.QPoint(0, 0))
            self.listMenu.move(parent_position)
            self.listMenu.show()

    def delete(self):
        pr = profile.Profile.get_instance()
        pr.delete_message(self._time)

    def mark_as_sent(self):
        if self.t:
            self.time.setText(convert_time(self._time))
            self.t = False
            return True
        return False

    def set_avatar(self, pixmap):
        self.name.setAlignment(QtCore.Qt.AlignCenter)
        self.message.setAlignment(QtCore.Qt.AlignVCenter)
        self.setFixedHeight(max(self.height(), 36))
        self.name.setFixedHeight(self.height())
        self.message.setFixedHeight(self.height())
        self.name.setPixmap(pixmap.scaled(30, 30, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation))

    def select_text(self, text):
        tmp = self.message.toHtml()
        text = h.escape(text)
        strings = re.findall(text, tmp, flags=re.IGNORECASE)
        for s in strings:
            tmp = self.replace_all(tmp, s)
        self.message.setHtml(tmp)

    @staticmethod
    def replace_all(text, substring):
        i, l = 0, len(substring)
        while i < len(text) - l + 1:
            index = text[i:].find(substring)
            if index == -1:
                break
            i += index
            lgt, rgt = text[i:].find('<'), text[i:].find('>')
            if rgt < lgt:
                i += rgt + 1
                continue
            sub = '<font color="red"><b>{}</b></font>'.format(substring)
            text = text[:i] + sub + text[i + l:]
            i += len(sub)
        return text
Ejemplo n.º 12
0
class MessageItem(QtGui.QWidget):
    """
    Message in messages list
    """
    def __init__(self,
                 text,
                 time,
                 user='',
                 message_type=TOX_MESSAGE_TYPE['NORMAL'],
                 parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(0, 2, 95, 20))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(11)
        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(parent.width() - 50, 0, 50, 25))
        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 = MessageEdit(text, parent.width() - 150, self)
        self.message.setGeometry(
            QtCore.QRect(100, 0,
                         parent.width() - 150, self.message.height()))
        self.setFixedHeight(self.message.height())

        if message_type == TOX_MESSAGE_TYPE['ACTION']:
            self.name.setStyleSheet("QLabel { color: #4169E1; }")
            self.message.setStyleSheet("QTextEdit { color: #4169E1; }")
        else:
            if text[0] == '>':
                self.message.setStyleSheet("QTextEdit { color: green; }")
            if text[-1] == '<':
                self.message.setStyleSheet("QTextEdit { color: red; }")
Ejemplo n.º 13
0
    def __init__(self, file_name, size, time, user, friend_number, file_number, state, parent=None):

        QtGui.QListWidget.__init__(self, parent)
        self.resize(QtCore.QSize(620, 50))
        if state != FILE_TRANSFER_MESSAGE_STATUS['CANCELLED']:
            self.setStyleSheet('QWidget { background-color: green; }')
        else:
            self.setStyleSheet('QWidget { background-color: #B40404; }')

        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(1, 15, 95, 20))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)
        self.name.setStyleSheet('QLabel { color: black; }')

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(570, 2, 50, 46))
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self.time.setText(convert_time(time))
        self.time.setStyleSheet('QLabel { color: black; }')

        self.cancel = QtGui.QPushButton(self)
        self.cancel.setGeometry(QtCore.QRect(500, 2, 46, 46))
        pixmap = QtGui.QPixmap(curr_directory() + '/images/decline.png')
        icon = QtGui.QIcon(pixmap)
        self.cancel.setIcon(icon)
        self.cancel.setIconSize(QtCore.QSize(30, 30))
        self.cancel.setVisible(state > 1)
        self.cancel.clicked.connect(lambda: self.cancel_transfer(friend_number, file_number))
        self.cancel.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; }')

        self.accept = QtGui.QPushButton(self)
        self.accept.setGeometry(QtCore.QRect(450, 2, 46, 46))
        pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png')
        icon = QtGui.QIcon(pixmap)
        self.accept.setIcon(icon)
        self.accept.setIconSize(QtCore.QSize(30, 30))
        self.accept.clicked.connect(lambda: self.accept_transfer(friend_number, file_number, size))
        self.accept.setVisible(state == FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED'])
        self.accept.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; }')

        self.pb = QtGui.QProgressBar(self)
        self.pb.setGeometry(QtCore.QRect(100, 15, 100, 20))
        self.pb.setValue(0)
        self.pb.setStyleSheet('QProgressBar { background-color: #302F2F; }')
        if state < 2:
            self.pb.setVisible(False)

        self.file_name = DataLabel(self)
        self.file_name.setGeometry(QtCore.QRect(210, 2, 230, 46))
        font.setPointSize(12)
        self.file_name.setFont(font)
        file_size = size / 1024
        if not file_size:
            file_size = '{}B'.format(size)
        elif file_size >= 1024:
            file_size = '{}MB'.format(file_size / 1024)
        else:
            file_size = '{}KB'.format(file_size)
        file_data = u'{} {}'.format(file_size, file_name)
        self.file_name.setText(file_data)
        self.file_name.setStyleSheet('QLabel { color: black; }')
        self.saved_name = file_name
Ejemplo n.º 14
0
    def __init__(self, file_name, size, time, user, friend_number, file_number, state, width, parent=None):

        QtGui.QListWidget.__init__(self, parent)
        self.resize(QtCore.QSize(width, 34))
        if state == TOX_FILE_TRANSFER_STATE["CANCELLED"]:
            self.setStyleSheet("QListWidget { border: 1px solid #B40404; }")
        elif state in PAUSED_FILE_TRANSFERS:
            self.setStyleSheet("QListWidget { border: 1px solid #FF8000; }")
        else:
            self.setStyleSheet("QListWidget { border: 1px solid green; }")
        self.state = state

        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(3, 7, 95, 25))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily(settings.Settings.get_instance()["font"])
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(width - 60, 7, 50, 25))
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self.time.setText(convert_time(time))

        self.cancel = QtGui.QPushButton(self)
        self.cancel.setGeometry(QtCore.QRect(width - 125, 2, 30, 30))
        pixmap = QtGui.QPixmap(curr_directory() + "/images/decline.png")
        icon = QtGui.QIcon(pixmap)
        self.cancel.setIcon(icon)
        self.cancel.setIconSize(QtCore.QSize(30, 30))
        self.cancel.setVisible(state in ACTIVE_FILE_TRANSFERS)
        self.cancel.clicked.connect(lambda: self.cancel_transfer(friend_number, file_number))
        self.cancel.setStyleSheet("QPushButton:hover { border: 1px solid #3A3939; background-color: none;}")

        self.accept_or_pause = QtGui.QPushButton(self)
        self.accept_or_pause.setGeometry(QtCore.QRect(width - 170, 2, 30, 30))
        if state == TOX_FILE_TRANSFER_STATE["INCOMING_NOT_STARTED"]:
            self.accept_or_pause.setVisible(True)
            self.button_update("accept")
        elif state in DO_NOT_SHOW_ACCEPT_BUTTON:
            self.accept_or_pause.setVisible(False)
        elif state == TOX_FILE_TRANSFER_STATE["PAUSED_BY_USER"]:  # setup for continue
            self.accept_or_pause.setVisible(True)
            self.button_update("resume")
        else:  # pause
            self.accept_or_pause.setVisible(True)
            self.button_update("pause")
        self.accept_or_pause.clicked.connect(lambda: self.accept_or_pause_transfer(friend_number, file_number, size))

        self.accept_or_pause.setStyleSheet("QPushButton:hover { border: 1px solid #3A3939; background-color: none}")

        self.pb = QtGui.QProgressBar(self)
        self.pb.setGeometry(QtCore.QRect(100, 7, 100, 20))
        self.pb.setValue(0)
        self.pb.setStyleSheet("QProgressBar { background-color: #302F2F; }")
        self.pb.setVisible(state in SHOW_PROGRESS_BAR)

        self.file_name = DataLabel(self)
        self.file_name.setGeometry(QtCore.QRect(210, 7, width - 420, 20))
        font.setPointSize(12)
        self.file_name.setFont(font)
        file_size = size // 1024
        if not file_size:
            file_size = "{}B".format(size)
        elif file_size >= 1024:
            file_size = "{}MB".format(file_size // 1024)
        else:
            file_size = "{}KB".format(file_size)
        file_data = "{} {}".format(file_size, file_name)
        self.file_name.setText(file_data)
        self.file_name.setToolTip(file_name)
        self.saved_name = file_name
        self.time_left = QtGui.QLabel(self)
        self.time_left.setGeometry(QtCore.QRect(width - 92, 7, 30, 20))
        font.setPointSize(10)
        self.time_left.setFont(font)
        self.time_left.setVisible(state == TOX_FILE_TRANSFER_STATE["RUNNING"])
        self.setFocusPolicy(QtCore.Qt.NoFocus)
        self.paused = False
Ejemplo n.º 15
0
class FileTransferItem(QtGui.QListWidget):
    def __init__(self, file_name, size, time, user, friend_number, file_number, state, width, parent=None):

        QtGui.QListWidget.__init__(self, parent)
        self.resize(QtCore.QSize(width, 34))
        if state == TOX_FILE_TRANSFER_STATE["CANCELLED"]:
            self.setStyleSheet("QListWidget { border: 1px solid #B40404; }")
        elif state in PAUSED_FILE_TRANSFERS:
            self.setStyleSheet("QListWidget { border: 1px solid #FF8000; }")
        else:
            self.setStyleSheet("QListWidget { border: 1px solid green; }")
        self.state = state

        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(3, 7, 95, 25))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily(settings.Settings.get_instance()["font"])
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(width - 60, 7, 50, 25))
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self.time.setText(convert_time(time))

        self.cancel = QtGui.QPushButton(self)
        self.cancel.setGeometry(QtCore.QRect(width - 125, 2, 30, 30))
        pixmap = QtGui.QPixmap(curr_directory() + "/images/decline.png")
        icon = QtGui.QIcon(pixmap)
        self.cancel.setIcon(icon)
        self.cancel.setIconSize(QtCore.QSize(30, 30))
        self.cancel.setVisible(state in ACTIVE_FILE_TRANSFERS)
        self.cancel.clicked.connect(lambda: self.cancel_transfer(friend_number, file_number))
        self.cancel.setStyleSheet("QPushButton:hover { border: 1px solid #3A3939; background-color: none;}")

        self.accept_or_pause = QtGui.QPushButton(self)
        self.accept_or_pause.setGeometry(QtCore.QRect(width - 170, 2, 30, 30))
        if state == TOX_FILE_TRANSFER_STATE["INCOMING_NOT_STARTED"]:
            self.accept_or_pause.setVisible(True)
            self.button_update("accept")
        elif state in DO_NOT_SHOW_ACCEPT_BUTTON:
            self.accept_or_pause.setVisible(False)
        elif state == TOX_FILE_TRANSFER_STATE["PAUSED_BY_USER"]:  # setup for continue
            self.accept_or_pause.setVisible(True)
            self.button_update("resume")
        else:  # pause
            self.accept_or_pause.setVisible(True)
            self.button_update("pause")
        self.accept_or_pause.clicked.connect(lambda: self.accept_or_pause_transfer(friend_number, file_number, size))

        self.accept_or_pause.setStyleSheet("QPushButton:hover { border: 1px solid #3A3939; background-color: none}")

        self.pb = QtGui.QProgressBar(self)
        self.pb.setGeometry(QtCore.QRect(100, 7, 100, 20))
        self.pb.setValue(0)
        self.pb.setStyleSheet("QProgressBar { background-color: #302F2F; }")
        self.pb.setVisible(state in SHOW_PROGRESS_BAR)

        self.file_name = DataLabel(self)
        self.file_name.setGeometry(QtCore.QRect(210, 7, width - 420, 20))
        font.setPointSize(12)
        self.file_name.setFont(font)
        file_size = size // 1024
        if not file_size:
            file_size = "{}B".format(size)
        elif file_size >= 1024:
            file_size = "{}MB".format(file_size // 1024)
        else:
            file_size = "{}KB".format(file_size)
        file_data = "{} {}".format(file_size, file_name)
        self.file_name.setText(file_data)
        self.file_name.setToolTip(file_name)
        self.saved_name = file_name
        self.time_left = QtGui.QLabel(self)
        self.time_left.setGeometry(QtCore.QRect(width - 92, 7, 30, 20))
        font.setPointSize(10)
        self.time_left.setFont(font)
        self.time_left.setVisible(state == TOX_FILE_TRANSFER_STATE["RUNNING"])
        self.setFocusPolicy(QtCore.Qt.NoFocus)
        self.paused = False

    def cancel_transfer(self, friend_number, file_number):
        pr = profile.Profile.get_instance()
        pr.cancel_transfer(friend_number, file_number)
        self.setStyleSheet("QListWidget { border: 1px solid #B40404; }")
        self.cancel.setVisible(False)
        self.accept_or_pause.setVisible(False)
        self.pb.setVisible(False)

    def accept_or_pause_transfer(self, friend_number, file_number, size):
        if self.state == TOX_FILE_TRANSFER_STATE["INCOMING_NOT_STARTED"]:
            directory = QtGui.QFileDialog.getExistingDirectory(
                self,
                QtGui.QApplication.translate("MainWindow", "Choose folder", None, QtGui.QApplication.UnicodeUTF8),
                curr_directory(),
                QtGui.QFileDialog.ShowDirsOnly | QtGui.QFileDialog.DontUseNativeDialog,
            )
            self.pb.setVisible(True)
            if directory:
                pr = profile.Profile.get_instance()
                pr.accept_transfer(self, directory + "/" + self.saved_name, friend_number, file_number, size)
                self.button_update("pause")
        elif self.state == TOX_FILE_TRANSFER_STATE["PAUSED_BY_USER"]:  # resume
            self.paused = False
            profile.Profile.get_instance().resume_transfer(friend_number, file_number)
            self.button_update("pause")
            self.state = TOX_FILE_TRANSFER_STATE["RUNNING"]
        else:  # pause
            self.paused = True
            self.state = TOX_FILE_TRANSFER_STATE["PAUSED_BY_USER"]
            profile.Profile.get_instance().pause_transfer(friend_number, file_number)
            self.button_update("resume")
        self.accept_or_pause.clearFocus()

    def button_update(self, path):
        pixmap = QtGui.QPixmap(curr_directory() + "/images/{}.png".format(path))
        icon = QtGui.QIcon(pixmap)
        self.accept_or_pause.setIcon(icon)
        self.accept_or_pause.setIconSize(QtCore.QSize(30, 30))

    @QtCore.Slot(int, float, int)
    def update(self, state, progress, time):
        self.pb.setValue(int(progress * 100))
        if time + 1:
            m, s = divmod(time, 60)
            self.time_left.setText("{0:02d}:{1:02d}".format(m, s))
        if self.state != state and self.state in ACTIVE_FILE_TRANSFERS:
            if state == TOX_FILE_TRANSFER_STATE["CANCELLED"]:
                self.setStyleSheet("QListWidget { border: 1px solid #B40404; }")
                self.cancel.setVisible(False)
                self.accept_or_pause.setVisible(False)
                self.pb.setVisible(False)
                self.state = state
                self.time_left.setVisible(False)
            elif state == TOX_FILE_TRANSFER_STATE["FINISHED"]:
                self.accept_or_pause.setVisible(False)
                self.pb.setVisible(False)
                self.cancel.setVisible(False)
                self.setStyleSheet("QListWidget { border: 1px solid green; }")
                self.state = state
                self.time_left.setVisible(False)
            elif state == TOX_FILE_TRANSFER_STATE["PAUSED_BY_FRIEND"]:
                self.accept_or_pause.setVisible(False)
                self.setStyleSheet("QListWidget { border: 1px solid #FF8000; }")
                self.state = state
                self.time_left.setVisible(False)
            elif state == TOX_FILE_TRANSFER_STATE["PAUSED_BY_USER"]:
                self.button_update("resume")  # setup button continue
                self.setStyleSheet("QListWidget { border: 1px solid green; }")
                self.state = state
                self.time_left.setVisible(False)
            elif state == TOX_FILE_TRANSFER_STATE["OUTGOING_NOT_STARTED"]:
                self.setStyleSheet("QListWidget { border: 1px solid #FF8000; }")
                self.accept_or_pause.setVisible(False)
                self.time_left.setVisible(False)
                self.pb.setVisible(False)
            elif not self.paused:  # active
                self.pb.setVisible(True)
                self.accept_or_pause.setVisible(True)  # setup to pause
                self.button_update("pause")
                self.setStyleSheet("QListWidget { border: 1px solid green; }")
                self.state = state
                self.time_left.setVisible(True)

    def mark_as_sent(self):
        return False
Ejemplo n.º 16
0
class AddContact(CenteredWidget):
    """Add contact form"""

    def __init__(self, tox_id=''):
        super(AddContact, self).__init__()
        self.initUI(tox_id)
        self._adding = False

    def initUI(self, tox_id):
        self.setObjectName('AddContact')
        self.resize(568, 306)
        self.sendRequestButton = QtGui.QPushButton(self)
        self.sendRequestButton.setGeometry(QtCore.QRect(50, 270, 471, 31))
        self.sendRequestButton.setMinimumSize(QtCore.QSize(0, 0))
        self.sendRequestButton.setBaseSize(QtCore.QSize(0, 0))
        self.sendRequestButton.setObjectName("sendRequestButton")
        self.sendRequestButton.clicked.connect(self.add_friend)
        self.tox_id = LineEdit(self)
        self.tox_id.setGeometry(QtCore.QRect(50, 40, 471, 27))
        self.tox_id.setObjectName("lineEdit")
        self.tox_id.setText(tox_id)
        self.label = QtGui.QLabel(self)
        self.label.setGeometry(QtCore.QRect(50, 10, 80, 20))
        self.error_label = DataLabel(self)
        self.error_label.setGeometry(QtCore.QRect(120, 10, 420, 20))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setWeight(30)
        self.error_label.setFont(font)
        self.error_label.setStyleSheet("QLabel { color: #BC1C1C; }")
        self.label.setObjectName("label")
        self.message_edit = QtGui.QTextEdit(self)
        self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
        self.message_edit.setObjectName("textEdit")
        self.message = QtGui.QLabel(self)
        self.message.setGeometry(QtCore.QRect(50, 70, 101, 31))
        self.message.setFont(font)
        self.message.setObjectName("label_2")
        self.retranslateUi()
        self.message_edit.setText('Hello! Add me to your contact list please')
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        self.label.setFont(font)
        self.message.setFont(font)
        QtCore.QMetaObject.connectSlotsByName(self)

    def add_friend(self):
        if self._adding:
            return
        self._adding = True
        profile = Profile.get_instance()
        send = profile.send_friend_request(self.tox_id.text().strip(), self.message_edit.toPlainText())
        self._adding = False
        if send is True:
            # request was successful
            self.close()
        else:  # print error data
            self.error_label.setText(send)

    def retranslateUi(self):
        self.setWindowTitle(QtGui.QApplication.translate('AddContact', "Add contact", None, QtGui.QApplication.UnicodeUTF8))
        self.sendRequestButton.setText(QtGui.QApplication.translate("Form", "Send request", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate('AddContact', "TOX ID:", None, QtGui.QApplication.UnicodeUTF8))
        self.message.setText(QtGui.QApplication.translate('AddContact', "Message:", None, QtGui.QApplication.UnicodeUTF8))
        self.tox_id.setPlaceholderText(QtGui.QApplication.translate('AddContact', "TOX ID or public key of contact", None, QtGui.QApplication.UnicodeUTF8))
Ejemplo n.º 17
0
    def __init__(self, file_name, size, time, user, friend_number, file_number, state, width, parent=None):

        QtGui.QListWidget.__init__(self, parent)
        self.resize(QtCore.QSize(width, 34))
        if state == TOX_FILE_TRANSFER_STATE['CANCELLED']:
            self.setStyleSheet('QListWidget { border: 1px solid #B40404; }')
        elif state in PAUSED_FILE_TRANSFERS:
            self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }')
        else:
            self.setStyleSheet('QListWidget { border: 1px solid green; }')
        self.state = state

        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(3, 7, 95, 20))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(width - 53, 7, 50, 20))
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self.time.setText(convert_time(time))

        self.cancel = QtGui.QPushButton(self)
        self.cancel.setGeometry(QtCore.QRect(width - 120, 2, 30, 30))
        pixmap = QtGui.QPixmap(curr_directory() + '/images/decline.png')
        icon = QtGui.QIcon(pixmap)
        self.cancel.setIcon(icon)
        self.cancel.setIconSize(QtCore.QSize(30, 30))
        self.cancel.setVisible(state in ACTIVE_FILE_TRANSFERS)
        self.cancel.clicked.connect(lambda: self.cancel_transfer(friend_number, file_number))
        self.cancel.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; background-color: none;}')

        self.accept_or_pause = QtGui.QPushButton(self)
        self.accept_or_pause.setGeometry(QtCore.QRect(width - 170, 2, 30, 30))
        if state == TOX_FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']:
            self.accept_or_pause.setVisible(True)
            self.button_update('accept')
        elif state in DO_NOT_SHOW_ACCEPT_BUTTON:
            self.accept_or_pause.setVisible(False)
        elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']:  # setup for continue
            self.accept_or_pause.setVisible(True)
            self.button_update('resume')
        else:  # pause
            self.accept_or_pause.setVisible(True)
            self.button_update('pause')
        self.accept_or_pause.clicked.connect(lambda: self.accept_or_pause_transfer(friend_number, file_number, size))

        self.accept_or_pause.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; background-color: none}')

        self.pb = QtGui.QProgressBar(self)
        self.pb.setGeometry(QtCore.QRect(100, 7, 100, 20))
        self.pb.setValue(0)
        self.pb.setStyleSheet('QProgressBar { background-color: #302F2F; }')
        self.pb.setVisible(state in SHOW_PROGRESS_BAR)

        self.file_name = DataLabel(self)
        self.file_name.setGeometry(QtCore.QRect(210, 7, width - 420, 20))
        font.setPointSize(12)
        self.file_name.setFont(font)
        file_size = size // 1024
        if not file_size:
            file_size = '{}B'.format(size)
        elif file_size >= 1024:
            file_size = '{}MB'.format(file_size // 1024)
        else:
            file_size = '{}KB'.format(file_size)
        file_data = '{} {}'.format(file_size, file_name)
        self.file_name.setText(file_data)
        self.file_name.setToolTip(file_name)
        self.saved_name = file_name
        self.time_left = QtGui.QLabel(self)
        self.time_left.setGeometry(QtCore.QRect(width - 87, 7, 30, 20))
        font.setPointSize(10)
        self.time_left.setFont(font)
        self.time_left.setVisible(state == TOX_FILE_TRANSFER_STATE['RUNNING'])
        self.setFocusPolicy(QtCore.Qt.NoFocus)
        self.paused = False
Ejemplo n.º 18
0
class FileTransferItem(QtGui.QListWidget):

    def __init__(self, file_name, size, time, user, friend_number, file_number, state, width, parent=None):

        QtGui.QListWidget.__init__(self, parent)
        self.resize(QtCore.QSize(width, 34))
        if state == TOX_FILE_TRANSFER_STATE['CANCELLED']:
            self.setStyleSheet('QListWidget { border: 1px solid #B40404; }')
        elif state in PAUSED_FILE_TRANSFERS:
            self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }')
        else:
            self.setStyleSheet('QListWidget { border: 1px solid green; }')
        self.state = state

        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(3, 7, 95, 20))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(width - 53, 7, 50, 20))
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self.time.setText(convert_time(time))

        self.cancel = QtGui.QPushButton(self)
        self.cancel.setGeometry(QtCore.QRect(width - 120, 2, 30, 30))
        pixmap = QtGui.QPixmap(curr_directory() + '/images/decline.png')
        icon = QtGui.QIcon(pixmap)
        self.cancel.setIcon(icon)
        self.cancel.setIconSize(QtCore.QSize(30, 30))
        self.cancel.setVisible(state in ACTIVE_FILE_TRANSFERS)
        self.cancel.clicked.connect(lambda: self.cancel_transfer(friend_number, file_number))
        self.cancel.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; background-color: none;}')

        self.accept_or_pause = QtGui.QPushButton(self)
        self.accept_or_pause.setGeometry(QtCore.QRect(width - 170, 2, 30, 30))
        if state == TOX_FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']:
            self.accept_or_pause.setVisible(True)
            self.button_update('accept')
        elif state in DO_NOT_SHOW_ACCEPT_BUTTON:
            self.accept_or_pause.setVisible(False)
        elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']:  # setup for continue
            self.accept_or_pause.setVisible(True)
            self.button_update('resume')
        else:  # pause
            self.accept_or_pause.setVisible(True)
            self.button_update('pause')
        self.accept_or_pause.clicked.connect(lambda: self.accept_or_pause_transfer(friend_number, file_number, size))

        self.accept_or_pause.setStyleSheet('QPushButton:hover { border: 1px solid #3A3939; background-color: none}')

        self.pb = QtGui.QProgressBar(self)
        self.pb.setGeometry(QtCore.QRect(100, 7, 100, 20))
        self.pb.setValue(0)
        self.pb.setStyleSheet('QProgressBar { background-color: #302F2F; }')
        self.pb.setVisible(state in SHOW_PROGRESS_BAR)

        self.file_name = DataLabel(self)
        self.file_name.setGeometry(QtCore.QRect(210, 7, width - 420, 20))
        font.setPointSize(12)
        self.file_name.setFont(font)
        file_size = size // 1024
        if not file_size:
            file_size = '{}B'.format(size)
        elif file_size >= 1024:
            file_size = '{}MB'.format(file_size // 1024)
        else:
            file_size = '{}KB'.format(file_size)
        file_data = '{} {}'.format(file_size, file_name)
        self.file_name.setText(file_data)
        self.file_name.setToolTip(file_name)
        self.saved_name = file_name
        self.time_left = QtGui.QLabel(self)
        self.time_left.setGeometry(QtCore.QRect(width - 87, 7, 30, 20))
        font.setPointSize(10)
        self.time_left.setFont(font)
        self.time_left.setVisible(state == TOX_FILE_TRANSFER_STATE['RUNNING'])
        self.setFocusPolicy(QtCore.Qt.NoFocus)
        self.paused = False

    def cancel_transfer(self, friend_number, file_number):
        pr = profile.Profile.get_instance()
        pr.cancel_transfer(friend_number, file_number)
        self.setStyleSheet('QListWidget { border: 1px solid #B40404; }')
        self.cancel.setVisible(False)
        self.accept_or_pause.setVisible(False)
        self.pb.setVisible(False)

    def accept_or_pause_transfer(self, friend_number, file_number, size):
        if self.state == TOX_FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']:
            directory = QtGui.QFileDialog.getExistingDirectory(self,
                                                               QtGui.QApplication.translate("MainWindow", 'Choose folder', None, QtGui.QApplication.UnicodeUTF8),
                                                               curr_directory(),
                                                               QtGui.QFileDialog.ShowDirsOnly)
            self.pb.setVisible(True)
            if directory:
                pr = profile.Profile.get_instance()
                pr.accept_transfer(self, directory + '/' + self.saved_name, friend_number, file_number, size)
                self.button_update('pause')
        elif self.state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']:  # resume
            self.paused = False
            profile.Profile.get_instance().resume_transfer(friend_number, file_number)
            self.button_update('pause')
            self.state = TOX_FILE_TRANSFER_STATE['RUNNING']
        else:  # pause
            self.paused = True
            self.state = TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']
            profile.Profile.get_instance().pause_transfer(friend_number, file_number)
            self.button_update('resume')
        self.accept_or_pause.clearFocus()

    def button_update(self, path):
        pixmap = QtGui.QPixmap(curr_directory() + '/images/{}.png'.format(path))
        icon = QtGui.QIcon(pixmap)
        self.accept_or_pause.setIcon(icon)
        self.accept_or_pause.setIconSize(QtCore.QSize(30, 30))

    @QtCore.Slot(int, float, int)
    def update(self, state, progress, time):
        self.pb.setValue(int(progress * 100))
        if time + 1:
            m, s = divmod(time, 60)
            self.time_left.setText('{0:02d}:{1:02d}'.format(m, s))
        if self.state != state:
            if state == TOX_FILE_TRANSFER_STATE['CANCELLED']:
                self.setStyleSheet('QListWidget { border: 1px solid #B40404; }')
                self.cancel.setVisible(False)
                self.accept_or_pause.setVisible(False)
                self.pb.setVisible(False)
                self.state = state
                self.time_left.setVisible(False)
            elif state == TOX_FILE_TRANSFER_STATE['FINISHED']:
                self.accept_or_pause.setVisible(False)
                self.pb.setVisible(False)
                self.cancel.setVisible(False)
                self.setStyleSheet('QListWidget { border: 1px solid green; }')
                self.state = state
                self.time_left.setVisible(False)
            elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND']:
                self.accept_or_pause.setVisible(False)
                self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }')
                self.state = state
                self.time_left.setVisible(False)
            elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']:
                self.button_update('resume')  # setup button continue
                self.setStyleSheet('QListWidget { border: 1px solid green; }')
                self.state = state
                self.time_left.setVisible(False)
            elif state == TOX_FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']:
                self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }')
                self.accept_or_pause.setVisible(False)
                self.time_left.setVisible(False)
                self.pb.setVisible(False)
            elif not self.paused:  # active
                self.pb.setVisible(True)
                self.accept_or_pause.setVisible(True)  # setup to pause
                self.button_update('pause')
                self.setStyleSheet('QListWidget { border: 1px solid green; }')
                self.state = state
                self.time_left.setVisible(True)

    def mark_as_sent(self):
        return False
Ejemplo n.º 19
0
class MessageItem(QtWidgets.QWidget):
    """
    Message in messages list
    """
    def __init__(self, text, time, user='', sent=True, message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(2, 2, 95, 23))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily(settings.Settings.get_instance()['font'])
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)

        self.time = QtWidgets.QLabel(self)
        self.time.setGeometry(QtCore.QRect(parent.width() - 60, 0, 50, 25))
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self._time = time
        if not sent:
            movie = QtGui.QMovie(curr_directory() + '/images/spinner.gif')
            self.time.setMovie(movie)
            movie.start()
            self.t = True
        else:
            self.time.setText(convert_time(time))
            self.t = False

        self.message = MessageEdit(text, parent.width() - 160, message_type, self)
        if message_type != TOX_MESSAGE_TYPE['NORMAL']:
            self.name.setStyleSheet("QLabel { color: #5CB3FF; }")
            self.message.setAlignment(QtCore.Qt.AlignCenter)
            self.time.setStyleSheet("QLabel { color: #5CB3FF; }")
        self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 160, self.message.height()))
        self.setFixedHeight(self.message.height())

    def mouseReleaseEvent(self, event):
        if event.button() == QtCore.Qt.RightButton and event.x() > self.time.x():
            self.listMenu = QtWidgets.QMenu()
            delete_item = self.listMenu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Delete message'))
            delete_item.triggered.connect(self.delete)
            parent_position = self.time.mapToGlobal(QtCore.QPoint(0, 0))
            self.listMenu.move(parent_position)
            self.listMenu.show()

    def delete(self):
        pr = profile.Profile.get_instance()
        pr.delete_message(self._time)

    def mark_as_sent(self):
        if self.t:
            self.time.setText(convert_time(self._time))
            self.t = False
            return True
        return False

    def set_avatar(self, pixmap):
        self.name.setAlignment(QtCore.Qt.AlignCenter)
        self.message.setAlignment(QtCore.Qt.AlignVCenter)
        self.setFixedHeight(max(self.height(), 36))
        self.name.setFixedHeight(self.height())
        self.message.setFixedHeight(self.height())
        self.name.setPixmap(pixmap.scaled(30, 30, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation))

    def select_text(self, text):
        tmp = self.message.toHtml()
        text = h.escape(text)
        strings = re.findall(text, tmp, flags=re.IGNORECASE)
        for s in strings:
            tmp = self.replace_all(tmp, s)
        self.message.setHtml(tmp)

    @staticmethod
    def replace_all(text, substring):
        i, l = 0, len(substring)
        while i < len(text) - l + 1:
            index = text[i:].find(substring)
            if index == -1:
                break
            i += index
            lgt, rgt = text[i:].find('<'), text[i:].find('>')
            if rgt < lgt:
                i += rgt + 1
                continue
            sub = '<font color="red"><b>{}</b></font>'.format(substring)
            text = text[:i] + sub + text[i + l:]
            i += len(sub)
        return text
Ejemplo n.º 20
0
    def __init__(self,
                 file_name,
                 size,
                 time,
                 user,
                 friend_number,
                 file_number,
                 state,
                 parent=None):

        QtGui.QListWidget.__init__(self, parent)
        self.resize(QtCore.QSize(620, 50))
        if state != FILE_TRANSFER_MESSAGE_STATUS['CANCELLED']:
            self.setStyleSheet('QWidget { background-color: green; }')
        else:
            self.setStyleSheet('QWidget { background-color: #B40404; }')

        self.name = DataLabel(self)
        self.name.setGeometry(QtCore.QRect(1, 15, 95, 20))
        self.name.setTextFormat(QtCore.Qt.PlainText)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(11)
        font.setBold(True)
        self.name.setFont(font)
        self.name.setText(user)
        self.name.setStyleSheet('QLabel { color: black; }')

        self.time = QtGui.QLabel(self)
        self.time.setGeometry(QtCore.QRect(570, 2, 50, 46))
        font.setPointSize(10)
        font.setBold(False)
        self.time.setFont(font)
        self.time.setText(convert_time(time))
        self.time.setStyleSheet('QLabel { color: black; }')

        self.cancel = QtGui.QPushButton(self)
        self.cancel.setGeometry(QtCore.QRect(500, 2, 46, 46))
        pixmap = QtGui.QPixmap(curr_directory() + '/images/decline.png')
        icon = QtGui.QIcon(pixmap)
        self.cancel.setIcon(icon)
        self.cancel.setIconSize(QtCore.QSize(30, 30))
        self.cancel.setVisible(state > 1)
        self.cancel.clicked.connect(
            lambda: self.cancel_transfer(friend_number, file_number))
        self.cancel.setStyleSheet(
            'QPushButton:hover { border: 1px solid #3A3939; }')

        self.accept = QtGui.QPushButton(self)
        self.accept.setGeometry(QtCore.QRect(450, 2, 46, 46))
        pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png')
        icon = QtGui.QIcon(pixmap)
        self.accept.setIcon(icon)
        self.accept.setIconSize(QtCore.QSize(30, 30))
        self.accept.clicked.connect(
            lambda: self.accept_transfer(friend_number, file_number, size))
        self.accept.setVisible(
            state == FILE_TRANSFER_MESSAGE_STATUS['INCOMING_NOT_STARTED'])
        self.accept.setStyleSheet(
            'QPushButton:hover { border: 1px solid #3A3939; }')

        self.pb = QtGui.QProgressBar(self)
        self.pb.setGeometry(QtCore.QRect(100, 15, 100, 20))
        self.pb.setValue(0)
        self.pb.setStyleSheet('QProgressBar { background-color: #302F2F; }')
        if state < 2:
            self.pb.setVisible(False)

        self.file_name = DataLabel(self)
        self.file_name.setGeometry(QtCore.QRect(210, 2, 230, 46))
        font.setPointSize(12)
        self.file_name.setFont(font)
        file_size = size / 1024
        if not file_size:
            file_size = '{}B'.format(size)
        elif file_size >= 1024:
            file_size = '{}MB'.format(file_size / 1024)
        else:
            file_size = '{}KB'.format(file_size)
        file_data = u'{} {}'.format(file_size, file_name)
        self.file_name.setText(file_data)
        self.file_name.setStyleSheet('QLabel { color: black; }')
        self.saved_name = file_name
Ejemplo n.º 21
0
class AddContact(CenteredWidget):
    """Add contact form"""
    def __init__(self, tox_id=''):
        super(AddContact, self).__init__()
        self.initUI(tox_id)

    def initUI(self, tox_id):
        self.setObjectName('AddContact')
        self.resize(568, 306)
        self.sendRequestButton = QtGui.QPushButton(self)
        self.sendRequestButton.setGeometry(QtCore.QRect(50, 270, 471, 31))
        self.sendRequestButton.setMinimumSize(QtCore.QSize(0, 0))
        self.sendRequestButton.setBaseSize(QtCore.QSize(0, 0))
        self.sendRequestButton.setObjectName("sendRequestButton")
        self.sendRequestButton.clicked.connect(self.add_friend)
        self.tox_id = LineEdit(self)
        self.tox_id.setGeometry(QtCore.QRect(50, 40, 471, 27))
        self.tox_id.setObjectName("lineEdit")
        self.tox_id.setText(tox_id)
        self.label = QtGui.QLabel(self)
        self.label.setGeometry(QtCore.QRect(50, 10, 80, 20))
        self.error_label = DataLabel(self)
        self.error_label.setGeometry(QtCore.QRect(120, 10, 420, 20))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setWeight(30)
        self.error_label.setFont(font)
        self.error_label.setStyleSheet("QLabel { color: #BC1C1C; }")
        self.label.setObjectName("label")
        self.message_edit = QtGui.QTextEdit(self)
        self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
        self.message_edit.setObjectName("textEdit")
        self.message = QtGui.QLabel(self)
        self.message.setGeometry(QtCore.QRect(50, 70, 101, 31))
        self.message.setFont(font)
        self.message.setObjectName("label_2")
        self.retranslateUi()
        self.message_edit.setText('Hello! Add me to your contact list please')
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        self.label.setFont(font)
        self.message.setFont(font)
        QtCore.QMetaObject.connectSlotsByName(self)

    def add_friend(self):
        profile = Profile.get_instance()
        send = profile.send_friend_request(self.tox_id.text(),
                                           self.message_edit.toPlainText())
        if send is True:
            # request was successful
            self.close()
        else:  # print error data
            self.error_label.setText(send)

    def retranslateUi(self):
        self.setWindowTitle(
            QtGui.QApplication.translate('AddContact', "Add contact", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.sendRequestButton.setText(
            QtGui.QApplication.translate("Form", "Send request", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.label.setText(
            QtGui.QApplication.translate('AddContact', "TOX ID:", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.message.setText(
            QtGui.QApplication.translate('AddContact', "Message:", None,
                                         QtGui.QApplication.UnicodeUTF8))
        self.tox_id.setPlaceholderText(
            QtGui.QApplication.translate('AddContact',
                                         "TOX ID or public key of contact",
                                         None, QtGui.QApplication.UnicodeUTF8))