From 13b2d17786d1e1f5a1ade312573fba9ac9ff60be Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 24 May 2018 23:58:39 +0300 Subject: [PATCH] notifications and audio settings views converted --- toxygen/ui/create_profile_screen.py | 4 +- toxygen/ui/groups_widgets.py | 13 +- toxygen/ui/login_screen.py | 20 +-- toxygen/ui/menu.py | 118 ++++++------------ toxygen/ui/views/audio_settings_screen.ui | 87 +++++++++++++ toxygen/ui/views/create_profile_screen.ui | 18 +-- .../ui/views/notifications_settings_screen.ui | 71 +++++++++++ 7 files changed, 229 insertions(+), 102 deletions(-) create mode 100644 toxygen/ui/views/audio_settings_screen.ui create mode 100644 toxygen/ui/views/notifications_settings_screen.ui diff --git a/toxygen/ui/create_profile_screen.py b/toxygen/ui/create_profile_screen.py index 9d7b503..512c141 100644 --- a/toxygen/ui/create_profile_screen.py +++ b/toxygen/ui/create_profile_screen.py @@ -29,9 +29,9 @@ class CreateProfileScreen(CenteredWidget, DialogWithResult): uic.loadUi(util.get_views_path('create_profile_screen'), self) self.center() self.createProfile.clicked.connect(self._create_profile) - self.retranslateUi() + self._retranslate_ui() - def retranslateUi(self): + def _retranslate_ui(self): self.setWindowTitle(util_ui.tr('New profile settings')) self.defaultFolder.setText(util_ui.tr('Save in default folder')) self.programFolder.setText(util_ui.tr('Save in program folder')) diff --git a/toxygen/ui/groups_widgets.py b/toxygen/ui/groups_widgets.py index 4dc39d5..c6d0248 100644 --- a/toxygen/ui/groups_widgets.py +++ b/toxygen/ui/groups_widgets.py @@ -11,11 +11,14 @@ class CreateGroupScreen(CenteredWidget): self._groups_service = groups_service uic.loadUi(util.get_views_path('create_group_screen'), self) self.center() - self.retranslateUi() + self._update_ui() + + def _update_ui(self): + self._retranslate_ui() self.addGroupButton.clicked.connect(self._create_group) self.groupNameLineEdit.textChanged.connect(self._group_name_changed) - def retranslateUi(self): + def _retranslate_ui(self): self.setWindowTitle(util_ui.tr('Create new group chat')) self.groupNameLabel.setText(util_ui.tr('Group name:')) self.groupTypeLabel.setText(util_ui.tr('Group type:')) @@ -42,11 +45,13 @@ class JoinGroupScreen(CenteredWidget): self._groups_service = groups_service uic.loadUi(util.get_views_path('join_group_screen'), self) self.center() - self.retranslateUi() + + def _update_ui(self): + self._retranslate_ui() self.chatIdLineEdit.textChanged.connect(self._chat_id_changed) self.joinGroupButton.clicked.connect(self._join_group) - def retranslateUi(self): + def _retranslate_ui(self): self.setWindowTitle(util_ui.tr('Join public group chat')) self.chatIdLabel.setText(util_ui.tr('Group ID:')) self.passwordLabel.setText(util_ui.tr('Password:')) diff --git a/toxygen/ui/login_screen.py b/toxygen/ui/login_screen.py index 946dc7a..7198c36 100644 --- a/toxygen/ui/login_screen.py +++ b/toxygen/ui/login_screen.py @@ -41,15 +41,6 @@ class LoginScreen(CenteredWidget, DialogWithResult): self._profiles = [] self._update_ui() - def retranslateUi(self): - self.setWindowTitle(util_ui.tr('Log in')) - self.profileNameLineEdit.setPlaceholderText(util_ui.tr('Profile name')) - self.createProfilePushButton.setText(util_ui.tr('Create')) - self.loadProfilePushButton.setText(util_ui.tr('Load profile')) - self.defaultProfileCheckBox.setText(util_ui.tr('Use as default')) - self.existingProfileGroupBox.setTitle(util_ui.tr('Load existing profile')) - self.newProfileGroupBox.setTitle(util_ui.tr('Create new profile')) - def update_select(self, profiles): profiles = sorted(profiles, key=lambda p: p[1]) self._profiles = list(profiles) @@ -59,7 +50,7 @@ class LoginScreen(CenteredWidget, DialogWithResult): def _update_ui(self): self.profileNameLineEdit = LineEditWithEnterSupport(self._create_profile, self) self.profileNameLineEdit.setGeometry(QtCore.QRect(20, 100, 170, 30)) - self.retranslateUi() + self._retranslate_ui() self.createProfilePushButton.clicked.connect(self._create_profile) self.loadProfilePushButton.clicked.connect(self._load_existing_profile) @@ -75,3 +66,12 @@ class LoginScreen(CenteredWidget, DialogWithResult): path = util.join_path(self._profiles[index][0], self._profiles[index][1] + '.tox') result = LoginScreenResult(path, load_as_default) self.close_with_result(result) + + def _retranslate_ui(self): + self.setWindowTitle(util_ui.tr('Log in')) + self.profileNameLineEdit.setPlaceholderText(util_ui.tr('Profile name')) + self.createProfilePushButton.setText(util_ui.tr('Create')) + self.loadProfilePushButton.setText(util_ui.tr('Load profile')) + self.defaultProfileCheckBox.setText(util_ui.tr('Use as default')) + self.existingProfileGroupBox.setTitle(util_ui.tr('Load existing profile')) + self.newProfileGroupBox.setTitle(util_ui.tr('Create new profile')) diff --git a/toxygen/ui/menu.py b/toxygen/ui/menu.py index 2f55bb5..36930dd 100644 --- a/toxygen/ui/menu.py +++ b/toxygen/ui/menu.py @@ -1,4 +1,4 @@ -from PyQt5 import QtCore, QtGui, QtWidgets +from PyQt5 import QtCore, QtGui, QtWidgets, uic from user_data.settings import * from utils.util import * from ui.widgets import CenteredWidget, DataLabel, LineEdit, RubberBandWindow @@ -493,50 +493,31 @@ class NotificationsSettings(CenteredWidget): def __init__(self, setttings): super().__init__() self._settings = setttings - self.initUI() + uic.loadUi(get_views_path('notifications_settings_screen'), self) + self._update_ui() self.center() - def initUI(self): - self.setObjectName("notificationsForm") - 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) - self.callsSound.setGeometry(QtCore.QRect(10, 170, 340, 18)) - self.soundNotifications = QtWidgets.QCheckBox(self) - self.soundNotifications.setGeometry(QtCore.QRect(10, 70, 340, 18)) - self.groupNotifications = QtWidgets.QCheckBox(self) - self.groupNotifications.setGeometry(QtCore.QRect(10, 120, 340, 18)) - font = QtGui.QFont() - font.setFamily(self._settings['font']) - font.setPointSize(12) - self.callsSound.setFont(font) - self.soundNotifications.setFont(font) - self.enableNotifications.setFont(font) - self.groupNotifications.setFont(font) - self.enableNotifications.setChecked(self._settings['notifications']) - self.soundNotifications.setChecked(self._settings['sound_notifications']) - self.groupNotifications.setChecked(self._settings['group_notifications']) - self.callsSound.setChecked(self._settings['calls_sound']) - self.retranslateUi() - QtCore.QMetaObject.connectSlotsByName(self) - - def retranslateUi(self): - self.setWindowTitle(util_ui.tr("Notification settings")) - self.enableNotifications.setText(util_ui.tr("Enable notifications")) - self.groupNotifications.setText(util_ui.tr("Notify about all messages in groups")) - self.callsSound.setText(util_ui.tr("Enable call\'s sound")) - self.soundNotifications.setText(util_ui.tr("Enable sound notifications")) - def closeEvent(self, *args, **kwargs): - self._settings['notifications'] = self.enableNotifications.isChecked() - self._settings['sound_notifications'] = self.soundNotifications.isChecked() - self._settings['group_notifications'] = self.groupNotifications.isChecked() - self._settings['calls_sound'] = self.callsSound.isChecked() + self._settings['notifications'] = self.notificationsCheckBox.isChecked() + self._settings['sound_notifications'] = self.soundNotificationsCheckBox.isChecked() + self._settings['group_notifications'] = self.groupNotificationsCheckBox.isChecked() + self._settings['calls_sound'] = self.callsSoundCheckBox.isChecked() self._settings.save() + def _update_ui(self): + self.notificationsCheckBox.setChecked(self._settings['notifications']) + self.soundNotificationsCheckBox.setChecked(self._settings['sound_notifications']) + self.groupNotificationsCheckBox.setChecked(self._settings['group_notifications']) + self.callsSoundCheckBox.setChecked(self._settings['calls_sound']) + self._retranslate_ui() + + def _retranslate_ui(self): + self.setWindowTitle(util_ui.tr("Notifications settings")) + self.notificationsCheckBox.setText(util_ui.tr("Enable notifications")) + self.groupNotificationsCheckBox.setText(util_ui.tr("Notify about all messages in groups")) + self.callsSoundCheckBox.setText(util_ui.tr("Enable call\'s sound")) + self.soundNotificationsCheckBox.setText(util_ui.tr("Enable sound notifications")) + class InterfaceSettings(CenteredWidget): """Interface settings form""" @@ -729,52 +710,35 @@ class AudioSettings(CenteredWidget): def __init__(self, settings): super().__init__() self._settings = settings - self.initUI() - self.retranslateUi() + self._in_indexes = self._out_indexes = None + uic.loadUi(get_views_path('audio_settings_screen'), self) + self._update_ui() self.center() - 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) - self.in_label.setGeometry(QtCore.QRect(25, 5, 350, 20)) - self.out_label = QtWidgets.QLabel(self) - self.out_label.setGeometry(QtCore.QRect(25, 65, 350, 20)) - font = QtGui.QFont() - font.setPointSize(16) - font.setBold(True) - font.setFamily(self._settings['font']) - self.in_label.setFont(font) - self.out_label.setFont(font) - self.input = QtWidgets.QComboBox(self) - self.input.setGeometry(QtCore.QRect(25, 30, 350, 30)) - self.output = QtWidgets.QComboBox(self) - self.output.setGeometry(QtCore.QRect(25, 90, 350, 30)) + def closeEvent(self, event): + self._settings.audio['input'] = self._in_indexes[self.inputDeviceComboBox.currentIndex()] + self._settings.audio['output'] = self._out_indexes[self.outputDeviceComboBox.currentIndex()] + self._settings.save() + + def _update_ui(self): p = pyaudio.PyAudio() - self.in_indexes, self.out_indexes = [], [] + self._in_indexes, self._out_indexes = [], [] for i in range(p.get_device_count()): device = p.get_device_info_by_index(i) if device["maxInputChannels"]: - self.input.addItem(str(device["name"])) - self.in_indexes.append(i) + self.inputDeviceComboBox.addItem(str(device["name"])) + self._in_indexes.append(i) if device["maxOutputChannels"]: - self.output.addItem(str(device["name"])) - self.out_indexes.append(i) - self.input.setCurrentIndex(self.in_indexes.index(self._settings.audio['input'])) - self.output.setCurrentIndex(self.out_indexes.index(self._settings.audio['output'])) - QtCore.QMetaObject.connectSlotsByName(self) + self.outputDeviceComboBox.addItem(str(device["name"])) + self._out_indexes.append(i) + self.inputDeviceComboBox.setCurrentIndex(self._in_indexes.index(self._settings.audio['input'])) + self.outputDeviceComboBox.setCurrentIndex(self._out_indexes.index(self._settings.audio['output'])) + self._retranslate_ui() - def retranslateUi(self): + def _retranslate_ui(self): self.setWindowTitle(util_ui.tr("Audio settings")) - self.in_label.setText(util_ui.tr("Input device:")) - self.out_label.setText(util_ui.tr("Output device:")) - - def closeEvent(self, event): - self._settings.audio['input'] = self.in_indexes[self.input.currentIndex()] - self._settings.audio['output'] = self.out_indexes[self.output.currentIndex()] - self._settings.save() + self.inputDeviceLabel.setText(util_ui.tr("Input device:")) + self.outputDeviceLabel.setText(util_ui.tr("Output device:")) class DesktopAreaSelectionWindow(RubberBandWindow): diff --git a/toxygen/ui/views/audio_settings_screen.ui b/toxygen/ui/views/audio_settings_screen.ui new file mode 100644 index 0000000..a404592 --- /dev/null +++ b/toxygen/ui/views/audio_settings_screen.ui @@ -0,0 +1,87 @@ + + + Form + + + + 0 + 0 + 315 + 218 + + + + + 315 + 218 + + + + + 315 + 218 + + + + Form + + + + + 30 + 10 + 261 + 30 + + + + + 16 + + + + TextLabel + + + + + + 30 + 100 + 261 + 30 + + + + + 16 + + + + TextLabel + + + + + + 30 + 50 + 255 + 41 + + + + + + + 30 + 140 + 255 + 41 + + + + + + + diff --git a/toxygen/ui/views/create_profile_screen.ui b/toxygen/ui/views/create_profile_screen.ui index 5407dca..bfffee5 100644 --- a/toxygen/ui/views/create_profile_screen.ui +++ b/toxygen/ui/views/create_profile_screen.ui @@ -7,19 +7,19 @@ 0 0 400 - 380 + 340 400 - 380 + 340 400 - 380 + 340 @@ -29,7 +29,7 @@ 30 - 290 + 270 341 51 @@ -42,7 +42,7 @@ 30 - 190 + 170 341 41 @@ -55,7 +55,7 @@ 30 - 140 + 120 341 41 @@ -68,7 +68,7 @@ 30 - 100 + 80 330 20 @@ -97,7 +97,7 @@ 30 - 50 + 40 330 23 @@ -110,7 +110,7 @@ 30 - 250 + 220 341 30 diff --git a/toxygen/ui/views/notifications_settings_screen.ui b/toxygen/ui/views/notifications_settings_screen.ui new file mode 100644 index 0000000..67e2dc6 --- /dev/null +++ b/toxygen/ui/views/notifications_settings_screen.ui @@ -0,0 +1,71 @@ + + + Form + + + + 0 + 0 + 320 + 201 + + + + Form + + + + + 20 + 20 + 271 + 41 + + + + CheckBox + + + + + + 20 + 60 + 271 + 41 + + + + CheckBox + + + + + + 20 + 100 + 271 + 41 + + + + CheckBox + + + + + + 20 + 140 + 271 + 41 + + + + CheckBox + + + + + +