add friend screen coverted

This commit is contained in:
ingvar1995 2018-05-25 11:48:47 +03:00
parent 423bda93c6
commit 03e2fa4cb8
3 changed files with 120 additions and 49 deletions

View File

@ -15,70 +15,41 @@ class AddContact(CenteredWidget):
super().__init__() super().__init__()
self._settings = settings self._settings = settings
self._contacts_manager = contacts_manager self._contacts_manager = contacts_manager
self.initUI(tox_id) uic.loadUi(get_views_path('add_contact_screen'), self)
self._update_ui(tox_id)
self._adding = False self._adding = False
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
def initUI(self, tox_id): def _update_ui(self, tox_id):
self.setObjectName('AddContact') self.toxIdLineEdit = LineEdit(self)
self.resize(568, 306) self.toxIdLineEdit.setGeometry(QtCore.QRect(50, 40, 460, 30))
self.sendRequestButton = QtWidgets.QPushButton(self) self.toxIdLineEdit.setText(tox_id)
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 = QtWidgets.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.setFamily(self._settings['font'])
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 = QtWidgets.QTextEdit(self)
self.message_edit.setGeometry(QtCore.QRect(50, 110, 471, 151))
self.message_edit.setObjectName("textEdit")
self.message = QtWidgets.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.setPointSize(12)
font.setBold(True)
self.label.setFont(font)
self.message.setFont(font)
QtCore.QMetaObject.connectSlotsByName(self)
def add_friend(self): self.messagePlainTextEdit.document().setPlainText(util_ui.tr('Hello! Please add me to your contact list.'))
self.addContactPushButton.clicked.connect(self._add_friend)
self._retranslate_ui()
def _add_friend(self):
if self._adding: if self._adding:
return return
self._adding = True self._adding = True
tox_id = self.tox_id.text().strip() tox_id = self.toxIdLineEdit.text().strip()
if tox_id.startswith('tox:'): if tox_id.startswith('tox:'):
tox_id = tox_id[4:] tox_id = tox_id[4:]
send = self._contacts_manager.send_friend_request(tox_id, self.message_edit.toPlainText()) message = self.messagePlainTextEdit.toPlainText()
send = self._contacts_manager.send_friend_request(tox_id, message)
self._adding = False self._adding = False
if send is True: if send is True:
# request was successful # request was successful
self.close() self.close()
else: # print error data else: # print error data
self.error_label.setText(send) self.errorLabel.setText(send)
def retranslateUi(self): def _retranslate_ui(self):
self.setWindowTitle(util_ui.tr('Add contact')) self.setWindowTitle(util_ui.tr('Add contact'))
self.sendRequestButton.setText(util_ui.tr('Send request')) self.addContactPushButton.setText(util_ui.tr('Send request'))
self.label.setText(util_ui.tr('TOX ID:')) self.toxIdLabel.setText(util_ui.tr('TOX ID:'))
self.message.setText(util_ui.tr('Message:')) self.messageLabel.setText(util_ui.tr('Message:'))
self.tox_id.setPlaceholderText(util_ui.tr('TOX ID or public key of contact')) self.toxIdLineEdit.setPlaceholderText(util_ui.tr('TOX ID or public key of contact'))
class ProfileSettings(CenteredWidget): class ProfileSettings(CenteredWidget):

View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>320</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>560</width>
<height>320</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>560</width>
<height>320</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="toxIdLabel">
<property name="geometry">
<rect>
<x>50</x>
<y>10</y>
<width>150</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLabel" name="messageLabel">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>150</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="messagePlainTextEdit">
<property name="geometry">
<rect>
<x>50</x>
<y>110</y>
<width>460</width>
<height>150</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="addContactPushButton">
<property name="geometry">
<rect>
<x>50</x>
<y>270</y>
<width>460</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QLabel" name="errorLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>220</x>
<y>10</y>
<width>321</width>
<height>31</height>
</rect>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -24,6 +24,7 @@ class CenteredWidget(QtWidgets.QWidget):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.center() self.center()
def center(self): def center(self):