toxygen/toxygen/menu.py

1096 lines
52 KiB
Python
Raw Normal View History

from PyQt5 import QtCore, QtGui, QtWidgets
2016-04-03 20:51:46 +00:00
from settings import *
2016-07-06 13:25:04 +00:00
from profile import Profile
2016-07-10 19:32:35 +00:00
from util import curr_directory, copy
2017-07-13 18:02:42 +00:00
from widgets import CenteredWidget, DataLabel, LineEdit, RubberBandWindow
2016-04-24 10:45:11 +00:00
import pyaudio
2017-02-11 17:07:28 +00:00
import toxes
2016-05-28 10:06:13 +00:00
import plugin_support
import updater
2016-03-11 11:37:45 +00:00
class AddContact(CenteredWidget):
2016-02-19 16:04:01 +00:00
"""Add contact form"""
2016-02-19 15:04:53 +00:00
def __init__(self, tox_id=''):
2016-02-19 15:04:53 +00:00
super(AddContact, self).__init__()
self.initUI(tox_id)
2016-07-10 14:51:33 +00:00
self._adding = False
2016-02-19 15:04:53 +00:00
def initUI(self, tox_id):
2016-02-19 15:04:53 +00:00
self.setObjectName('AddContact')
self.resize(568, 306)
self.sendRequestButton = QtWidgets.QPushButton(self)
2016-02-19 15:04:53 +00:00
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")
2016-03-09 18:11:36 +00:00
self.sendRequestButton.clicked.connect(self.add_friend)
self.tox_id = LineEdit(self)
2016-03-09 18:11:36 +00:00
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))
2016-02-19 15:04:53 +00:00
font = QtGui.QFont()
2016-08-05 12:58:25 +00:00
font.setFamily(Settings.get_instance()['font'])
font.setPointSize(10)
font.setWeight(30)
2016-03-09 18:11:36 +00:00
self.error_label.setFont(font)
self.error_label.setStyleSheet("QLabel { color: #BC1C1C; }")
2016-02-19 15:04:53 +00:00
self.label.setObjectName("label")
self.message_edit = QtWidgets.QTextEdit(self)
2016-03-09 18:11:36 +00:00
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))
2016-05-09 20:09:07 +00:00
self.message.setFont(font)
self.message.setObjectName("label_2")
2016-02-19 15:04:53 +00:00
self.retranslateUi()
self.message_edit.setText('Hello! Add me to your contact list please')
2016-05-09 20:09:07 +00:00
font.setPointSize(12)
font.setBold(True)
self.label.setFont(font)
self.message.setFont(font)
2016-02-19 15:04:53 +00:00
QtCore.QMetaObject.connectSlotsByName(self)
2016-03-09 18:11:36 +00:00
def add_friend(self):
2016-07-10 14:51:33 +00:00
if self._adding:
return
self._adding = True
2016-03-09 18:11:36 +00:00
profile = Profile.get_instance()
2016-07-10 21:38:25 +00:00
send = profile.send_friend_request(self.tox_id.text().strip(), self.message_edit.toPlainText())
2016-07-10 14:51:33 +00:00
self._adding = False
2016-03-09 18:11:36 +00:00
if send is True:
# request was successful
self.close()
else: # print error data
self.error_label.setText(send)
2016-02-19 15:04:53 +00:00
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate('AddContact', "Add contact"))
self.sendRequestButton.setText(QtWidgets.QApplication.translate("Form", "Send request"))
self.label.setText(QtWidgets.QApplication.translate('AddContact', "TOX ID:"))
self.message.setText(QtWidgets.QApplication.translate('AddContact', "Message:"))
self.tox_id.setPlaceholderText(QtWidgets.QApplication.translate('AddContact', "TOX ID or public key of contact"))
2016-02-19 15:04:53 +00:00
2016-02-19 16:04:01 +00:00
2016-03-11 11:37:45 +00:00
class ProfileSettings(CenteredWidget):
2016-02-19 16:04:01 +00:00
"""Form with profile settings such as name, status, TOX ID"""
def __init__(self):
2016-02-19 16:04:01 +00:00
super(ProfileSettings, self).__init__()
self.initUI()
2016-05-18 21:38:21 +00:00
self.center()
2016-02-19 16:04:01 +00:00
def initUI(self):
self.setObjectName("ProfileSettingsForm")
2016-06-18 19:32:14 +00:00
self.setMinimumSize(QtCore.QSize(700, 600))
self.setMaximumSize(QtCore.QSize(700, 600))
self.nick = LineEdit(self)
2016-04-04 09:20:32 +00:00
self.nick.setGeometry(QtCore.QRect(30, 60, 350, 27))
profile = Profile.get_instance()
self.nick.setText(profile.name)
self.status = QtWidgets.QComboBox(self)
2016-06-18 19:32:14 +00:00
self.status.setGeometry(QtCore.QRect(400, 60, 200, 27))
self.status_message = LineEdit(self)
self.status_message.setGeometry(QtCore.QRect(30, 130, 350, 27))
self.status_message.setText(profile.status_message)
self.label = QtWidgets.QLabel(self)
2016-05-09 20:09:07 +00:00
self.label.setGeometry(QtCore.QRect(40, 30, 91, 25))
2016-02-19 16:04:01 +00:00
font = QtGui.QFont()
2016-08-05 12:58:25 +00:00
font.setFamily(Settings.get_instance()['font'])
2016-02-19 16:04:01 +00:00
font.setPointSize(18)
font.setWeight(75)
font.setBold(True)
self.label.setFont(font)
self.label_2 = QtWidgets.QLabel(self)
2016-05-09 20:09:07 +00:00
self.label_2.setGeometry(QtCore.QRect(40, 100, 100, 25))
2016-02-19 16:04:01 +00:00
self.label_2.setFont(font)
self.label_3 = QtWidgets.QLabel(self)
2016-05-09 20:09:07 +00:00
self.label_3.setGeometry(QtCore.QRect(40, 180, 100, 25))
2016-02-19 16:04:01 +00:00
self.label_3.setFont(font)
self.tox_id = QtWidgets.QLabel(self)
2016-06-20 17:39:10 +00:00
self.tox_id.setGeometry(QtCore.QRect(15, 210, 685, 21))
font.setPointSize(10)
2016-02-19 16:04:01 +00:00
self.tox_id.setFont(font)
s = profile.tox_id
2016-02-25 08:32:40 +00:00
self.tox_id.setText(s)
self.copyId = QtWidgets.QPushButton(self)
2016-06-18 19:32:14 +00:00
self.copyId.setGeometry(QtCore.QRect(40, 250, 180, 30))
2016-02-25 08:32:40 +00:00
self.copyId.clicked.connect(self.copy)
self.export = QtWidgets.QPushButton(self)
2016-06-18 19:32:14 +00:00
self.export.setGeometry(QtCore.QRect(230, 250, 180, 30))
self.export.clicked.connect(self.export_profile)
self.new_nospam = QtWidgets.QPushButton(self)
2016-06-18 19:32:14 +00:00
self.new_nospam.setGeometry(QtCore.QRect(420, 250, 180, 30))
2016-05-03 19:02:56 +00:00
self.new_nospam.clicked.connect(self.new_no_spam)
self.copy_pk = QtWidgets.QPushButton(self)
2016-07-04 21:24:44 +00:00
self.copy_pk.setGeometry(QtCore.QRect(40, 300, 180, 30))
self.copy_pk.clicked.connect(self.copy_public_key)
self.new_avatar = QtWidgets.QPushButton(self)
2016-07-04 21:24:44 +00:00
self.new_avatar.setGeometry(QtCore.QRect(230, 300, 180, 30))
self.delete_avatar = QtWidgets.QPushButton(self)
2016-07-04 21:24:44 +00:00
self.delete_avatar.setGeometry(QtCore.QRect(420, 300, 180, 30))
2016-03-11 11:37:45 +00:00
self.delete_avatar.clicked.connect(self.reset_avatar)
self.new_avatar.clicked.connect(self.set_avatar)
self.profilepass = QtWidgets.QLabel(self)
2016-07-06 13:25:04 +00:00
self.profilepass.setGeometry(QtCore.QRect(40, 340, 300, 30))
2016-05-15 13:06:41 +00:00
font.setPointSize(18)
2016-07-06 13:25:04 +00:00
self.profilepass.setFont(font)
self.password = LineEdit(self)
2016-06-18 19:32:14 +00:00
self.password.setGeometry(QtCore.QRect(40, 380, 300, 30))
self.password.setEchoMode(QtWidgets.QLineEdit.Password)
self.leave_blank = QtWidgets.QLabel(self)
2016-06-18 19:32:14 +00:00
self.leave_blank.setGeometry(QtCore.QRect(350, 380, 300, 30))
self.confirm_password = LineEdit(self)
2016-06-18 19:32:14 +00:00
self.confirm_password.setGeometry(QtCore.QRect(40, 420, 300, 30))
self.confirm_password.setEchoMode(QtWidgets.QLineEdit.Password)
self.set_password = QtWidgets.QPushButton(self)
2016-06-18 19:32:14 +00:00
self.set_password.setGeometry(QtCore.QRect(40, 470, 300, 30))
2016-05-15 13:06:41 +00:00
self.set_password.clicked.connect(self.new_password)
self.not_match = QtWidgets.QLabel(self)
self.not_match.setGeometry(QtCore.QRect(350, 420, 300, 30))
2016-05-15 13:06:41 +00:00
self.not_match.setVisible(False)
self.not_match.setStyleSheet('QLabel { color: #BC1C1C; }')
self.warning = QtWidgets.QLabel(self)
2016-06-18 19:32:14 +00:00
self.warning.setGeometry(QtCore.QRect(40, 510, 500, 30))
self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')
self.default = QtWidgets.QPushButton(self)
2016-06-20 17:39:10 +00:00
self.default.setGeometry(QtCore.QRect(40, 550, 620, 30))
2016-06-18 19:32:14 +00:00
path, name = Settings.get_auto_profile()
self.auto = path + name == ProfileHelper.get_path() + Settings.get_instance().name
self.default.clicked.connect(self.auto_profile)
2016-02-19 16:04:01 +00:00
self.retranslateUi()
2016-06-18 19:32:14 +00:00
if profile.status is not None:
self.status.setCurrentIndex(profile.status)
else:
self.status.setVisible(False)
2016-02-19 16:04:01 +00:00
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.export.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Export profile"))
self.setWindowTitle(QtWidgets.QApplication.translate("ProfileSettingsForm", "Profile settings"))
self.label.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Name:"))
self.label_2.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Status:"))
self.label_3.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "TOX ID:"))
self.copyId.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Copy TOX ID"))
self.new_avatar.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "New avatar"))
self.delete_avatar.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Reset avatar"))
self.new_nospam.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "New NoSpam"))
self.profilepass.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Profile password"))
self.password.setPlaceholderText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Password (at least 8 symbols)"))
self.confirm_password.setPlaceholderText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Confirm password"))
self.set_password.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Set password"))
self.not_match.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Passwords do not match"))
self.leave_blank.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Leaving blank will reset current password"))
self.warning.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "There is no way to recover lost passwords"))
self.status.addItem(QtWidgets.QApplication.translate("ProfileSettingsForm", "Online"))
self.status.addItem(QtWidgets.QApplication.translate("ProfileSettingsForm", "Away"))
self.status.addItem(QtWidgets.QApplication.translate("ProfileSettingsForm", "Busy"))
self.copy_pk.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Copy public key"))
2016-06-18 19:32:14 +00:00
if self.auto:
self.default.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Mark as not default profile"))
2016-06-18 19:32:14 +00:00
else:
self.default.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Mark as default profile"))
2016-06-18 19:32:14 +00:00
def auto_profile(self):
if self.auto:
Settings.reset_auto_profile()
else:
Settings.set_auto_profile(ProfileHelper.get_path(), Settings.get_instance().name)
self.auto = not self.auto
if self.auto:
self.default.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Mark as not default profile"))
2016-06-18 19:32:14 +00:00
else:
self.default.setText(
QtWidgets.QApplication.translate("ProfileSettingsForm", "Mark as default profile"))
2016-05-15 13:06:41 +00:00
def new_password(self):
if self.password.text() == self.confirm_password.text():
2016-05-16 12:25:51 +00:00
if not len(self.password.text()) or len(self.password.text()) >= 8:
2017-02-11 17:07:28 +00:00
e = toxes.ToxES.get_instance()
2016-05-16 12:25:51 +00:00
e.set_password(self.password.text())
self.close()
else:
self.not_match.setText(
QtWidgets.QApplication.translate("ProfileSettingsForm", "Password must be at least 8 symbols"))
2016-05-16 12:25:51 +00:00
self.not_match.setVisible(True)
2016-05-15 13:06:41 +00:00
else:
self.not_match.setText(QtWidgets.QApplication.translate("ProfileSettingsForm", "Passwords do not match"))
2016-05-15 13:06:41 +00:00
self.not_match.setVisible(True)
2016-02-19 16:04:01 +00:00
2016-02-25 08:32:40 +00:00
def copy(self):
clipboard = QtWidgets.QApplication.clipboard()
profile = Profile.get_instance()
clipboard.setText(profile.tox_id)
2016-05-09 20:09:07 +00:00
pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png')
icon = QtGui.QIcon(pixmap)
self.copyId.setIcon(icon)
self.copyId.setIconSize(QtCore.QSize(10, 10))
2016-02-25 08:32:40 +00:00
2016-07-04 21:24:44 +00:00
def copy_public_key(self):
clipboard = QtWidgets.QApplication.clipboard()
2016-07-04 21:24:44 +00:00
profile = Profile.get_instance()
clipboard.setText(profile.tox_id[:64])
pixmap = QtGui.QPixmap(curr_directory() + '/images/accept.png')
icon = QtGui.QIcon(pixmap)
self.copy_pk.setIcon(icon)
self.copy_pk.setIconSize(QtCore.QSize(10, 10))
2016-05-03 19:02:56 +00:00
def new_no_spam(self):
self.tox_id.setText(Profile.get_instance().new_nospam())
2016-03-11 11:37:45 +00:00
def reset_avatar(self):
Profile.get_instance().reset_avatar()
def set_avatar(self):
choose = QtWidgets.QApplication.translate("ProfileSettingsForm", "Choose avatar")
name = QtWidgets.QFileDialog.getOpenFileName(self, choose, None, 'Images (*.png)',
2017-07-09 14:22:37 +00:00
options=QtWidgets.QFileDialog.DontUseNativeDialog)
2016-03-11 11:37:45 +00:00
if name[0]:
2016-06-04 12:19:15 +00:00
bitmap = QtGui.QPixmap(name[0])
2017-07-09 14:22:37 +00:00
bitmap.scaled(QtCore.QSize(128, 128), aspectRatioMode=QtCore.Qt.KeepAspectRatio,
transformMode=QtCore.Qt.SmoothTransformation)
2016-06-04 12:19:15 +00:00
byte_array = QtCore.QByteArray()
buffer = QtCore.QBuffer(byte_array)
buffer.open(QtCore.QIODevice.WriteOnly)
bitmap.save(buffer, 'PNG')
2016-07-13 14:16:15 +00:00
Profile.get_instance().set_avatar(bytes(byte_array.data()))
2016-03-11 11:37:45 +00:00
def export_profile(self):
2017-07-09 14:37:05 +00:00
directory = QtWidgets.QFileDialog.getExistingDirectory(self, '', curr_directory(),
QtWidgets.QFileDialog.DontUseNativeDialog) + '/'
2016-03-18 16:33:54 +00:00
if directory != '/':
reply = QtWidgets.QMessageBox.question(None,
QtWidgets.QApplication.translate("ProfileSettingsForm",
2017-07-09 14:22:37 +00:00
'Use new path'),
QtWidgets.QApplication.translate("ProfileSettingsForm",
2017-07-09 14:22:37 +00:00
'Do you want to move your profile to this location?'),
QtWidgets.QMessageBox.Yes,
QtWidgets.QMessageBox.No)
2016-03-18 16:33:54 +00:00
settings = Settings.get_instance()
settings.export(directory)
profile = Profile.get_instance()
2016-07-28 20:00:04 +00:00
profile.export_db(directory)
ProfileHelper.get_instance().export_profile(directory, reply == QtWidgets.QMessageBox.Yes)
def closeEvent(self, event):
profile = Profile.get_instance()
2016-06-24 12:00:13 +00:00
profile.set_name(self.nick.text())
2016-06-18 19:32:14 +00:00
profile.set_status_message(self.status_message.text().encode('utf-8'))
profile.set_status(self.status.currentIndex())
2016-02-19 16:04:01 +00:00
2016-03-11 11:37:45 +00:00
class NetworkSettings(CenteredWidget):
2016-02-19 16:04:01 +00:00
"""Network settings form: UDP, Ipv6 and proxy"""
2016-03-15 17:05:19 +00:00
def __init__(self, reset):
2016-02-19 16:04:01 +00:00
super(NetworkSettings, self).__init__()
2016-03-15 17:05:19 +00:00
self.reset = reset
2016-02-19 16:04:01 +00:00
self.initUI()
2016-05-18 21:38:21 +00:00
self.center()
2016-02-19 16:04:01 +00:00
def initUI(self):
self.setObjectName("NetworkSettings")
self.resize(300, 400)
self.setMinimumSize(QtCore.QSize(300, 400))
self.setMaximumSize(QtCore.QSize(300, 400))
self.setBaseSize(QtCore.QSize(300, 400))
self.ipv = QtWidgets.QCheckBox(self)
2016-02-19 16:04:01 +00:00
self.ipv.setGeometry(QtCore.QRect(20, 10, 97, 22))
self.ipv.setObjectName("ipv")
self.udp = QtWidgets.QCheckBox(self)
2016-04-26 19:56:06 +00:00
self.udp.setGeometry(QtCore.QRect(150, 10, 97, 22))
2016-02-19 16:04:01 +00:00
self.udp.setObjectName("udp")
self.proxy = QtWidgets.QCheckBox(self)
2016-04-26 19:56:06 +00:00
self.proxy.setGeometry(QtCore.QRect(20, 40, 97, 22))
self.http = QtWidgets.QCheckBox(self)
2016-04-26 19:56:06 +00:00
self.http.setGeometry(QtCore.QRect(20, 70, 97, 22))
2016-02-19 16:04:01 +00:00
self.proxy.setObjectName("proxy")
self.proxyip = LineEdit(self)
2016-04-26 19:56:06 +00:00
self.proxyip.setGeometry(QtCore.QRect(40, 130, 231, 27))
2016-02-19 16:04:01 +00:00
self.proxyip.setObjectName("proxyip")
self.proxyport = LineEdit(self)
2016-04-26 19:56:06 +00:00
self.proxyport.setGeometry(QtCore.QRect(40, 190, 231, 27))
2016-02-19 16:04:01 +00:00
self.proxyport.setObjectName("proxyport")
self.label = QtWidgets.QLabel(self)
2016-04-26 19:56:06 +00:00
self.label.setGeometry(QtCore.QRect(40, 100, 66, 17))
self.label_2 = QtWidgets.QLabel(self)
2016-04-26 19:56:06 +00:00
self.label_2.setGeometry(QtCore.QRect(40, 165, 66, 17))
self.reconnect = QtWidgets.QPushButton(self)
2016-05-09 19:37:11 +00:00
self.reconnect.setGeometry(QtCore.QRect(40, 230, 231, 30))
self.reconnect.clicked.connect(self.restart_core)
2016-03-13 16:14:17 +00:00
settings = Settings.get_instance()
self.ipv.setChecked(settings['ipv6_enabled'])
self.udp.setChecked(settings['udp_enabled'])
self.proxy.setChecked(settings['proxy_type'])
2016-03-13 16:14:17 +00:00
self.proxyip.setText(settings['proxy_host'])
2016-06-21 11:58:11 +00:00
self.proxyport.setText(str(settings['proxy_port']))
2016-05-02 20:20:02 +00:00
self.http.setChecked(settings['proxy_type'] == 1)
self.warning = QtWidgets.QLabel(self)
2016-05-28 19:43:51 +00:00
self.warning.setGeometry(QtCore.QRect(5, 270, 290, 60))
self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')
self.nodes = QtWidgets.QCheckBox(self)
self.nodes.setGeometry(QtCore.QRect(20, 350, 270, 22))
self.nodes.setChecked(settings['download_nodes_list'])
2016-02-19 16:04:01 +00:00
self.retranslateUi()
2016-04-26 19:56:06 +00:00
self.proxy.stateChanged.connect(lambda x: self.activate())
self.activate()
2016-02-19 16:04:01 +00:00
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate("NetworkSettings", "Network settings"))
self.ipv.setText(QtWidgets.QApplication.translate("Form", "IPv6"))
self.udp.setText(QtWidgets.QApplication.translate("Form", "UDP"))
self.proxy.setText(QtWidgets.QApplication.translate("Form", "Proxy"))
self.label.setText(QtWidgets.QApplication.translate("Form", "IP:"))
self.label_2.setText(QtWidgets.QApplication.translate("Form", "Port:"))
self.reconnect.setText(QtWidgets.QApplication.translate("NetworkSettings", "Restart TOX core"))
self.http.setText(QtWidgets.QApplication.translate("Form", "HTTP"))
self.nodes.setText(QtWidgets.QApplication.translate("Form", "Download nodes list from tox.chat"))
self.warning.setText(QtWidgets.QApplication.translate("Form", "WARNING:\nusing proxy with enabled UDP\ncan produce IP leak"))
2016-04-26 19:56:06 +00:00
def activate(self):
bl = self.proxy.isChecked()
self.proxyip.setEnabled(bl)
self.http.setEnabled(bl)
self.proxyport.setEnabled(bl)
2016-02-19 16:04:01 +00:00
def restart_core(self):
2016-05-09 19:37:11 +00:00
try:
settings = Settings.get_instance()
settings['ipv6_enabled'] = self.ipv.isChecked()
settings['udp_enabled'] = self.udp.isChecked()
settings['proxy_type'] = 2 - int(self.http.isChecked()) if self.proxy.isChecked() else 0
settings['proxy_host'] = str(self.proxyip.text())
settings['proxy_port'] = int(self.proxyport.text())
settings['download_nodes_list'] = self.nodes.isChecked()
2016-05-09 19:37:11 +00:00
settings.save()
# recreate tox instance
Profile.get_instance().reset(self.reset)
self.close()
2016-05-28 10:06:13 +00:00
except Exception as ex:
log('Exception in restart: ' + str(ex))
2016-02-19 16:04:01 +00:00
2016-03-11 11:37:45 +00:00
class PrivacySettings(CenteredWidget):
2016-02-20 20:50:10 +00:00
"""Privacy settings form: history, typing notifications"""
def __init__(self):
super(PrivacySettings, self).__init__()
self.initUI()
2016-05-18 21:38:21 +00:00
self.center()
2016-02-20 20:50:10 +00:00
def initUI(self):
self.setObjectName("privacySettings")
2016-06-29 12:39:44 +00:00
self.resize(370, 600)
self.setMinimumSize(QtCore.QSize(370, 600))
self.setMaximumSize(QtCore.QSize(370, 600))
self.saveHistory = QtWidgets.QCheckBox(self)
2016-06-29 12:39:44 +00:00
self.saveHistory.setGeometry(QtCore.QRect(10, 20, 350, 22))
self.saveUnsentOnly = QtWidgets.QCheckBox(self)
2016-06-29 12:39:44 +00:00
self.saveUnsentOnly.setGeometry(QtCore.QRect(10, 60, 350, 22))
self.fileautoaccept = QtWidgets.QCheckBox(self)
2016-06-29 12:39:44 +00:00
self.fileautoaccept.setGeometry(QtCore.QRect(10, 100, 350, 22))
self.typingNotifications = QtWidgets.QCheckBox(self)
self.typingNotifications.setGeometry(QtCore.QRect(10, 140, 350, 30))
self.inlines = QtWidgets.QCheckBox(self)
self.inlines.setGeometry(QtCore.QRect(10, 180, 350, 30))
self.auto_path = QtWidgets.QLabel(self)
self.auto_path.setGeometry(QtCore.QRect(10, 230, 350, 30))
self.path = QtWidgets.QPlainTextEdit(self)
2016-07-02 19:19:04 +00:00
self.path.setGeometry(QtCore.QRect(10, 265, 350, 45))
self.change_path = QtWidgets.QPushButton(self)
2016-06-29 12:39:44 +00:00
self.change_path.setGeometry(QtCore.QRect(10, 320, 350, 30))
2016-03-03 19:19:09 +00:00
settings = Settings.get_instance()
self.typingNotifications.setChecked(settings['typing_notifications'])
self.fileautoaccept.setChecked(settings['allow_auto_accept'])
self.saveHistory.setChecked(settings['save_history'])
2016-04-14 08:29:59 +00:00
self.inlines.setChecked(settings['allow_inline'])
self.saveUnsentOnly.setChecked(settings['save_unsent_only'])
self.saveUnsentOnly.setEnabled(settings['save_history'])
self.saveHistory.stateChanged.connect(self.update)
2016-03-18 16:33:54 +00:00
self.path.setPlainText(settings['auto_accept_path'] or curr_directory())
self.change_path.clicked.connect(self.new_path)
self.block_user_label = QtWidgets.QLabel(self)
2016-06-29 12:39:44 +00:00
self.block_user_label.setGeometry(QtCore.QRect(10, 360, 350, 30))
self.block_id = QtWidgets.QPlainTextEdit(self)
2016-06-29 12:39:44 +00:00
self.block_id.setGeometry(QtCore.QRect(10, 390, 350, 30))
self.block = QtWidgets.QPushButton(self)
2016-06-29 12:39:44 +00:00
self.block.setGeometry(QtCore.QRect(10, 430, 350, 30))
self.block.clicked.connect(lambda: Profile.get_instance().block_user(self.block_id.toPlainText()) or self.close())
self.blocked_users_label = QtWidgets.QLabel(self)
2016-06-29 12:39:44 +00:00
self.blocked_users_label.setGeometry(QtCore.QRect(10, 470, 350, 30))
self.comboBox = QtWidgets.QComboBox(self)
2016-06-29 12:39:44 +00:00
self.comboBox.setGeometry(QtCore.QRect(10, 500, 350, 30))
self.comboBox.addItems(settings['blocked'])
self.unblock = QtWidgets.QPushButton(self)
2016-06-29 12:39:44 +00:00
self.unblock.setGeometry(QtCore.QRect(10, 540, 350, 30))
self.unblock.clicked.connect(lambda: self.unblock_user())
self.retranslateUi()
2016-02-20 20:50:10 +00:00
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate("privacySettings", "Privacy settings"))
self.saveHistory.setText(QtWidgets.QApplication.translate("privacySettings", "Save chat history"))
self.fileautoaccept.setText(QtWidgets.QApplication.translate("privacySettings", "Allow file auto accept"))
self.typingNotifications.setText(QtWidgets.QApplication.translate("privacySettings", "Send typing notifications"))
self.auto_path.setText(QtWidgets.QApplication.translate("privacySettings", "Auto accept default path:"))
self.change_path.setText(QtWidgets.QApplication.translate("privacySettings", "Change"))
self.inlines.setText(QtWidgets.QApplication.translate("privacySettings", "Allow inlines"))
self.block_user_label.setText(QtWidgets.QApplication.translate("privacySettings", "Block by public key:"))
self.blocked_users_label.setText(QtWidgets.QApplication.translate("privacySettings", "Blocked users:"))
self.unblock.setText(QtWidgets.QApplication.translate("privacySettings", "Unblock"))
self.block.setText(QtWidgets.QApplication.translate("privacySettings", "Block user"))
self.saveUnsentOnly.setText(QtWidgets.QApplication.translate("privacySettings", "Save unsent messages only"))
def update(self, new_state):
self.saveUnsentOnly.setEnabled(new_state)
if not new_state:
self.saveUnsentOnly.setChecked(False)
def unblock_user(self):
if not self.comboBox.count():
return
title = QtWidgets.QApplication.translate("privacySettings", "Add to friend list")
info = QtWidgets.QApplication.translate("privacySettings", "Do you want to add this user to friend list?")
reply = QtWidgets.QMessageBox.question(None, title, info, QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
Profile.get_instance().unblock_user(self.comboBox.currentText(), reply == QtWidgets.QMessageBox.Yes)
self.close()
2016-02-20 20:50:10 +00:00
def closeEvent(self, event):
2016-03-03 19:19:09 +00:00
settings = Settings.get_instance()
settings['typing_notifications'] = self.typingNotifications.isChecked()
settings['allow_auto_accept'] = self.fileautoaccept.isChecked()
2016-03-13 16:14:17 +00:00
if settings['save_history'] and not self.saveHistory.isChecked(): # clear history
reply = QtWidgets.QMessageBox.question(None,
QtWidgets.QApplication.translate("privacySettings",
'Chat history'),
QtWidgets.QApplication.translate("privacySettings",
'History will be cleaned! Continue?'),
QtWidgets.QMessageBox.Yes,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
2016-04-14 08:29:59 +00:00
Profile.get_instance().clear_history()
settings['save_history'] = self.saveHistory.isChecked()
else:
settings['save_history'] = self.saveHistory.isChecked()
if self.saveUnsentOnly.isChecked() and not settings['save_unsent_only']:
reply = QtWidgets.QMessageBox.question(None,
QtWidgets.QApplication.translate("privacySettings",
'Chat history'),
QtWidgets.QApplication.translate("privacySettings",
'History will be cleaned! Continue?'),
QtWidgets.QMessageBox.Yes,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
Profile.get_instance().clear_history(None, True)
settings['save_unsent_only'] = self.saveUnsentOnly.isChecked()
else:
settings['save_unsent_only'] = self.saveUnsentOnly.isChecked()
2016-03-18 16:33:54 +00:00
settings['auto_accept_path'] = self.path.toPlainText()
2016-04-14 08:29:59 +00:00
settings['allow_inline'] = self.inlines.isChecked()
settings.save()
2016-03-18 16:33:54 +00:00
def new_path(self):
directory = QtWidgets.QFileDialog.getExistingDirectory(options=QtWidgets.QFileDialog.DontUseNativeDialog) + '/'
2016-03-18 16:33:54 +00:00
if directory != '/':
self.path.setPlainText(directory)
2016-02-20 20:50:10 +00:00
2016-03-11 11:37:45 +00:00
class NotificationsSettings(CenteredWidget):
2016-02-20 20:50:10 +00:00
"""Notifications settings form"""
def __init__(self):
super(NotificationsSettings, self).__init__()
self.initUI()
2016-05-18 21:38:21 +00:00
self.center()
2016-02-20 20:50:10 +00:00
def initUI(self):
self.setObjectName("notificationsForm")
2017-07-18 18:36:14 +00:00
self.resize(350, 210)
self.setMinimumSize(QtCore.QSize(350, 210))
self.setMaximumSize(QtCore.QSize(350, 210))
self.enableNotifications = QtWidgets.QCheckBox(self)
self.enableNotifications.setGeometry(QtCore.QRect(10, 20, 340, 18))
self.callsSound = QtWidgets.QCheckBox(self)
2017-07-18 18:36:14 +00:00
self.callsSound.setGeometry(QtCore.QRect(10, 170, 340, 18))
self.soundNotifications = QtWidgets.QCheckBox(self)
self.soundNotifications.setGeometry(QtCore.QRect(10, 70, 340, 18))
2017-07-18 18:36:14 +00:00
self.groupNotifications = QtWidgets.QCheckBox(self)
self.groupNotifications.setGeometry(QtCore.QRect(10, 120, 340, 18))
2016-05-02 20:20:02 +00:00
font = QtGui.QFont()
2016-08-05 12:58:25 +00:00
s = Settings.get_instance()
font.setFamily(s['font'])
2016-05-02 20:20:02 +00:00
font.setPointSize(12)
self.callsSound.setFont(font)
self.soundNotifications.setFont(font)
self.enableNotifications.setFont(font)
2017-07-18 18:36:14 +00:00
self.groupNotifications.setFont(font)
2016-02-25 11:22:15 +00:00
self.enableNotifications.setChecked(s['notifications'])
self.soundNotifications.setChecked(s['sound_notifications'])
2017-07-18 18:36:14 +00:00
self.groupNotifications.setChecked(s['group_notifications'])
2016-02-25 11:22:15 +00:00
self.callsSound.setChecked(s['calls_sound'])
2016-02-20 20:50:10 +00:00
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate("notificationsForm", "Notification settings"))
self.enableNotifications.setText(QtWidgets.QApplication.translate("notificationsForm", "Enable notifications"))
2017-07-18 18:36:14 +00:00
self.groupNotifications.setText(QtWidgets.QApplication.translate("notificationsForm", "Notify about all messages in groups"))
self.callsSound.setText(QtWidgets.QApplication.translate("notificationsForm", "Enable call\'s sound"))
self.soundNotifications.setText(QtWidgets.QApplication.translate("notificationsForm", "Enable sound notifications"))
2016-02-25 11:22:15 +00:00
def closeEvent(self, *args, **kwargs):
2016-03-03 19:19:09 +00:00
settings = Settings.get_instance()
2016-02-25 11:22:15 +00:00
settings['notifications'] = self.enableNotifications.isChecked()
settings['sound_notifications'] = self.soundNotifications.isChecked()
2017-07-18 18:36:14 +00:00
settings['group_notifications'] = self.groupNotifications.isChecked()
2016-02-25 11:22:15 +00:00
settings['calls_sound'] = self.callsSound.isChecked()
settings.save()
2016-02-20 20:50:10 +00:00
2016-03-11 11:37:45 +00:00
class InterfaceSettings(CenteredWidget):
2016-02-20 20:50:10 +00:00
"""Interface settings form"""
def __init__(self):
super(InterfaceSettings, self).__init__()
self.initUI()
2016-05-18 21:38:21 +00:00
self.center()
2016-02-20 20:50:10 +00:00
def initUI(self):
self.setObjectName("interfaceForm")
2016-08-05 12:58:25 +00:00
self.setMinimumSize(QtCore.QSize(400, 650))
self.setMaximumSize(QtCore.QSize(400, 650))
self.label = QtWidgets.QLabel(self)
self.label.setGeometry(QtCore.QRect(30, 10, 370, 20))
2016-08-05 12:58:25 +00:00
settings = Settings.get_instance()
2016-02-20 20:50:10 +00:00
font = QtGui.QFont()
font.setPointSize(14)
2016-02-20 20:50:10 +00:00
font.setBold(True)
2016-08-05 12:58:25 +00:00
font.setFamily(settings['font'])
2016-02-20 20:50:10 +00:00
self.label.setFont(font)
self.themeSelect = QtWidgets.QComboBox(self)
self.themeSelect.setGeometry(QtCore.QRect(30, 40, 120, 30))
2017-05-01 23:59:24 +00:00
self.themeSelect.addItems(list(settings.built_in_themes().keys()))
2016-04-04 09:20:32 +00:00
theme = settings['theme']
2017-05-01 23:59:24 +00:00
if theme in settings.built_in_themes().keys():
index = list(settings.built_in_themes().keys()).index(theme)
2016-06-11 12:37:52 +00:00
else:
index = 0
self.themeSelect.setCurrentIndex(index)
self.lang_choose = QtWidgets.QComboBox(self)
self.lang_choose.setGeometry(QtCore.QRect(30, 110, 120, 30))
2016-07-02 19:19:04 +00:00
supported = sorted(Settings.supported_languages().keys(), reverse=True)
2016-06-18 20:50:12 +00:00
for key in supported:
self.lang_choose.insertItem(0, key)
if settings['language'] == key:
self.lang_choose.setCurrentIndex(0)
self.lang = QtWidgets.QLabel(self)
self.lang.setGeometry(QtCore.QRect(30, 80, 370, 20))
2016-04-04 09:20:32 +00:00
self.lang.setFont(font)
self.mirror_mode = QtWidgets.QCheckBox(self)
self.mirror_mode.setGeometry(QtCore.QRect(30, 160, 370, 20))
2016-06-11 12:37:52 +00:00
self.mirror_mode.setChecked(settings['mirror_mode'])
self.smileys = QtWidgets.QCheckBox(self)
2016-06-11 12:37:52 +00:00
self.smileys.setGeometry(QtCore.QRect(30, 190, 120, 20))
self.smileys.setChecked(settings['smileys'])
self.smiley_pack_label = QtWidgets.QLabel(self)
self.smiley_pack_label.setGeometry(QtCore.QRect(30, 230, 370, 20))
2016-06-11 12:37:52 +00:00
self.smiley_pack_label.setFont(font)
self.smiley_pack = QtWidgets.QComboBox(self)
2016-06-11 12:37:52 +00:00
self.smiley_pack.setGeometry(QtCore.QRect(30, 260, 160, 30))
sm = smileys.SmileyLoader.get_instance()
self.smiley_pack.addItems(sm.get_packs_list())
try:
ind = sm.get_packs_list().index(settings['smiley_pack'])
except:
ind = sm.get_packs_list().index('default')
self.smiley_pack.setCurrentIndex(ind)
self.messages_font_size_label = QtWidgets.QLabel(self)
self.messages_font_size_label.setGeometry(QtCore.QRect(30, 300, 370, 20))
self.messages_font_size_label.setFont(font)
self.messages_font_size = QtWidgets.QComboBox(self)
self.messages_font_size.setGeometry(QtCore.QRect(30, 330, 160, 30))
2017-08-30 19:20:31 +00:00
self.messages_font_size.addItems([str(x) for x in range(10, 25)])
self.messages_font_size.setCurrentIndex(settings['message_font_size'] - 10)
self.unread = QtWidgets.QPushButton(self)
2016-08-05 12:58:25 +00:00
self.unread.setGeometry(QtCore.QRect(30, 470, 340, 30))
self.unread.clicked.connect(self.select_color)
self.compact_mode = QtWidgets.QCheckBox(self)
2016-07-10 19:32:35 +00:00
self.compact_mode.setGeometry(QtCore.QRect(30, 380, 370, 20))
2016-07-01 13:25:46 +00:00
self.compact_mode.setChecked(settings['compact_mode'])
self.close_to_tray = QtWidgets.QCheckBox(self)
2016-08-05 12:58:25 +00:00
self.close_to_tray.setGeometry(QtCore.QRect(30, 410, 370, 20))
self.close_to_tray.setChecked(settings['close_to_tray'])
self.show_avatars = QtWidgets.QCheckBox(self)
2016-08-05 12:58:25 +00:00
self.show_avatars.setGeometry(QtCore.QRect(30, 440, 370, 20))
2016-07-13 20:09:34 +00:00
self.show_avatars.setChecked(settings['show_avatars'])
self.choose_font = QtWidgets.QPushButton(self)
2016-08-05 12:58:25 +00:00
self.choose_font.setGeometry(QtCore.QRect(30, 510, 340, 30))
self.choose_font.clicked.connect(self.new_font)
self.import_smileys = QtWidgets.QPushButton(self)
2016-08-05 12:58:25 +00:00
self.import_smileys.setGeometry(QtCore.QRect(30, 550, 340, 30))
2016-07-10 19:32:35 +00:00
self.import_smileys.clicked.connect(self.import_sm)
self.import_stickers = QtWidgets.QPushButton(self)
2016-08-05 12:58:25 +00:00
self.import_stickers.setGeometry(QtCore.QRect(30, 590, 340, 30))
2016-07-10 19:32:35 +00:00
self.import_stickers.clicked.connect(self.import_st)
2016-02-20 20:50:10 +00:00
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.show_avatars.setText(QtWidgets.QApplication.translate("interfaceForm", "Show avatars in chat"))
self.setWindowTitle(QtWidgets.QApplication.translate("interfaceForm", "Interface settings"))
self.label.setText(QtWidgets.QApplication.translate("interfaceForm", "Theme:"))
self.lang.setText(QtWidgets.QApplication.translate("interfaceForm", "Language:"))
self.smileys.setText(QtWidgets.QApplication.translate("interfaceForm", "Smileys"))
self.smiley_pack_label.setText(QtWidgets.QApplication.translate("interfaceForm", "Smiley pack:"))
self.mirror_mode.setText(QtWidgets.QApplication.translate("interfaceForm", "Mirror mode"))
self.messages_font_size_label.setText(QtWidgets.QApplication.translate("interfaceForm", "Messages font size:"))
self.unread.setText(QtWidgets.QApplication.translate("interfaceForm", "Select unread messages notification color"))
self.compact_mode.setText(QtWidgets.QApplication.translate("interfaceForm", "Compact contact list"))
self.import_smileys.setText(QtWidgets.QApplication.translate("interfaceForm", "Import smiley pack"))
self.import_stickers.setText(QtWidgets.QApplication.translate("interfaceForm", "Import sticker pack"))
self.close_to_tray.setText(QtWidgets.QApplication.translate("interfaceForm", "Close to tray"))
self.choose_font.setText(QtWidgets.QApplication.translate("interfaceForm", "Select font"))
2016-07-10 19:32:35 +00:00
def import_st(self):
directory = QtWidgets.QFileDialog.getExistingDirectory(self,
QtWidgets.QApplication.translate("MainWindow",
'Choose folder with sticker pack'),
2016-07-10 19:32:35 +00:00
curr_directory(),
QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontUseNativeDialog)
2016-07-10 19:32:35 +00:00
if directory:
src = directory + '/'
dest = curr_directory() + '/stickers/' + os.path.basename(directory) + '/'
copy(src, dest)
def import_sm(self):
directory = QtWidgets.QFileDialog.getExistingDirectory(self,
QtWidgets.QApplication.translate("MainWindow",
'Choose folder with smiley pack'),
2016-07-10 19:32:35 +00:00
curr_directory(),
QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontUseNativeDialog)
2016-07-10 19:32:35 +00:00
if directory:
src = directory + '/'
dest = curr_directory() + '/smileys/' + os.path.basename(directory) + '/'
copy(src, dest)
2016-08-05 12:58:25 +00:00
def new_font(self):
settings = Settings.get_instance()
font, ok = QtWidgets.QFontDialog.getFont(QtGui.QFont(settings['font'], 10), self)
2016-08-05 12:58:25 +00:00
if ok:
settings['font'] = font.family()
settings.save()
msgBox = QtWidgets.QMessageBox()
text = QtWidgets.QApplication.translate("interfaceForm", 'Restart app to apply settings')
msgBox.setWindowTitle(QtWidgets.QApplication.translate("interfaceForm", 'Restart required'))
2016-08-05 12:58:25 +00:00
msgBox.setText(text)
msgBox.exec_()
def select_color(self):
2016-09-03 11:10:36 +00:00
settings = Settings.get_instance()
col = QtWidgets.QColorDialog.getColor(QtGui.QColor(settings['unread_color']))
if col.isValid():
name = col.name()
settings['unread_color'] = name
settings.save()
def closeEvent(self, event):
2016-03-03 19:19:09 +00:00
settings = Settings.get_instance()
2016-06-11 12:37:52 +00:00
settings['theme'] = str(self.themeSelect.currentText())
2017-05-01 23:59:24 +00:00
try:
theme = settings['theme']
2017-06-20 19:55:48 +00:00
app = QtWidgets.QApplication.instance()
2017-05-01 23:59:24 +00:00
with open(curr_directory() + settings.built_in_themes()[theme]) as fl:
style = fl.read()
app.setStyleSheet(style)
except IsADirectoryError:
app.setStyleSheet('') # for default style
2016-06-11 12:37:52 +00:00
settings['smileys'] = self.smileys.isChecked()
2016-07-01 13:25:46 +00:00
restart = False
if settings['mirror_mode'] != self.mirror_mode.isChecked():
settings['mirror_mode'] = self.mirror_mode.isChecked()
2016-07-01 13:25:46 +00:00
restart = True
if settings['compact_mode'] != self.compact_mode.isChecked():
settings['compact_mode'] = self.compact_mode.isChecked()
restart = True
2016-07-13 20:09:34 +00:00
if settings['show_avatars'] != self.show_avatars.isChecked():
settings['show_avatars'] = self.show_avatars.isChecked()
restart = True
2016-06-11 12:37:52 +00:00
settings['smiley_pack'] = self.smiley_pack.currentText()
2016-08-05 12:58:25 +00:00
settings['close_to_tray'] = self.close_to_tray.isChecked()
2016-06-11 12:37:52 +00:00
smileys.SmileyLoader.get_instance().load_pack()
2016-04-04 09:20:32 +00:00
language = self.lang_choose.currentText()
if settings['language'] != language:
settings['language'] = language
2016-06-18 20:50:12 +00:00
text = self.lang_choose.currentText()
path = Settings.supported_languages()[text]
app = QtWidgets.QApplication.instance()
2016-04-04 09:20:32 +00:00
app.removeTranslator(app.translator)
app.translator.load(curr_directory() + '/translations/' + path)
app.installTranslator(app.translator)
settings['message_font_size'] = self.messages_font_size.currentIndex() + 10
Profile.get_instance().update()
2016-04-04 09:20:32 +00:00
settings.save()
2016-07-01 13:25:46 +00:00
if restart:
msgBox = QtWidgets.QMessageBox()
text = QtWidgets.QApplication.translate("interfaceForm", 'Restart app to apply settings')
msgBox.setWindowTitle(QtWidgets.QApplication.translate("interfaceForm", 'Restart required'))
2016-07-01 13:25:46 +00:00
msgBox.setText(text)
msgBox.exec_()
2016-04-04 09:20:32 +00:00
2016-04-24 10:45:11 +00:00
class AudioSettings(CenteredWidget):
2016-06-05 17:17:39 +00:00
"""
Audio calls settings form
"""
2016-04-24 10:45:11 +00:00
def __init__(self):
super(AudioSettings, self).__init__()
self.initUI()
self.retranslateUi()
2016-05-18 21:38:21 +00:00
self.center()
2016-04-24 10:45:11 +00:00
def initUI(self):
self.setObjectName("audioSettingsForm")
self.resize(400, 150)
self.setMinimumSize(QtCore.QSize(400, 150))
self.setMaximumSize(QtCore.QSize(400, 150))
self.in_label = QtWidgets.QLabel(self)
2016-04-24 10:45:11 +00:00
self.in_label.setGeometry(QtCore.QRect(25, 5, 350, 20))
self.out_label = QtWidgets.QLabel(self)
2016-04-24 10:45:11 +00:00
self.out_label.setGeometry(QtCore.QRect(25, 65, 350, 20))
2016-08-05 12:58:25 +00:00
settings = Settings.get_instance()
2016-04-24 10:45:11 +00:00
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
2016-08-05 12:58:25 +00:00
font.setFamily(settings['font'])
2016-04-24 10:45:11 +00:00
self.in_label.setFont(font)
self.out_label.setFont(font)
self.input = QtWidgets.QComboBox(self)
2016-04-24 10:45:11 +00:00
self.input.setGeometry(QtCore.QRect(25, 30, 350, 30))
self.output = QtWidgets.QComboBox(self)
2016-04-24 10:45:11 +00:00
self.output.setGeometry(QtCore.QRect(25, 90, 350, 30))
p = pyaudio.PyAudio()
self.in_indexes, self.out_indexes = [], []
2016-06-21 11:58:11 +00:00
for i in range(p.get_device_count()):
2016-04-24 10:45:11 +00:00
device = p.get_device_info_by_index(i)
if device["maxInputChannels"]:
2016-06-21 11:58:11 +00:00
self.input.addItem(str(device["name"]))
2016-04-24 10:45:11 +00:00
self.in_indexes.append(i)
if device["maxOutputChannels"]:
2016-06-21 11:58:11 +00:00
self.output.addItem(str(device["name"]))
2016-04-24 10:45:11 +00:00
self.out_indexes.append(i)
self.input.setCurrentIndex(self.in_indexes.index(settings.audio['input']))
self.output.setCurrentIndex(self.out_indexes.index(settings.audio['output']))
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate("audioSettingsForm", "Audio settings"))
self.in_label.setText(QtWidgets.QApplication.translate("audioSettingsForm", "Input device:"))
self.out_label.setText(QtWidgets.QApplication.translate("audioSettingsForm", "Output device:"))
2016-04-24 10:45:11 +00:00
def closeEvent(self, event):
settings = Settings.get_instance()
settings.audio['input'] = self.in_indexes[self.input.currentIndex()]
settings.audio['output'] = self.out_indexes[self.output.currentIndex()]
settings.save()
2016-05-28 10:06:13 +00:00
2017-07-13 18:02:42 +00:00
class DesktopAreaSelectionWindow(RubberBandWindow):
def mouseReleaseEvent(self, event):
if self.rubberband.isVisible():
self.rubberband.hide()
rect = self.rubberband.geometry()
width, height = rect.width(), rect.height()
if width >= 8 and height >= 8:
2017-10-07 21:39:08 +00:00
self.parent.save(rect.x(), rect.y(), width - (width % 4), height - (height % 4))
2017-07-13 18:02:42 +00:00
self.close()
2017-06-13 19:32:32 +00:00
class VideoSettings(CenteredWidget):
"""
Audio calls settings form
"""
def __init__(self):
super().__init__()
self.initUI()
self.retranslateUi()
self.center()
2017-07-13 18:02:42 +00:00
self.desktopAreaSelection = None
2017-06-13 19:32:32 +00:00
def initUI(self):
self.setObjectName("videoSettingsForm")
2017-06-17 21:50:42 +00:00
self.resize(400, 120)
self.setMinimumSize(QtCore.QSize(400, 120))
self.setMaximumSize(QtCore.QSize(400, 120))
2017-06-13 19:32:32 +00:00
self.in_label = QtWidgets.QLabel(self)
self.in_label.setGeometry(QtCore.QRect(25, 5, 350, 20))
settings = Settings.get_instance()
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setFamily(settings['font'])
self.in_label.setFont(font)
2017-06-17 21:50:42 +00:00
self.video_size = QtWidgets.QComboBox(self)
self.video_size.setGeometry(QtCore.QRect(25, 70, 350, 30))
2017-06-13 19:32:32 +00:00
self.input = QtWidgets.QComboBox(self)
self.input.setGeometry(QtCore.QRect(25, 30, 350, 30))
2017-06-17 21:50:42 +00:00
self.input.currentIndexChanged.connect(self.selectionChanged)
2017-07-13 18:02:42 +00:00
self.button = QtWidgets.QPushButton(self)
self.button.clicked.connect(self.button_clicked)
self.button.setGeometry(QtCore.QRect(25, 70, 350, 30))
2017-06-13 19:32:32 +00:00
import cv2
2017-07-12 18:18:21 +00:00
self.devices = [-1]
screen = QtWidgets.QApplication.primaryScreen()
size = screen.size()
self.frame_max_sizes = [(size.width(), size.height())]
desktop = QtWidgets.QApplication.translate("videoSettingsForm", "Desktop")
self.input.addItem(desktop)
2017-06-13 19:42:05 +00:00
for i in range(10):
2017-06-13 19:32:32 +00:00
v = cv2.VideoCapture(i)
if v.isOpened():
2017-06-17 21:30:08 +00:00
v.set(cv2.CAP_PROP_FRAME_WIDTH, 10000)
v.set(cv2.CAP_PROP_FRAME_HEIGHT, 10000)
width = int(v.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(v.get(cv2.CAP_PROP_FRAME_HEIGHT))
2017-06-13 19:32:32 +00:00
del v
self.devices.append(i)
2017-06-17 21:30:08 +00:00
self.frame_max_sizes.append((width, height))
2017-06-13 19:32:32 +00:00
self.input.addItem('Device #' + str(i))
2017-06-20 19:55:48 +00:00
try:
index = self.devices.index(settings.video['device'])
2017-06-17 21:30:08 +00:00
self.input.setCurrentIndex(index)
2017-06-20 19:55:48 +00:00
except:
print('Video devices error!')
2017-06-13 19:32:32 +00:00
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate("videoSettingsForm", "Video settings"))
self.in_label.setText(QtWidgets.QApplication.translate("videoSettingsForm", "Device:"))
2017-07-13 18:02:42 +00:00
self.button.setText(QtWidgets.QApplication.translate("videoSettingsForm", "Select region"))
def button_clicked(self):
self.desktopAreaSelection = DesktopAreaSelectionWindow(self)
2017-06-13 19:32:32 +00:00
def closeEvent(self, event):
2017-07-15 20:11:49 +00:00
if self.input.currentIndex() == 0:
return
2017-07-06 18:39:15 +00:00
try:
settings = Settings.get_instance()
settings.video['device'] = self.devices[self.input.currentIndex()]
text = self.video_size.currentText()
settings.video['width'] = int(text.split(' ')[0])
settings.video['height'] = int(text.split(' ')[-1])
settings.save()
except Exception as ex:
print('Saving video settings error: ' + str(ex))
2017-06-13 19:32:32 +00:00
2017-07-14 18:37:50 +00:00
def save(self, x, y, width, height):
2017-07-13 18:02:42 +00:00
self.desktopAreaSelection = None
settings = Settings.get_instance()
settings.video['device'] = -1
settings.video['width'] = width
settings.video['height'] = height
2017-07-14 18:37:50 +00:00
settings.video['x'] = x
settings.video['y'] = y
2017-07-13 18:02:42 +00:00
settings.save()
2017-06-17 21:30:08 +00:00
def selectionChanged(self):
2017-07-13 18:02:42 +00:00
if self.input.currentIndex() == 0:
self.button.setVisible(True)
self.video_size.setVisible(False)
else:
self.button.setVisible(False)
self.video_size.setVisible(True)
2017-06-17 21:30:08 +00:00
width, height = self.frame_max_sizes[self.input.currentIndex()]
2017-06-17 21:50:42 +00:00
self.video_size.clear()
2017-06-17 21:30:08 +00:00
dims = [
(320, 240),
(640, 360),
(640, 480),
(720, 480),
(1280, 720),
(1920, 1080),
(2560, 1440)
]
for w, h in dims:
if w <= width and h <= height:
2017-06-17 21:50:42 +00:00
self.video_size.addItem(str(w) + ' * ' + str(h))
2017-06-17 21:30:08 +00:00
2017-06-13 19:32:32 +00:00
2016-05-28 10:06:13 +00:00
class PluginsSettings(CenteredWidget):
2016-06-05 17:17:39 +00:00
"""
Plugins settings form
"""
2016-05-28 10:06:13 +00:00
def __init__(self):
super(PluginsSettings, self).__init__()
self.initUI()
self.center()
self.retranslateUi()
def initUI(self):
self.resize(400, 210)
self.setMinimumSize(QtCore.QSize(400, 210))
self.setMaximumSize(QtCore.QSize(400, 210))
self.comboBox = QtWidgets.QComboBox(self)
2016-05-28 10:06:13 +00:00
self.comboBox.setGeometry(QtCore.QRect(30, 10, 340, 30))
self.label = QtWidgets.QLabel(self)
2016-05-28 10:06:13 +00:00
self.label.setGeometry(QtCore.QRect(30, 40, 340, 90))
self.label.setWordWrap(True)
self.button = QtWidgets.QPushButton(self)
2016-05-28 10:06:13 +00:00
self.button.setGeometry(QtCore.QRect(30, 130, 340, 30))
self.button.clicked.connect(self.button_click)
self.open = QtWidgets.QPushButton(self)
2016-05-28 10:06:13 +00:00
self.open.setGeometry(QtCore.QRect(30, 170, 340, 30))
self.open.clicked.connect(self.open_plugin)
self.pl_loader = plugin_support.PluginLoader.get_instance()
self.update_list()
self.comboBox.currentIndexChanged.connect(self.show_data)
self.show_data()
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate('PluginsForm', "Plugins"))
self.open.setText(QtWidgets.QApplication.translate('PluginsForm', "Open selected plugin"))
2016-05-28 10:06:13 +00:00
def open_plugin(self):
ind = self.comboBox.currentIndex()
plugin = self.data[ind]
window = self.pl_loader.plugin_window(plugin[-1])
if window is not None:
self.window = window
self.window.show()
else:
msgBox = QtWidgets.QMessageBox()
text = QtWidgets.QApplication.translate("PluginsForm", 'No GUI found for this plugin')
msgBox.setWindowTitle(QtWidgets.QApplication.translate("PluginsForm", 'Error'))
2016-05-28 10:06:13 +00:00
msgBox.setText(text)
msgBox.exec_()
def update_list(self):
self.comboBox.clear()
data = self.pl_loader.get_plugins_list()
self.comboBox.addItems(list(map(lambda x: x[0], data)))
2016-05-28 10:06:13 +00:00
self.data = data
def show_data(self):
ind = self.comboBox.currentIndex()
2016-06-05 11:59:36 +00:00
if len(self.data):
plugin = self.data[ind]
descr = plugin[2] or QtWidgets.QApplication.translate("PluginsForm", "No description available")
2016-06-05 11:59:36 +00:00
self.label.setText(descr)
if plugin[1]:
self.button.setText(QtWidgets.QApplication.translate("PluginsForm", "Disable plugin"))
2016-06-05 11:59:36 +00:00
else:
self.button.setText(QtWidgets.QApplication.translate("PluginsForm", "Enable plugin"))
2016-05-28 10:06:13 +00:00
else:
2016-06-05 11:59:36 +00:00
self.open.setVisible(False)
self.button.setVisible(False)
self.label.setText(QtWidgets.QApplication.translate("PluginsForm", "No plugins found"))
2016-05-28 10:06:13 +00:00
def button_click(self):
ind = self.comboBox.currentIndex()
plugin = self.data[ind]
self.pl_loader.toggle_plugin(plugin[-1])
plugin[1] = not plugin[1]
if plugin[1]:
self.button.setText(QtWidgets.QApplication.translate("PluginsForm", "Disable plugin"))
2016-05-28 10:06:13 +00:00
else:
self.button.setText(QtWidgets.QApplication.translate("PluginsForm", "Enable plugin"))
class UpdateSettings(CenteredWidget):
"""
2016-10-09 13:04:59 +00:00
Updates settings form
"""
def __init__(self):
super(UpdateSettings, self).__init__()
self.initUI()
self.center()
def initUI(self):
self.setObjectName("updateSettingsForm")
self.resize(400, 150)
self.setMinimumSize(QtCore.QSize(400, 120))
self.setMaximumSize(QtCore.QSize(400, 120))
self.in_label = QtWidgets.QLabel(self)
self.in_label.setGeometry(QtCore.QRect(25, 5, 350, 20))
settings = Settings.get_instance()
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setFamily(settings['font'])
self.in_label.setFont(font)
self.autoupdate = QtWidgets.QComboBox(self)
self.autoupdate.setGeometry(QtCore.QRect(25, 30, 350, 30))
self.button = QtWidgets.QPushButton(self)
self.button.setGeometry(QtCore.QRect(25, 70, 350, 30))
self.button.setEnabled(settings['update'])
self.button.clicked.connect(self.update_client)
self.retranslateUi()
self.autoupdate.setCurrentIndex(settings['update'])
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
self.setWindowTitle(QtWidgets.QApplication.translate("updateSettingsForm", "Update settings"))
self.in_label.setText(QtWidgets.QApplication.translate("updateSettingsForm", "Select update mode:"))
self.button.setText(QtWidgets.QApplication.translate("updateSettingsForm", "Update Toxygen"))
self.autoupdate.addItem(QtWidgets.QApplication.translate("updateSettingsForm", "Disabled"))
self.autoupdate.addItem(QtWidgets.QApplication.translate("updateSettingsForm", "Manual"))
self.autoupdate.addItem(QtWidgets.QApplication.translate("updateSettingsForm", "Auto"))
def closeEvent(self, event):
settings = Settings.get_instance()
settings['update'] = self.autoupdate.currentIndex()
settings.save()
def update_client(self):
2016-10-15 16:47:02 +00:00
if not updater.connection_available():
msgBox = QtWidgets.QMessageBox()
2016-10-15 16:47:02 +00:00
msgBox.setWindowTitle(
QtWidgets.QApplication.translate("updateSettingsForm", "Error"))
text = (QtWidgets.QApplication.translate("updateSettingsForm", 'Problems with internet connection'))
2016-10-15 16:47:02 +00:00
msgBox.setText(text)
msgBox.exec_()
return
2016-10-22 17:31:34 +00:00
if not updater.updater_available():
msgBox = QtWidgets.QMessageBox()
2016-10-22 17:31:34 +00:00
msgBox.setWindowTitle(
QtWidgets.QApplication.translate("updateSettingsForm", "Error"))
text = (QtWidgets.QApplication.translate("updateSettingsForm", 'Updater not found'))
2016-10-22 17:31:34 +00:00
msgBox.setText(text)
msgBox.exec_()
return
version = updater.check_for_updates()
if version is not None:
updater.download(version)
QtWidgets.QApplication.closeAllWindows()
else:
msgBox = QtWidgets.QMessageBox()
msgBox.setWindowTitle(
QtWidgets.QApplication.translate("updateSettingsForm", "No updates found"))
text = (QtWidgets.QApplication.translate("updateSettingsForm", 'Toxygen is up to date'))
msgBox.setText(text)
msgBox.exec_()