refactoring - app.py, files moved to different folders
This commit is contained in:
parent
91d3f885c0
commit
8a2665ed4d
26 changed files with 287 additions and 302 deletions
|
@ -6,6 +6,7 @@ import plugin_support
|
|||
from ui.main_screen_widgets import *
|
||||
from user_data import toxes, settings
|
||||
import util.util as util
|
||||
import util.ui as util_ui
|
||||
|
||||
|
||||
class MainWindow(QtWidgets.QMainWindow):
|
||||
|
@ -414,12 +415,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def about_program(self):
|
||||
import util
|
||||
msgBox = QtWidgets.QMessageBox()
|
||||
msgBox.setWindowTitle(QtWidgets.QApplication.translate("MainWindow", "About"))
|
||||
text = (QtWidgets.QApplication.translate("MainWindow", 'Toxygen is Tox client written on Python.\nVersion: '))
|
||||
msgBox.setText(text + util.program_version + '\nGitHub: https://github.com/toxygen-project/toxygen/')
|
||||
msgBox.exec_()
|
||||
text = util_ui.tr('Toxygen is Tox client written on Python.\nVersion: ')
|
||||
text += '' + '\nGitHub: https://github.com/toxygen-project/toxygen/'
|
||||
title = util_ui.tr('About')
|
||||
util_ui.message_box(text, title)
|
||||
|
||||
def network_settings(self):
|
||||
self.n_s = NetworkSettings(self.reset)
|
||||
|
|
|
@ -2,7 +2,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
|||
from ui.widgets import RubberBandWindow, create_menu, QRightClickButton, CenteredWidget, LineEdit
|
||||
from contacts.profile import Profile
|
||||
import smileys
|
||||
import util
|
||||
import util.util as util
|
||||
|
||||
|
||||
class MessageArea(QtWidgets.QPlainTextEdit):
|
||||
|
@ -194,7 +194,7 @@ class DropdownMenu(QtWidgets.QWidget):
|
|||
self.stickerButton = QtWidgets.QPushButton(self)
|
||||
self.stickerButton.setGeometry(QtCore.QRect(60, 0, 60, 60))
|
||||
|
||||
pixmap = QtGui.QPixmap(util.curr_directory() + '/images/file.png')
|
||||
pixmap = QtGui.QPixmap(util.get_images_directory() + 'file.png')
|
||||
icon = QtGui.QIcon(pixmap)
|
||||
self.fileTransferButton.setIcon(icon)
|
||||
self.fileTransferButton.setIconSize(QtCore.QSize(50, 50))
|
||||
|
|
110
toxygen/ui/tray.py
Normal file
110
toxygen/ui/tray.py
Normal file
|
@ -0,0 +1,110 @@
|
|||
from PyQt5 import QtWidgets, QtGui, QtCore
|
||||
from util.ui import tr
|
||||
from util.util import get_images_directory
|
||||
import os.path
|
||||
|
||||
|
||||
class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
|
||||
|
||||
leftClicked = QtCore.pyqtSignal()
|
||||
|
||||
def __init__(self, icon, parent=None):
|
||||
super().__init__(icon, parent)
|
||||
self.activated.connect(self.icon_activated)
|
||||
|
||||
def icon_activated(self, reason):
|
||||
if reason == QtWidgets.QSystemTrayIcon.Trigger:
|
||||
self.leftClicked.emit()
|
||||
|
||||
|
||||
class Menu(QtWidgets.QMenu):
|
||||
|
||||
def __init__(self, settings, profile, *args):
|
||||
super().__init__(*args)
|
||||
self._settings = settings
|
||||
self._profile = profile
|
||||
|
||||
def newStatus(self, status):
|
||||
if not self._settings.locked:
|
||||
self._profile.Profile.get_instance().set_status(status)
|
||||
self.aboutToShowHandler()
|
||||
self.hide()
|
||||
|
||||
def aboutToShowHandler(self):
|
||||
status = self._profile.status
|
||||
act = self.act
|
||||
if status is None or self._ettings.get_instance().locked:
|
||||
self.actions()[1].setVisible(False)
|
||||
else:
|
||||
self.actions()[1].setVisible(True)
|
||||
act.actions()[0].setChecked(False)
|
||||
act.actions()[1].setChecked(False)
|
||||
act.actions()[2].setChecked(False)
|
||||
act.actions()[status].setChecked(True)
|
||||
self.actions()[2].setVisible(not self._settings.locked)
|
||||
|
||||
def languageChange(self, *args, **kwargs):
|
||||
self.actions()[0].setText(tr('Open Toxygen'))
|
||||
self.actions()[1].setText(tr('Set status'))
|
||||
self.actions()[2].setText(tr('Exit'))
|
||||
self.act.actions()[0].setText(tr('Online'))
|
||||
self.act.actions()[1].setText(tr('Away'))
|
||||
self.act.actions()[2].setText(tr('Busy'))
|
||||
|
||||
|
||||
def init_tray(profile, settings, main_screen):
|
||||
icon = os.path.join(get_images_directory(), 'icon.png')
|
||||
tray = SystemTrayIcon(QtGui.QIcon(icon))
|
||||
tray.setObjectName('tray')
|
||||
|
||||
menu = Menu(settings, profile)
|
||||
show = menu.addAction(tr('Open Toxygen'))
|
||||
sub = menu.addMenu(tr('Set status'))
|
||||
online = sub.addAction(tr('Online'))
|
||||
away = sub.addAction(tr('Away'))
|
||||
busy = sub.addAction(tr('Busy'))
|
||||
online.setCheckable(True)
|
||||
away.setCheckable(True)
|
||||
busy.setCheckable(True)
|
||||
menu.act = sub
|
||||
exit = menu.addAction(tr('Exit'))
|
||||
|
||||
def show_window():
|
||||
def show():
|
||||
if not main_screen.isActiveWindow():
|
||||
main_screen.setWindowState(main_screen.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
|
||||
main_screen.activateWindow()
|
||||
main_screen.show()
|
||||
if not settings.locked:
|
||||
show()
|
||||
else:
|
||||
def correct_pass():
|
||||
show()
|
||||
settings.locked = False
|
||||
settings.unlockScreen = False
|
||||
if not settings.unlockScreen:
|
||||
settings.unlockScreen = True
|
||||
self.p = UnlockAppScreen(toxes.ToxES.get_instance(), correct_pass)
|
||||
self.p.show()
|
||||
|
||||
def tray_activated(reason):
|
||||
if reason == QtWidgets.QSystemTrayIcon.DoubleClick:
|
||||
show_window()
|
||||
|
||||
def close_app():
|
||||
if not settings.locked:
|
||||
settings.closing = True
|
||||
main_screen.close()
|
||||
|
||||
show.triggered.connect(show_window)
|
||||
exit.triggered.connect(close_app)
|
||||
menu.aboutToShow.connect(lambda: menu.aboutToShowHandler())
|
||||
online.triggered.connect(lambda: menu.newStatus(0))
|
||||
away.triggered.connect(lambda: menu.newStatus(1))
|
||||
busy.triggered.connect(lambda: menu.newStatus(2))
|
||||
|
||||
tray.setContextMenu(menu)
|
||||
tray.show()
|
||||
tray.activated.connect(tray_activated)
|
||||
|
||||
return tray
|
Loading…
Add table
Add a link
Reference in a new issue