From b0e82dfd08a523867749263732a91c953ad42ee3 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 5 Aug 2016 15:58:25 +0300 Subject: [PATCH] font and closing to tray update --- toxygen/avwidgets.py | 2 +- toxygen/list_items.py | 12 +++++------ toxygen/main.py | 10 ++++++--- toxygen/mainscreen.py | 25 ++++++++++++++-------- toxygen/menu.py | 49 ++++++++++++++++++++++++++++++++++--------- toxygen/settings.py | 5 ++++- 6 files changed, 72 insertions(+), 31 deletions(-) diff --git a/toxygen/avwidgets.py b/toxygen/avwidgets.py index 511fd8c..a01b52d 100644 --- a/toxygen/avwidgets.py +++ b/toxygen/avwidgets.py @@ -23,7 +23,7 @@ class IncomingCallWidget(widgets.CenteredWidget): self.name = widgets.DataLabel(self) self.name.setGeometry(QtCore.QRect(90, 20, 300, 25)) font = QtGui.QFont() - font.setFamily("Times New Roman") + font.setFamily(settings.Settings.get_instance['font']) font.setPointSize(16) font.setBold(True) self.name.setFont(font) diff --git a/toxygen/list_items.py b/toxygen/list_items.py index 49e9c5a..d0301ca 100644 --- a/toxygen/list_items.py +++ b/toxygen/list_items.py @@ -33,7 +33,7 @@ class MessageEdit(QtGui.QTextBrowser): else: self.setHtml(text) font = QtGui.QFont() - font.setFamily("Times New Roman") + font.setFamily(settings.Settings.get_instance()['font']) font.setPixelSize(settings.Settings.get_instance()['message_font_size']) font.setBold(False) self.setFont(font) @@ -130,7 +130,7 @@ class MessageItem(QtGui.QWidget): self.name.setGeometry(QtCore.QRect(2, 2, 95, 20)) self.name.setTextFormat(QtCore.Qt.PlainText) font = QtGui.QFont() - font.setFamily("Times New Roman") + font.setFamily(settings.Settings.get_instance()['font']) font.setPointSize(11) font.setBold(True) self.name.setFont(font) @@ -138,8 +138,6 @@ class MessageItem(QtGui.QWidget): 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) @@ -207,7 +205,7 @@ class ContactItem(QtGui.QWidget): 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("Times New Roman") + font.setFamily(settings.Settings.get_instance()['font']) font.setPointSize(10 if mode else 12) font.setBold(True) self.name.setFont(font) @@ -264,7 +262,7 @@ class UnreadMessagesCount(QtGui.QWidget): self.label.setGeometry(QtCore.QRect(0, 0, 30, 20)) self.label.setVisible(False) font = QtGui.QFont() - font.setFamily("Times New Roman") + font.setFamily(settings.Settings.get_instance()['font']) font.setPointSize(12) font.setBold(True) self.label.setFont(font) @@ -300,7 +298,7 @@ class FileTransferItem(QtGui.QListWidget): self.name.setGeometry(QtCore.QRect(3, 7, 95, 20)) self.name.setTextFormat(QtCore.Qt.PlainText) font = QtGui.QFont() - font.setFamily("Times New Roman") + font.setFamily(settings.Settings.get_instance()['font']) font.setPointSize(11) font.setBold(True) self.name.setFont(font) diff --git a/toxygen/main.py b/toxygen/main.py index fc988f6..3d4d9be 100644 --- a/toxygen/main.py +++ b/toxygen/main.py @@ -239,11 +239,15 @@ class Toxygen: self.p.show() def tray_activated(reason): - if reason == QtGui.QSystemTrayIcon.DoubleClick: - show_window() + if reason == QtGui.QSystemTrayIcon.DoubleClick: + show_window() + + def close_app(): + settings.closing = True + self.ms.close() m.connect(show, QtCore.SIGNAL("triggered()"), show_window) - m.connect(exit, QtCore.SIGNAL("triggered()"), lambda: app.exit()) + m.connect(exit, QtCore.SIGNAL("triggered()"), close_app) m.connect(m, QtCore.SIGNAL("aboutToShow()"), lambda: m.aboutToShow()) sub.connect(onl, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(0)) sub.connect(away, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(1)) diff --git a/toxygen/mainscreen.py b/toxygen/mainscreen.py index eb04dff..cb7eba2 100644 --- a/toxygen/mainscreen.py +++ b/toxygen/mainscreen.py @@ -6,6 +6,7 @@ from list_items import * from widgets import MultilineEdit, LineEdit import plugin_support from mainscreen_widgets import * +import settings class MainWindow(QtGui.QMainWindow, Singleton): @@ -126,6 +127,7 @@ class MainWindow(QtGui.QMainWindow, Singleton): self.messageEdit.setObjectName("messageEdit") font = QtGui.QFont() font.setPointSize(10) + font.setFamily(settings.Settings.get_instance()['font']) self.messageEdit.setFont(font) self.sendMessageButton = QtGui.QPushButton(Form) @@ -182,7 +184,7 @@ class MainWindow(QtGui.QMainWindow, Singleton): self.name = Form.name = DataLabel(Form) Form.name.setGeometry(QtCore.QRect(75, 40, 150, 25)) font = QtGui.QFont() - font.setFamily("Times New Roman") + font.setFamily(settings.Settings.get_instance()['font']) font.setPointSize(14) font.setBold(True) Form.name.setFont(font) @@ -210,7 +212,7 @@ class MainWindow(QtGui.QMainWindow, Singleton): self.account_name.setGeometry(QtCore.QRect(100, 25, 400, 25)) self.account_name.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse) font = QtGui.QFont() - font.setFamily("Times New Roman") + font.setFamily(settings.Settings.get_instance()['font']) font.setPointSize(14) font.setBold(True) self.account_name.setFont(font) @@ -322,16 +324,21 @@ class MainWindow(QtGui.QMainWindow, Singleton): self.retranslateUi() self.profile = Profile(tox, self) - def closeEvent(self, *args, **kwargs): + def closeEvent(self, event): self.profile.save_history() self.profile.close() s = Settings.get_instance() - s['x'] = self.geometry().x() - s['y'] = self.geometry().y() - s['width'] = self.width() - s['height'] = self.height() - s.save() - QtGui.QApplication.closeAllWindows() + if not s['close_to_tray'] or s.closing: + s['x'] = self.geometry().x() + s['y'] = self.geometry().y() + s['width'] = self.width() + s['height'] = self.height() + s.save() + QtGui.QApplication.closeAllWindows() + event.accept() + else: + event.ignore() + self.hide() def resizeEvent(self, *args, **kwargs): self.messages.setGeometry(0, 0, self.width() - 270, self.height() - 155) diff --git a/toxygen/menu.py b/toxygen/menu.py index 0d83a2e..1a8bc28 100644 --- a/toxygen/menu.py +++ b/toxygen/menu.py @@ -37,6 +37,7 @@ class AddContact(CenteredWidget): self.error_label = DataLabel(self) self.error_label.setGeometry(QtCore.QRect(120, 10, 420, 20)) font = QtGui.QFont() + font.setFamily(Settings.get_instance()['font']) font.setPointSize(10) font.setWeight(30) self.error_label.setFont(font) @@ -51,7 +52,6 @@ class AddContact(CenteredWidget): 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) @@ -102,6 +102,7 @@ class ProfileSettings(CenteredWidget): self.label = QtGui.QLabel(self) self.label.setGeometry(QtCore.QRect(40, 30, 91, 25)) font = QtGui.QFont() + font.setFamily(Settings.get_instance()['font']) font.setPointSize(18) font.setWeight(75) font.setBold(True) @@ -532,11 +533,12 @@ class NotificationsSettings(CenteredWidget): self.soundNotifications = QtGui.QCheckBox(self) self.soundNotifications.setGeometry(QtCore.QRect(10, 70, 340, 18)) font = QtGui.QFont() + s = Settings.get_instance() + font.setFamily(s['font']) font.setPointSize(12) self.callsSound.setFont(font) self.soundNotifications.setFont(font) self.enableNotifications.setFont(font) - s = Settings.get_instance() self.enableNotifications.setChecked(s['notifications']) self.soundNotifications.setChecked(s['sound_notifications']) self.callsSound.setChecked(s['calls_sound']) @@ -566,19 +568,20 @@ class InterfaceSettings(CenteredWidget): def initUI(self): self.setObjectName("interfaceForm") - self.setMinimumSize(QtCore.QSize(400, 580)) - self.setMaximumSize(QtCore.QSize(400, 580)) + self.setMinimumSize(QtCore.QSize(400, 650)) + self.setMaximumSize(QtCore.QSize(400, 650)) self.label = QtGui.QLabel(self) self.label.setGeometry(QtCore.QRect(30, 10, 370, 20)) + settings = Settings.get_instance() font = QtGui.QFont() font.setPointSize(14) font.setBold(True) + font.setFamily(settings['font']) self.label.setFont(font) self.themeSelect = QtGui.QComboBox(self) self.themeSelect.setGeometry(QtCore.QRect(30, 40, 120, 30)) list_of_themes = ['dark'] self.themeSelect.addItems(list_of_themes) - settings = Settings.get_instance() theme = settings['theme'] if theme in list_of_themes: index = list_of_themes.index(theme) @@ -622,23 +625,31 @@ class InterfaceSettings(CenteredWidget): self.messages_font_size.setCurrentIndex(settings['message_font_size'] - 10) self.unread = QtGui.QPushButton(self) - self.unread.setGeometry(QtCore.QRect(30, 465, 340, 30)) + self.unread.setGeometry(QtCore.QRect(30, 470, 340, 30)) self.unread.clicked.connect(self.select_color) self.compact_mode = QtGui.QCheckBox(self) self.compact_mode.setGeometry(QtCore.QRect(30, 380, 370, 20)) self.compact_mode.setChecked(settings['compact_mode']) + self.close_to_tray = QtGui.QCheckBox(self) + self.close_to_tray.setGeometry(QtCore.QRect(30, 410, 370, 20)) + self.close_to_tray.setChecked(settings['close_to_tray']) + self.show_avatars = QtGui.QCheckBox(self) - self.show_avatars.setGeometry(QtCore.QRect(30, 410, 370, 20)) + self.show_avatars.setGeometry(QtCore.QRect(30, 440, 370, 20)) self.show_avatars.setChecked(settings['show_avatars']) + self.choose_font = QtGui.QPushButton(self) + self.choose_font.setGeometry(QtCore.QRect(30, 510, 340, 30)) + self.choose_font.clicked.connect(self.new_font) + self.import_smileys = QtGui.QPushButton(self) - self.import_smileys.setGeometry(QtCore.QRect(30, 505, 340, 30)) + self.import_smileys.setGeometry(QtCore.QRect(30, 550, 340, 30)) self.import_smileys.clicked.connect(self.import_sm) self.import_stickers = QtGui.QPushButton(self) - self.import_stickers.setGeometry(QtCore.QRect(30, 545, 340, 30)) + self.import_stickers.setGeometry(QtCore.QRect(30, 590, 340, 30)) self.import_stickers.clicked.connect(self.import_st) self.retranslateUi() @@ -657,6 +668,8 @@ class InterfaceSettings(CenteredWidget): self.compact_mode.setText(QtGui.QApplication.translate("interfaceForm", "Compact contact list", None, QtGui.QApplication.UnicodeUTF8)) self.import_smileys.setText(QtGui.QApplication.translate("interfaceForm", "Import smiley pack", None, QtGui.QApplication.UnicodeUTF8)) self.import_stickers.setText(QtGui.QApplication.translate("interfaceForm", "Import sticker pack", None, QtGui.QApplication.UnicodeUTF8)) + self.close_to_tray.setText(QtGui.QApplication.translate("interfaceForm", "Close to tray", None, QtGui.QApplication.UnicodeUTF8)) + self.choose_font.setText(QtGui.QApplication.translate("interfaceForm", "Select font", None, QtGui.QApplication.UnicodeUTF8)) def import_st(self): directory = QtGui.QFileDialog.getExistingDirectory(self, @@ -686,6 +699,20 @@ class InterfaceSettings(CenteredWidget): dest = curr_directory() + '/smileys/' + os.path.basename(directory) + '/' copy(src, dest) + def new_font(self): + settings = Settings.get_instance() + font, ok = QtGui.QFontDialog.getFont(QtGui.QFont(settings['font'], 10), self) + if ok: + settings['font'] = font.family() + settings.save() + msgBox = QtGui.QMessageBox() + text = QtGui.QApplication.translate("interfaceForm", 'Restart app to apply settings', None, + QtGui.QApplication.UnicodeUTF8) + msgBox.setWindowTitle(QtGui.QApplication.translate("interfaceForm", 'Restart required', None, + QtGui.QApplication.UnicodeUTF8)) + msgBox.setText(text) + msgBox.exec_() + def select_color(self): col = QtGui.QColorDialog.getColor() @@ -710,6 +737,7 @@ class InterfaceSettings(CenteredWidget): settings['show_avatars'] = self.show_avatars.isChecked() restart = True settings['smiley_pack'] = self.smiley_pack.currentText() + settings['close_to_tray'] = self.close_to_tray.isChecked() smileys.SmileyLoader.get_instance().load_pack() language = self.lang_choose.currentText() if settings['language'] != language: @@ -753,9 +781,11 @@ class AudioSettings(CenteredWidget): self.in_label.setGeometry(QtCore.QRect(25, 5, 350, 20)) self.out_label = QtGui.QLabel(self) self.out_label.setGeometry(QtCore.QRect(25, 65, 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.out_label.setFont(font) self.input = QtGui.QComboBox(self) @@ -763,7 +793,6 @@ class AudioSettings(CenteredWidget): self.output = QtGui.QComboBox(self) self.output.setGeometry(QtCore.QRect(25, 90, 350, 30)) p = pyaudio.PyAudio() - settings = Settings.get_instance() self.in_indexes, self.out_indexes = [], [] for i in range(p.get_device_count()): device = p.get_device_info_by_index(i) diff --git a/toxygen/settings.py b/toxygen/settings.py index cb54947..45da619 100644 --- a/toxygen/settings.py +++ b/toxygen/settings.py @@ -34,6 +34,7 @@ class Settings(dict, Singleton): self.save() smileys.SmileyLoader(self) self.locked = False + self.closing = False p = pyaudio.PyAudio() input_devices = output_devices = 0 for i in range(p.get_device_count()): @@ -134,7 +135,9 @@ class Settings(dict, Singleton): 'unread_color': 'red', 'save_unsent_only': False, 'compact_mode': False, - 'show_welcome_screen': True + 'show_welcome_screen': True, + 'close_to_tray': False, + 'font': 'Times New Roman' } @staticmethod