#!/usr/bin/python3 -u

## Copyright (C) 2015 - 2023 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

import sys
import signal

from PyQt5 import QtGui
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon, QPixmap, QImage

class Frame(QtWidgets.QDialog):
    def __init__(self, parent=None):
        QtWidgets.QDialog.__init__(self, parent)
        self.setWindowTitle('Time Synchronization Monitor')
        self.setMinimumWidth(200)
        self.m_content = QtWidgets.QWidget(self)

        frame_layout = QtWidgets.QGridLayout(self)
        frame_layout.addWidget(self.m_content)

    def widget_content(self):
        return self.m_content

def close_popup():
    popup.close()

if __name__ == '__main__':
    app = QtWidgets.QApplication([]);
    pos_x = int(sys.argv[1])
    pos_y = int(sys.argv[2])
    msg = sys.argv[3]
    icon_type = sys.argv[4]

    popup = Frame()

    icon = QtWidgets.QLabel()
    image = QtGui.QImage(icon_type)
    icon.setAlignment(Qt.AlignLeft)
    icon.setPixmap(QPixmap.fromImage(image))

    text = QtWidgets.QLabel()
    text.setTextInteractionFlags(Qt.LinksAccessibleByMouse |
                                 Qt.TextSelectableByMouse)
    text.setTextFormat(Qt.RichText)
    text.setAlignment(QtCore.Qt.AlignTop)
    text.setText(msg)

    button = QtWidgets.QPushButton('Close')
    button.setMaximumWidth(50)
    button.clicked.connect(close_popup)

    frame_content = QtWidgets.QGridLayout(popup.widget_content())
    frame_content.addWidget(icon, 0, 0 , 1, 1)
    frame_content.addWidget(text, 0, 1, 1, 2)
    frame_content.addWidget(button, 1, 1, 1, 2)

    popup.move(pos_x, pos_y)
    popup.show()

    sys.exit(app.exec_())
