1# -*- coding: utf-8 -*-
2
3# Copyright (c) 2013 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4#
5
6"""
7Module implementing a progress dialog allowing a customized progress bar label.
8"""
9
10from PyQt5.QtCore import Qt
11from PyQt5.QtWidgets import QProgressBar, QProgressDialog
12
13
14class E5ProgressDialog(QProgressDialog):
15    """
16    Class implementing a progress dialog allowing a customized progress bar
17    label.
18    """
19    def __init__(self, labelText, cancelButtonText, minimum, maximum,
20                 labelFormat=None, parent=None, flags=None):
21        """
22        Constructor
23
24        @param labelText text of the dialog label (string)
25        @param cancelButtonText text of the cancel button (string)
26        @param minimum minimum value (integer)
27        @param maximum maximum value (integer)
28        @param labelFormat label format of the progress bar (string)
29        @param parent reference to the parent widget (QWidget)
30        @param flags window flags of the dialog (Qt.WindowFlags)
31        """
32        if flags is None:
33            flags = Qt.WindowFlags()
34        super().__init__(
35            labelText, cancelButtonText, minimum, maximum, parent, flags)
36
37        self.__progressBar = QProgressBar(self)
38        self.__progressBar.setMinimum(minimum)
39        self.__progressBar.setMaximum(maximum)
40        if labelFormat:
41            self.__progressBar.setFormat(labelFormat)
42
43        self.setBar(self.__progressBar)
44
45    def format(self):
46        """
47        Public method to get the progress bar format.
48
49        @return progress bar format (string)
50        """
51        return self.__progressBar.format()
52
53    def setFormat(self, labelFormat):
54        """
55        Public method to set the progress bar format.
56
57        @param labelFormat progress bar format (string)
58        """
59        self.__progressBar.setFormat(labelFormat)
60