utils refactoring

This commit is contained in:
ingvar1995 2018-05-10 20:47:34 +03:00
parent ae903cf405
commit 729bd84d2b
39 changed files with 97 additions and 74 deletions

View file

@ -4,7 +4,7 @@ from db.database import History
from toxygen.smileys import SmileyLoader
from messenger.messages import *
import user_data.toxes as encr
import toxygen.util as util
import toxygen.utils as util
import time

View file

@ -2,7 +2,7 @@ from middleware import threads
import middleware.callbacks as callbacks
from PyQt5 import QtWidgets, QtGui, QtCore
import ui.password_screen as password_screen
from util.util import *
from utils.util import *
import updater.updater as updater
import os
from middleware.tox_factory import tox_factory
@ -14,8 +14,8 @@ from user_data.profile_manager import ProfileManager
from plugin_support.plugin_support import PluginLoader
from ui.main_screen import MainWindow
from ui import tray
import util.ui as util_ui
import util.util as util
import utils.ui as util_ui
import utils.util as util
from contacts.profile import Profile
from file_transfers.file_transfers_handler import FileTransfersHandler
from contacts.contact_provider import ContactProvider

View file

@ -1,6 +1,6 @@
import random
import urllib.request
from util.util import *
from utils.util import *
from PyQt5 import QtNetwork, QtCore
import json

View file

@ -6,7 +6,7 @@ class Event:
self._callbacks = set()
def __iadd__(self, callback):
self._callbacks.add(callback)
self.add_callback(callback)
def __isub__(self, callback):
self.remove_callback(callback)

View file

@ -0,0 +1,9 @@
class ToxSave:
def __init__(self, tox):
self._tox = tox
def set_tox(self, tox):
self._tox = tox

View file

@ -1,7 +1,7 @@
from user_data.settings import *
from PyQt5 import QtCore, QtGui
from wrapper.toxcore_enums_and_consts import TOX_PUBLIC_KEY_SIZE
import util.util as util
import utils.util as util
import common.event as event
@ -24,10 +24,11 @@ class BaseContact:
self._name, self._status_message = name, status_message
self._status, self._widget = None, widget
self._tox_id = tox_id
self.init_widget()
self._name_changed_event = event.Event()
self._status_message_changed_event = event.Event()
self._status_changed_event = event.Event()
self._avatar_changed_event = event.Event()
self.init_widget()
# -----------------------------------------------------------------------------------------------------------------
# Name - current name or alias of user
@ -116,6 +117,7 @@ class BaseContact:
self._widget.avatar_label.setPixmap(pixmap.scaled(width, width, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))
self._widget.avatar_label.repaint()
self._avatar_changed_event(avatar_path)
def reset_avatar(self):
avatar_path = self.get_avatar_path()
@ -143,13 +145,18 @@ class BaseContact:
@staticmethod
def get_default_avatar_name():
return 'avatar.png'
def get_avatar_changed_event(self):
return self._avatar_changed_event
avatar_changed_event = property(get_avatar_changed_event)
# -----------------------------------------------------------------------------------------------------------------
# Widgets
# -----------------------------------------------------------------------------------------------------------------
def init_widget(self):
if self._widget is not None:
self._widget.name.setText(self._name)
self._widget.status_message.setText(self._status_message)
self._widget.connection_status.update(self._status)
self.load_avatar()
self._widget.name.setText(self._name)
self._widget.status_message.setText(self._status_message)
self._widget.connection_status.update(self._status)
self.load_avatar()

View file

@ -1,6 +1,6 @@
from history.database import *
from contacts import basecontact, common
import util.util as util
import utils.util as util
from messenger.messages import *
from file_transfers import file_transfers as ft
import re

View file

@ -1,7 +1,8 @@
import util.util as util
import utils.util as util
import common.tox_save as tox_save
class ContactProvider(util.ToxSave):
class ContactProvider(tox_save.ToxSave):
def __init__(self, tox, friend_factory):
super().__init__(tox)
@ -50,7 +51,7 @@ class ContactProvider(util.ToxSave):
# -----------------------------------------------------------------------------------------------------------------
def get_all(self):
return self.get_all_friends() + self.get_all_gc()
return self.get_all_friends() + self.get_all_groups()
# -----------------------------------------------------------------------------------------------------------------
# Caching

View file

@ -1,8 +1,7 @@
import util.util as util
import util.ui as util_ui
import utils.util as util
import utils.ui as util_ui
from contacts.friend import Friend
from PyQt5 import QtCore, QtGui
from messenger.messages import *
from wrapper.toxcore_enums_and_consts import *
from history.history_loader import HistoryLoader
@ -440,9 +439,27 @@ class ContactsManager:
def _subscribe_to_events(self, contact):
contact.name_changed_event.add_callback(self._current_contact_name_changed)
contact.status_changed_event.add_callback(self._current_contact_status_changed)
contact.status_message_changed_event.add_callback(self._current_contact_status_message_changed)
contact.avatar_changed_event.add_callback(self._current_contact_avatar_changed)
def _unsubscribe_from_events(self, contact):
contact.name_changed_event.remove_callback(self._current_contact_name_changed)
contact.status_changed_event.remove_callback(self._current_contact_status_changed)
contact.status_message_changed_event.remove_callback(self._current_contact_status_message_changed)
contact.avatar_changed_event.remove_callback(self._current_contact_avatar_changed)
def _current_contact_name_changed(self, name):
self._screen.account_name.setText(name)
def _current_contact_status_changed(self, status):
pass
def _current_contact_status_message_changed(self, status_message):
self._screen.account_status.setText(status_message)
def _current_contact_avatar_changed(self, avatar_path):
width = self._screen.account_avatar.width()
pixmap = QtGui.QPixmap(avatar_path)
self._screen.account_avatar.avatar_label.setPixmap(pixmap.scaled(width, width, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))

View file

@ -1,5 +1,5 @@
from contacts import contact
import util.util as util
import utils.util as util
from PyQt5 import QtGui, QtCore
from wrapper import toxcore_enums_and_consts as constants

View file

@ -5,7 +5,7 @@ from file_transfers.file_transfers import *
import time
from contacts import basecontact
from contacts.group_chat import *
import util.ui as util_ui
import utils.ui as util_ui
class Profile(basecontact.BaseContact):

View file

@ -3,7 +3,7 @@ from messenger.messages import *
from history.database import MESSAGE_AUTHOR
from ui.list_items import *
from PyQt5 import QtWidgets
import util.util as util
import utils.util as util
class FileTransfersHandler:

View file

@ -1,6 +1,6 @@
from sqlite3 import connect
import os.path
import util.util as util
import utils.util as util
TIMEOUT = 11

View file

@ -1,5 +1,5 @@
from messenger.messages import *
import util.util as util
import utils.util as util
class HistoryLogsGenerator:

View file

@ -1,6 +1,6 @@
import app
from user_data.settings import *
import util.util as util
import utils.util as util
import argparse

View file

@ -1,11 +1,12 @@
import util.util as util
import utils.util as util
import common.tox_save as tox_save
from wrapper.toxcore_enums_and_consts import *
from messenger.messages import *
# TODO: sub profile name changed event?
class Messenger(util.ToxSave):
class Messenger(tox_save.ToxSave):
def __init__(self, tox, plugin_loader, screen, contacts_manager, contacts_provider, items_factory, profile):
super().__init__(tox)

View file

@ -4,8 +4,8 @@ from contacts.profile import Profile
from wrapper.toxcore_enums_and_consts import *
from wrapper.toxav_enums import *
from wrapper.tox import bin_to_string
import util.ui as util_ui
import util.util as util
import utils.ui as util_ui
import utils.util as util
import cv2
import numpy as np
from middleware.threads import invoke_in_main_thread, execute

View file

@ -1,7 +1,7 @@
from bootstrap.bootstrap import *
import threading
import queue
from util import util
from utils import util
import time

View file

@ -1,6 +1,6 @@
import json
import urllib.request
import util.util as util
import utils.util as util
from PyQt5 import QtNetwork, QtCore

View file

@ -1,4 +1,4 @@
import util.util
import utils.util
import wave
import pyaudio
import os.path
@ -51,4 +51,4 @@ def sound_notification(t):
def get_file_path(file_name):
return os.path.join(util.util.get_sounds_directory(), file_name)
return os.path.join(utils.util.get_sounds_directory(), file_name)

View file

@ -1,4 +1,4 @@
import util.util as util
import utils.util as util
from contacts import profile
import os
import importlib

View file

@ -1,4 +1,4 @@
from util import util
from utils import util
import json
import os
from collections import OrderedDict

View file

@ -1,5 +1,5 @@
import os
import util.util as util
import utils.util as util
def load_stickers():

View file

@ -1,11 +1,11 @@
from PyQt5 import QtCore, QtGui, QtWidgets
from ui import widgets
from contacts import profile
import util
import utils
import pyaudio
import wave
from user_data import settings
from util.util import *
from utils.util import *
class IncomingCallWidget(widgets.CenteredWidget):
@ -34,13 +34,13 @@ class IncomingCallWidget(widgets.CenteredWidget):
self.accept_video.setGeometry(QtCore.QRect(170, 100, 150, 150))
self.decline = QtWidgets.QPushButton(self)
self.decline.setGeometry(QtCore.QRect(320, 100, 150, 150))
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/accept_audio.png')
pixmap = QtGui.QPixmap(utils.curr_directory() + '/images/accept_audio.png')
icon = QtGui.QIcon(pixmap)
self.accept_audio.setIcon(icon)
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/accept_video.png')
pixmap = QtGui.QPixmap(utils.curr_directory() + '/images/accept_video.png')
icon = QtGui.QIcon(pixmap)
self.accept_video.setIcon(icon)
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/decline_call.png')
pixmap = QtGui.QPixmap(utils.curr_directory() + '/images/decline_call.png')
icon = QtGui.QIcon(pixmap)
self.decline.setIcon(icon)
self.accept_audio.setIconSize(QtCore.QSize(150, 150))

View file

@ -1,7 +1,7 @@
from ui.widgets import *
from PyQt5 import uic
import util.util as util
import util.ui as util_ui
import utils.util as util
import utils.ui as util_ui
class CreateProfileScreenResult:

View file

@ -2,7 +2,7 @@ from wrapper.toxcore_enums_and_consts import *
from PyQt5 import QtCore, QtGui, QtWidgets
from contacts import profile
from file_transfers.file_transfers import TOX_FILE_TRANSFER_STATE, PAUSED_FILE_TRANSFERS, DO_NOT_SHOW_ACCEPT_BUTTON, ACTIVE_FILE_TRANSFERS, SHOW_PROGRESS_BAR
from util.util import *
from utils.util import *
from ui.widgets import DataLabel, create_menu
import html as h
import smileys

View file

@ -2,8 +2,8 @@ from contacts.profile import *
from ui.list_items import *
from ui.widgets import MultilineEdit, ComboBox
from ui.main_screen_widgets import *
import util.util as util
import util.ui as util_ui
import utils.util as util
import utils.ui as util_ui
class MainWindow(QtWidgets.QMainWindow):

View file

@ -2,8 +2,8 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from ui.widgets import RubberBandWindow, create_menu, QRightClickButton, CenteredWidget, LineEdit
from contacts.profile import Profile
import urllib
import util.util as util
import util.ui as util_ui
import utils.util as util
import utils.ui as util_ui
from stickers.stickers import load_stickers

View file

@ -1,12 +1,12 @@
from PyQt5 import QtCore, QtGui, QtWidgets
from user_data.settings import *
from contacts.profile import Profile
from util.util import *
from utils.util import *
from ui.widgets import CenteredWidget, DataLabel, LineEdit, RubberBandWindow
import pyaudio
from user_data import toxes
import updater.updater as updater
import util.ui as util_ui
import utils.ui as util_ui
class AddContact(CenteredWidget):

View file

@ -1,8 +1,8 @@
from PyQt5 import QtWidgets, QtGui, QtCore
from wrapper.toxcore_enums_and_consts import *
import ui.widgets as widgets
import util.ui as util_ui
import util.util as util
import utils.ui as util_ui
import utils.util as util
import ui.menu as menu
import html as h
import re

View file

@ -1,6 +1,6 @@
from PyQt5 import QtWidgets, QtGui, QtCore
from util.ui import tr
from util.util import *
from utils.ui import tr
from utils.util import *
import os.path

View file

@ -1,5 +1,5 @@
from PyQt5 import QtCore, QtGui, QtWidgets
import util.ui as util_ui
import utils.ui as util_ui
class DataLabel(QtWidgets.QLabel):

View file

@ -1,7 +1,6 @@
import util.util as util
import util.ui as util_ui
import utils.util as util
import utils.ui as util_ui
import os
from user_data import settings
import platform
import urllib
from PyQt5 import QtNetwork, QtCore

View file

@ -1,4 +1,4 @@
import util.util as util
import utils.util as util
import os
from user_data.settings import Settings

View file

@ -1,6 +1,6 @@
import json
import os
from util.util import *
from utils.util import *
import pyaudio
import smileys.smileys as smileys

View file

@ -1,5 +1,5 @@
from PyQt5 import QtWidgets
import util.util as util
import utils.util as util
def tr(s):

View file

@ -156,14 +156,3 @@ def is_re_valid(regex):
def get_platform():
return platform.system()
# TODO: to common
class ToxSave:
def __init__(self, tox):
self._tox = tox
def set_tox(self, tox):
self._tox = tox

View file

@ -1,6 +1,6 @@
from platform import system
from ctypes import CDLL
import util.util as util
import utils.util as util
class LibToxCore: