# -*- coding: utf-8 -*-
"""
@author: Philipp Temminghoff
"""

from qtpy import QtWidgets, QtCore
import qtawesome as qta


class ProgressDialog(QtWidgets.QProgressDialog):
    """Progress dialog

    wrapper for QtWidgets.QProgressDialog
    """

    def __init__(self, parent=None):
        super().__init__(parent)

        progress_bar = QtWidgets.QProgressBar()
        progress_bar.setRange(0, 0)
        progress_bar.setTextVisible(False)
        self.setBar(progress_bar)

        self.setWindowIcon(qta.icon("mdi.timer-sand-empty", color="lightgray"))
        self.setWindowModality(QtCore.Qt.ApplicationModal)
        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.Window)
        self.set_titlebar_buttons()
        self.setCancelButton(None)
        self.cancel()

    def open(self, message=None):
        if not message:
            message = "Processing..."
        self.setLabelText(message)
        self.show()

    def set_titlebar_buttons(self, minimize=False, maximize=False, close=False):
        self.setWindowFlag(QtCore.Qt.WindowMinimizeButtonHint, minimize)
        self.setWindowFlag(QtCore.Qt.WindowMaximizeButtonHint, maximize)
        self.setWindowFlag(QtCore.Qt.WindowCloseButtonHint, close)
