images path fixes, all screens loading fixed

This commit is contained in:
ingvar1995 2018-04-30 20:46:44 +03:00
parent 5ebfa702ec
commit c81d9a3696
7 changed files with 79 additions and 73 deletions

View file

@ -156,8 +156,9 @@ class App:
self._contacts_provider = ContactProvider(self._tox, self._friend_factory)
profile = Profile(self._profile_manager, self._tox, self._ms, self._file_transfer_handler)
self._smiley_loader = SmileyLoader(self._settings)
self._plugin_loader = PluginLoader(self._tox, self._toxes, profile, self._settings) # plugins support
widgets_factory = WidgetsFactory(self._settings, profile, self._contacts_manager, self._file_transfer_handler,
self._smiley_loader, self._plugin_loader)
self._smiley_loader, self._plugin_loader, self._toxes)
self._contacts_manager = ContactsManager(self._tox, self._settings, self._ms, self._profile_manager,
self._contacts_provider, db)
self._calls_manager = CallsManager(self._tox.AV, self._settings)
@ -167,10 +168,9 @@ class App:
self._ms.show()
self._tray = tray.init_tray(profile, self._settings, self._ms)
self._ms.set_tray(self._tray)
self._tray.show()
self._plugin_loader = PluginLoader(self._tox, self._toxes, profile, self._settings) # plugins support
# callbacks initialization
callbacks.init_callbacks(self._tox, profile, self._settings, self._plugin_loader, self._contacts_manager,
self._calls_manager, self._file_transfer_handler, self._ms, self._tray)

View file

@ -1,4 +1,3 @@
from ui.menu import *
from contacts.profile import *
from ui.list_items import *
from ui.widgets import MultilineEdit, ComboBox
@ -12,7 +11,7 @@ class MainWindow(QtWidgets.QMainWindow):
def __init__(self, settings, tox, tray):
super().__init__()
self._settings = settings
self.tray = tray
self._tray = tray
self._widget_factory = None
self._modal_window = None
self.setAcceptDrops(True)
@ -23,6 +22,9 @@ class MainWindow(QtWidgets.QMainWindow):
def set_widget_factory(self, widget_factory):
self._widget_factory = widget_factory
def set_tray(self, tray):
self._tray = tray
def show(self):
super().show()
if self._settings['show_welcome_screen']:
@ -112,7 +114,7 @@ class MainWindow(QtWidgets.QMainWindow):
def event(self, event):
if event.type() == QtCore.QEvent.WindowActivate:
self.tray.setIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
self._tray.setIcon(QtGui.QIcon(util.join_path(util.get_images_directory(), 'icon.png')))
self.messages.repaint()
return super().event(event)
@ -168,12 +170,12 @@ class MainWindow(QtWidgets.QMainWindow):
self.menuButton = MenuButton(Form, self.show_menu)
self.menuButton.setGeometry(QtCore.QRect(QtCore.QRect(455, 3, 55, 55)))
pixmap = QtGui.QPixmap('send.png')
pixmap = QtGui.QPixmap(util.join_path(util.get_images_directory(), 'send.png'))
icon = QtGui.QIcon(pixmap)
self.sendMessageButton.setIcon(icon)
self.sendMessageButton.setIconSize(QtCore.QSize(45, 60))
pixmap = QtGui.QPixmap('menu.png')
pixmap = QtGui.QPixmap(util.join_path(util.get_images_directory(), 'menu.png'))
icon = QtGui.QIcon(pixmap)
self.menuButton.setIcon(icon)
self.menuButton.setIconSize(QtCore.QSize(40, 40))
@ -187,7 +189,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.search_label = QtWidgets.QLabel(Form)
self.search_label.setGeometry(QtCore.QRect(3, 2, 20, 20))
pixmap = QtGui.QPixmap()
pixmap.load(curr_directory() + '/images/search.png')
pixmap.load(util.join_path(util.get_images_directory(), 'search.png'))
self.search_label.setScaledContents(False)
self.search_label.setPixmap(pixmap)
@ -267,7 +269,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.typing = QtWidgets.QLabel(Form)
self.typing.setGeometry(QtCore.QRect(500, 25, 50, 30))
pixmap = QtGui.QPixmap(QtCore.QSize(50, 30))
pixmap.load(curr_directory() + '/images/typing.png')
pixmap.load(util.join_path(util.get_images_directory(), 'typing.png'))
self.typing.setScaledContents(False)
self.typing.setPixmap(pixmap.scaled(50, 30, QtCore.Qt.KeepAspectRatio))
self.typing.setVisible(False)

View file

@ -5,6 +5,7 @@ import smileys
import urllib
import util.util as util
import util.ui as util_ui
from stickers.stickers import load_stickers
class MessageArea(QtWidgets.QPlainTextEdit):
@ -206,30 +207,30 @@ class DropdownMenu(QtWidgets.QWidget):
self.stickerButton = QtWidgets.QPushButton(self)
self.stickerButton.setGeometry(QtCore.QRect(60, 0, 60, 60))
pixmap = QtGui.QPixmap(util.get_images_directory() + 'file.png')
pixmap = QtGui.QPixmap(util.join_path(util.get_images_directory(), 'file.png'))
icon = QtGui.QIcon(pixmap)
self.fileTransferButton.setIcon(icon)
self.fileTransferButton.setIconSize(QtCore.QSize(50, 50))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/screenshot.png')
pixmap = QtGui.QPixmap(util.join_path(util.get_images_directory(), 'screenshot.png'))
icon = QtGui.QIcon(pixmap)
self.screenshotButton.setIcon(icon)
self.screenshotButton.setIconSize(QtCore.QSize(50, 60))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/smiley.png')
pixmap = QtGui.QPixmap(util.join_path(util.get_images_directory(), 'smiley.png'))
icon = QtGui.QIcon(pixmap)
self.smileyButton.setIcon(icon)
self.smileyButton.setIconSize(QtCore.QSize(50, 50))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/sticker.png')
pixmap = QtGui.QPixmap(util.join_path(util.get_images_directory(), 'sticker.png'))
icon = QtGui.QIcon(pixmap)
self.stickerButton.setIcon(icon)
self.stickerButton.setIconSize(QtCore.QSize(55, 55))
self.screenshotButton.setToolTip(QtWidgets.QApplication.translate("MenuWindow", "Send screenshot"))
self.fileTransferButton.setToolTip(QtWidgets.QApplication.translate("MenuWindow", "Send file"))
self.smileyButton.setToolTip(QtWidgets.QApplication.translate("MenuWindow", "Add smiley"))
self.stickerButton.setToolTip(QtWidgets.QApplication.translate("MenuWindow", "Send sticker"))
self.screenshotButton.setToolTip(util_ui.tr("Send screenshot"))
self.fileTransferButton.setToolTip(util_ui.tr("Send file"))
self.smileyButton.setToolTip(util_ui.tr("Add smiley"))
self.stickerButton.setToolTip(util_ui.tr("Send sticker"))
self.fileTransferButton.clicked.connect(parent.send_file)
self.screenshotButton.clicked.connect(parent.send_screenshot)
@ -263,15 +264,16 @@ class StickerItem(QtWidgets.QWidget):
class StickerWindow(QtWidgets.QWidget):
"""Sticker selection window"""
def __init__(self, parent):
def __init__(self, parent, file_transfer_handler):
super().__init__()
self._file_transfer_handler = file_transfer_handler
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setMaximumSize(250, 200)
self.setMinimumSize(250, 200)
self.list = QtWidgets.QListWidget(self)
self.list.setGeometry(QtCore.QRect(0, 0, 250, 200))
self.arr = smileys.sticker_loader()
for sticker in self.arr:
self._stickers = load_stickers()
for sticker in self._stickers:
item = StickerItem(sticker)
elem = QtWidgets.QListWidgetItem()
elem.setSizeHint(QtCore.QSize(250, item.height()))
@ -284,7 +286,7 @@ class StickerWindow(QtWidgets.QWidget):
def click(self, index):
num = index.row()
self.parent.profile.send_sticker(self.arr[num])
self._file_transfer_handler.send_sticker(self._stickers[num])
self.close()
def leaveEvent(self, event):
@ -377,7 +379,7 @@ class SearchScreen(QtWidgets.QWidget):
self.search_button = ClickableLabel(self)
self.search_button.setGeometry(width - 160, 0, 40, 40)
pixmap = QtGui.QPixmap()
pixmap.load(util.curr_directory() + '/images/search.png')
pixmap.load(util.join_path(util.get_images_directory(), 'search.png'))
self.search_button.setScaledContents(False)
self.search_button.setAlignment(QtCore.Qt.AlignCenter)
self.search_button.setPixmap(pixmap)

View file

@ -1,7 +1,7 @@
from PyQt5 import QtCore, QtGui, QtWidgets
from user_data.settings import *
from contacts.profile import Profile
from util.util import curr_directory, copy
from util.util import curr_directory, copy, get_stickers_directory, join_path
from ui.widgets import CenteredWidget, DataLabel, LineEdit, RubberBandWindow
import pyaudio
from user_data import toxes
@ -12,8 +12,9 @@ import util.ui as util_ui
class AddContact(CenteredWidget):
"""Add contact form"""
def __init__(self, contacts_manager, tox_id=''):
def __init__(self, settings, contacts_manager, tox_id=''):
super().__init__()
self._settings = settings
self._contacts_manager = contacts_manager
self.initUI(tox_id)
self._adding = False
@ -37,7 +38,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.setFamily(self._settings['font'])
font.setPointSize(10)
font.setWeight(30)
self.error_label.setFont(font)
@ -83,9 +84,11 @@ class AddContact(CenteredWidget):
class ProfileSettings(CenteredWidget):
"""Form with profile settings such as name, status, TOX ID"""
def __init__(self, profile):
def __init__(self, profile, settings, toxes):
super().__init__()
self._profile = profile
self._settings = settings
self._toxes = toxes
self.initUI()
self.center()
@ -104,7 +107,7 @@ class ProfileSettings(CenteredWidget):
self.label = QtWidgets.QLabel(self)
self.label.setGeometry(QtCore.QRect(40, 30, 91, 25))
font = QtGui.QFont()
font.setFamily(Settings.get_instance()['font'])
font.setFamily(self._settings['font'])
font.setPointSize(18)
font.setWeight(75)
font.setBold(True)
@ -119,8 +122,7 @@ class ProfileSettings(CenteredWidget):
self.tox_id.setGeometry(QtCore.QRect(15, 210, 685, 21))
font.setPointSize(10)
self.tox_id.setFont(font)
s = profile.tox_id
self.tox_id.setText(s)
self.tox_id.setText(self._profile.tox_id)
self.copyId = QtWidgets.QPushButton(self)
self.copyId.setGeometry(QtCore.QRect(40, 250, 180, 30))
self.copyId.clicked.connect(self.copy)
@ -163,7 +165,7 @@ class ProfileSettings(CenteredWidget):
self.warning.setStyleSheet('QLabel { color: #BC1C1C; }')
self.default = QtWidgets.QPushButton(self)
self.default.setGeometry(QtCore.QRect(40, 550, 620, 30))
path, name = Settings.get_auto_profile()
auto_profile = Settings.get_auto_profile()
self.auto = path + name == ProfileManager.get_path() + Settings.get_instance().name
self.default.clicked.connect(self.auto_profile)
self.retranslateUi()
@ -214,8 +216,7 @@ class ProfileSettings(CenteredWidget):
def new_password(self):
if self.password.text() == self.confirm_password.text():
if not len(self.password.text()) or len(self.password.text()) >= 8:
e = toxes.ToxES.get_instance()
e.set_password(self.password.text())
self._toxes.set_password(self.password.text())
self.close()
else:
self.not_match.setText(
@ -266,7 +267,7 @@ class ProfileSettings(CenteredWidget):
if directory != '/':
reply = util_ui.question(util_ui.tr('Do you want to move your profile to this location?'),
util_ui.tr('Use new path'))
settings.export(directory)
self._settings.export(directory)
self._profile.export_db(directory)
ProfileManager.get_instance().export_profile(directory, reply)
@ -652,9 +653,8 @@ class InterfaceSettings(CenteredWidget):
def import_st(self):
directory = util_ui.directory_dialog(util_ui.tr('Choose folder with sticker pack'))
if directory:
src = directory + '/'
dest = curr_directory() + '/stickers/' + os.path.basename(directory) + '/'
copy(src, dest)
dest = join_path(get_stickers_directory(), os.path.basename(directory))
copy(directory, dest)
def import_sm(self):
directory = util_ui.directory_dialog(util_ui.tr('Choose folder with smiley pack'))
@ -668,6 +668,7 @@ class InterfaceSettings(CenteredWidget):
if ok:
self._settings['font'] = font.family()
self._settings.save()
util_ui.question()
msgBox = QtWidgets.QMessageBox()
text = util_ui.tr('Restart app to apply settings')
msgBox.setWindowTitle(util_ui.tr('Restart required'))
@ -675,51 +676,49 @@ class InterfaceSettings(CenteredWidget):
msgBox.exec_()
def select_color(self):
settings = Settings.get_instance()
col = QtWidgets.QColorDialog.getColor(QtGui.QColor(settings['unread_color']))
col = QtWidgets.QColorDialog.getColor(QtGui.QColor(self._settings['unread_color']))
if col.isValid():
name = col.name()
settings['unread_color'] = name
settings.save()
self._settings['unread_color'] = name
self._settings.save()
def closeEvent(self, event):
settings = Settings.get_instance()
settings['theme'] = str(self.themeSelect.currentText())
self._settings['theme'] = str(self.themeSelect.currentText())
try:
theme = settings['theme']
theme = self._settings['theme']
app = QtWidgets.QApplication.instance()
with open(curr_directory() + settings.built_in_themes()[theme]) as fl:
with open(curr_directory() + self._settings.built_in_themes()[theme]) as fl:
style = fl.read()
app.setStyleSheet(style)
except IsADirectoryError:
app.setStyleSheet('') # for default style
settings['smileys'] = self.smileys.isChecked()
self._settings['smileys'] = self.smileys.isChecked()
restart = False
if settings['mirror_mode'] != self.mirror_mode.isChecked():
settings['mirror_mode'] = self.mirror_mode.isChecked()
if self._settings['mirror_mode'] != self.mirror_mode.isChecked():
self._settings['mirror_mode'] = self.mirror_mode.isChecked()
restart = True
if settings['compact_mode'] != self.compact_mode.isChecked():
settings['compact_mode'] = self.compact_mode.isChecked()
if self._settings['compact_mode'] != self.compact_mode.isChecked():
self._settings['compact_mode'] = self.compact_mode.isChecked()
restart = True
if settings['show_avatars'] != self.show_avatars.isChecked():
settings['show_avatars'] = self.show_avatars.isChecked()
if self._settings['show_avatars'] != self.show_avatars.isChecked():
self._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()
self._settings['smiley_pack'] = self.smiley_pack.currentText()
self._settings['close_to_tray'] = self.close_to_tray.isChecked()
smileys.SmileyLoader.get_instance().load_pack()
language = self.lang_choose.currentText()
if settings['language'] != language:
settings['language'] = language
if self._settings['language'] != language:
self._settings['language'] = language
text = self.lang_choose.currentText()
path = Settings.supported_languages()[text]
app = QtWidgets.QApplication.instance()
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
self._settings['message_font_size'] = self.messages_font_size.currentIndex() + 10
Profile.get_instance().update()
settings.save()
self._settings.save()
if restart:
util_ui.message_box(util_ui.tr('Restart app to apply settings'), util_ui.tr('Restart required'))

View file

@ -1,4 +1,5 @@
from PyQt5 import QtCore, QtGui, QtWidgets
import util.ui as util_ui
class DataLabel(QtWidgets.QLabel):
@ -22,7 +23,7 @@ class ComboBox(QtWidgets.QComboBox):
class CenteredWidget(QtWidgets.QWidget):
def __init__(self):
super(CenteredWidget, self).__init__()
super().__init__()
self.center()
def center(self):
@ -137,21 +138,21 @@ def create_menu(menu):
text = action.text()
if 'Link Location' in text:
text = text.replace('Copy &Link Location',
QtWidgets.QApplication.translate("MainWindow", "Copy link location"))
util_ui.tr("Copy link location"))
elif '&Copy' in text:
text = text.replace('&Copy', QtWidgets.QApplication.translate("MainWindow", "Copy"))
text = text.replace('&Copy', util_ui.tr("Copy"))
elif 'All' in text:
text = text.replace('Select All', QtWidgets.QApplication.translate("MainWindow", "Select all"))
text = text.replace('Select All', util_ui.tr("Select all"))
elif 'Delete' in text:
text = text.replace('Delete', QtWidgets.QApplication.translate("MainWindow", "Delete"))
text = text.replace('Delete', util_ui.tr("Delete"))
elif '&Paste' in text:
text = text.replace('&Paste', QtWidgets.QApplication.translate("MainWindow", "Paste"))
text = text.replace('&Paste', util_ui.tr("Paste"))
elif 'Cu&t' in text:
text = text.replace('Cu&t', QtWidgets.QApplication.translate("MainWindow", "Cut"))
text = text.replace('Cu&t', util_ui.tr("Cut"))
elif '&Undo' in text:
text = text.replace('&Undo', QtWidgets.QApplication.translate("MainWindow", "Undo"))
text = text.replace('&Undo', util_ui.tr("Undo"))
elif '&Redo' in text:
text = text.replace('&Redo', QtWidgets.QApplication.translate("MainWindow", "Redo"))
text = text.replace('&Redo', util_ui.tr("Redo"))
else:
menu.removeAction(action)
continue
@ -172,7 +173,7 @@ class MultilineEdit(CenteredWidget):
self.edit.setText(text)
self.button = QtWidgets.QPushButton(self)
self.button.setGeometry(QtCore.QRect(0, 150, 350, 50))
self.button.setText(QtWidgets.QApplication.translate("MainWindow", "Save"))
self.button.setText(util_ui.tr("Save"))
self.button.clicked.connect(self.button_click)
self.center()
self.save = save

View file

@ -4,13 +4,15 @@ from ui.menu import *
class WidgetsFactory:
def __init__(self, settings, profile, contacts_manager, file_transfer_handler, smiley_loader, plugin_loader):
def __init__(self, settings, profile, contacts_manager, file_transfer_handler, smiley_loader, plugin_loader,
toxes):
self._settings = settings
self._profile = profile
self._contacts_manager = contacts_manager
self._file_transfer_handler = file_transfer_handler
self._smiley_loader = smiley_loader
self._plugin_loader = plugin_loader
self._toxes = toxes
def create_screenshot_window(self, *args):
return ScreenShotWindow(self._file_transfer_handler, *args)
@ -22,7 +24,7 @@ class WidgetsFactory:
return WelcomeScreen(self._settings)
def create_profile_settings_window(self):
return ProfileSettings(self._profile)
return ProfileSettings(self._profile, self._settings, self._toxes)
def create_network_settings_window(self):
return NetworkSettings(self._settings, self._profile.reset)
@ -40,7 +42,7 @@ class WidgetsFactory:
return PluginsSettings(self._plugin_loader)
def create_add_contact_window(self, tox_id):
return AddContact(self._contacts_manager, tox_id)
return AddContact(self._settings, self._contacts_manager, tox_id)
def create_welcome_window(self):
return WelcomeScreen(self._settings)

View file

@ -1,6 +1,6 @@
import json
import os
from util.util import log, get_base_directory, append_slash, get_platform
from util.util import log, get_base_directory, get_platform, join_path
import pyaudio
import smileys.smileys as smileys
@ -56,7 +56,7 @@ class Settings(dict):
if 'path' in auto and 'name' in auto:
path = str(auto['path'])
name = str(auto['name'])
if os.path.isfile(append_slash(path) + name + '.tox'):
if os.path.isfile(join_path(path, name + '.tox')):
return path, name
return None